Patchwork [BUG:1304,4/5] mgmt/glusterd: cli: Various fixes for replace brick.

login
register
Submitter Pavan Sondur
Date 2010-08-16 08:07:34
Message ID <20100816080734.GA5608@gluster.com>
Download mbox | patch
Permalink /patch/4146/
State Accepted
Headers show

Comments

Pavan Sondur - 2010-08-16 08:07:34
Signed-off-by: Pavan Vilas Sondur <pavan@gluster.com>
---
 cli/src/cli3_1-cops.c                      |   12 +++-
 extras/volgen/CreateVolfile.py             |    2 +
 xlators/mgmt/glusterd/src/glusterd-op-sm.c |  133 +++++++++++++++++++++------
 xlators/mgmt/glusterd/src/glusterd-utils.c |    4 +-
 xlators/mgmt/glusterd/src/glusterd.h       |    1 +
 5 files changed, 120 insertions(+), 32 deletions(-)

Patch

diff --git a/cli/src/cli3_1-cops.c b/cli/src/cli3_1-cops.c
index 8f81815..9d1b3c1 100644
--- a/cli/src/cli3_1-cops.c
+++ b/cli/src/cli3_1-cops.c
@@ -750,6 +750,16 @@  gf_cli3_1_replace_brick_cbk (struct rpc_req *req, struct iovec *iov,
                         goto out;
                 }
 
+                snprintf (cmd_str, 4096, "gluster volume replace-brick %s %s %s abort >/dev/null",
+                          local->u.replace_brick.volname, src_brick, dst_brick);
+
+                ret = system (cmd_str);
+                if (ret) {
+                        gf_log ("", GF_LOG_DEBUG,
+                                "add brick failed");
+                        goto out;
+                }
+
                 snprintf (cmd_str, 4096, "gluster volume add-brick %s %s >/dev/null",
                           local->u.replace_brick.volname, dst_brick);
 
@@ -1362,7 +1372,7 @@  gf_cli3_1_replace_brick (call_frame_t *frame, xlator_t *this,
                 goto out;
         }
 
-        local->u.replace_brick.volname = strdup (req.volname);
+        local->u.replace_brick.volname = gf_strdup (req.volname);
         if (!local->u.replace_brick.volname) {
                 gf_log (this->name, GF_LOG_ERROR,
                         "Out of memory");
diff --git a/extras/volgen/CreateVolfile.py b/extras/volgen/CreateVolfile.py
index fdcf605..5519917 100644
--- a/extras/volgen/CreateVolfile.py
+++ b/extras/volgen/CreateVolfile.py
@@ -299,6 +299,8 @@  class CreateVolfile:
             exp_fd.write ("    type protocol/client\n")
             if self.transport:
                 exp_fd.write ("    option transport-type %s\n" % self.transport)
+            if self.gfs_port:
+                exp_fd.write ("    option transport.remote-port 34034\n")
             exp_fd.write ("    option ping-timeout 42\n")
             exp_fd.write ("end-volume\n\n")
 
diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
index 8c7d75c..0843bc2 100644
--- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c
+++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
@@ -606,6 +606,12 @@  glusterd_op_stage_replace_brick (gd1_mgmt_stage_op_req *req)
                 goto out;
         }
 
+        ret = glusterd_volinfo_find (volname, &volinfo);
+        if (ret) {
+                gf_log ("", GF_LOG_ERROR, "Unable to allocate memory");
+                goto out;
+        }
+
         ret = glusterd_brickinfo_get (src_brick, volinfo,
                                       &src_brickinfo);
         if (ret) {
@@ -1058,8 +1064,8 @@  static const char *client_volfile_str =  "volume client/protocol\n"
         "type protocol/client\n"
         "option remote-host %s\n"
         "option remote-subvolume %s\n"
-        "option remote-port 34034\n"
-        "echo end-volume\n";
+        "option remote-port %d\n"
+        "end-volume\n";
 
 static int
 rb_generate_client_volfile (glusterd_volinfo_t *volinfo,
@@ -1087,8 +1093,10 @@  rb_generate_client_volfile (glusterd_volinfo_t *volinfo,
                 goto out;
         }
 
+        GF_ASSERT (src_brickinfo->port);
+
         fprintf (file, client_volfile_str, src_brickinfo->hostname,
-                 src_brickinfo->path);
+                 src_brickinfo->path, src_brickinfo->port);
 
         fclose (file);
 
@@ -1152,6 +1160,58 @@  out:
 }
 
 static int
+rb_mountpoint_mkdir (glusterd_volinfo_t *volinfo,
+                     glusterd_brickinfo_t *src_brickinfo)
+{
+        glusterd_conf_t *priv                       = NULL;
+        char             mount_point_path[PATH_MAX] = {0,};
+        int              ret                        = -1;
+
+        priv = THIS->private;
+
+        snprintf (mount_point_path, PATH_MAX, "%s/vols/%s/%s",
+                  priv->workdir, volinfo->volname,
+                  RB_CLIENT_MOUNTPOINT);
+
+        ret = mkdir (mount_point_path, 0777);
+        if (ret) {
+                gf_log ("", GF_LOG_DEBUG, "mkdir failed");
+                goto out;
+        }
+
+        ret = 0;
+
+out:
+        return ret;
+}
+
+static int
+rb_mountpoint_rmdir (glusterd_volinfo_t *volinfo,
+                     glusterd_brickinfo_t *src_brickinfo)
+{
+        glusterd_conf_t *priv                       = NULL;
+        char             mount_point_path[PATH_MAX] = {0,};
+        int              ret                        = -1;
+
+        priv = THIS->private;
+
+        snprintf (mount_point_path, PATH_MAX, "%s/vols/%s/%s",
+                  priv->workdir, volinfo->volname,
+                  RB_CLIENT_MOUNTPOINT);
+
+        ret = rmdir (mount_point_path);
+        if (ret) {
+                gf_log ("", GF_LOG_DEBUG, "rmdir failed");
+                goto out;
+        }
+
+        ret = 0;
+
+out:
+        return ret;
+}
+
+static int
 rb_destroy_maintainence_client (glusterd_volinfo_t *volinfo,
                                 glusterd_brickinfo_t *src_brickinfo)
 {
@@ -1176,7 +1236,7 @@  rb_destroy_maintainence_client (glusterd_volinfo_t *volinfo,
                 goto out;
         }
 
-        snprintf (cmd_str, 8192, "umount %s/vols/%s/%s",
+        snprintf (cmd_str, 8192, "umount -f %s/vols/%s/%s",
                   priv->workdir, volinfo->volname,
                   RB_CLIENT_MOUNTPOINT);
 
@@ -1187,6 +1247,13 @@  rb_destroy_maintainence_client (glusterd_volinfo_t *volinfo,
                 goto out;
         }
 
+        ret = rb_mountpoint_rmdir (volinfo, src_brickinfo);
+        if (ret) {
+                gf_log ("", GF_LOG_DEBUG,
+                        "rmdir of mountpoint failed");
+                goto out;
+        }
+
         snprintf (filename, PATH_MAX, "%s/vols/%s/%s",
                   priv->workdir, volinfo->volname,
                   RB_CLIENTVOL_FILENAME);
@@ -1217,6 +1284,13 @@  rb_spawn_maintainence_client (glusterd_volinfo_t *volinfo,
                 goto out;
         }
 
+        ret = rb_mountpoint_mkdir (volinfo, src_brickinfo);
+        if (ret) {
+                gf_log ("", GF_LOG_DEBUG, "Unable to mkdir "
+                        "mountpoint");
+                goto out;
+        }
+
         ret = rb_spawn_glusterfs_client (volinfo, src_brickinfo);
         if (ret) {
                 gf_log ("", GF_LOG_DEBUG, "Unable to start glusterfs");
@@ -1231,6 +1305,7 @@  out:
 static int
 rb_spawn_destination_brick (glusterd_volinfo_t *volinfo,
                             glusterd_brickinfo_t *dst_brickinfo)
+
 {
         int ret = -1;
 
@@ -1315,26 +1390,6 @@  out:
         return ret;
 }
 
-/* replace brick commit is handled by cli directly.
- * return success all the time.
- */
-static int
-rb_do_operation_commit (glusterd_volinfo_t *volinfo,
-                        glusterd_brickinfo_t *src_brickinfo,
-                        glusterd_brickinfo_t *dst_brickinfo)
-{
-        gf_log ("", GF_LOG_DEBUG,
-                "received commit on %s:%s to %s:%s "
-                "on volume %s",
-                src_brickinfo->hostname,
-                src_brickinfo->path,
-                dst_brickinfo->hostname,
-                dst_brickinfo->path,
-                volinfo->volname);
-
-        return 0;
-}
-
 static int
 rb_do_operation_pause (glusterd_volinfo_t *volinfo,
                        glusterd_brickinfo_t *src_brickinfo,
@@ -1381,17 +1436,17 @@  static int
 rb_kill_destination_brick (glusterd_volinfo_t *volinfo,
                            glusterd_brickinfo_t *dst_brickinfo)
 {
-        glusterd_conf_t  *priv     = NULL;
-        int               ret      = -1;
-        char             *pidfile  = NULL;
-        pid_t             pid      = -1;
-        FILE             *file     = NULL;
+        glusterd_conf_t  *priv               = NULL;
+        int               ret                = -1;
+        char              pidfile[PATH_MAX]  = {0,};
+        pid_t             pid                = -1;
+        FILE             *file               = NULL;
 
         priv = THIS->private;
 
         snprintf (pidfile, PATH_MAX, "%s/vols/%s/%s",
                   priv->workdir, volinfo->volname,
-                  RB_DSTBRICKVOL_FILENAME);
+                  RB_DSTBRICK_PIDFILE);
 
         file = fopen (pidfile, "r+");
         if (!file) {
@@ -1481,6 +1536,24 @@  out:
 }
 
 static int
+rb_do_operation_commit (glusterd_volinfo_t *volinfo,
+                        glusterd_brickinfo_t *src_brickinfo,
+                        glusterd_brickinfo_t *dst_brickinfo)
+{
+
+        gf_log ("", GF_LOG_DEBUG,
+                "received commit on %s:%s to %s:%s "
+                "on volume %s",
+                src_brickinfo->hostname,
+                src_brickinfo->path,
+                dst_brickinfo->hostname,
+                dst_brickinfo->path,
+                volinfo->volname);
+
+        return 0;
+}
+
+static int
 rb_get_xattr_command (glusterd_volinfo_t *volinfo,
                       glusterd_brickinfo_t *src_brickinfo,
                       glusterd_brickinfo_t *dst_brickinfo,
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
index 959a9c9..ab9936a 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
@@ -771,8 +771,10 @@  glusterd_volume_start_glusterfs (glusterd_volinfo_t  *volinfo,
                   port, volfile, pidfile);
         ret = system (cmd_str);
 
-        if (ret == 0)
+        if (ret == 0) {
                 pmap_registry_bind (THIS, port, brickinfo->path);
+                brickinfo->port = port;
+        }
 out:
         return ret;
 }
diff --git a/xlators/mgmt/glusterd/src/glusterd.h b/xlators/mgmt/glusterd/src/glusterd.h
index c0ac17c..5e44ea4 100644
--- a/xlators/mgmt/glusterd/src/glusterd.h
+++ b/xlators/mgmt/glusterd/src/glusterd.h
@@ -77,6 +77,7 @@  struct glusterd_brickinfo {
         char    path[PATH_MAX];
         struct list_head  brick_list;
         uuid_t  uuid;
+        int     port;
         glusterd_store_handle_t *shandle;
 };