e7a346
From 6c176a6f9743ab0518619f784a1fc5ac9562b991 Mon Sep 17 00:00:00 2001
e7a346
From: Pranith Kumar K <pkarampu@redhat.com>
e7a346
Date: Tue, 18 Jul 2017 18:39:01 +0530
e7a346
Subject: [PATCH 076/128] cluster/ec: Handle parallel get_size_version
e7a346
e7a346
upstream patch: https://review.gluster.org/#/c/17820/
e7a346
e7a346
>Updates #251
e7a346
>Change-Id: I6244014dbc90af3239d63d75a064ae22ec12a054
e7a346
>Signed-off-by: Pranith Kumar K <pkarampu@redhat.com>
e7a346
e7a346
BUG: 1459101
e7a346
Change-Id: I6244014dbc90af3239d63d75a064ae22ec12a054
e7a346
Signed-off-by: Sunil Kumar Acharya <sheggodu@redhat.com>
e7a346
Reviewed-on: https://code.engineering.redhat.com/gerrit/123551
e7a346
Tested-by: RHGS Build Bot <nigelb@redhat.com>
e7a346
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
e7a346
Reviewed-by: Ashish Pandey <aspandey@redhat.com>
e7a346
---
e7a346
 xlators/cluster/ec/src/ec-common.c | 151 +++++++++++++++++++++++--------------
e7a346
 xlators/cluster/ec/src/ec-common.h |   8 +-
e7a346
 xlators/cluster/ec/src/ec-types.h  |   3 +-
e7a346
 3 files changed, 103 insertions(+), 59 deletions(-)
e7a346
e7a346
diff --git a/xlators/cluster/ec/src/ec-common.c b/xlators/cluster/ec/src/ec-common.c
e7a346
index 732d422..6963907 100644
e7a346
--- a/xlators/cluster/ec/src/ec-common.c
e7a346
+++ b/xlators/cluster/ec/src/ec-common.c
e7a346
@@ -21,6 +21,10 @@
e7a346
 #include "ec.h"
e7a346
 #include "ec-messages.h"
e7a346
 
e7a346
+#define EC_XATTROP_ALL_WAITING_FLAGS (EC_FLAG_WAITING_XATTROP |\
e7a346
+                                   EC_FLAG_WAITING_DATA_DIRTY |\
e7a346
+                                   EC_FLAG_WAITING_METADATA_DIRTY)
e7a346
+
e7a346
 uint32_t
e7a346
 ec_select_first_by_read_policy (ec_t *ec, ec_fop_data_t *fop)
e7a346
 {
e7a346
@@ -882,11 +886,11 @@ void ec_lock_prepare_fd(ec_fop_data_t *fop, fd_t *fd, uint32_t flags)
e7a346
 }
e7a346
 
e7a346
 gf_boolean_t
e7a346
-ec_config_check (ec_fop_data_t *fop, ec_config_t *config)
e7a346
+ec_config_check (xlator_t *xl, ec_config_t *config)
e7a346
 {
e7a346
     ec_t *ec;
e7a346
 
e7a346
-    ec = fop->xl->private;
e7a346
+    ec = xl->private;
e7a346
     if ((config->version != EC_CONFIG_VERSION) ||
e7a346
         (config->algorithm != EC_CONFIG_ALGORITHM) ||
e7a346
         (config->gf_word_size != EC_GF_BITS) ||
e7a346
@@ -911,11 +915,11 @@ ec_config_check (ec_fop_data_t *fop, ec_config_t *config)
e7a346
             !ec_is_power_of_2(config->gf_word_size) ||
e7a346
             ((config->chunk_size * 8) % (config->gf_word_size * data_bricks)
e7a346
                                                                        != 0)) {
e7a346
-            gf_msg (fop->xl->name, GF_LOG_ERROR, EINVAL,
e7a346
+            gf_msg (xl->name, GF_LOG_ERROR, EINVAL,
e7a346
                     EC_MSG_INVALID_CONFIG,
e7a346
                     "Invalid or corrupted config");
e7a346
         } else {
e7a346
-            gf_msg (fop->xl->name, GF_LOG_ERROR, EINVAL,
e7a346
+            gf_msg (xl->name, GF_LOG_ERROR, EINVAL,
e7a346
                     EC_MSG_INVALID_CONFIG,
e7a346
                     "Unsupported config "
e7a346
                     "(V=%u, A=%u, W=%u, "
e7a346
@@ -962,24 +966,28 @@ ec_prepare_update_cbk (call_frame_t *frame, void *cookie,
e7a346
 {
e7a346
     struct list_head list;
e7a346
     ec_fop_data_t *fop = cookie, *parent, *tmp;
e7a346
-    ec_lock_link_t *link = fop->data;
e7a346
+    ec_lock_link_t *parent_link = fop->data;
e7a346
+    ec_lock_link_t *link = NULL;
e7a346
     ec_lock_t *lock = NULL;
e7a346
     ec_inode_t *ctx;
e7a346
     gf_boolean_t release = _gf_false;
e7a346
+    uint64_t waiting_flags = 0;
e7a346
+    uint64_t dirty[EC_VERSION_SIZE] = {0, 0};
e7a346
 
e7a346
-    lock = link->lock;
e7a346
-    parent = link->fop;
e7a346
+    lock = parent_link->lock;
e7a346
+    parent = parent_link->fop;
e7a346
     ctx = lock->ctx;
e7a346
 
e7a346
     INIT_LIST_HEAD(&list);
e7a346
+    waiting_flags = parent_link->waiting_flags & EC_XATTROP_ALL_WAITING_FLAGS;
e7a346
 
e7a346
     LOCK(&lock->loc.inode->lock);
e7a346
 
e7a346
     list_for_each_entry(link, &lock->owners, owner_list) {
e7a346
-        if ((link->fop->flags & EC_FLAG_WAITING_XATTROP) != 0) {
e7a346
-            link->fop->flags ^= EC_FLAG_WAITING_XATTROP;
e7a346
-
e7a346
-            list_add_tail(&link->fop->cbk_list, &list);
e7a346
+        if ((link->waiting_flags & waiting_flags) != 0) {
e7a346
+            link->waiting_flags ^= (link->waiting_flags & waiting_flags);
e7a346
+            if ((link->waiting_flags & EC_XATTROP_ALL_WAITING_FLAGS) == 0)
e7a346
+                    list_add_tail(&link->fop->cbk_list, &list);
e7a346
         }
e7a346
     }
e7a346
 
e7a346
@@ -991,8 +999,7 @@ ec_prepare_update_cbk (call_frame_t *frame, void *cookie,
e7a346
         goto unlock;
e7a346
     }
e7a346
 
e7a346
-    if (parent->flags & EC_FLAG_QUERY_METADATA) {
e7a346
-            parent->flags ^= EC_FLAG_QUERY_METADATA;
e7a346
+    if (waiting_flags & EC_FLAG_WAITING_XATTROP) {
e7a346
             op_errno = -ec_dict_del_array(dict, EC_XATTR_VERSION,
e7a346
                                           ctx->pre_version,
e7a346
                                           EC_VERSION_SIZE);
e7a346
@@ -1036,7 +1043,7 @@ ec_prepare_update_cbk (call_frame_t *frame, void *cookie,
e7a346
                         goto unlock;
e7a346
                     }
e7a346
                 } else {
e7a346
-                    if (!ec_config_check(parent, &ctx->config)) {
e7a346
+                    if (!ec_config_check(parent->xl, &ctx->config)) {
e7a346
                         gf_msg (this->name, GF_LOG_ERROR, EINVAL,
e7a346
                                 EC_MSG_CONFIG_XATTR_INVALID,
e7a346
                                 "Invalid config xattr");
e7a346
@@ -1051,12 +1058,22 @@ ec_prepare_update_cbk (call_frame_t *frame, void *cookie,
e7a346
             ctx->have_info = _gf_true;
e7a346
     }
e7a346
 
e7a346
-    ec_set_dirty_flag (fop->data, ctx, ctx->dirty);
e7a346
+    ec_set_dirty_flag (fop->data, ctx, dirty);
e7a346
+    if (dirty[EC_METADATA_TXN] &&
e7a346
+        (waiting_flags & EC_FLAG_WAITING_METADATA_DIRTY)) {
e7a346
+            GF_ASSERT (!ctx->dirty[EC_METADATA_TXN]);
e7a346
+            ctx->dirty[EC_METADATA_TXN] = 1;
e7a346
+    }
e7a346
+
e7a346
+    if (dirty[EC_DATA_TXN] &&
e7a346
+        (waiting_flags & EC_FLAG_WAITING_DATA_DIRTY)) {
e7a346
+            GF_ASSERT (!ctx->dirty[EC_DATA_TXN]);
e7a346
+            ctx->dirty[EC_DATA_TXN] = 1;
e7a346
+    }
e7a346
     op_errno = 0;
e7a346
 unlock:
e7a346
-    lock->getting_xattr = _gf_false;
e7a346
 
e7a346
-    UNLOCK(&lock->loc.inode->lock);
e7a346
+    lock->waiting_flags ^= waiting_flags;
e7a346
 
e7a346
     if (op_errno == 0) {
e7a346
         /* If the fop fails on any of the good bricks, it is important to mark
e7a346
@@ -1066,33 +1083,24 @@ unlock:
e7a346
                 release = _gf_true;
e7a346
         }
e7a346
 
e7a346
-        /* lock->release is a critical field that is checked and modified most
e7a346
-         * of the time inside a locked region. This use here is safe because we
e7a346
-         * are in a modifying fop and we currently don't allow two modifying
e7a346
-         * fops to be processed concurrently, so no one else could be checking
e7a346
-         * or modifying it.*/
e7a346
-        if (link->update[0] && !link->dirty[0]) {
e7a346
+        if (parent_link->update[0] && !parent_link->dirty[0]) {
e7a346
                 lock->release |= release;
e7a346
         }
e7a346
 
e7a346
-        if (link->update[1] && !link->dirty[1]) {
e7a346
+        if (parent_link->update[1] && !parent_link->dirty[1]) {
e7a346
                 lock->release |= release;
e7a346
         }
e7a346
 
e7a346
         /* We don't allow the main fop to be executed on bricks that have not
e7a346
          * succeeded the initial xattrop. */
e7a346
-        parent->mask &= fop->good;
e7a346
         ec_lock_update_good (lock, fop);
e7a346
 
e7a346
         /*As of now only data healing marks bricks as healing*/
e7a346
         lock->healing |= fop->healing;
e7a346
-        if (ec_is_data_fop (parent->id)) {
e7a346
-            parent->healing |= fop->healing;
e7a346
-        }
e7a346
-    } else {
e7a346
-        ec_fop_set_error(parent, op_errno);
e7a346
     }
e7a346
 
e7a346
+    UNLOCK(&lock->loc.inode->lock);
e7a346
+
e7a346
     while (!list_empty(&list)) {
e7a346
         tmp = list_entry(list.next, ec_fop_data_t, cbk_list);
e7a346
         list_del_init(&tmp->cbk_list);
e7a346
@@ -1104,16 +1112,50 @@ unlock:
e7a346
             if (ec_is_data_fop (tmp->id)) {
e7a346
                 tmp->healing |= fop->healing;
e7a346
             }
e7a346
-        } else {
e7a346
-            ec_fop_set_error(tmp, op_errno);
e7a346
         }
e7a346
 
e7a346
-        ec_resume(tmp, 0);
e7a346
+        ec_resume(tmp, op_errno);
e7a346
     }
e7a346
 
e7a346
     return 0;
e7a346
 }
e7a346
 
e7a346
+static uint64_t
e7a346
+ec_set_xattrop_flags_and_params (ec_lock_t *lock, ec_lock_link_t *link,
e7a346
+                                 uint64_t *dirty)
e7a346
+{
e7a346
+        uint64_t        oldflags = 0;
e7a346
+        uint64_t        newflags = 0;
e7a346
+        ec_inode_t *ctx     = lock->ctx;
e7a346
+
e7a346
+        oldflags = lock->waiting_flags & EC_XATTROP_ALL_WAITING_FLAGS;
e7a346
+
e7a346
+        if (lock->query && !ctx->have_info) {
e7a346
+                lock->waiting_flags |= EC_FLAG_WAITING_XATTROP;
e7a346
+                link->waiting_flags |= EC_FLAG_WAITING_XATTROP;
e7a346
+        }
e7a346
+
e7a346
+        if (dirty[EC_DATA_TXN]) {
e7a346
+                if (oldflags & EC_FLAG_WAITING_DATA_DIRTY) {
e7a346
+                        dirty[EC_DATA_TXN] = 0;
e7a346
+                } else {
e7a346
+                        lock->waiting_flags |= EC_FLAG_WAITING_DATA_DIRTY;
e7a346
+                }
e7a346
+                link->waiting_flags |= EC_FLAG_WAITING_DATA_DIRTY;
e7a346
+        }
e7a346
+
e7a346
+        if (dirty[EC_METADATA_TXN]) {
e7a346
+                if (oldflags & EC_FLAG_WAITING_METADATA_DIRTY) {
e7a346
+                        dirty[EC_METADATA_TXN] = 0;
e7a346
+                } else {
e7a346
+                        lock->waiting_flags |= EC_FLAG_WAITING_METADATA_DIRTY;
e7a346
+                }
e7a346
+                link->waiting_flags |= EC_FLAG_WAITING_METADATA_DIRTY;
e7a346
+        }
e7a346
+        newflags = lock->waiting_flags & EC_XATTROP_ALL_WAITING_FLAGS;
e7a346
+        return oldflags ^ newflags;
e7a346
+}
e7a346
+
e7a346
 void ec_get_size_version(ec_lock_link_t *link)
e7a346
 {
e7a346
     loc_t loc;
e7a346
@@ -1124,7 +1166,6 @@ void ec_get_size_version(ec_lock_link_t *link)
e7a346
     dict_t *xdata = NULL;
e7a346
     ec_t   *ec = NULL;
e7a346
     int32_t error = 0;
e7a346
-    gf_boolean_t getting_xattr;
e7a346
     gf_boolean_t set_dirty = _gf_false;
e7a346
     uint64_t allzero[EC_VERSION_SIZE] = {0, 0};
e7a346
     uint64_t dirty[EC_VERSION_SIZE] = {0, 0};
e7a346
@@ -1132,6 +1173,7 @@ void ec_get_size_version(ec_lock_link_t *link)
e7a346
     ctx = lock->ctx;
e7a346
     fop = link->fop;
e7a346
     ec  = fop->xl->private;
e7a346
+    uint64_t changed_flags = 0;
e7a346
 
e7a346
     if (ec->optimistic_changelog &&
e7a346
         !(ec->node_mask & ~link->lock->good_mask) && !ec_is_data_fop (fop->id))
e7a346
@@ -1159,19 +1201,20 @@ void ec_get_size_version(ec_lock_link_t *link)
e7a346
 
e7a346
     LOCK(&lock->loc.inode->lock);
e7a346
 
e7a346
-    getting_xattr = lock->getting_xattr;
e7a346
-    lock->getting_xattr = _gf_true;
e7a346
-    if (getting_xattr) {
e7a346
-        fop->flags |= EC_FLAG_WAITING_XATTROP;
e7a346
-
e7a346
-        ec_sleep(fop);
e7a346
+    changed_flags = ec_set_xattrop_flags_and_params (lock, link, dirty);
e7a346
+    if (link->waiting_flags) {
e7a346
+            /* This fop needs to wait until all its flags are cleared which
e7a346
+             * potentially can be cleared by other xattrops that are already
e7a346
+             * wound*/
e7a346
+            ec_sleep(fop);
e7a346
+    } else {
e7a346
+            GF_ASSERT (!changed_flags);
e7a346
     }
e7a346
 
e7a346
     UNLOCK(&lock->loc.inode->lock);
e7a346
 
e7a346
-    if (getting_xattr) {
e7a346
+    if (!changed_flags)
e7a346
         goto out;
e7a346
-    }
e7a346
 
e7a346
     dict = dict_new();
e7a346
     if (dict == NULL) {
e7a346
@@ -1179,17 +1222,7 @@ void ec_get_size_version(ec_lock_link_t *link)
e7a346
         goto out;
e7a346
     }
e7a346
 
e7a346
-    if (lock->loc.inode->ia_type == IA_IFREG ||
e7a346
-        lock->loc.inode->ia_type == IA_INVAL) {
e7a346
-            xdata = dict_new();
e7a346
-            if (xdata == NULL || dict_set_int32 (xdata, GF_GET_SIZE, 1)) {
e7a346
-                error = -ENOMEM;
e7a346
-                goto out;
e7a346
-            }
e7a346
-    }
e7a346
-
e7a346
-    if (lock->query && !ctx->have_info) {
e7a346
-            fop->flags |= EC_FLAG_QUERY_METADATA;
e7a346
+    if (changed_flags & EC_FLAG_WAITING_XATTROP) {
e7a346
             /* Once we know that an xattrop will be needed,
e7a346
              * we try to get all available information in a
e7a346
              * single call. */
e7a346
@@ -1208,9 +1241,17 @@ void ec_get_size_version(ec_lock_link_t *link)
e7a346
                 if (error != 0) {
e7a346
                     goto out;
e7a346
                 }
e7a346
+
e7a346
+                xdata = dict_new();
e7a346
+                if (xdata == NULL || dict_set_int32 (xdata, GF_GET_SIZE, 1)) {
e7a346
+                    error = -ENOMEM;
e7a346
+                    goto out;
e7a346
+                }
e7a346
+
e7a346
             }
e7a346
     }
e7a346
-    if (set_dirty) {
e7a346
+
e7a346
+    if (memcmp (allzero, dirty, sizeof (allzero))) {
e7a346
             error = ec_dict_set_array(dict, EC_XATTR_DIRTY, dirty,
e7a346
                                       EC_VERSION_SIZE);
e7a346
             if (error != 0) {
e7a346
@@ -1943,7 +1984,7 @@ int32_t ec_update_size_version_done(call_frame_t * frame, void * cookie,
e7a346
             ctx->have_size = _gf_true;
e7a346
         }
e7a346
         if ((ec_dict_del_config(xdata, EC_XATTR_CONFIG, &ctx->config) == 0) &&
e7a346
-            ec_config_check(fop->parent, &ctx->config)) {
e7a346
+            ec_config_check(fop->xl, &ctx->config)) {
e7a346
             ctx->have_config = _gf_true;
e7a346
         }
e7a346
 
e7a346
diff --git a/xlators/cluster/ec/src/ec-common.h b/xlators/cluster/ec/src/ec-common.h
e7a346
index a03a590..8f5d20a 100644
e7a346
--- a/xlators/cluster/ec/src/ec-common.h
e7a346
+++ b/xlators/cluster/ec/src/ec-common.h
e7a346
@@ -27,9 +27,11 @@ typedef enum {
e7a346
 
e7a346
 #define EC_CONFIG_ALGORITHM 0
e7a346
 
e7a346
-#define EC_FLAG_LOCK_SHARED       0x0001
e7a346
-#define EC_FLAG_WAITING_XATTROP   0x0002
e7a346
-#define EC_FLAG_QUERY_METADATA    0x0004
e7a346
+#define EC_FLAG_LOCK_SHARED             0x0001
e7a346
+
e7a346
+#define EC_FLAG_WAITING_XATTROP         0x0001
e7a346
+#define EC_FLAG_WAITING_DATA_DIRTY      0x0002
e7a346
+#define EC_FLAG_WAITING_METADATA_DIRTY  0x0004
e7a346
 
e7a346
 #define EC_SELFHEAL_BIT 62
e7a346
 
e7a346
diff --git a/xlators/cluster/ec/src/ec-types.h b/xlators/cluster/ec/src/ec-types.h
e7a346
index 3e93a1a..5601f96 100644
e7a346
--- a/xlators/cluster/ec/src/ec-types.h
e7a346
+++ b/xlators/cluster/ec/src/ec-types.h
e7a346
@@ -227,8 +227,8 @@ struct _ec_lock {
e7a346
     uintptr_t          healing;
e7a346
     uint32_t           refs_owners;  /* Refs for fops owning the lock */
e7a346
     uint32_t           refs_pending; /* Refs assigned to fops being prepared */
e7a346
+    uint32_t           waiting_flags; /*Track xattrop/dirty marking*/
e7a346
     gf_boolean_t       acquired;
e7a346
-    gf_boolean_t       getting_xattr;
e7a346
     gf_boolean_t       unlock_now;
e7a346
     gf_boolean_t       release;
e7a346
     gf_boolean_t       query;
e7a346
@@ -250,6 +250,7 @@ struct _ec_lock_link {
e7a346
     gf_boolean_t      optimistic_changelog;
e7a346
     loc_t            *base;
e7a346
     uint64_t          size;
e7a346
+    uint32_t          waiting_flags;
e7a346
 };
e7a346
 
e7a346
 struct _ec_fop_data {
e7a346
-- 
e7a346
1.8.3.1
e7a346