Patchwork [BRANCH:release-3.1,BUG:2904] mgmt/glusterd: add upgrade/downgrade xlator options

login
register
Submitter Vijay Bellur
Date 2011-06-17 12:49:10
Message ID <20110617124910.GA12964@shell.gluster.com>
Download mbox | patch
Permalink /patch/7543/
State Accepted
Headers show

Comments

Vijay Bellur - 2011-06-17 12:49:10
Signed-off-by: shishir gowda <shishirng@gluster.com>
Signed-off-by: Vijay Bellur <vijay@gluster.com>
---
 xlators/mgmt/glusterd/src/glusterd-utils.c  |   64 +++++++++++++++++++++++++++
 xlators/mgmt/glusterd/src/glusterd-utils.h  |    6 +++
 xlators/mgmt/glusterd/src/glusterd-volgen.c |    2 +-
 xlators/mgmt/glusterd/src/glusterd-volgen.h |    1 +
 xlators/mgmt/glusterd/src/glusterd.c        |   10 ++++
 5 files changed, 82 insertions(+), 1 deletions(-)

Patch

diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
index db82e5e..a2da435 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
@@ -2679,3 +2679,67 @@  glusterd_peer_destroy (glusterd_peerinfo_t *peerinfo)
 out:
         return ret;
 }
+
+int32_t
+glusterd_recreate_bricks (glusterd_conf_t *conf)
+{
+
+        glusterd_volinfo_t      *volinfo = NULL;
+        int                      ret = 0;
+
+        GF_ASSERT (conf);
+        list_for_each_entry (volinfo, &conf->volumes, vol_list) {
+                ret = generate_brick_volfiles (volinfo);
+        }
+        return ret;
+}
+
+int32_t
+glusterd_handle_upgrade_downgrade (dict_t *options, glusterd_conf_t *conf)
+{
+        int              ret                            = 0;
+        char            *type                           = NULL;
+        gf_boolean_t     upgrade                        = _gf_false;
+        gf_boolean_t     downgrade                      = _gf_false;
+        gf_boolean_t     regenerate_brick_volfiles      = _gf_false;
+
+        ret = dict_get_str (options, "upgrade", &type);
+        if (!ret) {
+                ret = gf_string2boolean (type, &upgrade);
+                if (ret) {
+                        gf_log ("glusterd", GF_LOG_ERROR, "upgrade option "
+                                "%s is not a valid boolean type", type);
+                        ret = -1;
+                        goto out;
+                }
+                if (_gf_true == upgrade)
+                        regenerate_brick_volfiles = _gf_true;
+        }
+
+        ret = dict_get_str (options, "downgrade", &type);
+        if (!ret) {
+                ret = gf_string2boolean (type, &downgrade);
+                if (ret) {
+                        gf_log ("glusterd", GF_LOG_ERROR, "downgrade option "
+                                "%s is not a valid boolean type", type);
+                        ret = -1;
+                        goto out;
+                }
+        }
+
+        if (upgrade && downgrade) {
+                gf_log ("glusterd", GF_LOG_ERROR, "Both upgrade and downgrade"
+                        " options are set. Only one should be on");
+                ret = -1;
+                goto out;
+        }
+
+        if (!upgrade && !downgrade)
+                ret = 0;
+        if (regenerate_brick_volfiles) {
+                ret = glusterd_recreate_bricks (conf);
+        }
+out:
+        return ret;
+}
+
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.h b/xlators/mgmt/glusterd/src/glusterd-utils.h
index 79b2454..f6f3ba3 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.h
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.h
@@ -252,4 +252,10 @@  glusterd_sm_tr_log_delete (glusterd_sm_tr_log_t *log);
 int
 glusterd_sm_tr_log_add_to_dict (dict_t *dict,
                                 glusterd_sm_tr_log_t *circular_log);
+
+int32_t
+glusterd_recreate_bricks (glusterd_conf_t *conf);
+
+int32_t
+glusterd_handle_upgrade_downgrade (dict_t *options, glusterd_conf_t *conf);
 #endif
diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.c b/xlators/mgmt/glusterd/src/glusterd-volgen.c
index 0a20eee..1c7626c 100644
--- a/xlators/mgmt/glusterd/src/glusterd-volgen.c
+++ b/xlators/mgmt/glusterd/src/glusterd-volgen.c
@@ -1761,7 +1761,7 @@  get_vol_tstamp_file (char *filename, glusterd_volinfo_t *volinfo)
                  PATH_MAX - strlen(filename) - 1);
 }
 
-static int
+int
 generate_brick_volfiles (glusterd_volinfo_t *volinfo)
 {
         glusterd_brickinfo_t    *brickinfo = NULL;
diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.h b/xlators/mgmt/glusterd/src/glusterd-volgen.h
index 4f4b4b7..e34937c 100644
--- a/xlators/mgmt/glusterd/src/glusterd-volgen.h
+++ b/xlators/mgmt/glusterd/src/glusterd-volgen.h
@@ -48,4 +48,5 @@  int glusterd_validate_globalopts (glusterd_volinfo_t *volinfo, dict_t *val_dict,
 int glusterd_validate_localopts (dict_t *val_dict, char **op_errstr);
 gf_boolean_t glusterd_check_globaloption (char *key);
 
+int generate_brick_volfiles (glusterd_volinfo_t *volinfo);
 #endif
diff --git a/xlators/mgmt/glusterd/src/glusterd.c b/xlators/mgmt/glusterd/src/glusterd.c
index cf03614..86713f3 100644
--- a/xlators/mgmt/glusterd/src/glusterd.c
+++ b/xlators/mgmt/glusterd/src/glusterd.c
@@ -449,6 +449,10 @@  init (xlator_t *this)
         glusterd_op_sm_init ();
         glusterd_opinfo_init ();
 
+        ret = glusterd_handle_upgrade_downgrade (this->options, conf);
+        if (ret)
+                goto out;
+
         glusterd_restart_bricks (conf);
         ret = 0;
 out:
@@ -550,6 +554,12 @@  struct volume_options options[] = {
         { .key   = {"rpc-auth-allow-insecure"},
           .type  = GF_OPTION_TYPE_BOOL,
         },
+        { .key  = {"upgrade"},
+          .type = GF_OPTION_TYPE_BOOL,
+        },
+        { .key  = {"downgrade"},
+          .type = GF_OPTION_TYPE_BOOL,
+        },
 
         { .key   = {NULL} },
 };