Patchwork [BUG:1779] mgmt/glusterd: print peer state names instead of state numbers

login
register
Submitter Pranith K
Date 2010-10-02 09:42:51
Message ID <20101002094251.GA10340@dev.gluster.com>
Download mbox | patch
Permalink /patch/5179/
State Accepted
Headers show

Comments

Pranith K - 2010-10-02 09:42:51
Signed-off-by: Pranith Kumar K <pranithk@gluster.com>
---
 cli/src/cli3_1-cops.c                        |   15 ++++++++-------
 xlators/mgmt/glusterd/src/glusterd-handler.c |    3 ++-
 xlators/mgmt/glusterd/src/glusterd-sm.c      |   19 +++++++++++++++++++
 xlators/mgmt/glusterd/src/glusterd-sm.h      |    2 ++
 4 files changed, 31 insertions(+), 8 deletions(-)

Patch

diff --git a/cli/src/cli3_1-cops.c b/cli/src/cli3_1-cops.c
index 1538a4c..8a775e9 100644
--- a/cli/src/cli3_1-cops.c
+++ b/cli/src/cli3_1-cops.c
@@ -200,7 +200,7 @@  gf_cli3_1_list_friends_cbk (struct rpc_req *req, struct iovec *iov,
         char                       *hostname_buf = NULL;
         int32_t                    i = 1;
         char                       key[256] = {0,};
-        int32_t                    state = 0;
+        char                       *state = NULL;
         int32_t                    port = 0;
         int32_t                    connected = 0;
         char                       *connected_str = NULL;
@@ -272,9 +272,9 @@  gf_cli3_1_list_friends_cbk (struct rpc_req *req, struct iovec *iov,
                         if (ret)
                                 goto out;
                         if (connected)
-                                connected_str = "connected";
+                                connected_str = "Connected";
                         else
-                                connected_str = "disconnected";
+                                connected_str = "Disconnected";
 
                         snprintf (key, 256, "friend%d.port", i);
                         ret = dict_get_int32 (dict, key, &port);
@@ -282,17 +282,18 @@  gf_cli3_1_list_friends_cbk (struct rpc_req *req, struct iovec *iov,
                                 goto out;
 
                         snprintf (key, 256, "friend%d.state", i);
-                        ret = dict_get_int32 (dict, key, &state);
+                        ret = dict_get_str (dict, key, &state);
                         if (ret)
                                 goto out;
 
                         if (!port) {
-                                cli_out ("hostname:%s, uuid:%s, state:%d (%s)",
+                                cli_out ("\nHostname: %s\nUuid: %s\nState: %s "
+                                         "(%s)",
                                          hostname_buf, uuid_buf, state,
                                          connected_str);
                         } else {
-                                cli_out ("hostname:%s, port:%d, uuid:%s, "
-                                         "state:%d, (%s)", hostname_buf, port,
+                                cli_out ("\nHostname: %s\nPort: %d\nUuid: %s\n"
+                                         "State: %s (%s)", hostname_buf, port,
                                          uuid_buf, state, connected_str);
                         }
                         i++;
diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c
index f178124..67b4ab6 100644
--- a/xlators/mgmt/glusterd/src/glusterd-handler.c
+++ b/xlators/mgmt/glusterd/src/glusterd-handler.c
@@ -271,7 +271,8 @@  glusterd_add_peer_detail_to_dict (glusterd_peerinfo_t   *peerinfo,
                 goto out;
 
         snprintf (key, 256, "friend%d.state", count);
-        ret = dict_set_int32 (friends, key, (int32_t)peerinfo->state.state);
+        ret = dict_set_str (friends, key,
+                    glusterd_friend_sm_state_name_get(peerinfo->state.state));
         if (ret)
                 goto out;
 
diff --git a/xlators/mgmt/glusterd/src/glusterd-sm.c b/xlators/mgmt/glusterd/src/glusterd-sm.c
index f540658..fbe8430 100644
--- a/xlators/mgmt/glusterd/src/glusterd-sm.c
+++ b/xlators/mgmt/glusterd/src/glusterd-sm.c
@@ -46,6 +46,25 @@ 
 
 static struct list_head gd_friend_sm_queue;
 
+static  char *glusterd_friend_sm_state_names[] = {
+        "Establishing Connection",
+        "Probe Sent to Peer",
+        "Probe Received from Peer",
+        "Peer in Cluster",
+        "Accepted peer request",
+        "Sent and Received peer request",
+        "Peer Rejected",
+        "Peer detach in progress",
+        "Invalid State"
+};
+
+char*
+glusterd_friend_sm_state_name_get (glusterd_friend_sm_state_t state)
+{
+        if (state < 0 || state >= GD_FRIEND_STATE_MAX)
+                return glusterd_friend_sm_state_names[GD_FRIEND_STATE_MAX];
+        return glusterd_friend_sm_state_names[state];
+}
 void
 glusterd_destroy_probe_ctx (glusterd_probe_ctx_t *ctx)
 {
diff --git a/xlators/mgmt/glusterd/src/glusterd-sm.h b/xlators/mgmt/glusterd/src/glusterd-sm.h
index 0ad8946..72dca81 100644
--- a/xlators/mgmt/glusterd/src/glusterd-sm.h
+++ b/xlators/mgmt/glusterd/src/glusterd-sm.h
@@ -165,4 +165,6 @@  glusterd_destroy_probe_ctx (glusterd_probe_ctx_t *ctx);
 
 void
 glusterd_destroy_friend_req_ctx (glusterd_friend_req_ctx_t *ctx);
+char*
+glusterd_friend_sm_state_name_get (glusterd_friend_sm_state_t state);
 #endif