From 7927e8747c731dbb105e93ae66c336338f48f0e6 Mon Sep 17 00:00:00 2001 From: Venky Shankar Date: Sun, 15 Feb 2015 15:05:19 +0530 Subject: features/bit-rot: Implementation of bit-rot xlator This is the "Signer" -- responsible for signing files with their checksums upon last file descriptor close (last release()). The event notification facility provided by the changelog xlator is made use of. Moreover, checksums are as of now SHA256 hash of the object data and is the only available hash at this point of time. Therefore, there is no special "what hash to use" type check, although it's does not take much to add various hashing algorithms to sign objects with. Signatures are stored in extended attributes of the objects along with the the type of hashing used to calculate the signature. This makes thing future proof when other hash types are added. The signature infrastructure is provided by bitrot stub: a little piece of code that sits over the POSIX xlator providing interfaces to "get or set" objects signature and it's staleness. Since objects are signed upon receiving release() notification, pre-existing data which are "never" modified would never be signed. To counter this, an initial crawler thread is spawned The crawler scans the entire brick for objects that are unsigned or "missed" signing due to the server going offline (node reboots, crashes, etc..) and triggers an explicit sign. This would also sign objects when bit-rot is enabled for a volume and/or after upgrade. Change-Id: I1d9a98bee6cad1c39c35c53c8fb0fc4bad2bf67b BUG: 1170075 Original-Author: Raghavendra Bhat Signed-off-by: Venky Shankar Reviewed-on: http://review.gluster.org/9711 Tested-by: Gluster Build System Reviewed-by: Vijay Bellur --- libglusterfs/src/Makefile.am | 3 ++ libglusterfs/src/changelog.h | 116 ++++++++++++++++++++++++++++++++++++++++ libglusterfs/src/common-utils.c | 23 ++++++++ libglusterfs/src/common-utils.h | 4 ++ libglusterfs/src/dict.c | 19 +++++++ libglusterfs/src/dict.h | 4 ++ libglusterfs/src/mem-types.h | 2 + libglusterfs/src/syncop-utils.c | 86 +++++++++++++++++++++++++++++ libglusterfs/src/syncop-utils.h | 6 +++ libglusterfs/src/xlator.c | 10 ++++ libglusterfs/src/xlator.h | 3 ++ 11 files changed, 276 insertions(+) create mode 100644 libglusterfs/src/changelog.h (limited to 'libglusterfs/src') diff --git a/libglusterfs/src/Makefile.am b/libglusterfs/src/Makefile.am index 818de91cf36..33de0a287c7 100644 --- a/libglusterfs/src/Makefile.am +++ b/libglusterfs/src/Makefile.am @@ -11,6 +11,7 @@ libglusterfs_la_LIBADD = @LEXLIB@ $(ZLIB_LIBS) $(MATH_LIB) libglusterfs_la_LDFLAGS = -version-info $(LIBGLUSTERFS_LT_VERSION) lib_LTLIBRARIES = libglusterfs.la +libgfchangelogdir = $(includedir)/glusterfs/gfchangelog CONTRIB_BUILDDIR = $(top_builddir)/contrib @@ -53,6 +54,8 @@ noinst_HEADERS = common-utils.h defaults.h dict.h glusterfs.h hashfn.h timespec. unittest/unittest.h quota-common-utils.h rot-buffs.h \ $(CONTRIBDIR)/timer-wheel/timer-wheel.h +libgfchangelog_HEADERS = changelog.h + EXTRA_DIST = graph.l graph.y graph.lex.c: graph.l y.tab.h diff --git a/libglusterfs/src/changelog.h b/libglusterfs/src/changelog.h new file mode 100644 index 00000000000..08307810704 --- /dev/null +++ b/libglusterfs/src/changelog.h @@ -0,0 +1,116 @@ +/* + Copyright (c) 2013 Red Hat, Inc. + This file is part of GlusterFS. + + This file is licensed to you under your choice of the GNU Lesser + General Public License, version 3 or any later version (LGPLv3 or + later), or the GNU General Public License, version 2 (GPLv2), in all + cases as published by the Free Software Foundation. +*/ + +#ifndef _GF_CHANGELOG_H +#define _GF_CHANGELOG_H + +struct gf_brick_spec; + +/** + * Max bit shiter for event selection + */ +#define CHANGELOG_EV_SELECTION_RANGE 5 + +#define CHANGELOG_OP_TYPE_JOURNAL (1<<0) +#define CHANGELOG_OP_TYPE_OPEN (1<<1) +#define CHANGELOG_OP_TYPE_CREATE (1<<2) +#define CHANGELOG_OP_TYPE_RELEASE (1<<3) +#define CHANGELOG_OP_TYPE_BR_RELEASE (1<<4) /* logical release (last close()), + sent by bitrot stub */ +#define CHANGELOG_OP_TYPE_MAX (1< 0) { + /* If the entries are only '.', and '..' then ret + * value will be non-zero. so set it to zero here. */ + ret = 0; + } + + tmp = 0; + + list_for_each_entry (entry, &entries.list, list) { + offset = entry->d_off; + + if (!strcmp (entry->d_name, ".") || + !strcmp (entry->d_name, "..")) + continue; + + if (++tmp >= count) + sleep (sleep_time); + + gf_link_inode_from_dirent (NULL, fd->inode, entry); + + ret = fn (subvol, entry, loc, data); + if (ret) + continue; + + if (entry->d_stat.ia_type == IA_IFDIR) { + child_loc.inode = inode_ref (entry->inode); + uuid_copy (child_loc.gfid, entry->inode->gfid); + ret = syncop_ftw_throttle (subvol, &child_loc, + pid, data, fn, count, + sleep_time); + loc_wipe (&child_loc); + if (ret) + continue; + } + } + + gf_dirent_free (&entries); + if (ret) + break; + } + +out: + if (fd) + fd_unref (fd); + return ret; +} + int syncop_dir_scan (xlator_t *subvol, loc_t *loc, int pid, void *data, int (*fn) (xlator_t *subvol, gf_dirent_t *entry, loc_t *parent, diff --git a/libglusterfs/src/syncop-utils.h b/libglusterfs/src/syncop-utils.h index 918b3b7c666..7a9ccacb285 100644 --- a/libglusterfs/src/syncop-utils.h +++ b/libglusterfs/src/syncop-utils.h @@ -30,4 +30,10 @@ syncop_is_subvol_local (xlator_t *this, loc_t *loc, gf_boolean_t *is_local); int syncop_gfid_to_path (inode_table_t *itable, xlator_t *subvol, uuid_t gfid, char **path_p); + +int +syncop_ftw_throttle (xlator_t *subvol, loc_t *loc, int pid, void *data, + int (*fn) (xlator_t *subvol, gf_dirent_t *entry, + loc_t *parent, void *data), + int count, int sleep_time); #endif /* _SYNCOP_H */ diff --git a/libglusterfs/src/xlator.c b/libglusterfs/src/xlator.c index cc4726e0ea5..00f411e275b 100644 --- a/libglusterfs/src/xlator.c +++ b/libglusterfs/src/xlator.c @@ -1024,3 +1024,13 @@ glusterd_check_log_level (const char *value) return log_level; } +int +xlator_subvolume_count (xlator_t *this) +{ + int i = 0; + xlator_list_t *list = NULL; + + for (list = this->children; list; list = list->next) + i++; + return i; +} diff --git a/libglusterfs/src/xlator.h b/libglusterfs/src/xlator.h index 5a0b114d6a8..9bea950d720 100644 --- a/libglusterfs/src/xlator.h +++ b/libglusterfs/src/xlator.h @@ -989,4 +989,7 @@ glusterfs_leaf_position(xlator_t *tgt); int glusterfs_reachable_leaves(xlator_t *base, dict_t *leaves); +int +xlator_subvolume_count (xlator_t *this); + #endif /* _XLATOR_H */ -- cgit