Patchwork [BUG:2904,v3] glusterd: add upgrade/downgrade xlator options

login
register
Submitter shishir gowda
Date 2011-05-27 09:58:15
Message ID <20110527095815.GA31035@gluster.com>
Download mbox | patch
Permalink /patch/7273/
State Accepted
Headers show

Comments

shishir gowda - 2011-05-27 09:58:15
If started with upgrade-option, the current behavior is to recreate
brick volfiles, as from 3.2 marker xlator is default.

Signed-off-by: shishir gowda <shishirng@gluster.com>
---
 xlators/mgmt/glusterd/src/glusterd-utils.c  |   64 +++++++++++++++++++++++++++
 xlators/mgmt/glusterd/src/glusterd-utils.h  |    5 ++
 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, 81 insertions(+), 1 deletions(-)

Patch

diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
index 8ab4665..8ef38fc 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
@@ -3393,3 +3393,67 @@  out:
         gf_log ("", GF_LOG_DEBUG, "Returning %d", ret);
         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 85d5b82..380db90 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.h
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.h
@@ -276,4 +276,9 @@  glusterd_restart_gsyncds (glusterd_conf_t *conf);
 int
 glusterd_start_gsync (glusterd_volinfo_t *master_vol, char *slave,
                       char *glusterd_uuid_str, char **op_errstr);
+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 a8b8816..57da428 100644
--- a/xlators/mgmt/glusterd/src/glusterd-volgen.c
+++ b/xlators/mgmt/glusterd/src/glusterd-volgen.c
@@ -2004,7 +2004,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 014e64d..b98b399 100644
--- a/xlators/mgmt/glusterd/src/glusterd-volgen.h
+++ b/xlators/mgmt/glusterd/src/glusterd-volgen.h
@@ -64,5 +64,6 @@  gf_boolean_t
 glusterd_check_voloption_flags (char *key, int32_t flags);
 gf_boolean_t
 glusterd_is_valid_volfpath (char *volname, char *brick);
+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 15894b3..8bd1323 100644
--- a/xlators/mgmt/glusterd/src/glusterd.c
+++ b/xlators/mgmt/glusterd/src/glusterd.c
@@ -708,6 +708,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 = glusterd_restart_gsyncds (conf);
         if (ret)
@@ -813,6 +817,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} },
 };