21ab4e
From dcc96757fbafa555a548271c7efd52ca796f9552 Mon Sep 17 00:00:00 2001
21ab4e
From: Samikshan Bairagya <samikshan@gmail.com>
21ab4e
Date: Wed, 28 Dec 2016 20:33:54 +0530
21ab4e
Subject: [PATCH 309/361] glusterd: Add info on op-version for clients in vol
21ab4e
 status output
21ab4e
21ab4e
Currently the `gluster volume status <VOLNAME|all> clients` command
21ab4e
gives us the following information on clients:
21ab4e
1. Brick name
21ab4e
2. Client count for each brick
21ab4e
3. hostname:port for each client
21ab4e
4. Bytes read and written for each client
21ab4e
21ab4e
There is no information regarding op-version for each client. This
21ab4e
patch adds that to the output.
21ab4e
21ab4e
mainline:
21ab4e
> BUG: 1409078
21ab4e
> Reviewed-on: http://review.gluster.org/16303
21ab4e
> Smoke: Gluster Build System <jenkins@build.gluster.org>
21ab4e
> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
21ab4e
> CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
21ab4e
> Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
21ab4e
(cherry picked from commit fc39ed4d69f7e7f7ca9b3fd100f8be307ae53fe2)
21ab4e
21ab4e
BUG: 1351185
21ab4e
Change-Id: Ib2ece93ab00c234162bb92b7c67a7d86f3350a8d
21ab4e
Signed-off-by: Samikshan Bairagya <samikshan@gmail.com>
21ab4e
Reviewed-on: https://code.engineering.redhat.com/gerrit/101289
21ab4e
Tested-by: Milind Changire <mchangir@redhat.com>
21ab4e
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
21ab4e
---
21ab4e
 cli/src/cli-rpc-ops.c                          | 19 +++++++++++++------
21ab4e
 cli/src/cli-xml-output.c                       | 12 ++++++++++++
21ab4e
 xlators/protocol/client/src/client-handshake.c |  6 ++++++
21ab4e
 xlators/protocol/server/src/server-handshake.c | 18 ++++++++++++++++++
21ab4e
 xlators/protocol/server/src/server-messages.h  | 11 ++++++++++-
21ab4e
 xlators/protocol/server/src/server.c           |  8 ++++++++
21ab4e
 6 files changed, 67 insertions(+), 7 deletions(-)
21ab4e
21ab4e
diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c
21ab4e
index bea5437..5a0cfdf 100644
21ab4e
--- a/cli/src/cli-rpc-ops.c
21ab4e
+++ b/cli/src/cli-rpc-ops.c
21ab4e
@@ -7253,6 +7253,7 @@ cli_print_volume_status_clients (dict_t *dict, gf_boolean_t notbrick)
21ab4e
         char            *clientname = NULL;
21ab4e
         uint64_t        bytesread = 0;
21ab4e
         uint64_t        byteswrite = 0;
21ab4e
+        uint32_t        opversion = 0;
21ab4e
         char            key[1024] = {0,};
21ab4e
         int             i = 0;
21ab4e
         int             j = 0;
21ab4e
@@ -7318,10 +7319,10 @@ cli_print_volume_status_clients (dict_t *dict, gf_boolean_t notbrick)
21ab4e
                 if (client_count == 0)
21ab4e
                         continue;
21ab4e
 
21ab4e
-                cli_out ("%-48s %15s %15s", "Hostname", "BytesRead",
21ab4e
-                         "BytesWritten");
21ab4e
-                cli_out ("%-48s %15s %15s", "--------", "---------",
21ab4e
-                         "------------");
21ab4e
+                cli_out ("%-48s %15s %15s %15s", "Hostname", "BytesRead",
21ab4e
+                         "BytesWritten", "OpVersion");
21ab4e
+                cli_out ("%-48s %15s %15s %15s", "--------", "---------",
21ab4e
+                         "------------", "---------");
21ab4e
                 for (j =0; j < client_count; j++) {
21ab4e
                         memset (key, 0, sizeof (key));
21ab4e
                         snprintf (key, sizeof (key),
21ab4e
@@ -7338,8 +7339,14 @@ cli_print_volume_status_clients (dict_t *dict, gf_boolean_t notbrick)
21ab4e
                                  "brick%d.client%d.byteswrite", i, j);
21ab4e
                         ret = dict_get_uint64 (dict, key, &byteswrite);
21ab4e
 
21ab4e
-                        cli_out ("%-48s %15"PRIu64" %15"PRIu64,
21ab4e
-                                 clientname, bytesread, byteswrite);
21ab4e
+                        memset (key, 0, sizeof (key));
21ab4e
+                        snprintf (key, sizeof (key),
21ab4e
+                                 "brick%d.client%d.opversion", i, j);
21ab4e
+                        ret = dict_get_uint32 (dict, key, &opversion);
21ab4e
+
21ab4e
+                        cli_out ("%-48s %15"PRIu64" %15"PRIu64" %15"PRIu32,
21ab4e
+                                  clientname, bytesread, byteswrite,
21ab4e
+                                  opversion);
21ab4e
                 }
21ab4e
         }
21ab4e
 out:
21ab4e
diff --git a/cli/src/cli-xml-output.c b/cli/src/cli-xml-output.c
21ab4e
index 063e171..d0d8179 100644
21ab4e
--- a/cli/src/cli-xml-output.c
21ab4e
+++ b/cli/src/cli-xml-output.c
21ab4e
@@ -743,6 +743,7 @@ cli_xml_output_vol_status_clients (xmlTextWriterPtr writer, dict_t *dict,
21ab4e
         char            *hostname = NULL;
21ab4e
         uint64_t        bytes_read = 0;
21ab4e
         uint64_t        bytes_write = 0;
21ab4e
+        uint32_t        opversion = 0;
21ab4e
         char            key[1024] = {0,};
21ab4e
         int             i = 0;
21ab4e
 
21ab4e
@@ -797,6 +798,17 @@ cli_xml_output_vol_status_clients (xmlTextWriterPtr writer, dict_t *dict,
21ab4e
                                                        "%"PRIu64, bytes_write);
21ab4e
                 XML_RET_CHECK_AND_GOTO (ret, out);
21ab4e
 
21ab4e
+                memset (key, 0, sizeof (key));
21ab4e
+                snprintf (key, sizeof (key), "brick%d.client%d.opversion",
21ab4e
+                          brick_index, i);
21ab4e
+                ret = dict_get_uint32 (dict, key, &opversion);
21ab4e
+                if (ret)
21ab4e
+                        goto out;
21ab4e
+                ret = xmlTextWriterWriteFormatElement (writer,
21ab4e
+                                                       (xmlChar *)"opVersion",
21ab4e
+                                                       "%"PRIu32, opversion);
21ab4e
+                XML_RET_CHECK_AND_GOTO (ret, out);
21ab4e
+
21ab4e
                 /* </client> */
21ab4e
                 ret = xmlTextWriterEndElement (writer);
21ab4e
                 XML_RET_CHECK_AND_GOTO (ret, out);
21ab4e
diff --git a/xlators/protocol/client/src/client-handshake.c b/xlators/protocol/client/src/client-handshake.c
21ab4e
index 7866697..f51c43f 100644
21ab4e
--- a/xlators/protocol/client/src/client-handshake.c
21ab4e
+++ b/xlators/protocol/client/src/client-handshake.c
21ab4e
@@ -1379,6 +1379,12 @@ client_setvolume (xlator_t *this, struct rpc_clnt *rpc)
21ab4e
                         "msg", client_get_lk_ver (conf));
21ab4e
         }
21ab4e
 
21ab4e
+        ret = dict_set_int32 (options, "opversion", GD_OP_VERSION_MAX);
21ab4e
+        if (ret < 0) {
21ab4e
+                gf_msg (this->name, GF_LOG_ERROR, 0, PC_MSG_DICT_SET_FAILED,
21ab4e
+                        "Failed to set client opversion in handshake message");
21ab4e
+        }
21ab4e
+
21ab4e
         ret = dict_serialized_length (options);
21ab4e
         if (ret < 0) {
21ab4e
                 gf_msg (this->name, GF_LOG_ERROR, 0, PC_MSG_DICT_ERROR,
21ab4e
diff --git a/xlators/protocol/server/src/server-handshake.c b/xlators/protocol/server/src/server-handshake.c
21ab4e
index 1230cdf..a33efb8 100644
21ab4e
--- a/xlators/protocol/server/src/server-handshake.c
21ab4e
+++ b/xlators/protocol/server/src/server-handshake.c
21ab4e
@@ -431,6 +431,8 @@ server_setvolume (rpcsvc_request_t *req)
21ab4e
         uint32_t             lk_version    = 0;
21ab4e
         char                *buf           = NULL;
21ab4e
         gf_boolean_t        cancelled      = _gf_false;
21ab4e
+        uint32_t            opversion      = 0;
21ab4e
+        rpc_transport_t     *xprt          = NULL;
21ab4e
 
21ab4e
         params = dict_new ();
21ab4e
         reply  = dict_new ();
21ab4e
@@ -669,6 +671,22 @@ server_setvolume (rpcsvc_request_t *req)
21ab4e
                         gf_msg_debug (this->name, 0, "failed to set "
21ab4e
                                       "peer-info");
21ab4e
         }
21ab4e
+
21ab4e
+        ret = dict_get_uint32 (params, "opversion", &opversion);
21ab4e
+        if (ret)
21ab4e
+                gf_msg (this->name, GF_LOG_INFO, 0,
21ab4e
+                        PS_MSG_CLIENT_OPVERSION_GET_FAILED,
21ab4e
+                        "Failed to get client opversion");
21ab4e
+
21ab4e
+        /* Assign op-version value to the client */
21ab4e
+        pthread_mutex_lock (&conf->mutex);
21ab4e
+        list_for_each_entry (xprt, &conf->xprt_list, list) {
21ab4e
+                if (strcmp (peerinfo->identifier, xprt->peerinfo.identifier))
21ab4e
+                        continue;
21ab4e
+                xprt->peerinfo.max_op_version = opversion;
21ab4e
+        }
21ab4e
+        pthread_mutex_unlock (&conf->mutex);
21ab4e
+
21ab4e
         if (conf->auth_modules == NULL) {
21ab4e
                 gf_msg (this->name, GF_LOG_ERROR, 0, PS_MSG_AUTH_INIT_FAILED,
21ab4e
                         "Authentication module not initialized");
21ab4e
diff --git a/xlators/protocol/server/src/server-messages.h b/xlators/protocol/server/src/server-messages.h
21ab4e
index 5593e68..b8245af 100644
21ab4e
--- a/xlators/protocol/server/src/server-messages.h
21ab4e
+++ b/xlators/protocol/server/src/server-messages.h
21ab4e
@@ -40,7 +40,7 @@
21ab4e
  */
21ab4e
 
21ab4e
 #define GLFS_PS_BASE                GLFS_MSGID_COMP_PS
21ab4e
-#define GLFS_NUM_MESSAGES           90
21ab4e
+#define GLFS_NUM_MESSAGES           91
21ab4e
 #define GLFS_MSGID_END              (GLFS_PS_BASE + GLFS_NUM_MESSAGES + 1)
21ab4e
 /* Messages with message IDs */
21ab4e
 #define glfs_msg_start_x GLFS_PS_BASE, "Invalid: Start of messages"
21ab4e
@@ -848,6 +848,15 @@
21ab4e
  */
21ab4e
 
21ab4e
 #define PS_MSG_COMPOUND_INFO                    (GLFS_PS_BASE + 90)
21ab4e
+
21ab4e
+/*!
21ab4e
+ * @messageid
21ab4e
+ * @diagnosis
21ab4e
+ * @recommendedaction
21ab4e
+ *
21ab4e
+ */
21ab4e
+
21ab4e
+#define PS_MSG_CLIENT_OPVERSION_GET_FAILED      (GLFS_PS_BASE + 91)
21ab4e
 /*------------*/
21ab4e
 #define glfs_msg_end_x GLFS_MSGID_END, "Invalid: End of messages"
21ab4e
 
21ab4e
diff --git a/xlators/protocol/server/src/server.c b/xlators/protocol/server/src/server.c
21ab4e
index 0bbfd09..db4338e 100644
21ab4e
--- a/xlators/protocol/server/src/server.c
21ab4e
+++ b/xlators/protocol/server/src/server.c
21ab4e
@@ -276,6 +276,14 @@ server_priv_to_dict (xlator_t *this, dict_t *dict)
21ab4e
                         if (ret)
21ab4e
                                 goto unlock;
21ab4e
 
21ab4e
+                        memset (key, 0, sizeof (key));
21ab4e
+                        snprintf (key, sizeof (key), "client%d.opversion",
21ab4e
+                                  count);
21ab4e
+                        ret = dict_set_uint32 (dict, key,
21ab4e
+                                               peerinfo->max_op_version);
21ab4e
+                        if (ret)
21ab4e
+                                goto unlock;
21ab4e
+
21ab4e
                         count++;
21ab4e
                 }
21ab4e
         }
21ab4e
-- 
21ab4e
1.8.3.1
21ab4e