e7a346
From dbf993f9c56c7ee995e9054b09c5552f88253bb3 Mon Sep 17 00:00:00 2001
e7a346
From: Ashish Pandey <aspandey@redhat.com>
e7a346
Date: Mon, 31 Jul 2017 12:45:21 +0530
e7a346
Subject: [PATCH 100/128] cluster/ec: Improve heal info command to handle
e7a346
 obvious cases
e7a346
e7a346
Problem:
e7a346
1 - If a brick is down and we see an index entry in
e7a346
.glusterfs/indices, we should show it in heal info
e7a346
output as it most certainly needs heal.
e7a346
e7a346
2 - The first problem is also not getting handled after
e7a346
ec_heal_inspect. Even if in ec_heal_inspect, lookup will
e7a346
mark need_heal as true, we don't handle it properly in
e7a346
ec_get_heal_info and continue with locked inspect which
e7a346
takes lot of time.
e7a346
e7a346
Solution:
e7a346
1 - In first case we need not to do any further invstigation.
e7a346
As soon as we see that a brick is down, we should say that
e7a346
this index entry needs heal for sure.
e7a346
e7a346
2 - In second case, if we have need_heal as _gf_true after
e7a346
ec_heal_inspect, we should show it as heal requires.
e7a346
e7a346
>Change-Id: Ibe7f9d7602cc0b382ba53bddaf75a2a2c3326aa6
e7a346
>BUG: 1476668
e7a346
>Signed-off-by: Ashish Pandey <aspandey@redhat.com>
e7a346
Upstream Patch: https://review.gluster.org/#/c/17923/
e7a346
e7a346
BUG: 1509833
e7a346
Change-Id: Ibe7f9d7602cc0b382ba53bddaf75a2a2c3326aa6
e7a346
Signed-off-by: Sunil Kumar Acharya <sheggodu@redhat.com>
e7a346
Reviewed-on: https://code.engineering.redhat.com/gerrit/125194
e7a346
Tested-by: RHGS Build Bot <nigelb@redhat.com>
e7a346
---
e7a346
 xlators/cluster/ec/src/ec-common.h |  2 +-
e7a346
 xlators/cluster/ec/src/ec-heal.c   | 54 ++++++++++++++++++++++----------------
e7a346
 xlators/cluster/ec/src/ec-types.h  |  9 +++++++
e7a346
 3 files changed, 41 insertions(+), 24 deletions(-)
e7a346
e7a346
diff --git a/xlators/cluster/ec/src/ec-common.h b/xlators/cluster/ec/src/ec-common.h
e7a346
index 0f7a252..dec81ca 100644
e7a346
--- a/xlators/cluster/ec/src/ec-common.h
e7a346
+++ b/xlators/cluster/ec/src/ec-common.h
e7a346
@@ -132,7 +132,7 @@ int32_t
e7a346
 ec_heal_inspect (call_frame_t *frame, ec_t *ec,
e7a346
                  inode_t *inode, unsigned char *locked_on,
e7a346
                  gf_boolean_t self_locked, gf_boolean_t thorough,
e7a346
-                 gf_boolean_t *need_heal);
e7a346
+                 ec_heal_need_t *need_heal);
e7a346
 int32_t
e7a346
 ec_get_heal_info (xlator_t *this, loc_t *loc, dict_t **dict);
e7a346
 #endif /* __EC_COMMON_H__ */
e7a346
diff --git a/xlators/cluster/ec/src/ec-heal.c b/xlators/cluster/ec/src/ec-heal.c
e7a346
index bc25015..fd8c902 100644
e7a346
--- a/xlators/cluster/ec/src/ec-heal.c
e7a346
+++ b/xlators/cluster/ec/src/ec-heal.c
e7a346
@@ -2421,9 +2421,9 @@ ec_heal_do (xlator_t *this, void *data, loc_t *loc, int32_t partial)
e7a346
         intptr_t      bad            = 0;
e7a346
         ec_fop_data_t *fop           = data;
e7a346
         gf_boolean_t  blocking       = _gf_false;
e7a346
-        gf_boolean_t  need_heal      = _gf_false;
e7a346
+        ec_heal_need_t  need_heal    = EC_HEAL_NONEED;
e7a346
         unsigned char *up_subvols    = NULL;
e7a346
-	char up_bricks[32];
e7a346
+        char up_bricks[32];
e7a346
 
e7a346
         ec = this->private;
e7a346
 
e7a346
@@ -2470,7 +2470,8 @@ ec_heal_do (xlator_t *this, void *data, loc_t *loc, int32_t partial)
e7a346
          * triggers heals periodically which need not be thorough*/
e7a346
         ec_heal_inspect (frame, ec, loc->inode, up_subvols, _gf_false,
e7a346
                          !ec->shd.iamshd, &need_heal);
e7a346
-        if (!need_heal) {
e7a346
+
e7a346
+        if (need_heal == EC_HEAL_NONEED)  {
e7a346
                 gf_msg (ec->xl->name, GF_LOG_DEBUG, 0,
e7a346
                         EC_MSG_HEAL_FAIL, "Heal is not required for : %s ",
e7a346
                         uuid_utoa(loc->gfid));
e7a346
@@ -2776,18 +2777,18 @@ out:
e7a346
 static int32_t
e7a346
 _need_heal_calculate (ec_t *ec, uint64_t *dirty, unsigned char *sources,
e7a346
                       gf_boolean_t self_locked, int32_t lock_count,
e7a346
-                      gf_boolean_t *need_heal)
e7a346
+                      ec_heal_need_t *need_heal)
e7a346
 {
e7a346
         int i = 0;
e7a346
         int source_count = 0;
e7a346
 
e7a346
         source_count = EC_COUNT (sources, ec->nodes);
e7a346
         if (source_count == ec->nodes) {
e7a346
-                *need_heal = _gf_false;
e7a346
+                *need_heal = EC_HEAL_NONEED;
e7a346
                 if (self_locked || lock_count == 0) {
e7a346
                         for (i = 0; i < ec->nodes; i++) {
e7a346
                                 if (dirty[i]) {
e7a346
-                                        *need_heal = _gf_true;
e7a346
+                                        *need_heal = EC_HEAL_MUST;
e7a346
                                         goto out;
e7a346
                                 }
e7a346
                         }
e7a346
@@ -2799,13 +2800,13 @@ _need_heal_calculate (ec_t *ec, uint64_t *dirty, unsigned char *sources,
e7a346
                                  * set and this indicates a problem in the
e7a346
                                  * inode.*/
e7a346
                                 if (dirty[i] > 1) {
e7a346
-                                        *need_heal = _gf_true;
e7a346
+                                        *need_heal = EC_HEAL_MUST;
e7a346
                                         goto out;
e7a346
                                 }
e7a346
                         }
e7a346
                 }
e7a346
         } else {
e7a346
-                *need_heal = _gf_true;
e7a346
+                *need_heal = EC_HEAL_MUST;
e7a346
         }
e7a346
 
e7a346
 out:
e7a346
@@ -2815,7 +2816,7 @@ out:
e7a346
 static int32_t
e7a346
 ec_need_metadata_heal (ec_t *ec, inode_t *inode, default_args_cbk_t *replies,
e7a346
                        int32_t lock_count, gf_boolean_t self_locked,
e7a346
-                       gf_boolean_t thorough, gf_boolean_t *need_heal)
e7a346
+                       gf_boolean_t thorough, ec_heal_need_t *need_heal)
e7a346
 {
e7a346
         uint64_t           *dirty         = NULL;
e7a346
         unsigned char      *sources       = NULL;
e7a346
@@ -2836,10 +2837,10 @@ ec_need_metadata_heal (ec_t *ec, inode_t *inode, default_args_cbk_t *replies,
e7a346
 
e7a346
         ret = _need_heal_calculate (ec, dirty, sources, self_locked, lock_count,
e7a346
                                     need_heal);
e7a346
-        if (ret == ec->nodes && !(*need_heal)) {
e7a346
+        if (ret == ec->nodes && *need_heal == EC_HEAL_NONEED) {
e7a346
                 for (i = 1; i < ec->nodes; i++) {
e7a346
                         if (meta_versions[i] != meta_versions[0]) {
e7a346
-                                *need_heal = _gf_true;
e7a346
+                                *need_heal = EC_HEAL_MUST;
e7a346
                                 goto out;
e7a346
                         }
e7a346
                 }
e7a346
@@ -2851,7 +2852,7 @@ out:
e7a346
 static int32_t
e7a346
 ec_need_data_heal (ec_t *ec, inode_t *inode, default_args_cbk_t *replies,
e7a346
                    int32_t lock_count, gf_boolean_t self_locked,
e7a346
-                   gf_boolean_t thorough, gf_boolean_t *need_heal)
e7a346
+                   gf_boolean_t thorough, ec_heal_need_t *need_heal)
e7a346
 {
e7a346
         uint64_t           *dirty         = NULL;
e7a346
         unsigned char      *sources       = NULL;
e7a346
@@ -2888,7 +2889,7 @@ out:
e7a346
 static int32_t
e7a346
 ec_need_entry_heal (ec_t *ec, inode_t *inode, default_args_cbk_t *replies,
e7a346
                     int32_t lock_count, gf_boolean_t self_locked,
e7a346
-                    gf_boolean_t thorough, gf_boolean_t *need_heal)
e7a346
+                    gf_boolean_t thorough, ec_heal_need_t *need_heal)
e7a346
 {
e7a346
         uint64_t           *dirty         = NULL;
e7a346
         unsigned char      *sources       = NULL;
e7a346
@@ -2916,7 +2917,7 @@ out:
e7a346
 static int32_t
e7a346
 ec_need_heal (ec_t *ec, inode_t *inode, default_args_cbk_t *replies,
e7a346
               int32_t lock_count, gf_boolean_t self_locked,
e7a346
-              gf_boolean_t thorough, gf_boolean_t *need_heal)
e7a346
+              gf_boolean_t thorough, ec_heal_need_t *need_heal)
e7a346
 {
e7a346
         int                ret            = 0;
e7a346
 
e7a346
@@ -2926,7 +2927,7 @@ ec_need_heal (ec_t *ec, inode_t *inode, default_args_cbk_t *replies,
e7a346
         if (ret < 0)
e7a346
                 goto out;
e7a346
 
e7a346
-        if (*need_heal)
e7a346
+        if (*need_heal == EC_HEAL_MUST)
e7a346
                 goto out;
e7a346
 
e7a346
         if (inode->ia_type == IA_IFREG) {
e7a346
@@ -2945,7 +2946,7 @@ int32_t
e7a346
 ec_heal_inspect (call_frame_t *frame, ec_t *ec,
e7a346
                  inode_t *inode, unsigned char *locked_on,
e7a346
                  gf_boolean_t self_locked, gf_boolean_t thorough,
e7a346
-                 gf_boolean_t *need_heal)
e7a346
+                 ec_heal_need_t *need_heal)
e7a346
 {
e7a346
         loc_t              loc           = {0};
e7a346
         int                i             = 0;
e7a346
@@ -2989,7 +2990,7 @@ ec_heal_inspect (call_frame_t *frame, ec_t *ec,
e7a346
 
e7a346
         if (ret != ec->nodes) {
e7a346
                 ret = ec->nodes;
e7a346
-                *need_heal = _gf_true;
e7a346
+                *need_heal = EC_HEAL_MUST;
e7a346
                 goto out;
e7a346
         }
e7a346
 
e7a346
@@ -3009,6 +3010,9 @@ need_heal:
e7a346
         ret = ec_need_heal (ec, inode, replies, lock_count,
e7a346
                             self_locked, thorough, need_heal);
e7a346
 
e7a346
+        if (!self_locked && *need_heal == EC_HEAL_MUST) {
e7a346
+                *need_heal = EC_HEAL_MAYBE;
e7a346
+        }
e7a346
 out:
e7a346
         cluster_replies_wipe (replies, ec->nodes);
e7a346
         loc_wipe (&loc;;
e7a346
@@ -3020,7 +3024,7 @@ out:
e7a346
 
e7a346
 int32_t
e7a346
 ec_heal_locked_inspect (call_frame_t *frame, ec_t *ec, inode_t *inode,
e7a346
-                        gf_boolean_t *need_heal)
e7a346
+                        ec_heal_need_t *need_heal)
e7a346
 {
e7a346
         unsigned char      *locked_on  = NULL;
e7a346
         unsigned char      *up_subvols = NULL;
e7a346
@@ -3038,7 +3042,7 @@ ec_heal_locked_inspect (call_frame_t *frame, ec_t *ec, inode_t *inode,
e7a346
                                replies, locked_on, frame, ec->xl,
e7a346
                                ec->xl->name, inode, 0, 0);
e7a346
         if (ret != ec->nodes) {
e7a346
-                *need_heal = _gf_true;
e7a346
+                *need_heal = EC_HEAL_MUST;
e7a346
                 goto unlock;
e7a346
         }
e7a346
         ret = ec_heal_inspect (frame, ec, inode, locked_on, _gf_true, _gf_true,
e7a346
@@ -3055,7 +3059,7 @@ int32_t
e7a346
 ec_get_heal_info (xlator_t *this, loc_t *entry_loc, dict_t **dict_rsp)
e7a346
 {
e7a346
         int             ret             = -ENOMEM;
e7a346
-        gf_boolean_t    need_heal       = _gf_false;
e7a346
+        ec_heal_need_t  need_heal       = EC_HEAL_NONEED;
e7a346
         call_frame_t    *frame          = NULL;
e7a346
         ec_t            *ec             = NULL;
e7a346
         unsigned char   *up_subvols     = NULL;
e7a346
@@ -3068,6 +3072,10 @@ ec_get_heal_info (xlator_t *this, loc_t *entry_loc, dict_t **dict_rsp)
e7a346
         up_subvols = alloca0(ec->nodes);
e7a346
         ec_mask_to_char_array (ec->xl_up, up_subvols, ec->nodes);
e7a346
 
e7a346
+        if (EC_COUNT (up_subvols, ec->nodes) != ec->nodes) {
e7a346
+                need_heal = EC_HEAL_MUST;
e7a346
+                goto set_heal;
e7a346
+        }
e7a346
         frame = create_frame (this, this->ctx->pool);
e7a346
         if (!frame) {
e7a346
                 goto out;
e7a346
@@ -3092,16 +3100,16 @@ ec_get_heal_info (xlator_t *this, loc_t *entry_loc, dict_t **dict_rsp)
e7a346
 
e7a346
         ret = ec_heal_inspect (frame, ec, loc.inode, up_subvols, _gf_false,
e7a346
                                _gf_false, &need_heal);
e7a346
-        if (ret == ec->nodes && !need_heal) {
e7a346
+        if (ret == ec->nodes && need_heal == EC_HEAL_NONEED) {
e7a346
                 goto set_heal;
e7a346
         }
e7a346
-        need_heal = _gf_false;
e7a346
+        need_heal = EC_HEAL_NONEED;
e7a346
         ret = ec_heal_locked_inspect (frame, ec, loc.inode,
e7a346
                                       &need_heal);
e7a346
         if (ret < 0)
e7a346
                 goto out;
e7a346
 set_heal:
e7a346
-        if (need_heal) {
e7a346
+        if (need_heal == EC_HEAL_MUST) {
e7a346
                 ret =  ec_set_heal_info (dict_rsp, "heal");
e7a346
         } else {
e7a346
                 ret =  ec_set_heal_info (dict_rsp, "no-heal");
e7a346
diff --git a/xlators/cluster/ec/src/ec-types.h b/xlators/cluster/ec/src/ec-types.h
e7a346
index 354b4ed..a891ff5 100644
e7a346
--- a/xlators/cluster/ec/src/ec-types.h
e7a346
+++ b/xlators/cluster/ec/src/ec-types.h
e7a346
@@ -17,6 +17,9 @@
e7a346
 
e7a346
 #define EC_GF_MAX_REGS 16
e7a346
 
e7a346
+enum _ec_heal_need;
e7a346
+typedef enum _ec_heal_need ec_heal_need_t;
e7a346
+
e7a346
 enum _ec_read_policy;
e7a346
 typedef enum _ec_read_policy ec_read_policy_t;
e7a346
 
e7a346
@@ -115,6 +118,12 @@ enum _ec_read_policy {
e7a346
         EC_READ_POLICY_MAX
e7a346
 };
e7a346
 
e7a346
+enum _ec_heal_need {
e7a346
+        EC_HEAL_NONEED,
e7a346
+        EC_HEAL_MAYBE,
e7a346
+        EC_HEAL_MUST
e7a346
+};
e7a346
+
e7a346
 struct _ec_config {
e7a346
     uint32_t version;
e7a346
     uint8_t  algorithm;
e7a346
-- 
e7a346
1.8.3.1
e7a346