Patchwork [BUG:1322] mgmt/glusterd: Return replace-brick status

login
register
Submitter Pavan Sondur
Date 2010-08-30 21:35:16
Message ID <20100830213516.GA22361@gluster.com>
Download mbox | patch
Permalink /patch/4399/
State Accepted
Headers show

Comments

Pavan Sondur - 2010-08-30 21:35:16
Signed-off-by: Pavan Vilas Sondur <pavan@gluster.com>
---
 cli/src/cli3_1-cops.c                      |   44 +++++++++++++++++++++------
 xlators/mgmt/glusterd/src/glusterd-op-sm.c |   36 +++++++++++++++++-----
 2 files changed, 62 insertions(+), 18 deletions(-)

Patch

diff --git a/cli/src/cli3_1-cops.c b/cli/src/cli3_1-cops.c
index 728c790..d07df99 100644
--- a/cli/src/cli3_1-cops.c
+++ b/cli/src/cli3_1-cops.c
@@ -713,6 +713,7 @@  gf_cli3_1_replace_brick_cbk (struct rpc_req *req, struct iovec *iov,
         dict_t                          *dict             = NULL;
         char                            *src_brick        = NULL;
         char                            *dst_brick        = NULL;
+        char                            *status_reply     = NULL;
         gf1_cli_replace_op               replace_op       = 0;
         char                            *rb_operation_str = NULL;
         char                             cmd_str[8192]    = {0,};
@@ -742,24 +743,44 @@  gf_cli3_1_replace_brick_cbk (struct rpc_req *req, struct iovec *iov,
 
         switch (replace_op) {
         case GF_REPLACE_OP_START:
-                rb_operation_str = "Replace brick start operation";
+                if (rsp.op_ret)
+                        rb_operation_str = "replace-brick failed to start";
+                else
+                        rb_operation_str = "replace-brick started successfully";
                 break;
 
         case GF_REPLACE_OP_STATUS:
-                rb_operation_str = "Replace brick status operation";
+
+                ret = dict_get_str (dict, "status-reply",
+                                    &status_reply);
+                if (ret) {
+                        gf_log ("", GF_LOG_DEBUG,
+                                "dict_get failed on status reply");
+                        goto out;
+                }
+
+                if (rsp.op_ret || ret)
+                        rb_operation_str = "replace-brick status unknown";
+                else
+                        rb_operation_str = status_reply;
+
                 break;
 
         case GF_REPLACE_OP_PAUSE:
-                rb_operation_str = "Replace brick pause operation";
+                if (rsp.op_ret)
+                        rb_operation_str = "replace-brick pause failed";
+                else
+                        rb_operation_str = "replace-brick paused successfully";
                 break;
 
         case GF_REPLACE_OP_ABORT:
-                rb_operation_str = "Replace brick abort operation";
+                if (rsp.op_ret)
+                        rb_operation_str = "replace-brick abort failed";
+                else
+                        rb_operation_str = "replace-brick aborted successfully";
                 break;
 
         case GF_REPLACE_OP_COMMIT:
-                rb_operation_str = "Replace brick commit operation";
-
                 ret = dict_get_str (dict, "src-brick", &src_brick);
                 if (ret) {
                         gf_log ("", GF_LOG_DEBUG,
@@ -804,6 +825,11 @@  gf_cli3_1_replace_brick_cbk (struct rpc_req *req, struct iovec *iov,
                         goto out;
                 }
 
+                if (rsp.op_ret || ret)
+                        rb_operation_str = "replace-brick commit failed";
+                else
+                        rb_operation_str = "replace-brick commit successful";
+
                 break;
 
         default:
@@ -814,10 +840,8 @@  gf_cli3_1_replace_brick_cbk (struct rpc_req *req, struct iovec *iov,
 
 
         gf_log ("cli", GF_LOG_NORMAL, "Received resp to replace brick");
-        cli_out ("%s %s",
-                 rb_operation_str ? rb_operation_str : "Unknown operation",
-                 (rsp.op_ret) ? "unsuccessful":
-                 "successful");
+        cli_out ("%s",
+                 rb_operation_str ? rb_operation_str : "Unknown operation");
 
         ret = rsp.op_ret;
 
diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
index cb8acbe..0f412ec 100644
--- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c
+++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
@@ -1668,9 +1668,11 @@  out:
 static int
 rb_do_operation_status (glusterd_volinfo_t *volinfo,
                         glusterd_brickinfo_t *src_brickinfo,
-                        glusterd_brickinfo_t *dst_brickinfo)
+                        glusterd_brickinfo_t *dst_brickinfo,
+                        dict_t *dict)
 {
-        const char *status = NULL;
+        const char *status       = NULL;
+        char       *status_reply = NULL;
         int ret = -1;
 
         if (!glusterd_is_local_addr (src_brickinfo->hostname)) {
@@ -1696,6 +1698,22 @@  rb_do_operation_status (glusterd_volinfo_t *volinfo,
                 gf_log ("", GF_LOG_DEBUG,
                         "pump status is %s", status);
 
+                status_reply = gf_strdup (status);
+                if (!status_reply) {
+                        gf_log ("", GF_LOG_ERROR,
+                                "Out of memory");
+                        ret = -1;
+                        goto out;
+                }
+
+                ret = dict_set_dynstr (dict, "status-reply",
+                                       status_reply);
+                if (ret) {
+                        gf_log ("", GF_LOG_DEBUG,
+                                "failed to set pump status in dict");
+                        goto out;
+                }
+
                 ret = rb_destroy_maintainence_client (volinfo, src_brickinfo);
                 if (ret) {
                         gf_log ("", GF_LOG_DEBUG,
@@ -1794,26 +1812,28 @@  glusterd_op_replace_brick (gd1_mgmt_stage_op_req *req)
 
         switch (replace_op) {
         case GF_REPLACE_OP_START:
-                rb_do_operation_start (volinfo, src_brickinfo, dst_brickinfo);
+                ret = rb_do_operation_start (volinfo, src_brickinfo, dst_brickinfo);
                 break;
         case GF_REPLACE_OP_COMMIT:
-                rb_do_operation_commit (volinfo, src_brickinfo, dst_brickinfo);
+                ret = rb_do_operation_commit (volinfo, src_brickinfo, dst_brickinfo);
                 break;
         case GF_REPLACE_OP_PAUSE:
-                rb_do_operation_pause (volinfo, src_brickinfo, dst_brickinfo);
+                ret = rb_do_operation_pause (volinfo, src_brickinfo, dst_brickinfo);
                 break;
         case GF_REPLACE_OP_ABORT:
-                rb_do_operation_abort (volinfo, src_brickinfo, dst_brickinfo);
+                ret = rb_do_operation_abort (volinfo, src_brickinfo, dst_brickinfo);
                 break;
         case GF_REPLACE_OP_STATUS:
-                rb_do_operation_status (volinfo, src_brickinfo, dst_brickinfo);
+                ret = rb_do_operation_status (volinfo, src_brickinfo, dst_brickinfo,
+                                              dict);
                 break;
         default:
                 ret = -1;
                 goto out;
         }
 
-        ret = 0;
+        if (ret)
+                goto out;
 
 out:
         return ret;