Patchwork [BUG:1669] mgmt/glusterd: Restart src brick and add pump when replace brick cmds are given.

login
register
Submitter Pavan Sondur
Date 2010-09-22 07:31:36
Message ID <20100922073135.GA2882@gluster.com>
Download mbox | patch
Permalink /patch/4914/
State Accepted
Headers show

Comments

Pavan Sondur - 2010-09-22 07:31:36
Signed-off-by: Pavan Vilas Sondur <pavan@gluster.com>
---
 xlators/mgmt/glusterd/src/glusterd-op-sm.c  |  106 ++++++++++++++++++++++++++-
 xlators/mgmt/glusterd/src/glusterd-volgen.c |   38 +++++++---
 2 files changed, 129 insertions(+), 15 deletions(-)

Patch

diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
index 988290e..8ed6456 100644
--- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c
+++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
@@ -1525,6 +1525,81 @@  out:
 }
 
 static int
+rb_regenerate_volfiles (glusterd_volinfo_t *volinfo, int32_t pump_needed)
+{
+        dict_t *dict = NULL;
+        int ret = 0;
+
+        dict = volinfo->dict;
+
+        gf_log ("", GF_LOG_DEBUG,
+                "attempting to set pump value=%d", pump_needed);
+
+        ret = dict_set_int32 (dict, "enable-pump", pump_needed);
+        if (ret) {
+                gf_log ("", GF_LOG_DEBUG,
+                        "could not dict_set enable-pump");
+                goto out;
+        }
+
+        ret = glusterd_create_volfiles (volinfo);
+
+out:
+        return ret;
+}
+
+static int
+rb_src_brick_restart (glusterd_volinfo_t *volinfo,
+                      glusterd_brickinfo_t *src_brickinfo,
+                      int activate_pump)
+{
+        int ret = 0;
+
+        gf_log ("", GF_LOG_DEBUG,
+                "Attempting to kill src");
+
+        ret = glusterd_volume_stop_glusterfs
+                (volinfo, src_brickinfo, 0);
+        if (ret) {
+                gf_log ("", GF_LOG_ERROR, "Unable to stop "
+                        "glusterfs, ret: %d", ret);
+                goto out;
+        }
+
+        glusterd_delete_volfile (volinfo, src_brickinfo);
+        glusterd_store_delete_brick (volinfo, src_brickinfo);
+
+        if (activate_pump) {
+                ret = rb_regenerate_volfiles (volinfo, 1);
+                if (ret) {
+                        gf_log ("", GF_LOG_DEBUG,
+                                "Could not regenerate volfiles with pump");
+                        goto out;
+                }
+        } else {
+                ret = rb_regenerate_volfiles (volinfo, 0);
+                if (ret) {
+                        gf_log ("", GF_LOG_DEBUG,
+                                "Could not regenerate volfiles without pump");
+                        goto out;
+                }
+
+        }
+
+        ret = glusterd_volume_start_glusterfs
+                (volinfo, src_brickinfo, 0);
+        if (ret) {
+                gf_log ("", GF_LOG_ERROR, "Unable to start "
+                        "glusterfs, ret: %d", ret);
+                goto out;
+        }
+
+
+out:
+        return ret;
+}
+
+static int
 rb_send_xattr_command (glusterd_volinfo_t *volinfo,
                        glusterd_brickinfo_t *src_brickinfo,
                        glusterd_brickinfo_t *dst_brickinfo,
@@ -1932,7 +2007,15 @@  rb_do_operation_start (glusterd_volinfo_t *volinfo,
         char start_value[8192] = {0,};
         int ret = -1;
 
-        gf_log ("", GF_LOG_NORMAL,
+        ret = rb_src_brick_restart (volinfo, src_brickinfo,
+                                    1);
+        if (ret) {
+                gf_log ("", GF_LOG_DEBUG,
+                        "Could not restart src-brick");
+                goto out;
+        }
+
+        gf_log ("", GF_LOG_DEBUG,
                 "replace-brick sending start xattr");
 
         ret = rb_spawn_maintainence_client (volinfo, src_brickinfo);
@@ -2035,6 +2118,14 @@  rb_do_operation_abort (glusterd_volinfo_t *volinfo,
 {
         int ret = -1;
 
+        ret = rb_src_brick_restart (volinfo, src_brickinfo,
+                                    0);
+        if (ret) {
+                gf_log ("", GF_LOG_DEBUG,
+                        "Could not restart src-brick");
+                goto out;
+        }
+
         gf_log ("", GF_LOG_DEBUG,
                 "replace-brick sending abort xattr");
 
@@ -2074,6 +2165,15 @@  rb_do_operation_commit (glusterd_volinfo_t *volinfo,
                         glusterd_brickinfo_t *src_brickinfo,
                         glusterd_brickinfo_t *dst_brickinfo)
 {
+        int ret = 0;
+
+        ret = rb_src_brick_restart (volinfo, src_brickinfo,
+                                    0);
+        if (ret) {
+                gf_log ("", GF_LOG_DEBUG,
+                        "Could not restart src-brick");
+                goto out;
+        }
 
         gf_log ("", GF_LOG_DEBUG,
                 "received commit on %s:%s to %s:%s "
@@ -2083,8 +2183,8 @@  rb_do_operation_commit (glusterd_volinfo_t *volinfo,
                 dst_brickinfo->hostname,
                 dst_brickinfo->path,
                 volinfo->volname);
-
-        return 0;
+out:
+        return ret;
 }
 
 static int
diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.c b/xlators/mgmt/glusterd/src/glusterd-volgen.c
index f40dbe1..46a05d9 100644
--- a/xlators/mgmt/glusterd/src/glusterd-volgen.c
+++ b/xlators/mgmt/glusterd/src/glusterd-volgen.c
@@ -689,7 +689,7 @@  __write_access_control_xlator (FILE *file, dict_t *dict,
         const char *ac_str = "volume %s-access-control\n"
                              "    type features/access-control\n"
                              "    subvolumes %s\n"
-                             "end-volume\n";
+                             "end-volume\n\n";
 
         ret = dict_get_str (dict, "volname", &volname);
         if (ret) {
@@ -1589,6 +1589,7 @@  generate_server_volfile (glusterd_brickinfo_t *brickinfo,
         char  subvol[2048]  = {0,};
         char *volname       = NULL;
         int   ret           = -1;
+        int   activate_pump = 0;
 
         GF_ASSERT (filename);
 
@@ -1635,23 +1636,36 @@  generate_server_volfile (glusterd_brickinfo_t *brickinfo,
                 goto out;
         }
 
-        VOLGEN_GENERATE_VOLNAME (subvol, volname, "locks");
-
-        ret = __write_replace_brick_xlator (file, dict);
+        ret = dict_get_int32 (dict, "enable-pump", &activate_pump);
         if (ret) {
                 gf_log ("", GF_LOG_DEBUG,
-                        "Could not write xlator");
-                goto out;
+                        "Pump is disabled");
         }
 
-        ret = __write_pump_xlator (file, dict, subvol);
-        if (ret) {
+        if (activate_pump) {
                 gf_log ("", GF_LOG_DEBUG,
-                        "Could not write xlator");
-                goto out;
-        }
+                        "Pump is enabled");
+
+                VOLGEN_GENERATE_VOLNAME (subvol, volname, "locks");
+
+                ret = __write_replace_brick_xlator (file, dict);
+                if (ret) {
+                        gf_log ("", GF_LOG_DEBUG,
+                                "Could not write xlator");
+                        goto out;
+                }
+
+                ret = __write_pump_xlator (file, dict, subvol);
+                if (ret) {
+                        gf_log ("", GF_LOG_DEBUG,
+                                "Could not write xlator");
+                        goto out;
+                }
+
+                VOLGEN_GENERATE_VOLNAME (subvol, volname, "pump");
+        } else
+                VOLGEN_GENERATE_VOLNAME (subvol, volname, "locks");
 
-        VOLGEN_GENERATE_VOLNAME (subvol, volname, "pump");
 
         ret = dict_set_str (dict, "export-path", brickinfo->path);
         if (ret) {