74096c
From 54d4ea44fec96560aad9c41f7e4f5aad164ffb8b Mon Sep 17 00:00:00 2001
74096c
From: Ravishankar N <ravishankar@redhat.com>
74096c
Date: Fri, 5 Jun 2020 14:14:15 +0530
74096c
Subject: [PATCH 424/449] afr: make heal info lockless
74096c
74096c
Changes in locks xlator:
74096c
Added support for per-domain inodelk count requests.
74096c
Caller needs to set GLUSTERFS_MULTIPLE_DOM_LK_CNT_REQUESTS key in the
74096c
dict and then set each key with name
74096c
'GLUSTERFS_INODELK_DOM_PREFIX:<domain name>'.
74096c
In the response dict, the xlator will send the per domain count as
74096c
values for each of these keys.
74096c
74096c
Changes in AFR:
74096c
Replaced afr_selfheal_locked_inspect() with afr_lockless_inspect(). Logic has
74096c
been added to make the latter behave same as the former, thus not
74096c
breaking the current heal info output behaviour.
74096c
74096c
> Upstream patch: https://review.gluster.org/#/c/glusterfs/+/23771/
74096c
> fixes: bz#1774011
74096c
> Change-Id: Ie9e83c162aa77f44a39c2ba7115de558120ada4d
74096c
74096c
BUG: 1721355
74096c
Change-Id: I8ed4b504880b19e00068312efd90cd0706787404
74096c
Signed-off-by: Ravishankar N <ravishankar@redhat.com>
74096c
Reviewed-on: https://code.engineering.redhat.com/gerrit/202490
74096c
Tested-by: RHGS Build Bot <nigelb@redhat.com>
74096c
Reviewed-by: Karthik Subrahmanya <ksubrahm@redhat.com>
74096c
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
74096c
---
74096c
 heal/src/glfs-heal.c                           |  17 +-
74096c
 libglusterfs/src/glusterfs/glusterfs.h         |   2 +
74096c
 xlators/cluster/afr/src/afr-common.c           | 367 +++++++++++--------------
74096c
 xlators/cluster/afr/src/afr-self-heal-common.c |  43 ++-
74096c
 xlators/cluster/afr/src/afr-self-heal.h        |   3 +-
74096c
 xlators/features/locks/src/common.h            |   4 +
74096c
 xlators/features/locks/src/locks.h             |   8 +
74096c
 xlators/features/locks/src/posix.c             | 117 +++++++-
74096c
 8 files changed, 338 insertions(+), 223 deletions(-)
74096c
74096c
diff --git a/heal/src/glfs-heal.c b/heal/src/glfs-heal.c
74096c
index 125b12c..5af9e31 100644
74096c
--- a/heal/src/glfs-heal.c
74096c
+++ b/heal/src/glfs-heal.c
74096c
@@ -775,7 +775,8 @@ static int
74096c
 glfsh_process_entries(xlator_t *xl, fd_t *fd, gf_dirent_t *entries,
74096c
                       uint64_t *offset, num_entries_t *num_entries,
74096c
                       print_status glfsh_print_status,
74096c
-                      gf_boolean_t ignore_dirty, glfsh_fail_mode_t mode)
74096c
+                      gf_boolean_t ignore_dirty, glfsh_fail_mode_t mode,
74096c
+                      dict_t *xattr_req)
74096c
 {
74096c
     gf_dirent_t *entry = NULL;
74096c
     gf_dirent_t *tmp = NULL;
74096c
@@ -807,7 +808,7 @@ glfsh_process_entries(xlator_t *xl, fd_t *fd, gf_dirent_t *entries,
74096c
 
74096c
         gf_uuid_parse(entry->d_name, gfid);
74096c
         gf_uuid_copy(loc.gfid, gfid);
74096c
-        ret = syncop_getxattr(this, &loc, &dict, GF_HEAL_INFO, NULL, NULL);
74096c
+        ret = syncop_getxattr(this, &loc, &dict, GF_HEAL_INFO, xattr_req, NULL);
74096c
         if (ret) {
74096c
             if ((mode != GLFSH_MODE_CONTINUE_ON_ERROR) && (ret == -ENOTCONN))
74096c
                 goto out;
74096c
@@ -876,19 +877,19 @@ glfsh_crawl_directory(glfs_t *fs, xlator_t *top_subvol, loc_t *rootloc,
74096c
         if (heal_op == GF_SHD_OP_INDEX_SUMMARY) {
74096c
             ret = glfsh_process_entries(readdir_xl, fd, &entries, &offset,
74096c
                                         num_entries, glfsh_print_heal_status,
74096c
-                                        ignore, mode);
74096c
+                                        ignore, mode, xattr_req);
74096c
             if (ret < 0)
74096c
                 goto out;
74096c
         } else if (heal_op == GF_SHD_OP_SPLIT_BRAIN_FILES) {
74096c
             ret = glfsh_process_entries(readdir_xl, fd, &entries, &offset,
74096c
                                         num_entries, glfsh_print_spb_status,
74096c
-                                        ignore, mode);
74096c
+                                        ignore, mode, xattr_req);
74096c
             if (ret < 0)
74096c
                 goto out;
74096c
         } else if (heal_op == GF_SHD_OP_HEAL_SUMMARY) {
74096c
             ret = glfsh_process_entries(readdir_xl, fd, &entries, &offset,
74096c
                                         num_entries, glfsh_print_summary_status,
74096c
-                                        ignore, mode);
74096c
+                                        ignore, mode, xattr_req);
74096c
             if (ret < 0)
74096c
                 goto out;
74096c
         } else if (heal_op == GF_SHD_OP_SBRAIN_HEAL_FROM_BRICK) {
74096c
@@ -897,7 +898,7 @@ glfsh_crawl_directory(glfs_t *fs, xlator_t *top_subvol, loc_t *rootloc,
74096c
         } else if (heal_op == GF_SHD_OP_GRANULAR_ENTRY_HEAL_ENABLE) {
74096c
             ret = glfsh_process_entries(readdir_xl, fd, &entries, &offset,
74096c
                                         num_entries, glfsh_heal_status_boolean,
74096c
-                                        ignore, mode);
74096c
+                                        ignore, mode, xattr_req);
74096c
             if (ret < 0)
74096c
                 goto out;
74096c
         }
74096c
@@ -951,6 +952,10 @@ glfsh_print_pending_heals_type(glfs_t *fs, xlator_t *top_subvol, loc_t *rootloc,
74096c
     int32_t op_errno = 0;
74096c
     gf_boolean_t ignore = _gf_false;
74096c
 
74096c
+    ret = dict_set_str(xattr_req, "index-vgfid", vgfid);
74096c
+    if (ret)
74096c
+        return ret;
74096c
+
74096c
     if (!strcmp(vgfid, GF_XATTROP_DIRTY_GFID))
74096c
         ignore = _gf_true;
74096c
 
74096c
diff --git a/libglusterfs/src/glusterfs/glusterfs.h b/libglusterfs/src/glusterfs/glusterfs.h
74096c
index 3b594c0..177a020 100644
74096c
--- a/libglusterfs/src/glusterfs/glusterfs.h
74096c
+++ b/libglusterfs/src/glusterfs/glusterfs.h
74096c
@@ -217,6 +217,8 @@ enum gf_internal_fop_indicator {
74096c
 #define GLUSTERFS_POSIXLK_COUNT "glusterfs.posixlk-count"
74096c
 #define GLUSTERFS_PARENT_ENTRYLK "glusterfs.parent-entrylk"
74096c
 #define GLUSTERFS_INODELK_DOM_COUNT "glusterfs.inodelk-dom-count"
74096c
+#define GLUSTERFS_INODELK_DOM_PREFIX "glusterfs.inodelk-dom-prefix"
74096c
+#define GLUSTERFS_MULTIPLE_DOM_LK_CNT_REQUESTS "glusterfs.multi-dom-lk-cnt-req"
74096c
 #define GFID_TO_PATH_KEY "glusterfs.gfid2path"
74096c
 #define GF_XATTR_STIME_PATTERN "trusted.glusterfs.*.stime"
74096c
 #define GF_XATTR_XTIME_PATTERN "trusted.glusterfs.*.xtime"
74096c
diff --git a/xlators/cluster/afr/src/afr-common.c b/xlators/cluster/afr/src/afr-common.c
74096c
index 59710aa..c355ec5 100644
74096c
--- a/xlators/cluster/afr/src/afr-common.c
74096c
+++ b/xlators/cluster/afr/src/afr-common.c
74096c
@@ -5908,259 +5908,218 @@ out:
74096c
     return _gf_true;
74096c
 }
74096c
 
74096c
-int
74096c
-afr_selfheal_locked_metadata_inspect(call_frame_t *frame, xlator_t *this,
74096c
-                                     inode_t *inode, gf_boolean_t *msh,
74096c
-                                     unsigned char *pending)
74096c
+static dict_t *
74096c
+afr_set_heal_info(char *status)
74096c
 {
74096c
+    dict_t *dict = NULL;
74096c
     int ret = -1;
74096c
-    unsigned char *locked_on = NULL;
74096c
-    unsigned char *sources = NULL;
74096c
-    unsigned char *sinks = NULL;
74096c
-    unsigned char *healed_sinks = NULL;
74096c
-    unsigned char *undid_pending = NULL;
74096c
-    struct afr_reply *locked_replies = NULL;
74096c
-
74096c
-    afr_private_t *priv = this->private;
74096c
 
74096c
-    locked_on = alloca0(priv->child_count);
74096c
-    sources = alloca0(priv->child_count);
74096c
-    sinks = alloca0(priv->child_count);
74096c
-    healed_sinks = alloca0(priv->child_count);
74096c
-    undid_pending = alloca0(priv->child_count);
74096c
+    dict = dict_new();
74096c
+    if (!dict) {
74096c
+        ret = -ENOMEM;
74096c
+        goto out;
74096c
+    }
74096c
 
74096c
-    locked_replies = alloca0(sizeof(*locked_replies) * priv->child_count);
74096c
+    ret = dict_set_dynstr_sizen(dict, "heal-info", status);
74096c
+    if (ret)
74096c
+        gf_msg("", GF_LOG_WARNING, -ret, AFR_MSG_DICT_SET_FAILED,
74096c
+               "Failed to set heal-info key to "
74096c
+               "%s",
74096c
+               status);
74096c
+out:
74096c
+    /* Any error other than EINVAL, dict_set_dynstr frees status */
74096c
+    if (ret == -ENOMEM || ret == -EINVAL) {
74096c
+        GF_FREE(status);
74096c
+    }
74096c
 
74096c
-    ret = afr_selfheal_inodelk(frame, this, inode, this->name, LLONG_MAX - 1, 0,
74096c
-                               locked_on);
74096c
-    {
74096c
-        if (ret == 0) {
74096c
-            /* Not a single lock */
74096c
-            ret = -afr_final_errno(frame->local, priv);
74096c
-            if (ret == 0)
74096c
-                ret = -ENOTCONN; /* all invalid responses */
74096c
-            goto out;
74096c
-        }
74096c
-        ret = __afr_selfheal_metadata_prepare(
74096c
-            frame, this, inode, locked_on, sources, sinks, healed_sinks,
74096c
-            undid_pending, locked_replies, pending);
74096c
-        *msh = afr_decide_heal_info(priv, sources, ret);
74096c
+    if (ret && dict) {
74096c
+        dict_unref(dict);
74096c
+        dict = NULL;
74096c
     }
74096c
-    afr_selfheal_uninodelk(frame, this, inode, this->name, LLONG_MAX - 1, 0,
74096c
-                           locked_on);
74096c
-out:
74096c
-    if (locked_replies)
74096c
-        afr_replies_wipe(locked_replies, priv->child_count);
74096c
-    return ret;
74096c
+    return dict;
74096c
 }
74096c
 
74096c
-int
74096c
-afr_selfheal_locked_data_inspect(call_frame_t *frame, xlator_t *this, fd_t *fd,
74096c
-                                 gf_boolean_t *dsh, unsigned char *pflag)
74096c
+static gf_boolean_t
74096c
+afr_is_dirty_count_non_unary_for_txn(xlator_t *this, struct afr_reply *replies,
74096c
+                                     afr_transaction_type type)
74096c
 {
74096c
-    int ret = -1;
74096c
-    unsigned char *data_lock = NULL;
74096c
-    unsigned char *sources = NULL;
74096c
-    unsigned char *sinks = NULL;
74096c
-    unsigned char *healed_sinks = NULL;
74096c
-    unsigned char *undid_pending = NULL;
74096c
-    afr_private_t *priv = NULL;
74096c
-    struct afr_reply *locked_replies = NULL;
74096c
-    inode_t *inode = fd->inode;
74096c
+    afr_private_t *priv = this->private;
74096c
+    int *dirty = alloca0(priv->child_count * sizeof(int));
74096c
+    int i = 0;
74096c
 
74096c
-    priv = this->private;
74096c
-    data_lock = alloca0(priv->child_count);
74096c
-    sources = alloca0(priv->child_count);
74096c
-    sinks = alloca0(priv->child_count);
74096c
-    healed_sinks = alloca0(priv->child_count);
74096c
-    undid_pending = alloca0(priv->child_count);
74096c
+    afr_selfheal_extract_xattr(this, replies, type, dirty, NULL);
74096c
+    for (i = 0; i < priv->child_count; i++) {
74096c
+        if (dirty[i] > 1)
74096c
+            return _gf_true;
74096c
+    }
74096c
 
74096c
-    locked_replies = alloca0(sizeof(*locked_replies) * priv->child_count);
74096c
+    return _gf_false;
74096c
+}
74096c
 
74096c
-    ret = afr_selfheal_inodelk(frame, this, inode, this->name, 0, 0, data_lock);
74096c
-    {
74096c
-        if (ret == 0) {
74096c
-            ret = -afr_final_errno(frame->local, priv);
74096c
-            if (ret == 0)
74096c
-                ret = -ENOTCONN; /* all invalid responses */
74096c
-            goto out;
74096c
-        }
74096c
-        ret = __afr_selfheal_data_prepare(frame, this, inode, data_lock,
74096c
-                                          sources, sinks, healed_sinks,
74096c
-                                          undid_pending, locked_replies, pflag);
74096c
-        *dsh = afr_decide_heal_info(priv, sources, ret);
74096c
+static gf_boolean_t
74096c
+afr_is_dirty_count_non_unary(xlator_t *this, struct afr_reply *replies,
74096c
+                             ia_type_t ia_type)
74096c
+{
74096c
+    gf_boolean_t data_chk = _gf_false;
74096c
+    gf_boolean_t mdata_chk = _gf_false;
74096c
+    gf_boolean_t entry_chk = _gf_false;
74096c
+
74096c
+    switch (ia_type) {
74096c
+        case IA_IFDIR:
74096c
+            mdata_chk = _gf_true;
74096c
+            entry_chk = _gf_true;
74096c
+            break;
74096c
+        case IA_IFREG:
74096c
+            mdata_chk = _gf_true;
74096c
+            data_chk = _gf_true;
74096c
+            break;
74096c
+        default:
74096c
+            /*IA_IFBLK, IA_IFCHR, IA_IFLNK, IA_IFIFO, IA_IFSOCK*/
74096c
+            mdata_chk = _gf_true;
74096c
+            break;
74096c
     }
74096c
-    afr_selfheal_uninodelk(frame, this, inode, this->name, 0, 0, data_lock);
74096c
-out:
74096c
-    if (locked_replies)
74096c
-        afr_replies_wipe(locked_replies, priv->child_count);
74096c
-    return ret;
74096c
+
74096c
+    if (data_chk && afr_is_dirty_count_non_unary_for_txn(
74096c
+                        this, replies, AFR_DATA_TRANSACTION)) {
74096c
+        return _gf_true;
74096c
+    } else if (mdata_chk && afr_is_dirty_count_non_unary_for_txn(
74096c
+                                this, replies, AFR_METADATA_TRANSACTION)) {
74096c
+        return _gf_true;
74096c
+    } else if (entry_chk && afr_is_dirty_count_non_unary_for_txn(
74096c
+                                this, replies, AFR_ENTRY_TRANSACTION)) {
74096c
+        return _gf_true;
74096c
+    }
74096c
+
74096c
+    return _gf_false;
74096c
 }
74096c
 
74096c
-int
74096c
-afr_selfheal_locked_entry_inspect(call_frame_t *frame, xlator_t *this,
74096c
-                                  inode_t *inode, gf_boolean_t *esh,
74096c
-                                  unsigned char *pflag)
74096c
+static int
74096c
+afr_update_heal_status(xlator_t *this, struct afr_reply *replies,
74096c
+                       char *index_vgfid, ia_type_t ia_type, gf_boolean_t *esh,
74096c
+                       gf_boolean_t *dsh, gf_boolean_t *msh)
74096c
 {
74096c
     int ret = -1;
74096c
-    int source = -1;
74096c
+    GF_UNUSED int ret1 = 0;
74096c
+    int i = 0;
74096c
+    int io_domain_lk_count = 0;
74096c
+    int shd_domain_lk_count = 0;
74096c
     afr_private_t *priv = NULL;
74096c
-    unsigned char *locked_on = NULL;
74096c
-    unsigned char *data_lock = NULL;
74096c
-    unsigned char *sources = NULL;
74096c
-    unsigned char *sinks = NULL;
74096c
-    unsigned char *healed_sinks = NULL;
74096c
-    struct afr_reply *locked_replies = NULL;
74096c
-    gf_boolean_t granular_locks = _gf_false;
74096c
+    char *key1 = NULL;
74096c
+    char *key2 = NULL;
74096c
 
74096c
     priv = this->private;
74096c
-    granular_locks = priv->granular_locks; /*Assign to local variable so that
74096c
-                                             reconfigure doesn't change this
74096c
-                                             value between locking and unlocking
74096c
-                                             below*/
74096c
-    locked_on = alloca0(priv->child_count);
74096c
-    data_lock = alloca0(priv->child_count);
74096c
-    sources = alloca0(priv->child_count);
74096c
-    sinks = alloca0(priv->child_count);
74096c
-    healed_sinks = alloca0(priv->child_count);
74096c
-
74096c
-    locked_replies = alloca0(sizeof(*locked_replies) * priv->child_count);
74096c
+    key1 = alloca0(strlen(GLUSTERFS_INODELK_DOM_PREFIX) + 2 +
74096c
+                   strlen(this->name));
74096c
+    key2 = alloca0(strlen(GLUSTERFS_INODELK_DOM_PREFIX) + 2 +
74096c
+                   strlen(priv->sh_domain));
74096c
+    sprintf(key1, "%s:%s", GLUSTERFS_INODELK_DOM_PREFIX, this->name);
74096c
+    sprintf(key2, "%s:%s", GLUSTERFS_INODELK_DOM_PREFIX, priv->sh_domain);
74096c
 
74096c
-    if (!granular_locks) {
74096c
-        ret = afr_selfheal_tryentrylk(frame, this, inode, priv->sh_domain, NULL,
74096c
-                                      locked_on);
74096c
-    }
74096c
-    {
74096c
-        if (!granular_locks && ret == 0) {
74096c
-            ret = -afr_final_errno(frame->local, priv);
74096c
-            if (ret == 0)
74096c
-                ret = -ENOTCONN; /* all invalid responses */
74096c
-            goto out;
74096c
+    for (i = 0; i < priv->child_count; i++) {
74096c
+        if ((replies[i].valid != 1) || (replies[i].op_ret != 0))
74096c
+            continue;
74096c
+        if (!io_domain_lk_count) {
74096c
+            ret1 = dict_get_int32(replies[i].xdata, key1, &io_domain_lk_count);
74096c
         }
74096c
+        if (!shd_domain_lk_count) {
74096c
+            ret1 = dict_get_int32(replies[i].xdata, key2, &shd_domain_lk_count);
74096c
+        }
74096c
+    }
74096c
 
74096c
-        ret = afr_selfheal_entrylk(frame, this, inode, this->name, NULL,
74096c
-                                   data_lock);
74096c
-        {
74096c
-            if (ret == 0) {
74096c
-                ret = -afr_final_errno(frame->local, priv);
74096c
-                if (ret == 0)
74096c
-                    ret = -ENOTCONN;
74096c
-                /* all invalid responses */
74096c
-                goto unlock;
74096c
-            }
74096c
-            ret = __afr_selfheal_entry_prepare(frame, this, inode, data_lock,
74096c
-                                               sources, sinks, healed_sinks,
74096c
-                                               locked_replies, &source, pflag);
74096c
-            if ((ret == 0) && (*pflag & PFLAG_SBRAIN))
74096c
-                ret = -EIO;
74096c
-            *esh = afr_decide_heal_info(priv, sources, ret);
74096c
+    if (!strcmp(index_vgfid, GF_XATTROP_INDEX_GFID)) {
74096c
+        if (shd_domain_lk_count) {
74096c
+            ret = -EAGAIN; /*For 'possibly-healing'. */
74096c
+        } else {
74096c
+            ret = 0; /*needs heal. Just set a non -ve value so that it is
74096c
+                       assumed as the source index.*/
74096c
+        }
74096c
+    } else if (!strcmp(index_vgfid, GF_XATTROP_DIRTY_GFID)) {
74096c
+        if ((afr_is_dirty_count_non_unary(this, replies, ia_type)) ||
74096c
+            (!io_domain_lk_count)) {
74096c
+            /* Needs heal. */
74096c
+            ret = 0;
74096c
+        } else {
74096c
+            /* No heal needed. */
74096c
+            *dsh = *esh = *msh = 0;
74096c
         }
74096c
-        afr_selfheal_unentrylk(frame, this, inode, this->name, NULL, data_lock,
74096c
-                               NULL);
74096c
     }
74096c
-unlock:
74096c
-    if (!granular_locks)
74096c
-        afr_selfheal_unentrylk(frame, this, inode, priv->sh_domain, NULL,
74096c
-                               locked_on, NULL);
74096c
-out:
74096c
-    if (locked_replies)
74096c
-        afr_replies_wipe(locked_replies, priv->child_count);
74096c
     return ret;
74096c
 }
74096c
 
74096c
+/*return EIO, EAGAIN or pending*/
74096c
 int
74096c
-afr_selfheal_locked_inspect(call_frame_t *frame, xlator_t *this, uuid_t gfid,
74096c
-                            inode_t **inode, gf_boolean_t *entry_selfheal,
74096c
-                            gf_boolean_t *data_selfheal,
74096c
-                            gf_boolean_t *metadata_selfheal,
74096c
-                            unsigned char *pending)
74096c
-
74096c
+afr_lockless_inspect(call_frame_t *frame, xlator_t *this, uuid_t gfid,
74096c
+                     inode_t **inode, char *index_vgfid,
74096c
+                     gf_boolean_t *entry_selfheal, gf_boolean_t *data_selfheal,
74096c
+                     gf_boolean_t *metadata_selfheal, unsigned char *pending)
74096c
 {
74096c
     int ret = -1;
74096c
-    fd_t *fd = NULL;
74096c
+    int i = 0;
74096c
+    afr_private_t *priv = NULL;
74096c
+    struct afr_reply *replies = NULL;
74096c
     gf_boolean_t dsh = _gf_false;
74096c
     gf_boolean_t msh = _gf_false;
74096c
     gf_boolean_t esh = _gf_false;
74096c
+    unsigned char *sources = NULL;
74096c
+    unsigned char *sinks = NULL;
74096c
+    unsigned char *valid_on = NULL;
74096c
+    uint64_t *witness = NULL;
74096c
+
74096c
+    priv = this->private;
74096c
+    replies = alloca0(sizeof(*replies) * priv->child_count);
74096c
+    sources = alloca0(sizeof(*sources) * priv->child_count);
74096c
+    sinks = alloca0(sizeof(*sinks) * priv->child_count);
74096c
+    witness = alloca0(sizeof(*witness) * priv->child_count);
74096c
+    valid_on = alloca0(sizeof(*valid_on) * priv->child_count);
74096c
 
74096c
     ret = afr_selfheal_unlocked_inspect(frame, this, gfid, inode, &dsh, &msh,
74096c
-                                        &esh;;
74096c
+                                        &esh, replies);
74096c
     if (ret)
74096c
         goto out;
74096c
-
74096c
-    /* For every heal type hold locks and check if it indeed needs heal */
74096c
-
74096c
-    /* Heal-info does an open() on the file being examined so that the
74096c
-     * current eager-lock holding client, if present, at some point sees
74096c
-     * open-fd count being > 1 and releases the eager-lock so that heal-info
74096c
-     * doesn't remain blocked forever until IO completes.
74096c
-     */
74096c
-    if ((*inode)->ia_type == IA_IFREG) {
74096c
-        ret = afr_selfheal_data_open(this, *inode, &fd;;
74096c
-        if (ret < 0) {
74096c
-            gf_msg_debug(this->name, -ret, "%s: Failed to open",
74096c
-                         uuid_utoa((*inode)->gfid));
74096c
-            goto out;
74096c
+    for (i = 0; i < priv->child_count; i++) {
74096c
+        if (replies[i].valid && replies[i].op_ret == 0) {
74096c
+            valid_on[i] = 1;
74096c
         }
74096c
     }
74096c
-
74096c
     if (msh) {
74096c
-        ret = afr_selfheal_locked_metadata_inspect(frame, this, *inode, &msh,
74096c
-                                                   pending);
74096c
-        if (ret == -EIO)
74096c
+        ret = afr_selfheal_find_direction(frame, this, replies,
74096c
+                                          AFR_METADATA_TRANSACTION, valid_on,
74096c
+                                          sources, sinks, witness, pending);
74096c
+        if (*pending & PFLAG_SBRAIN)
74096c
+            ret = -EIO;
74096c
+        if (ret)
74096c
             goto out;
74096c
     }
74096c
-
74096c
     if (dsh) {
74096c
-        ret = afr_selfheal_locked_data_inspect(frame, this, fd, &dsh, pending);
74096c
-        if (ret == -EIO || (ret == -EAGAIN))
74096c
+        ret = afr_selfheal_find_direction(frame, this, replies,
74096c
+                                          AFR_DATA_TRANSACTION, valid_on,
74096c
+                                          sources, sinks, witness, pending);
74096c
+        if (*pending & PFLAG_SBRAIN)
74096c
+            ret = -EIO;
74096c
+        if (ret)
74096c
             goto out;
74096c
     }
74096c
-
74096c
     if (esh) {
74096c
-        ret = afr_selfheal_locked_entry_inspect(frame, this, *inode, &esh,
74096c
-                                                pending);
74096c
+        ret = afr_selfheal_find_direction(frame, this, replies,
74096c
+                                          AFR_ENTRY_TRANSACTION, valid_on,
74096c
+                                          sources, sinks, witness, pending);
74096c
+        if (*pending & PFLAG_SBRAIN)
74096c
+            ret = -EIO;
74096c
+        if (ret)
74096c
+            goto out;
74096c
     }
74096c
 
74096c
+    ret = afr_update_heal_status(this, replies, index_vgfid, (*inode)->ia_type,
74096c
+                                 &esh, &dsh, &msh;;
74096c
 out:
74096c
     *data_selfheal = dsh;
74096c
     *entry_selfheal = esh;
74096c
     *metadata_selfheal = msh;
74096c
-    if (fd)
74096c
-        fd_unref(fd);
74096c
+    if (replies)
74096c
+        afr_replies_wipe(replies, priv->child_count);
74096c
     return ret;
74096c
 }
74096c
 
74096c
-static dict_t *
74096c
-afr_set_heal_info(char *status)
74096c
-{
74096c
-    dict_t *dict = NULL;
74096c
-    int ret = -1;
74096c
-
74096c
-    dict = dict_new();
74096c
-    if (!dict) {
74096c
-        ret = -ENOMEM;
74096c
-        goto out;
74096c
-    }
74096c
-
74096c
-    ret = dict_set_dynstr_sizen(dict, "heal-info", status);
74096c
-    if (ret)
74096c
-        gf_msg("", GF_LOG_WARNING, -ret, AFR_MSG_DICT_SET_FAILED,
74096c
-               "Failed to set heal-info key to "
74096c
-               "%s",
74096c
-               status);
74096c
-out:
74096c
-    /* Any error other than EINVAL, dict_set_dynstr frees status */
74096c
-    if (ret == -ENOMEM || ret == -EINVAL) {
74096c
-        GF_FREE(status);
74096c
-    }
74096c
-
74096c
-    if (ret && dict) {
74096c
-        dict_unref(dict);
74096c
-        dict = NULL;
74096c
-    }
74096c
-    return dict;
74096c
-}
74096c
-
74096c
 int
74096c
 afr_get_heal_info(call_frame_t *frame, xlator_t *this, loc_t *loc)
74096c
 {
74096c
@@ -6174,10 +6133,18 @@ afr_get_heal_info(call_frame_t *frame, xlator_t *this, loc_t *loc)
74096c
     inode_t *inode = NULL;
74096c
     char *substr = NULL;
74096c
     char *status = NULL;
74096c
+    afr_local_t *local = NULL;
74096c
+    char *index_vgfid = NULL;
74096c
+
74096c
+    local = frame->local;
74096c
+    if (dict_get_str(local->xdata_req, "index-vgfid", &index_vgfid)) {
74096c
+        ret = -1;
74096c
+        goto out;
74096c
+    }
74096c
 
74096c
-    ret = afr_selfheal_locked_inspect(frame, this, loc->gfid, &inode,
74096c
-                                      &entry_selfheal, &data_selfheal,
74096c
-                                      &metadata_selfheal, &pending);
74096c
+    ret = afr_lockless_inspect(frame, this, loc->gfid, &inode, index_vgfid,
74096c
+                               &entry_selfheal, &data_selfheal,
74096c
+                               &metadata_selfheal, &pending);
74096c
 
74096c
     if (ret == -ENOMEM) {
74096c
         ret = -1;
74096c
diff --git a/xlators/cluster/afr/src/afr-self-heal-common.c b/xlators/cluster/afr/src/afr-self-heal-common.c
74096c
index d942ccf..1608f75 100644
74096c
--- a/xlators/cluster/afr/src/afr-self-heal-common.c
74096c
+++ b/xlators/cluster/afr/src/afr-self-heal-common.c
74096c
@@ -1827,6 +1827,37 @@ afr_selfheal_unlocked_lookup_on(call_frame_t *frame, inode_t *parent,
74096c
     return inode;
74096c
 }
74096c
 
74096c
+static int
74096c
+afr_set_multi_dom_lock_count_request(xlator_t *this, dict_t *dict)
74096c
+{
74096c
+    int ret = 0;
74096c
+    afr_private_t *priv = NULL;
74096c
+    char *key1 = NULL;
74096c
+    char *key2 = NULL;
74096c
+
74096c
+    priv = this->private;
74096c
+    key1 = alloca0(strlen(GLUSTERFS_INODELK_DOM_PREFIX) + 2 +
74096c
+                   strlen(this->name));
74096c
+    key2 = alloca0(strlen(GLUSTERFS_INODELK_DOM_PREFIX) + 2 +
74096c
+                   strlen(priv->sh_domain));
74096c
+
74096c
+    ret = dict_set_uint32(dict, GLUSTERFS_MULTIPLE_DOM_LK_CNT_REQUESTS, 1);
74096c
+    if (ret)
74096c
+        return ret;
74096c
+
74096c
+    sprintf(key1, "%s:%s", GLUSTERFS_INODELK_DOM_PREFIX, this->name);
74096c
+    ret = dict_set_uint32(dict, key1, 1);
74096c
+    if (ret)
74096c
+        return ret;
74096c
+
74096c
+    sprintf(key2, "%s:%s", GLUSTERFS_INODELK_DOM_PREFIX, priv->sh_domain);
74096c
+    ret = dict_set_uint32(dict, key2, 1);
74096c
+    if (ret)
74096c
+        return ret;
74096c
+
74096c
+    return 0;
74096c
+}
74096c
+
74096c
 int
74096c
 afr_selfheal_unlocked_discover_on(call_frame_t *frame, inode_t *inode,
74096c
                                   uuid_t gfid, struct afr_reply *replies,
74096c
@@ -1851,6 +1882,11 @@ afr_selfheal_unlocked_discover_on(call_frame_t *frame, inode_t *inode,
74096c
         return -ENOMEM;
74096c
     }
74096c
 
74096c
+    if (afr_set_multi_dom_lock_count_request(frame->this, xattr_req)) {
74096c
+        dict_unref(xattr_req);
74096c
+        return -1;
74096c
+    }
74096c
+
74096c
     loc.inode = inode_ref(inode);
74096c
     gf_uuid_copy(loc.gfid, gfid);
74096c
 
74096c
@@ -2241,7 +2277,8 @@ int
74096c
 afr_selfheal_unlocked_inspect(call_frame_t *frame, xlator_t *this, uuid_t gfid,
74096c
                               inode_t **link_inode, gf_boolean_t *data_selfheal,
74096c
                               gf_boolean_t *metadata_selfheal,
74096c
-                              gf_boolean_t *entry_selfheal)
74096c
+                              gf_boolean_t *entry_selfheal,
74096c
+                              struct afr_reply *replies_dst)
74096c
 {
74096c
     afr_private_t *priv = NULL;
74096c
     inode_t *inode = NULL;
74096c
@@ -2377,6 +2414,8 @@ afr_selfheal_unlocked_inspect(call_frame_t *frame, xlator_t *this, uuid_t gfid,
74096c
 
74096c
     ret = 0;
74096c
 out:
74096c
+    if (replies && replies_dst)
74096c
+        afr_replies_copy(replies_dst, replies, priv->child_count);
74096c
     if (inode)
74096c
         inode_unref(inode);
74096c
     if (replies)
74096c
@@ -2493,7 +2532,7 @@ afr_selfheal_do(call_frame_t *frame, xlator_t *this, uuid_t gfid)
74096c
 
74096c
     ret = afr_selfheal_unlocked_inspect(frame, this, gfid, &inode,
74096c
                                         &data_selfheal, &metadata_selfheal,
74096c
-                                        &entry_selfheal);
74096c
+                                        &entry_selfheal, NULL);
74096c
     if (ret)
74096c
         goto out;
74096c
 
74096c
diff --git a/xlators/cluster/afr/src/afr-self-heal.h b/xlators/cluster/afr/src/afr-self-heal.h
74096c
index f7ecf5d..b39af02 100644
74096c
--- a/xlators/cluster/afr/src/afr-self-heal.h
74096c
+++ b/xlators/cluster/afr/src/afr-self-heal.h
74096c
@@ -327,7 +327,8 @@ int
74096c
 afr_selfheal_unlocked_inspect(call_frame_t *frame, xlator_t *this, uuid_t gfid,
74096c
                               inode_t **link_inode, gf_boolean_t *data_selfheal,
74096c
                               gf_boolean_t *metadata_selfheal,
74096c
-                              gf_boolean_t *entry_selfheal);
74096c
+                              gf_boolean_t *entry_selfheal,
74096c
+                              struct afr_reply *replies);
74096c
 
74096c
 int
74096c
 afr_selfheal_do(call_frame_t *frame, xlator_t *this, uuid_t gfid);
74096c
diff --git a/xlators/features/locks/src/common.h b/xlators/features/locks/src/common.h
74096c
index 3a74967..ea86b96 100644
74096c
--- a/xlators/features/locks/src/common.h
74096c
+++ b/xlators/features/locks/src/common.h
74096c
@@ -45,6 +45,10 @@
74096c
                 fd_unref(__local->fd);                                         \
74096c
             if (__local->inode)                                                \
74096c
                 inode_unref(__local->inode);                                   \
74096c
+            if (__local->xdata) {                                              \
74096c
+                dict_unref(__local->xdata);                                    \
74096c
+                __local->xdata = NULL;                                         \
74096c
+            }                                                                  \
74096c
             mem_put(__local);                                                  \
74096c
         }                                                                      \
74096c
     } while (0)
74096c
diff --git a/xlators/features/locks/src/locks.h b/xlators/features/locks/src/locks.h
74096c
index b817960..aa267de 100644
74096c
--- a/xlators/features/locks/src/locks.h
74096c
+++ b/xlators/features/locks/src/locks.h
74096c
@@ -239,6 +239,7 @@ typedef struct {
74096c
     gf_boolean_t inodelk_count_req;
74096c
     gf_boolean_t posixlk_count_req;
74096c
     gf_boolean_t parent_entrylk_req;
74096c
+    gf_boolean_t multiple_dom_lk_requests;
74096c
     int update_mlock_enforced_flag;
74096c
 } pl_local_t;
74096c
 
74096c
@@ -260,6 +261,13 @@ typedef struct _locks_ctx {
74096c
     struct list_head metalk_list;
74096c
 } pl_ctx_t;
74096c
 
74096c
+typedef struct _multi_dom_lk_data {
74096c
+    xlator_t *this;
74096c
+    inode_t *inode;
74096c
+    dict_t *xdata_rsp;
74096c
+    gf_boolean_t keep_max;
74096c
+} multi_dom_lk_data;
74096c
+
74096c
 typedef enum { DECREMENT, INCREMENT } pl_count_op_t;
74096c
 
74096c
 pl_ctx_t *
74096c
diff --git a/xlators/features/locks/src/posix.c b/xlators/features/locks/src/posix.c
74096c
index 4592240..9a14c64 100644
74096c
--- a/xlators/features/locks/src/posix.c
74096c
+++ b/xlators/features/locks/src/posix.c
74096c
@@ -150,13 +150,20 @@ fetch_pathinfo(xlator_t *, inode_t *, int32_t *, char **);
74096c
 gf_boolean_t
74096c
 pl_has_xdata_requests(dict_t *xdata)
74096c
 {
74096c
-    static char *reqs[] = {GLUSTERFS_ENTRYLK_COUNT,     GLUSTERFS_INODELK_COUNT,
74096c
-                           GLUSTERFS_INODELK_DOM_COUNT, GLUSTERFS_POSIXLK_COUNT,
74096c
-                           GLUSTERFS_PARENT_ENTRYLK,    NULL};
74096c
-    static int reqs_size[] = {
74096c
-        SLEN(GLUSTERFS_ENTRYLK_COUNT),     SLEN(GLUSTERFS_INODELK_COUNT),
74096c
-        SLEN(GLUSTERFS_INODELK_DOM_COUNT), SLEN(GLUSTERFS_POSIXLK_COUNT),
74096c
-        SLEN(GLUSTERFS_PARENT_ENTRYLK),    0};
74096c
+    static char *reqs[] = {GLUSTERFS_ENTRYLK_COUNT,
74096c
+                           GLUSTERFS_INODELK_COUNT,
74096c
+                           GLUSTERFS_INODELK_DOM_COUNT,
74096c
+                           GLUSTERFS_POSIXLK_COUNT,
74096c
+                           GLUSTERFS_PARENT_ENTRYLK,
74096c
+                           GLUSTERFS_MULTIPLE_DOM_LK_CNT_REQUESTS,
74096c
+                           NULL};
74096c
+    static int reqs_size[] = {SLEN(GLUSTERFS_ENTRYLK_COUNT),
74096c
+                              SLEN(GLUSTERFS_INODELK_COUNT),
74096c
+                              SLEN(GLUSTERFS_INODELK_DOM_COUNT),
74096c
+                              SLEN(GLUSTERFS_POSIXLK_COUNT),
74096c
+                              SLEN(GLUSTERFS_PARENT_ENTRYLK),
74096c
+                              SLEN(GLUSTERFS_MULTIPLE_DOM_LK_CNT_REQUESTS),
74096c
+                              0};
74096c
     int i = 0;
74096c
 
74096c
     if (!xdata)
74096c
@@ -169,12 +176,22 @@ pl_has_xdata_requests(dict_t *xdata)
74096c
     return _gf_false;
74096c
 }
74096c
 
74096c
+static int
74096c
+dict_delete_domain_key(dict_t *dict, char *key, data_t *value, void *data)
74096c
+{
74096c
+    dict_del(dict, key);
74096c
+    return 0;
74096c
+}
74096c
+
74096c
 void
74096c
 pl_get_xdata_requests(pl_local_t *local, dict_t *xdata)
74096c
 {
74096c
     if (!local || !xdata)
74096c
         return;
74096c
 
74096c
+    GF_ASSERT(local->xdata == NULL);
74096c
+    local->xdata = dict_copy_with_ref(xdata, NULL);
74096c
+
74096c
     if (dict_get_sizen(xdata, GLUSTERFS_ENTRYLK_COUNT)) {
74096c
         local->entrylk_count_req = 1;
74096c
         dict_del_sizen(xdata, GLUSTERFS_ENTRYLK_COUNT);
74096c
@@ -183,6 +200,12 @@ pl_get_xdata_requests(pl_local_t *local, dict_t *xdata)
74096c
         local->inodelk_count_req = 1;
74096c
         dict_del_sizen(xdata, GLUSTERFS_INODELK_COUNT);
74096c
     }
74096c
+    if (dict_get_sizen(xdata, GLUSTERFS_MULTIPLE_DOM_LK_CNT_REQUESTS)) {
74096c
+        local->multiple_dom_lk_requests = 1;
74096c
+        dict_del_sizen(xdata, GLUSTERFS_MULTIPLE_DOM_LK_CNT_REQUESTS);
74096c
+        dict_foreach_fnmatch(xdata, GLUSTERFS_INODELK_DOM_PREFIX "*",
74096c
+                             dict_delete_domain_key, NULL);
74096c
+    }
74096c
 
74096c
     local->inodelk_dom_count_req = dict_get_sizen(xdata,
74096c
                                                   GLUSTERFS_INODELK_DOM_COUNT);
74096c
@@ -210,7 +233,7 @@ pl_needs_xdata_response(pl_local_t *local)
74096c
 
74096c
     if (local->parent_entrylk_req || local->entrylk_count_req ||
74096c
         local->inodelk_dom_count_req || local->inodelk_count_req ||
74096c
-        local->posixlk_count_req)
74096c
+        local->posixlk_count_req || local->multiple_dom_lk_requests)
74096c
         return _gf_true;
74096c
 
74096c
     return _gf_false;
74096c
@@ -411,6 +434,75 @@ pl_posixlk_xattr_fill(xlator_t *this, inode_t *inode, dict_t *dict,
74096c
 }
74096c
 
74096c
 void
74096c
+pl_inodelk_xattr_fill_each(xlator_t *this, inode_t *inode, dict_t *dict,
74096c
+                           char *domname, gf_boolean_t keep_max, char *key)
74096c
+{
74096c
+    int32_t count = 0;
74096c
+    int32_t maxcount = -1;
74096c
+    int ret = -1;
74096c
+
74096c
+    if (keep_max) {
74096c
+        ret = dict_get_int32(dict, key, &maxcount);
74096c
+        if (ret < 0)
74096c
+            gf_msg_debug(this->name, 0, " Failed to fetch the value for key %s",
74096c
+                         GLUSTERFS_INODELK_COUNT);
74096c
+    }
74096c
+    count = get_inodelk_count(this, inode, domname);
74096c
+    if (maxcount >= count)
74096c
+        return;
74096c
+
74096c
+    ret = dict_set_int32(dict, key, count);
74096c
+    if (ret < 0) {
74096c
+        gf_msg_debug(this->name, 0,
74096c
+                     "Failed to set count for "
74096c
+                     "key %s",
74096c
+                     key);
74096c
+    }
74096c
+
74096c
+    return;
74096c
+}
74096c
+
74096c
+static int
74096c
+pl_inodelk_xattr_fill_multiple(dict_t *this, char *key, data_t *value,
74096c
+                               void *data)
74096c
+{
74096c
+    multi_dom_lk_data *d = data;
74096c
+    char *tmp_key = NULL;
74096c
+    char *save_ptr = NULL;
74096c
+
74096c
+    tmp_key = gf_strdup(key);
74096c
+    strtok_r(tmp_key, ":", &save_ptr);
74096c
+    if (!*save_ptr) {
74096c
+        gf_msg(THIS->name, GF_LOG_ERROR, 0, EINVAL,
74096c
+               "Could not tokenize domain string from key %s", key);
74096c
+        return -1;
74096c
+    }
74096c
+
74096c
+    pl_inodelk_xattr_fill_each(d->this, d->inode, d->xdata_rsp, save_ptr,
74096c
+                               d->keep_max, key);
74096c
+    if (tmp_key)
74096c
+        GF_FREE(tmp_key);
74096c
+
74096c
+    return 0;
74096c
+}
74096c
+
74096c
+void
74096c
+pl_fill_multiple_dom_lk_requests(xlator_t *this, pl_local_t *local,
74096c
+                                 inode_t *inode, dict_t *dict,
74096c
+                                 gf_boolean_t keep_max)
74096c
+{
74096c
+    multi_dom_lk_data data;
74096c
+
74096c
+    data.this = this;
74096c
+    data.inode = inode;
74096c
+    data.xdata_rsp = dict;
74096c
+    data.keep_max = keep_max;
74096c
+
74096c
+    dict_foreach_fnmatch(local->xdata, GLUSTERFS_INODELK_DOM_PREFIX "*",
74096c
+                         pl_inodelk_xattr_fill_multiple, &data);
74096c
+}
74096c
+
74096c
+void
74096c
 pl_set_xdata_response(xlator_t *this, pl_local_t *local, inode_t *parent,
74096c
                       inode_t *inode, char *name, dict_t *xdata,
74096c
                       gf_boolean_t max_lock)
74096c
@@ -437,6 +529,9 @@ pl_set_xdata_response(xlator_t *this, pl_local_t *local, inode_t *parent,
74096c
 
74096c
     if (local->posixlk_count_req)
74096c
         pl_posixlk_xattr_fill(this, inode, xdata, max_lock);
74096c
+
74096c
+    if (local->multiple_dom_lk_requests)
74096c
+        pl_fill_multiple_dom_lk_requests(this, local, inode, xdata, max_lock);
74096c
 }
74096c
 
74096c
 /* Checks whether the region where fop is acting upon conflicts
74096c
@@ -773,9 +868,6 @@ pl_truncate_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
74096c
 {
74096c
     pl_local_t *local = frame->local;
74096c
 
74096c
-    if (local->xdata)
74096c
-        dict_unref(local->xdata);
74096c
-
74096c
     pl_track_io_fop_count(local, this, DECREMENT);
74096c
 
74096c
     if (local->op == GF_FOP_TRUNCATE)
74096c
@@ -932,9 +1024,6 @@ unwind:
74096c
                "ret: %d, error: %s",
74096c
                op_ret, strerror(op_errno));
74096c
 
74096c
-        if (local->xdata)
74096c
-            dict_unref(local->xdata);
74096c
-
74096c
         switch (local->op) {
74096c
             case GF_FOP_TRUNCATE:
74096c
                 PL_STACK_UNWIND(truncate, xdata, frame, op_ret, op_errno, buf,
74096c
-- 
74096c
1.8.3.1
74096c