cb8e9e
From ec6028d919a974dcbe9d8428a09fc9de85a5fafd Mon Sep 17 00:00:00 2001
cb8e9e
From: Anuradha Talur <atalur@redhat.com>
cb8e9e
Date: Fri, 11 Sep 2015 18:43:36 +0530
cb8e9e
Subject: [PATCH 329/330] afr : get split-brain-status in a synctask
cb8e9e
cb8e9e
On executing `getfattr -n replica.split-brain-status <file>` on mount,
cb8e9e
there is a possibility that the mount hangs. To avoid this hang,
cb8e9e
fetch the split-brain-status of a file in synctask.
cb8e9e
cb8e9e
Upstream master patch : review.gluster.org/12163
cb8e9e
Upstream 3.7 patch    : review.gluster.org/12166
cb8e9e
cb8e9e
Change-Id: I87b781419ffc63248f915325b845e3233143d385
cb8e9e
BUG: 1262291
cb8e9e
Signed-off-by: Anuradha Talur <atalur@redhat.com>
cb8e9e
Reviewed-on: https://code.engineering.redhat.com/gerrit/57674
cb8e9e
Reviewed-by: Pranith Kumar Karampuri <pkarampu@redhat.com>
cb8e9e
Tested-by: Pranith Kumar Karampuri <pkarampu@redhat.com>
cb8e9e
---
cb8e9e
 xlators/cluster/afr/src/afr-common.c      |   32 +++++++++++---
cb8e9e
 xlators/cluster/afr/src/afr-inode-read.c  |   67 +++++++++++++++++++++++-----
cb8e9e
 xlators/cluster/afr/src/afr-inode-write.c |    3 +
cb8e9e
 xlators/cluster/afr/src/afr-mem-types.h   |    1 +
cb8e9e
 xlators/cluster/afr/src/afr-messages.h    |    9 +++-
cb8e9e
 xlators/cluster/afr/src/afr.h             |   13 ++++-
cb8e9e
 6 files changed, 103 insertions(+), 22 deletions(-)
cb8e9e
cb8e9e
diff --git a/xlators/cluster/afr/src/afr-common.c b/xlators/cluster/afr/src/afr-common.c
cb8e9e
index 7255179..9abb96d 100644
cb8e9e
--- a/xlators/cluster/afr/src/afr-common.c
cb8e9e
+++ b/xlators/cluster/afr/src/afr-common.c
cb8e9e
@@ -4741,8 +4741,7 @@ out:
cb8e9e
 }
cb8e9e
 
cb8e9e
 int
cb8e9e
-afr_get_heal_info (call_frame_t *frame, xlator_t *this, loc_t *loc,
cb8e9e
-                   dict_t *xdata)
cb8e9e
+afr_get_heal_info (call_frame_t *frame, xlator_t *this, loc_t *loc)
cb8e9e
 {
cb8e9e
         gf_boolean_t    data_selfheal     = _gf_false;
cb8e9e
         gf_boolean_t    metadata_selfheal = _gf_false;
cb8e9e
@@ -4867,7 +4866,14 @@ out:
cb8e9e
 }
cb8e9e
 
cb8e9e
 int
cb8e9e
-afr_get_split_brain_status (call_frame_t *frame, xlator_t *this, loc_t *loc)
cb8e9e
+afr_get_split_brain_status_cbk (int ret, call_frame_t *frame, void *opaque)
cb8e9e
+{
cb8e9e
+        GF_FREE (opaque);
cb8e9e
+        return 0;
cb8e9e
+}
cb8e9e
+
cb8e9e
+int
cb8e9e
+afr_get_split_brain_status (void *opaque)
cb8e9e
 {
cb8e9e
         gf_boolean_t      d_spb             = _gf_false;
cb8e9e
         gf_boolean_t      m_spb             = _gf_false;
cb8e9e
@@ -4880,7 +4886,15 @@ afr_get_split_brain_status (call_frame_t *frame, xlator_t *this, loc_t *loc)
cb8e9e
         inode_t          *inode             = NULL;
cb8e9e
         afr_private_t    *priv              = NULL;
cb8e9e
         xlator_t         **children         = NULL;
cb8e9e
-
cb8e9e
+        call_frame_t     *frame             = NULL;
cb8e9e
+        xlator_t         *this              = NULL;
cb8e9e
+        loc_t            *loc               = NULL;
cb8e9e
+        afr_spb_status_t *data              = NULL;
cb8e9e
+
cb8e9e
+        data     = opaque;
cb8e9e
+        frame    = data->frame;
cb8e9e
+        this     = frame->this;
cb8e9e
+        loc      = data->loc;
cb8e9e
         priv     = this->private;
cb8e9e
         children = priv->children;
cb8e9e
 
cb8e9e
@@ -4930,14 +4944,20 @@ afr_get_split_brain_status (call_frame_t *frame, xlator_t *this, loc_t *loc)
cb8e9e
                         goto out;
cb8e9e
                 }
cb8e9e
                 ret = dict_set_dynstr (dict, GF_AFR_SBRAIN_STATUS, status);
cb8e9e
-                if (ret)
cb8e9e
+                if (ret) {
cb8e9e
+                        op_errno = -ret;
cb8e9e
+                        ret = -1;
cb8e9e
                         goto out;
cb8e9e
+                }
cb8e9e
         } else {
cb8e9e
                 ret = dict_set_str (dict, GF_AFR_SBRAIN_STATUS,
cb8e9e
                                     "The file is not under data or"
cb8e9e
                                     " metadata split-brain");
cb8e9e
-                if (ret)
cb8e9e
+                if (ret) {
cb8e9e
+                        op_errno = -ret;
cb8e9e
+                        ret = -1;
cb8e9e
                         goto out;
cb8e9e
+                }
cb8e9e
         }
cb8e9e
 
cb8e9e
         ret = 0;
cb8e9e
diff --git a/xlators/cluster/afr/src/afr-inode-read.c b/xlators/cluster/afr/src/afr-inode-read.c
cb8e9e
index 1ebe5e5..6afd51d 100644
cb8e9e
--- a/xlators/cluster/afr/src/afr-inode-read.c
cb8e9e
+++ b/xlators/cluster/afr/src/afr-inode-read.c
cb8e9e
@@ -1429,6 +1429,59 @@ afr_marker_populate_args (call_frame_t *frame, int type, int *gauge,
cb8e9e
         return priv->child_count;
cb8e9e
 }
cb8e9e
 
cb8e9e
+static int
cb8e9e
+afr_handle_heal_xattrs (call_frame_t *frame, xlator_t *this, loc_t *loc,
cb8e9e
+                        const char *heal_op)
cb8e9e
+{
cb8e9e
+        int                     ret     = -1;
cb8e9e
+        afr_spb_status_t       *data    = NULL;
cb8e9e
+
cb8e9e
+        if (!strcmp (heal_op, GF_HEAL_INFO)) {
cb8e9e
+                afr_get_heal_info (frame, this, loc);
cb8e9e
+                ret = 0;
cb8e9e
+                goto out;
cb8e9e
+        }
cb8e9e
+
cb8e9e
+        if (!strcmp (heal_op, GF_AFR_HEAL_SBRAIN)) {
cb8e9e
+                afr_heal_splitbrain_file (frame, this, loc);
cb8e9e
+                ret = 0;
cb8e9e
+                goto out;
cb8e9e
+        }
cb8e9e
+
cb8e9e
+        if (!strcmp (heal_op, GF_AFR_SBRAIN_STATUS)) {
cb8e9e
+                data = GF_CALLOC (1, sizeof (*data), gf_afr_mt_spb_status_t);
cb8e9e
+                if (!data) {
cb8e9e
+                        ret = 1;
cb8e9e
+                        goto out;
cb8e9e
+                }
cb8e9e
+                data->frame = frame;
cb8e9e
+                data->loc = loc;
cb8e9e
+                ret = synctask_new (this->ctx->env,
cb8e9e
+                                    afr_get_split_brain_status,
cb8e9e
+                                    afr_get_split_brain_status_cbk,
cb8e9e
+                                    NULL, data);
cb8e9e
+                if (ret) {
cb8e9e
+                        gf_msg (this->name, GF_LOG_ERROR, 0,
cb8e9e
+                                AFR_MSG_SPLIT_BRAIN_STATUS,
cb8e9e
+                                "Failed to create"
cb8e9e
+                                " synctask. Unable to fetch split-brain status"
cb8e9e
+                                " for %s.", loc->name);
cb8e9e
+                        ret = 1;
cb8e9e
+                        goto out;
cb8e9e
+                }
cb8e9e
+                goto out;
cb8e9e
+        }
cb8e9e
+
cb8e9e
+out:
cb8e9e
+        if (ret == 1) {
cb8e9e
+                AFR_STACK_UNWIND (getxattr, frame, -1, ENOMEM, NULL, NULL);
cb8e9e
+                if (data)
cb8e9e
+                        GF_FREE (data);
cb8e9e
+                ret = 0;
cb8e9e
+        }
cb8e9e
+        return ret;
cb8e9e
+}
cb8e9e
+
cb8e9e
 int32_t
cb8e9e
 afr_getxattr (call_frame_t *frame, xlator_t *this,
cb8e9e
               loc_t *loc, const char *name, dict_t *xdata)
cb8e9e
@@ -1478,20 +1531,10 @@ afr_getxattr (call_frame_t *frame, xlator_t *this,
cb8e9e
                                             afr_marker_populate_args) == 0)
cb8e9e
                 return 0;
cb8e9e
 
cb8e9e
-        if (!strcmp (name, GF_HEAL_INFO)) {
cb8e9e
-                afr_get_heal_info (frame, this, loc, xdata);
cb8e9e
+        ret = afr_handle_heal_xattrs (frame, this, &local->loc, name);
cb8e9e
+        if (ret == 0)
cb8e9e
                 return 0;
cb8e9e
-        }
cb8e9e
 
cb8e9e
-        if (!strcmp (name, GF_AFR_HEAL_SBRAIN)) {
cb8e9e
-                afr_heal_splitbrain_file (frame, this, loc);
cb8e9e
-                return 0;
cb8e9e
-        }
cb8e9e
-
cb8e9e
-        if (!strcmp (name, GF_AFR_SBRAIN_STATUS)) {
cb8e9e
-                afr_get_split_brain_status (frame, this, loc);
cb8e9e
-                return 0;
cb8e9e
-        }
cb8e9e
         /*
cb8e9e
          * Special xattrs which need responses from all subvols
cb8e9e
          */
cb8e9e
diff --git a/xlators/cluster/afr/src/afr-inode-write.c b/xlators/cluster/afr/src/afr-inode-write.c
cb8e9e
index be83781..01390f0 100644
cb8e9e
--- a/xlators/cluster/afr/src/afr-inode-write.c
cb8e9e
+++ b/xlators/cluster/afr/src/afr-inode-write.c
cb8e9e
@@ -1302,6 +1302,7 @@ afr_handle_split_brain_commands (xlator_t *this, call_frame_t *frame,
cb8e9e
                                 " synctask. Aborting split-brain choice set"
cb8e9e
                                 " for %s", loc->name);
cb8e9e
                         ret = 1;
cb8e9e
+                        op_errno = ENOMEM;
cb8e9e
                         goto out;
cb8e9e
                 }
cb8e9e
                 ret = 0;
cb8e9e
@@ -1325,6 +1326,8 @@ out:
cb8e9e
         /* key was correct but value was invalid when ret == 1 */
cb8e9e
         if (ret == 1) {
cb8e9e
                 AFR_STACK_UNWIND (setxattr, frame, -1, op_errno, NULL);
cb8e9e
+                if (data)
cb8e9e
+                        GF_FREE (data);
cb8e9e
                 ret = 0;
cb8e9e
         }
cb8e9e
         return ret;
cb8e9e
diff --git a/xlators/cluster/afr/src/afr-mem-types.h b/xlators/cluster/afr/src/afr-mem-types.h
cb8e9e
index a11063c..fd484e4 100644
cb8e9e
--- a/xlators/cluster/afr/src/afr-mem-types.h
cb8e9e
+++ b/xlators/cluster/afr/src/afr-mem-types.h
cb8e9e
@@ -44,6 +44,7 @@ enum gf_afr_mem_types_ {
cb8e9e
 	gf_afr_mt_reply_t,
cb8e9e
 	gf_afr_mt_subvol_healer_t,
cb8e9e
 	gf_afr_mt_spbc_timeout_t,
cb8e9e
+        gf_afr_mt_spb_status_t,
cb8e9e
         gf_afr_mt_end
cb8e9e
 };
cb8e9e
 #endif
cb8e9e
diff --git a/xlators/cluster/afr/src/afr-messages.h b/xlators/cluster/afr/src/afr-messages.h
cb8e9e
index e4bf85b..4793413 100644
cb8e9e
--- a/xlators/cluster/afr/src/afr-messages.h
cb8e9e
+++ b/xlators/cluster/afr/src/afr-messages.h
cb8e9e
@@ -45,7 +45,7 @@
cb8e9e
  */
cb8e9e
 
cb8e9e
 #define GLFS_COMP_BASE_AFR      GLFS_MSGID_COMP_AFR
cb8e9e
-#define GLFS_NUM_MESSAGES       37
cb8e9e
+#define GLFS_NUM_MESSAGES       38
cb8e9e
 #define GLFS_MSGID_END          (GLFS_COMP_BASE_AFR + GLFS_NUM_MESSAGES + 1)
cb8e9e
 
cb8e9e
 #define glfs_msg_start_x GLFS_COMP_BASE_AFR, "Invalid: Start of messages"
cb8e9e
@@ -333,6 +333,13 @@
cb8e9e
 #define AFR_MSG_SELF_HEAL_FAILED                (GLFS_COMP_BASE_AFR + 37)
cb8e9e
 
cb8e9e
 
cb8e9e
+/*!
cb8e9e
+ * @messageid 108038
cb8e9e
+ * @diagnosis
cb8e9e
+ * @recommendedaction
cb8e9e
+*/
cb8e9e
+#define AFR_MSG_SPLIT_BRAIN_STATUS      (GLFS_COMP_BASE_AFR + 38)
cb8e9e
+
cb8e9e
 
cb8e9e
 #define glfs_msg_end_x GLFS_MSGID_END, "Invalid: End of messages"
cb8e9e
 #endif /* !_AFR_MESSAGES_H_ */
cb8e9e
diff --git a/xlators/cluster/afr/src/afr.h b/xlators/cluster/afr/src/afr.h
cb8e9e
index 729ae82..316eeea 100644
cb8e9e
--- a/xlators/cluster/afr/src/afr.h
cb8e9e
+++ b/xlators/cluster/afr/src/afr.h
cb8e9e
@@ -755,6 +755,11 @@ typedef struct afr_spbc_timeout {
cb8e9e
         int          spb_child_index;
cb8e9e
 } afr_spbc_timeout_t;
cb8e9e
 
cb8e9e
+typedef struct afr_spb_status {
cb8e9e
+        call_frame_t *frame;
cb8e9e
+        loc_t        *loc;
cb8e9e
+} afr_spb_status_t;
cb8e9e
+
cb8e9e
 typedef struct afr_read_subvol_args {
cb8e9e
         ia_type_t ia_type;
cb8e9e
         uuid_t gfid;
cb8e9e
@@ -1050,14 +1055,16 @@ gf_boolean_t
cb8e9e
 afr_is_xattr_ignorable (char *key);
cb8e9e
 
cb8e9e
 int
cb8e9e
-afr_get_heal_info (call_frame_t *frame, xlator_t *this, loc_t *loc,
cb8e9e
-                   dict_t *xdata);
cb8e9e
+afr_get_heal_info (call_frame_t *frame, xlator_t *this, loc_t *loc);
cb8e9e
 
cb8e9e
 int
cb8e9e
 afr_heal_splitbrain_file(call_frame_t *frame, xlator_t *this, loc_t *loc);
cb8e9e
 
cb8e9e
 int
cb8e9e
-afr_get_split_brain_status (call_frame_t *frame, xlator_t *this, loc_t *loc);
cb8e9e
+afr_get_split_brain_status (void *opaque);
cb8e9e
+
cb8e9e
+int
cb8e9e
+afr_get_split_brain_status_cbk (int ret, call_frame_t *frame, void *opaque);
cb8e9e
 
cb8e9e
 int
cb8e9e
 afr_inode_split_brain_choice_set (inode_t *inode, xlator_t *this,
cb8e9e
-- 
cb8e9e
1.7.1
cb8e9e