e7a346
From 787e1e865ba4b9680c95ae78a11a4d84714cc9a3 Mon Sep 17 00:00:00 2001
e7a346
From: Ravishankar N <ravishankar@redhat.com>
e7a346
Date: Wed, 7 Mar 2018 11:03:50 +0530
e7a346
Subject: [PATCH 176/180] glusterd: volume get fixes for client-io-threads &
e7a346
 quorum-type
e7a346
e7a346
Backport of: https://review.gluster.org/#/c/19567/
e7a346
e7a346
1. If a replica volume created on glusterfs-3.8 was upgraded to
e7a346
glusterfs-3.12, `gluster vol get volname client-io-threads` displayed
e7a346
'on' even though it wasn't and the xlator wasn't loaded on
e7a346
the client-graph. This was due to removing certain checks in
e7a346
glusterd_get_default_val_for_volopt as a part of commit
e7a346
47604fad4c2a3951077e41e0c007ceb979bb2c24. Fix it.
e7a346
e7a346
2. Also, as a part of op-version bump-up, client-io-threads was being
e7a346
loaded on the clients  during volfile regeneration. Prevent it.
e7a346
e7a346
3. AFR assumes quorum-type to be auto in newly created replic 3 (odd
e7a346
replica in general) volumes but `gluster vol get quorum-type` displays
e7a346
'none'. Fix it.
e7a346
e7a346
Change-Id: I4a6099e50f2f10f2bd76f304b1e3bc0795e07a9d
e7a346
BUG: 1543068
e7a346
Signed-off-by: Ravishankar N <ravishankar@redhat.com>
e7a346
Reviewed-on: https://code.engineering.redhat.com/gerrit/131964
e7a346
Tested-by: RHGS Build Bot <nigelb@redhat.com>
e7a346
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
e7a346
---
e7a346
 xlators/mgmt/glusterd/src/glusterd-handler.c |  6 +++---
e7a346
 xlators/mgmt/glusterd/src/glusterd-op-sm.c   | 13 +++++++++++++
e7a346
 xlators/mgmt/glusterd/src/glusterd-utils.c   | 27 ++++++++++++++++++++++++++-
e7a346
 xlators/mgmt/glusterd/src/glusterd-utils.h   |  3 ++-
e7a346
 xlators/mgmt/glusterd/src/glusterd-volgen.c  |  8 +++++++-
e7a346
 5 files changed, 51 insertions(+), 6 deletions(-)
e7a346
e7a346
diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c
e7a346
index 8fc665d..cf280a7 100644
e7a346
--- a/xlators/mgmt/glusterd/src/glusterd-handler.c
e7a346
+++ b/xlators/mgmt/glusterd/src/glusterd-handler.c
e7a346
@@ -4913,7 +4913,7 @@ glusterd_get_volume_opts (rpcsvc_request_t *req, dict_t *dict)
e7a346
                                                                (dict,
e7a346
                                                                 _gf_false,
e7a346
                                                                 key, orig_key,
e7a346
-                                                                volinfo->dict,
e7a346
+                                                                volinfo,
e7a346
                                                                 &rsp.op_errstr);
e7a346
                                         if (ret && !rsp.op_errstr) {
e7a346
                                                 snprintf (err_str,
e7a346
@@ -4939,7 +4939,7 @@ glusterd_get_volume_opts (rpcsvc_request_t *req, dict_t *dict)
e7a346
         } else {
e7a346
                 /* Handle the "all" volume option request */
e7a346
                 ret = glusterd_get_default_val_for_volopt (dict, _gf_true, NULL,
e7a346
-                                                           NULL, volinfo->dict,
e7a346
+                                                           NULL, volinfo,
e7a346
                                                            &rsp.op_errstr);
e7a346
                 if (ret && !rsp.op_errstr) {
e7a346
                         snprintf (err_str, sizeof(err_str),
e7a346
@@ -5530,7 +5530,7 @@ glusterd_get_state (rpcsvc_request_t *req, dict_t *dict)
e7a346
                         vol_all_opts = dict_new ();
e7a346
 
e7a346
                         ret = glusterd_get_default_val_for_volopt (vol_all_opts,
e7a346
-                                        _gf_true, NULL, NULL, volinfo->dict,
e7a346
+                                        _gf_true, NULL, NULL, volinfo,
e7a346
                                         &rsp.op_errstr);
e7a346
                         if (ret) {
e7a346
                                 gf_msg (this->name, GF_LOG_ERROR, 0,
e7a346
diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
e7a346
index 0cf76dd..0a21e02 100644
e7a346
--- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c
e7a346
+++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
e7a346
@@ -2542,6 +2542,15 @@ out:
e7a346
         return ret;
e7a346
 }
e7a346
 
e7a346
+/* This is a hack to prevent client-io-threads from being loaded in the graph
e7a346
+ * when the cluster-op-version is bumped up from 3.8.x to 3.13.x. The key is
e7a346
+ * deleted subsequently in glusterd_create_volfiles(). */
e7a346
+static int
e7a346
+glusterd_dict_set_skip_cliot_key (glusterd_volinfo_t *volinfo)
e7a346
+{
e7a346
+        return  dict_set_int32 (volinfo->dict, "skip-CLIOT", 1);
e7a346
+}
e7a346
+
e7a346
 static int
e7a346
 glusterd_op_set_all_volume_options (xlator_t *this, dict_t *dict,
e7a346
                                     char **op_errstr)
e7a346
@@ -2633,6 +2642,10 @@ glusterd_op_set_all_volume_options (xlator_t *this, dict_t *dict,
e7a346
                                                 (volinfo, &start_nfs_svc);
e7a346
                                 if (ret)
e7a346
                                         goto out;
e7a346
+
e7a346
+                                if (glusterd_dict_set_skip_cliot_key (volinfo))
e7a346
+                                        goto out;
e7a346
+
e7a346
                                 if (!volinfo->is_snap_volume) {
e7a346
                                         svc = &(volinfo->snapd.svc);
e7a346
                                         ret = svc->manager (svc, volinfo,
e7a346
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
e7a346
index 9a67cfd..49605cc 100644
e7a346
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
e7a346
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
e7a346
@@ -12842,10 +12842,30 @@ out:
e7a346
         return ret;
e7a346
 }
e7a346
 
e7a346
+char *
e7a346
+glusterd_get_option_value (glusterd_volinfo_t *volinfo, char *key)
e7a346
+{
e7a346
+        char *value = NULL;
e7a346
+
e7a346
+        if (!glusterd_is_volume_replicate(volinfo))
e7a346
+                goto ret;
e7a346
+
e7a346
+        if (!strcmp (key, "performance.client-io-threads")) {
e7a346
+                value = "off";
e7a346
+        } else if (!strcmp (key, "cluster.quorum-type")) {
e7a346
+                if (volinfo->replica_count%2) {
e7a346
+                        value = "auto";
e7a346
+                }
e7a346
+        }
e7a346
+ret:
e7a346
+        return value;
e7a346
+}
e7a346
+
e7a346
 int
e7a346
 glusterd_get_default_val_for_volopt (dict_t *ctx, gf_boolean_t all_opts,
e7a346
                                      char *input_key, char *orig_key,
e7a346
-                                     dict_t *vol_dict, char **op_errstr)
e7a346
+                                     glusterd_volinfo_t *volinfo,
e7a346
+                                     char **op_errstr)
e7a346
 {
e7a346
         struct volopt_map_entry *vme = NULL;
e7a346
         int                      ret = -1;
e7a346
@@ -12856,6 +12876,7 @@ glusterd_get_default_val_for_volopt (dict_t *ctx, gf_boolean_t all_opts,
e7a346
         char                     dict_key[50] = {0,};
e7a346
         gf_boolean_t             key_found = _gf_false;
e7a346
         glusterd_conf_t         *priv = NULL;
e7a346
+        dict_t                  *vol_dict = NULL;
e7a346
 
e7a346
         this = THIS;
e7a346
         GF_ASSERT (this);
e7a346
@@ -12863,6 +12884,7 @@ glusterd_get_default_val_for_volopt (dict_t *ctx, gf_boolean_t all_opts,
e7a346
         priv = this->private;
e7a346
         GF_VALIDATE_OR_GOTO (this->name, priv, out);
e7a346
 
e7a346
+        vol_dict = volinfo->dict;
e7a346
         GF_VALIDATE_OR_GOTO (this->name, vol_dict, out);
e7a346
 
e7a346
         /* Check whether key is passed for a single option */
e7a346
@@ -12883,6 +12905,9 @@ glusterd_get_default_val_for_volopt (dict_t *ctx, gf_boolean_t all_opts,
e7a346
                 ret = dict_get_str (priv->opts, vme->key, &def_val);
e7a346
                 if (!def_val) {
e7a346
                         ret = dict_get_str (vol_dict, vme->key, &def_val);
e7a346
+                        if (ret == -ENOENT)
e7a346
+                                def_val = glusterd_get_option_value (volinfo,
e7a346
+                                                                     vme->key);
e7a346
                         if (!def_val) {
e7a346
                                 if (vme->value) {
e7a346
                                         def_val = vme->value;
e7a346
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.h b/xlators/mgmt/glusterd/src/glusterd-utils.h
e7a346
index 6c525e5..e69a779 100644
e7a346
--- a/xlators/mgmt/glusterd/src/glusterd-utils.h
e7a346
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.h
e7a346
@@ -730,7 +730,8 @@ glusterd_get_global_options_for_all_vols (rpcsvc_request_t *req, dict_t *dict,
e7a346
 int
e7a346
 glusterd_get_default_val_for_volopt (dict_t *dict, gf_boolean_t all_opts,
e7a346
                                      char *key, char *orig_key,
e7a346
-                                     dict_t *vol_dict, char **err_str);
e7a346
+                                     glusterd_volinfo_t *volinfo,
e7a346
+                                     char **err_str);
e7a346
 
e7a346
 int
e7a346
 glusterd_check_client_op_version_support (char *volname, uint32_t op_version,
e7a346
diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.c b/xlators/mgmt/glusterd/src/glusterd-volgen.c
e7a346
index 8ff76d6..0e287b6 100644
e7a346
--- a/xlators/mgmt/glusterd/src/glusterd-volgen.c
e7a346
+++ b/xlators/mgmt/glusterd/src/glusterd-volgen.c
e7a346
@@ -263,7 +263,6 @@ first_of (volgen_graph_t *graph)
e7a346
  *
e7a346
  *************************/
e7a346
 
e7a346
-
e7a346
 static int
e7a346
 volopt_selector (int lvl, char **patt, void *param,
e7a346
                      int (*optcbk)(char *word, void *param))
e7a346
@@ -514,6 +513,11 @@ volgen_graph_set_options_generic (volgen_graph_t *graph, dict_t *dict,
e7a346
                 odt.data_t_fake = _gf_false;
e7a346
 
e7a346
                 data = dict_get (dict, vme->key);
e7a346
+                if (!strcmp (vme->key, "performance.client-io-threads") &&
e7a346
+                    dict_get_str_boolean (dict, "skip-CLIOT",
e7a346
+                                          _gf_false) == _gf_true) {
e7a346
+                        continue;
e7a346
+                }
e7a346
 
e7a346
                 if (data)
e7a346
                         process_option (vme->key, data, &odt;;
e7a346
@@ -6393,6 +6397,8 @@ glusterd_create_volfiles (glusterd_volinfo_t *volinfo)
e7a346
                         GD_MSG_VOLFILE_CREATE_FAIL,
e7a346
                         "Could not generate client volfiles");
e7a346
 
e7a346
+        dict_del (volinfo->dict, "skip-CLIOT");
e7a346
+
e7a346
 out:
e7a346
         return ret;
e7a346
 }
e7a346
-- 
e7a346
1.8.3.1
e7a346