diff options
-rw-r--r-- | xlators/cluster/afr/src/afr-dir-read.c | 25 | ||||
-rw-r--r-- | xlators/cluster/afr/src/afr-open.c | 26 | ||||
-rw-r--r-- | xlators/cluster/afr/src/afr-self-heal-common.c | 132 | ||||
-rw-r--r-- | xlators/cluster/afr/src/afr-self-heal-data.c | 13 | ||||
-rw-r--r-- | xlators/cluster/afr/src/afr-self-heal-entry.c | 11 | ||||
-rw-r--r-- | xlators/cluster/afr/src/afr-self-heal-metadata.c | 12 | ||||
-rw-r--r-- | xlators/cluster/afr/src/afr-self-heal.h | 4 | ||||
-rw-r--r-- | xlators/cluster/afr/src/afr.c | 37 | ||||
-rw-r--r-- | xlators/cluster/afr/src/afr.h | 48 |
9 files changed, 141 insertions, 167 deletions
diff --git a/xlators/cluster/afr/src/afr-dir-read.c b/xlators/cluster/afr/src/afr-dir-read.c index ee80963b7..24227c33b 100644 --- a/xlators/cluster/afr/src/afr-dir-read.c +++ b/xlators/cluster/afr/src/afr-dir-read.c @@ -49,7 +49,7 @@ int -afr_examine_dir_completion_cbk (call_frame_t *frame, xlator_t *this) +afr_examine_dir_sh_unwind (call_frame_t *frame, xlator_t *this) { afr_local_t *local = NULL; afr_self_heal_t *sh = NULL; @@ -98,8 +98,9 @@ afr_examine_dir_readdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, gf_dirent_t *entries) { - afr_private_t * priv = NULL; - afr_local_t * local = NULL; + afr_private_t * priv = NULL; + afr_local_t * local = NULL; + afr_self_heal_t * sh = NULL; gf_dirent_t * entry = NULL; gf_dirent_t * tmp = NULL; @@ -113,6 +114,7 @@ afr_examine_dir_readdir_cbk (call_frame_t *frame, void *cookie, priv = this->private; local = frame->local; + sh = &local->self_heal; child_index = (long) cookie; @@ -151,22 +153,23 @@ out: if (__checksums_differ (local->cont.opendir.checksum, priv->child_count)) { - local->need_entry_self_heal = _gf_true; - local->self_heal.forced_merge = _gf_true; + /* self-heal will call AFR_STACK_DESTROY and + thus unref local->fd, so ref it here */ - local->cont.lookup.buf.st_mode = local->fd->inode->st_mode; + local->fd = fd_ref (local->fd); - local->child_count = afr_up_children_count (priv->child_count, - local->child_up); + sh->need_entry_self_heal = _gf_true; + sh->forced_merge = _gf_true; + sh->mode = local->fd->inode->st_mode; + sh->background = _gf_false; + sh->unwind = afr_examine_dir_sh_unwind; gf_log (this->name, GF_LOG_DEBUG, "checksums of directory %s differ," " triggering forced merge", local->loc.path); - afr_self_heal (frame, this, - afr_examine_dir_completion_cbk, - _gf_true); + afr_self_heal (frame, this); } else { afr_set_opendir_done (this, local->fd->inode); diff --git a/xlators/cluster/afr/src/afr-open.c b/xlators/cluster/afr/src/afr-open.c index 945f5cddf..1918dee81 100644 --- a/xlators/cluster/afr/src/afr-open.c +++ b/xlators/cluster/afr/src/afr-open.c @@ -199,7 +199,7 @@ out: int -afr_up_down_flush_sh_completion_cbk (call_frame_t *frame, xlator_t *this) +afr_up_down_flush_sh_unwind (call_frame_t *frame, xlator_t *this) { afr_local_t *local = NULL; @@ -222,30 +222,18 @@ afr_up_down_flush_post_post_op (call_frame_t *frame, xlator_t *this) local = frame->local; sh = &local->self_heal; - sh->calling_fop = GF_FOP_FLUSH; - -// sh->healing_fd = local->fd; - -// sh->healing_fd_opened = _gf_true; - - local->cont.lookup.inode = local->fd->inode; - inode_path (local->fd->inode, NULL, (char **)&local->loc.path); local->loc.name = strrchr (local->loc.path, '/'); local->loc.inode = inode_ref (local->fd->inode); local->loc.parent = inode_parent (local->fd->inode, 0, NULL); - sh->data_lock_held = _gf_true; - - local->need_data_self_heal = _gf_true; - local->cont.lookup.buf.st_mode = local->fd->inode->st_mode; - local->child_count = afr_up_children_count (priv->child_count, - local->child_up); - - sh->flush_self_heal_cbk = afr_up_down_flush_sh_completion_cbk; + sh->data_lock_held = _gf_true; + sh->need_data_self_heal = _gf_true; + sh->mode = local->fd->inode->st_mode; + sh->background = _gf_false; + sh->unwind = afr_up_down_flush_sh_unwind; - afr_self_heal (frame, this, afr_up_down_flush_sh_completion_cbk, - _gf_false); + afr_self_heal (frame, this); return 0; } diff --git a/xlators/cluster/afr/src/afr-self-heal-common.c b/xlators/cluster/afr/src/afr-self-heal-common.c index 0b4f22b01..ab28aa681 100644 --- a/xlators/cluster/afr/src/afr-self-heal-common.c +++ b/xlators/cluster/afr/src/afr-self-heal-common.c @@ -1239,8 +1239,10 @@ sh_missing_entries_lookup (call_frame_t *frame, xlator_t *this) int ret = -1; local = frame->local; - call_count = local->child_count; - priv = this->private; + priv = this->private; + + call_count = afr_up_children_count (priv->child_count, + local->child_up); local->call_count = call_count; @@ -1346,7 +1348,8 @@ afr_self_heal_missing_entries (call_frame_t *frame, xlator_t *this) afr_build_parent_loc (&sh->parent_loc, &local->loc); - call_count = local->child_count; + call_count = afr_up_children_count (priv->child_count, + local->child_up); local->call_count = call_count; @@ -1395,11 +1398,11 @@ afr_local_t *afr_local_copy (afr_local_t *l, xlator_t *this) int -afr_bgsh_completion_cbk (call_frame_t *bgsh_frame, xlator_t *this) +afr_self_heal_completion_cbk (call_frame_t *bgsh_frame, xlator_t *this) { - afr_private_t *priv = NULL; - afr_local_t *local = NULL; - afr_self_heal_t *sh = NULL; + afr_private_t * priv = NULL; + afr_local_t * local = NULL; + afr_self_heal_t * sh = NULL; priv = this->private; local = bgsh_frame->local; @@ -1413,73 +1416,38 @@ afr_bgsh_completion_cbk (call_frame_t *bgsh_frame, xlator_t *this) "background self-heal completed"); if (!sh->unwound) { - if (sh->calling_fop == GF_FOP_LOOKUP) { - AFR_STACK_UNWIND (lookup, sh->orig_frame, - local->op_ret, local->op_errno, - local->cont.lookup.inode, - &local->cont.lookup.buf, - local->cont.lookup.xattr, - &local->cont.lookup.postparent); - } else { - sh->flush_self_heal_cbk (sh->orig_frame, this); - } + sh->unwind (sh->orig_frame, this); } - LOCK (&priv->lock); - { - priv->background_self_heals_started--; + if (sh->background) { + LOCK (&priv->lock); + { + priv->background_self_heals_started--; + } + UNLOCK (&priv->lock); } - UNLOCK (&priv->lock); - - AFR_STACK_DESTROY (bgsh_frame); - - return 0; -} - - -int -afr_bgsh_unwind (call_frame_t *bgsh_frame, xlator_t *this) -{ - afr_local_t *local = NULL; - afr_self_heal_t *sh = NULL; - - local = bgsh_frame->local; - sh = &local->self_heal; - if (local->govinda_gOvinda) { - afr_set_split_brain (this, local->cont.lookup.inode); - } - - gf_log (this->name, GF_LOG_TRACE, - "unwinding lookup and continuing self-heal in the background"); + /* + * XXX Hack: Due to memcpy'ing of local, some pointers will + * also have ended up in bgsh_frame's local. We shouldn't free + * them. So set them to NULL here. + */ - sh->unwound = _gf_true; + local->cont.writev.vector = NULL; - if (sh->calling_fop == GF_FOP_LOOKUP) { - AFR_STACK_UNWIND (lookup, sh->orig_frame, - local->op_ret, local->op_errno, - local->cont.lookup.inode, - &local->cont.lookup.buf, - local->cont.lookup.xattr, - &local->cont.lookup.postparent); - } else { - sh->flush_self_heal_cbk (sh->orig_frame, this); - } + AFR_STACK_DESTROY (bgsh_frame); return 0; } int -afr_self_heal (call_frame_t *frame, xlator_t *this, - int (*completion_cbk) (call_frame_t *, xlator_t *), - int bgsh) +afr_self_heal (call_frame_t *frame, xlator_t *this) { afr_local_t *local = NULL; afr_self_heal_t *sh = NULL; afr_private_t *priv = NULL; int i = 0; - int background = 0; call_frame_t *sh_frame = NULL; afr_local_t *sh_local = NULL; @@ -1487,48 +1455,44 @@ afr_self_heal (call_frame_t *frame, xlator_t *this, local = frame->local; priv = this->private; - LOCK (&priv->lock); - { - if (priv->background_self_heals_started < priv->background_self_heal_count) { - priv->background_self_heals_started++; - background = 1; + if (local->self_heal.background) { + LOCK (&priv->lock); + { + if (priv->background_self_heals_started + > priv->background_self_heal_count) { + + local->self_heal.background = _gf_false; + + } else { + priv->background_self_heals_started++; + } } + UNLOCK (&priv->lock); } - UNLOCK (&priv->lock); gf_log (this->name, GF_LOG_TRACE, "performing self heal on %s (metadata=%d data=%d entry=%d)", local->loc.path, - local->need_metadata_self_heal, - local->need_data_self_heal, - local->need_entry_self_heal); + local->self_heal.need_metadata_self_heal, + local->self_heal.need_data_self_heal, + local->self_heal.need_entry_self_heal); sh_frame = copy_frame (frame); sh_local = afr_local_copy (local, this); sh_frame->local = sh_local; sh = &sh_local->self_heal; - sh->orig_frame = frame; - - if (bgsh) - sh->background = _gf_true; - else - sh->background = _gf_false; + sh->orig_frame = frame; - if (completion_cbk == NULL) { - sh->completion_cbk = afr_bgsh_completion_cbk; - } else { - sh->completion_cbk = completion_cbk; - } + sh->completion_cbk = afr_self_heal_completion_cbk; - sh->unwind = afr_bgsh_unwind; - sh->buf = CALLOC (priv->child_count, sizeof (struct stat)); - sh->child_errno = CALLOC (priv->child_count, sizeof (int)); - sh->success = CALLOC (priv->child_count, sizeof (int)); - sh->xattr = CALLOC (priv->child_count, sizeof (dict_t *)); - sh->sources = CALLOC (sizeof (*sh->sources), priv->child_count); - sh->locked_nodes = CALLOC (sizeof (*sh->locked_nodes), priv->child_count); + sh->buf = CALLOC (priv->child_count, sizeof (struct stat)); + sh->child_errno = CALLOC (priv->child_count, sizeof (int)); + sh->success = CALLOC (priv->child_count, sizeof (int)); + sh->xattr = CALLOC (priv->child_count, sizeof (dict_t *)); + sh->sources = CALLOC (priv->child_count, sizeof (*sh->sources)); + sh->locked_nodes = CALLOC (priv->child_count, sizeof (*sh->locked_nodes)); sh->pending_matrix = CALLOC (sizeof (int32_t *), priv->child_count); for (i = 0; i < priv->child_count; i++) { diff --git a/xlators/cluster/afr/src/afr-self-heal-data.c b/xlators/cluster/afr/src/afr-self-heal-data.c index e8384ec30..7662c1178 100644 --- a/xlators/cluster/afr/src/afr-self-heal-data.c +++ b/xlators/cluster/afr/src/afr-self-heal-data.c @@ -80,7 +80,7 @@ afr_sh_data_done (call_frame_t *frame, xlator_t *this) "self heal of %s completed", local->loc.path); - sh->completion_cbk (sh->orig_frame, this); + sh->completion_cbk (frame, this); return 0; } @@ -728,7 +728,8 @@ afr_sh_data_fix (call_frame_t *frame, xlator_t *this) afr_set_read_child (this, local->loc.inode, sh->source); if (sh->background) { - sh->unwind (frame, this); + sh->unwind (sh->orig_frame, this); + sh->unwound = _gf_true; } afr_sh_data_sync_prepare (frame, this); @@ -790,7 +791,8 @@ afr_sh_data_fstat (call_frame_t *frame, xlator_t *this) local = frame->local; sh = &local->self_heal; - call_count = local->child_count; + call_count = afr_up_children_count (priv->child_count, + local->child_up); local->call_count = call_count; @@ -868,7 +870,8 @@ afr_sh_data_fxattrop (call_frame_t *frame, xlator_t *this) local = frame->local; sh = &local->self_heal; - call_count = local->child_count; + call_count = afr_up_children_count (priv->child_count, + local->child_up); local->call_count = call_count; @@ -1142,7 +1145,7 @@ afr_self_heal_data (call_frame_t *frame, xlator_t *this) local = frame->local; sh = &local->self_heal; - if (local->need_data_self_heal && priv->data_self_heal) { + if (sh->need_data_self_heal && priv->data_self_heal) { afr_sh_data_open (frame, this); } else { gf_log (this->name, GF_LOG_TRACE, diff --git a/xlators/cluster/afr/src/afr-self-heal-entry.c b/xlators/cluster/afr/src/afr-self-heal-entry.c index 5c47d887e..50d11cc18 100644 --- a/xlators/cluster/afr/src/afr-self-heal-entry.c +++ b/xlators/cluster/afr/src/afr-self-heal-entry.c @@ -2347,7 +2347,8 @@ afr_sh_entry_fix (call_frame_t *frame, xlator_t *this) sh->source = source; if (sh->background) { - sh->unwind (frame, this); + sh->unwind (sh->orig_frame, this); + sh->unwound = _gf_true; } heal: @@ -2410,7 +2411,8 @@ afr_sh_entry_lookup (call_frame_t *frame, xlator_t *this) local = frame->local; sh = &local->self_heal; - call_count = local->child_count; + call_count = afr_up_children_count (priv->child_count, + local->child_up); local->call_count = call_count; @@ -2507,7 +2509,8 @@ afr_sh_entry_lock (call_frame_t *frame, xlator_t *this) sh = &local->self_heal; priv = this->private; - call_count = local->child_count; + call_count = afr_up_children_count (priv->child_count, + local->child_up); local->call_count = call_count; @@ -2545,7 +2548,7 @@ afr_self_heal_entry (call_frame_t *frame, xlator_t *this) local = frame->local; sh = &local->self_heal; - if (local->need_entry_self_heal && priv->entry_self_heal) { + if (local->self_heal.need_entry_self_heal && priv->entry_self_heal) { afr_sh_entry_lock (frame, this); } else { gf_log (this->name, GF_LOG_TRACE, diff --git a/xlators/cluster/afr/src/afr-self-heal-metadata.c b/xlators/cluster/afr/src/afr-self-heal-metadata.c index 9842902e6..bddccf682 100644 --- a/xlators/cluster/afr/src/afr-self-heal-metadata.c +++ b/xlators/cluster/afr/src/afr-self-heal-metadata.c @@ -81,7 +81,7 @@ afr_sh_metadata_done (call_frame_t *frame, xlator_t *this) local->loc.path); sh->completion_cbk (frame, this); } else { - if (S_ISREG (local->cont.lookup.buf.st_mode)) { + if (S_ISREG (sh->mode)) { gf_log (this->name, GF_LOG_TRACE, "proceeding to data check on %s", local->loc.path); @@ -89,7 +89,7 @@ afr_sh_metadata_done (call_frame_t *frame, xlator_t *this) return 0; } - if (S_ISDIR (local->cont.lookup.buf.st_mode)) { + if (S_ISDIR (sh->mode)) { gf_log (this->name, GF_LOG_TRACE, "proceeding to entry check on %s", local->loc.path); @@ -668,7 +668,8 @@ afr_sh_metadata_lookup (call_frame_t *frame, xlator_t *this) sh = &local->self_heal; priv = this->private; - call_count = local->child_count; + call_count = afr_up_children_count (priv->child_count, + local->child_up); local->call_count = call_count; xattr_req = dict_new(); @@ -769,7 +770,8 @@ afr_sh_metadata_lock (call_frame_t *frame, xlator_t *this) sh = &local->self_heal; priv = this->private; - call_count = local->child_count; + call_count = afr_up_children_count (priv->child_count, + local->child_up); local->call_count = call_count; for (i = 0; i < priv->child_count; i++) { @@ -809,7 +811,7 @@ afr_self_heal_metadata (call_frame_t *frame, xlator_t *this) local = frame->local; sh = &local->self_heal; - if (local->need_metadata_self_heal && priv->metadata_self_heal) { + if (local->self_heal.need_metadata_self_heal && priv->metadata_self_heal) { afr_sh_metadata_lock (frame, this); } else { afr_sh_metadata_done (frame, this); diff --git a/xlators/cluster/afr/src/afr-self-heal.h b/xlators/cluster/afr/src/afr-self-heal.h index 84a1380b7..3c8b1333e 100644 --- a/xlators/cluster/afr/src/afr-self-heal.h +++ b/xlators/cluster/afr/src/afr-self-heal.h @@ -46,8 +46,6 @@ int afr_self_heal_metadata (call_frame_t *frame, xlator_t *this); int -afr_self_heal (call_frame_t *frame, xlator_t *this, - int (*completion_cbk) (call_frame_t *, xlator_t *), - int bgsh); +afr_self_heal (call_frame_t *frame, xlator_t *this); #endif /* __AFR_SELF_HEAL_H__ */ diff --git a/xlators/cluster/afr/src/afr.c b/xlators/cluster/afr/src/afr.c index 467b8112d..994588c87 100644 --- a/xlators/cluster/afr/src/afr.c +++ b/xlators/cluster/afr/src/afr.c @@ -467,7 +467,7 @@ afr_deitransform (ino64_t ino, int child_count) int -afr_self_heal_cbk (call_frame_t *frame, xlator_t *this) +afr_self_heal_lookup_unwind (call_frame_t *frame, xlator_t *this) { afr_local_t *local = NULL; @@ -532,13 +532,13 @@ afr_lookup_cbk (call_frame_t *frame, void *cookie, } if (afr_sh_has_metadata_pending (xattr, child_index, this)) - local->need_metadata_self_heal = 1; + local->self_heal.need_metadata_self_heal = _gf_true; if (afr_sh_has_entry_pending (xattr, child_index, this)) - local->need_entry_self_heal = 1; + local->self_heal.need_entry_self_heal = _gf_true; if (afr_sh_has_data_pending (xattr, child_index, this)) - local->need_data_self_heal = 1; + local->self_heal.need_data_self_heal = _gf_true; ret = dict_get_uint32 (xattr, GLUSTERFS_OPEN_FD_COUNT, &open_fd_count); @@ -603,17 +603,17 @@ afr_lookup_cbk (call_frame_t *frame, void *cookie, if (PERMISSION_DIFFERS (buf, lookup_buf)) { /* mismatching permissions */ - local->need_metadata_self_heal = 1; + local->self_heal.need_metadata_self_heal = _gf_true; } if (OWNERSHIP_DIFFERS (buf, lookup_buf)) { /* mismatching permissions */ - local->need_metadata_self_heal = 1; + local->self_heal.need_metadata_self_heal = _gf_true; } if (SIZE_DIFFERS (buf, lookup_buf) && S_ISREG (buf->st_mode)) { - local->need_data_self_heal = 1; + local->self_heal.need_data_self_heal = _gf_true; } if (child_index == local->read_child_index) { @@ -667,21 +667,21 @@ unlock: } if (local->success_count && local->enoent_count) { - local->need_metadata_self_heal = 1; - local->need_data_self_heal = 1; - local->need_entry_self_heal = 1; + local->self_heal.need_metadata_self_heal = _gf_true; + local->self_heal.need_data_self_heal = _gf_true; + local->self_heal.need_entry_self_heal = _gf_true; } if (local->success_count) { /* check for split-brain case in previous lookup */ if (afr_is_split_brain (this, local->cont.lookup.inode)) - local->need_data_self_heal = 1; + local->self_heal.need_data_self_heal = _gf_true; } - if ((local->need_metadata_self_heal - || local->need_data_self_heal - || local->need_entry_self_heal) + if ((local->self_heal.need_metadata_self_heal + || local->self_heal.need_data_self_heal + || local->self_heal.need_entry_self_heal) && (!local->open_fd_count && !local->inodelk_count && !local->entrylk_count) @@ -694,9 +694,11 @@ unlock: lookup_buf->st_mode; } - local->self_heal.calling_fop = GF_FOP_LOOKUP; + local->self_heal.background = _gf_true; + local->self_heal.mode = local->cont.lookup.buf.st_mode; + local->self_heal.unwind = afr_self_heal_lookup_unwind; - afr_self_heal (frame, this, NULL, _gf_true); + afr_self_heal (frame, this); } else { AFR_STACK_UNWIND (lookup, frame, local->op_ret, @@ -765,9 +767,6 @@ afr_lookup (call_frame_t *frame, xlator_t *this, local->child_up); call_count = local->call_count; - local->child_count = afr_up_children_count (priv->child_count, - local->child_up); - if (local->call_count == 0) { ret = -1; op_errno = ENOTCONN; diff --git a/xlators/cluster/afr/src/afr.h b/xlators/cluster/afr/src/afr.h index 56f7a069d..4de1f2820 100644 --- a/xlators/cluster/afr/src/afr.h +++ b/xlators/cluster/afr/src/afr.h @@ -75,11 +75,37 @@ typedef struct _afr_private { } afr_private_t; typedef struct { - /* Is this a self-heal triggered to forcibly merge the - directories? */ - gf_boolean_t forced_merge; + /* External interface: These are variables (some optional) that + are set by whoever has triggered self-heal */ + + gf_boolean_t need_data_self_heal; + gf_boolean_t need_metadata_self_heal; + gf_boolean_t need_entry_self_heal; + + gf_boolean_t forced_merge; /* Is this a self-heal triggered to + forcibly merge the directories? */ + + gf_boolean_t healing_fd_opened; /* true if caller has already + opened fd */ + + gf_boolean_t data_lock_held; /* true if caller has already + acquired 0-0 lock */ + + fd_t *healing_fd; /* set if callers has opened fd */ + + gf_boolean_t background; /* do self-heal in background + if possible */ + + mode_t mode; /* st_mode of the entry we're doing + self-heal on */ + + /* Function to call to unwind. If self-heal is being done in the + background, this function will be called as soon as possible. */ + + int (*unwind) (call_frame_t *frame, xlator_t *this); + + /* End of external interface members */ - glusterfs_fop_t calling_fop; /* array of stat's, one for each child */ struct stat *buf; @@ -105,7 +131,6 @@ typedef struct { mode_t impunging_entry_mode; const char *linkname; - fd_t *healing_fd; int op_failed; int file_has_holes; @@ -117,23 +142,16 @@ typedef struct { call_frame_t *orig_frame; gf_boolean_t unwound; - gf_boolean_t background; /* is this self-heal in the background? */ - int (*unwind) (call_frame_t *frame, xlator_t *this); /* private data for the particular self-heal algorithm */ void *private; - gf_boolean_t healing_fd_opened; /* set by caller: true if caller - has already opened fd */ - - gf_boolean_t data_lock_held; /* set by caller: true if caller - has already acquired 0-0 lock */ - int (*flush_self_heal_cbk) (call_frame_t *frame, xlator_t *this); int (*completion_cbk) (call_frame_t *frame, xlator_t *this); int (*algo_completion_cbk) (call_frame_t *frame, xlator_t *this); int (*algo_abort_cbk) (call_frame_t *frame, xlator_t *this); + call_frame_t *sh_frame; } afr_self_heal_t; @@ -186,9 +204,6 @@ typedef struct _afr_local { unsigned int success_count; unsigned int enoent_count; - unsigned int need_metadata_self_heal; - unsigned int need_entry_self_heal; - unsigned int need_data_self_heal; unsigned int govinda_gOvinda; unsigned int read_child_index; @@ -210,7 +225,6 @@ typedef struct _afr_local { glusterfs_fop_t fop; unsigned char *child_up; - int child_count; int32_t *child_errno; |