a3470f
From a661f617d22ab7555a039841c1959019af3e80a3 Mon Sep 17 00:00:00 2001
a3470f
From: hari gowtham <hgowtham@redhat.com>
a3470f
Date: Thu, 19 Apr 2018 12:22:07 +0530
a3470f
Subject: [PATCH 230/236] glusterd: volume inode/fd status broken with brick
a3470f
 mux
a3470f
a3470f
        backport of:https://review.gluster.org/#/c/19846/6
a3470f
a3470f
Problem:
a3470f
The values for inode/fd was populated from the ctx received
a3470f
from the server xlator.
a3470f
Without brickmux, every brick from a volume belonged to a
a3470f
single brick from the volume.
a3470f
So searching the server and populating it worked.
a3470f
a3470f
With brickmux, a number of bricks can be confined to a single
a3470f
process. These bricks can be from different volumes too (if
a3470f
we use the max-bricks-per-process option).
a3470f
If they are from different volumes, using the server xlator
a3470f
to populate causes problem.
a3470f
a3470f
Fix:
a3470f
Use the brick to validate and populate the inode/fd status.
a3470f
a3470f
>Signed-off-by: hari gowtham <hgowtham@redhat.com>
a3470f
>Change-Id: I2543fa5397ea095f8338b518460037bba3dfdbfd
a3470f
>fixes: bz#1566067
a3470f
a3470f
Signed-off-by: hari gowtham <hgowtham@redhat.com>
a3470f
Change-Id: I2543fa5397ea095f8338b518460037bba3dfdbfd
a3470f
BUG: 1559452
a3470f
Reviewed-on: https://code.engineering.redhat.com/gerrit/136219
a3470f
Tested-by: RHGS Build Bot <nigelb@redhat.com>
a3470f
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
a3470f
---
a3470f
 glusterfsd/src/glusterfsd-mgmt.c             | 34 ++++++------
a3470f
 libglusterfs/src/client_t.c                  | 54 ++++++++++---------
a3470f
 libglusterfs/src/xlator.h                    |  3 +-
a3470f
 tests/basic/volume-status.t                  | 12 +++++
a3470f
 xlators/mgmt/glusterd/src/glusterd-handler.c |  4 ++
a3470f
 xlators/mgmt/glusterd/src/glusterd-op-sm.c   |  3 ++
a3470f
 xlators/nfs/server/src/nfs.c                 |  2 +-
a3470f
 xlators/protocol/server/src/server.c         | 77 ++++++++++++++++------------
a3470f
 8 files changed, 111 insertions(+), 78 deletions(-)
a3470f
a3470f
diff --git a/glusterfsd/src/glusterfsd-mgmt.c b/glusterfsd/src/glusterfsd-mgmt.c
a3470f
index fdf403c..3b9671c 100644
a3470f
--- a/glusterfsd/src/glusterfsd-mgmt.c
a3470f
+++ b/glusterfsd/src/glusterfsd-mgmt.c
a3470f
@@ -1111,14 +1111,14 @@ glusterfs_handle_brick_status (rpcsvc_request_t *req)
a3470f
         glusterfs_ctx_t         *ctx = NULL;
a3470f
         glusterfs_graph_t       *active = NULL;
a3470f
         xlator_t                *this = NULL;
a3470f
-        xlator_t                *any = NULL;
a3470f
-        xlator_t                *xlator = NULL;
a3470f
+        xlator_t                *server_xl = NULL;
a3470f
+        xlator_t                *brick_xl = NULL;
a3470f
         dict_t                  *dict = NULL;
a3470f
         dict_t                  *output = NULL;
a3470f
-        char                    *volname = NULL;
a3470f
         char                    *xname = NULL;
a3470f
         uint32_t                cmd = 0;
a3470f
         char                    *msg = NULL;
a3470f
+        char                    *brickname = NULL;
a3470f
 
a3470f
         GF_ASSERT (req);
a3470f
         this = THIS;
a3470f
@@ -1146,32 +1146,26 @@ glusterfs_handle_brick_status (rpcsvc_request_t *req)
a3470f
                 goto out;
a3470f
         }
a3470f
 
a3470f
-        ret = dict_get_str (dict, "volname", &volname);
a3470f
+        ret = dict_get_str (dict, "brick-name", &brickname);
a3470f
         if (ret) {
a3470f
-                gf_log (this->name, GF_LOG_ERROR, "Couldn't get volname");
a3470f
+                gf_log (this->name, GF_LOG_ERROR, "Couldn't get brickname from"
a3470f
+                        " dict");
a3470f
                 goto out;
a3470f
         }
a3470f
 
a3470f
         ctx = glusterfsd_ctx;
a3470f
         GF_ASSERT (ctx);
a3470f
         active = ctx->active;
a3470f
-        any = active->first;
a3470f
+        server_xl = active->first;
a3470f
 
a3470f
-        ret = gf_asprintf (&xname, "%s-server", volname);
a3470f
-        if (-1 == ret) {
a3470f
-                gf_log (this->name, GF_LOG_ERROR, "Out of memory");
a3470f
-                goto out;
a3470f
-        }
a3470f
-
a3470f
-        xlator = xlator_search_by_name (any, xname);
a3470f
-        if (!xlator) {
a3470f
+        brick_xl = get_xlator_by_name (server_xl, brickname);
a3470f
+        if (!brick_xl) {
a3470f
                 gf_log (this->name, GF_LOG_ERROR, "xlator %s is not loaded",
a3470f
                         xname);
a3470f
                 ret = -1;
a3470f
                 goto out;
a3470f
         }
a3470f
 
a3470f
-
a3470f
         output = dict_new ();
a3470f
         switch (cmd & GF_CLI_STATUS_MASK) {
a3470f
                 case GF_CLI_STATUS_MEM:
a3470f
@@ -1181,15 +1175,17 @@ glusterfs_handle_brick_status (rpcsvc_request_t *req)
a3470f
                         break;
a3470f
 
a3470f
                 case GF_CLI_STATUS_CLIENTS:
a3470f
-                        ret = xlator->dumpops->priv_to_dict (xlator, output);
a3470f
+                        ret = server_xl->dumpops->priv_to_dict (server_xl,
a3470f
+                                        output, brickname);
a3470f
                         break;
a3470f
 
a3470f
                 case GF_CLI_STATUS_INODE:
a3470f
-                        ret = xlator->dumpops->inode_to_dict (xlator, output);
a3470f
+                        ret = server_xl->dumpops->inode_to_dict (brick_xl,
a3470f
+                                                                 output);
a3470f
                         break;
a3470f
 
a3470f
                 case GF_CLI_STATUS_FD:
a3470f
-                        ret = xlator->dumpops->fd_to_dict (xlator, output);
a3470f
+                        ret = server_xl->dumpops->fd_to_dict (brick_xl, output);
a3470f
                         break;
a3470f
 
a3470f
                 case GF_CLI_STATUS_CALLPOOL:
a3470f
@@ -1365,7 +1361,7 @@ glusterfs_handle_node_status (rpcsvc_request_t *req)
a3470f
                                         "Error setting volname to dict");
a3470f
                                 goto out;
a3470f
                         }
a3470f
-                        ret = node->dumpops->priv_to_dict (node, output);
a3470f
+                        ret = node->dumpops->priv_to_dict (node, output, NULL);
a3470f
                         break;
a3470f
 
a3470f
                 case GF_CLI_STATUS_INODE:
a3470f
diff --git a/libglusterfs/src/client_t.c b/libglusterfs/src/client_t.c
a3470f
index 55d891f..dc153cc 100644
a3470f
--- a/libglusterfs/src/client_t.c
a3470f
+++ b/libglusterfs/src/client_t.c
a3470f
@@ -743,10 +743,13 @@ gf_client_dump_fdtables_to_dict (xlator_t *this, dict_t *dict)
a3470f
                             clienttable->cliententries[count].next_free)
a3470f
                                 continue;
a3470f
                         client = clienttable->cliententries[count].client;
a3470f
-                        memset(key, 0, sizeof key);
a3470f
-                        snprintf (key, sizeof key, "conn%d", count++);
a3470f
-                        fdtable_dump_to_dict (client->server_ctx.fdtable,
a3470f
-                                              key, dict);
a3470f
+                        if (!strcmp (client->bound_xl->name, this->name)) {
a3470f
+                                memset(key, 0, sizeof (key));
a3470f
+                                snprintf (key, sizeof (key), "conn%d", count++);
a3470f
+                                fdtable_dump_to_dict (client->server_ctx.
a3470f
+                                                      fdtable,
a3470f
+                                                      key, dict);
a3470f
+                        }
a3470f
                 }
a3470f
         }
a3470f
         UNLOCK(&clienttable->lock);
a3470f
@@ -859,25 +862,30 @@ gf_client_dump_inodes_to_dict (xlator_t *this, dict_t *dict)
a3470f
                             clienttable->cliententries[count].next_free)
a3470f
                                 continue;
a3470f
                         client = clienttable->cliententries[count].client;
a3470f
-                        memset(key, 0, sizeof key);
a3470f
-                        if (client->bound_xl && client->bound_xl->itable) {
a3470f
-                                /* Presently every brick contains only
a3470f
-                                 * one bound_xl for all connections.
a3470f
-                                 * This will lead to duplicating of
a3470f
-                                 *  the inode lists, if listing is
a3470f
-                                 * done for every connection. This
a3470f
-                                 * simple check prevents duplication
a3470f
-                                 * in the present case. If need arises
a3470f
-                                 * the check can be improved.
a3470f
-                                 */
a3470f
-                                if (client->bound_xl == prev_bound_xl)
a3470f
-                                        continue;
a3470f
-                                prev_bound_xl = client->bound_xl;
a3470f
-
a3470f
-                                memset (key, 0, sizeof (key));
a3470f
-                                snprintf (key, sizeof (key), "conn%d", count);
a3470f
-                                inode_table_dump_to_dict (client->bound_xl->itable,
a3470f
-                                                          key, dict);
a3470f
+                        if (!strcmp (client->bound_xl->name, this->name)) {
a3470f
+                                memset(key, 0, sizeof (key));
a3470f
+                                if (client->bound_xl && client->bound_xl->
a3470f
+                                                itable) {
a3470f
+                                        /* Presently every brick contains only
a3470f
+                                         * one bound_xl for all connections.
a3470f
+                                         * This will lead to duplicating of
a3470f
+                                         *  the inode lists, if listing is
a3470f
+                                         * done for every connection. This
a3470f
+                                         * simple check prevents duplication
a3470f
+                                         * in the present case. If need arises
a3470f
+                                         * the check can be improved.
a3470f
+                                         */
a3470f
+                                        if (client->bound_xl == prev_bound_xl)
a3470f
+                                                continue;
a3470f
+                                        prev_bound_xl = client->bound_xl;
a3470f
+
a3470f
+                                        memset (key, 0, sizeof (key));
a3470f
+                                        snprintf (key, sizeof (key), "conn%d",
a3470f
+                                                        count);
a3470f
+                                        inode_table_dump_to_dict (client->
a3470f
+                                                        bound_xl->itable,
a3470f
+                                                        key, dict);
a3470f
+                                }
a3470f
                         }
a3470f
                 }
a3470f
         }
a3470f
diff --git a/libglusterfs/src/xlator.h b/libglusterfs/src/xlator.h
a3470f
index 5ed8646..7434da8 100644
a3470f
--- a/libglusterfs/src/xlator.h
a3470f
+++ b/libglusterfs/src/xlator.h
a3470f
@@ -873,7 +873,8 @@ typedef int32_t (*dumpop_inodectx_t) (xlator_t *this, inode_t *ino);
a3470f
 
a3470f
 typedef int32_t (*dumpop_fdctx_t) (xlator_t *this, fd_t *fd);
a3470f
 
a3470f
-typedef int32_t (*dumpop_priv_to_dict_t) (xlator_t *this, dict_t *dict);
a3470f
+typedef int32_t (*dumpop_priv_to_dict_t) (xlator_t *this, dict_t *dict,
a3470f
+                 char *brickname);
a3470f
 
a3470f
 typedef int32_t (*dumpop_inode_to_dict_t) (xlator_t *this, dict_t *dict);
a3470f
 
a3470f
diff --git a/tests/basic/volume-status.t b/tests/basic/volume-status.t
a3470f
index f87b0a9..d3a79c9 100644
a3470f
--- a/tests/basic/volume-status.t
a3470f
+++ b/tests/basic/volume-status.t
a3470f
@@ -6,6 +6,14 @@
a3470f
 
a3470f
 cleanup;
a3470f
 
a3470f
+function gluster_fd_status () {
a3470f
+        gluster volume status $V0 fd | sed -n '/Brick :/ p' | wc -l
a3470f
+}
a3470f
+
a3470f
+function gluster_inode_status () {
a3470f
+        gluster volume status $V0 inode | sed -n '/Connection / p' | wc -l
a3470f
+}
a3470f
+
a3470f
 TEST glusterd
a3470f
 TEST pidof glusterd
a3470f
 TEST $CLI volume info;
a3470f
@@ -21,6 +29,10 @@ EXPECT_WITHIN $PROCESS_UP_TIMEOUT "Y" nfs_up_status
a3470f
 ## Mount FUSE
a3470f
 TEST $GFS -s $H0 --volfile-id $V0 $M0;
a3470f
 
a3470f
+EXPECT_WITHIN $PROCESS_UP_TIMEOUT "8" gluster_fd_status
a3470f
+
a3470f
+EXPECT_WITHIN $PROCESS_UP_TIMEOUT "1024" gluster_inode_status
a3470f
+
a3470f
 ##Wait for connection establishment between nfs server and brick process
a3470f
 EXPECT_WITHIN $NFS_EXPORT_TIMEOUT "1" is_nfs_export_available;
a3470f
 
a3470f
diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c
a3470f
index cb19321..30adb99 100644
a3470f
--- a/xlators/mgmt/glusterd/src/glusterd-handler.c
a3470f
+++ b/xlators/mgmt/glusterd/src/glusterd-handler.c
a3470f
@@ -5304,6 +5304,10 @@ glusterd_print_client_details (FILE *fp, dict_t *dict,
a3470f
         brick_req->op = GLUSTERD_BRICK_STATUS;
a3470f
         brick_req->name = "";
a3470f
 
a3470f
+        ret = dict_set_str (dict, "brick-name", brickinfo->path);
a3470f
+        if (ret)
a3470f
+                goto out;
a3470f
+
a3470f
         ret = dict_set_int32 (dict, "cmd", GF_CLI_STATUS_CLIENTS);
a3470f
         if (ret)
a3470f
                 goto out;
a3470f
diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
a3470f
index d479ed4..7107a46 100644
a3470f
--- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c
a3470f
+++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
a3470f
@@ -612,6 +612,9 @@ glusterd_brick_op_build_payload (glusterd_op_t op, glusterd_brickinfo_t *brickin
a3470f
                         goto out;
a3470f
                 brick_req->op = GLUSTERD_BRICK_STATUS;
a3470f
                 brick_req->name = "";
a3470f
+                ret = dict_set_str (dict, "brick-name", brickinfo->path);
a3470f
+                if (ret)
a3470f
+                        goto out;
a3470f
         }
a3470f
                 break;
a3470f
         case GD_OP_REBALANCE:
a3470f
diff --git a/xlators/nfs/server/src/nfs.c b/xlators/nfs/server/src/nfs.c
a3470f
index c2c3c86..10502c2 100644
a3470f
--- a/xlators/nfs/server/src/nfs.c
a3470f
+++ b/xlators/nfs/server/src/nfs.c
a3470f
@@ -1604,7 +1604,7 @@ _nfs_export_is_for_vol (char *exname, char *volname)
a3470f
 }
a3470f
 
a3470f
 int
a3470f
-nfs_priv_to_dict (xlator_t *this, dict_t *dict)
a3470f
+nfs_priv_to_dict (xlator_t *this, dict_t *dict, char *brickname)
a3470f
 {
a3470f
         int                     ret = -1;
a3470f
         struct nfs_state        *priv = NULL;
a3470f
diff --git a/xlators/protocol/server/src/server.c b/xlators/protocol/server/src/server.c
a3470f
index 792dfb3..eed4295 100644
a3470f
--- a/xlators/protocol/server/src/server.c
a3470f
+++ b/xlators/protocol/server/src/server.c
a3470f
@@ -225,7 +225,7 @@ ret:
a3470f
 
a3470f
 
a3470f
 int
a3470f
-server_priv_to_dict (xlator_t *this, dict_t *dict)
a3470f
+server_priv_to_dict (xlator_t *this, dict_t *dict, char *brickname)
a3470f
 {
a3470f
         server_conf_t   *conf = NULL;
a3470f
         rpc_transport_t *xprt = NULL;
a3470f
@@ -245,39 +245,48 @@ server_priv_to_dict (xlator_t *this, dict_t *dict)
a3470f
         pthread_mutex_lock (&conf->mutex);
a3470f
         {
a3470f
                 list_for_each_entry (xprt, &conf->xprt_list, list) {
a3470f
-                        peerinfo = &xprt->peerinfo;
a3470f
-                        memset (key, 0, sizeof (key));
a3470f
-                        snprintf (key, sizeof (key), "client%d.hostname",
a3470f
-                                  count);
a3470f
-                        ret = dict_set_str (dict, key, peerinfo->identifier);
a3470f
-                        if (ret)
a3470f
-                                goto unlock;
a3470f
-
a3470f
-                        memset (key, 0, sizeof (key));
a3470f
-                        snprintf (key, sizeof (key), "client%d.bytesread",
a3470f
-                                  count);
a3470f
-                        ret = dict_set_uint64 (dict, key,
a3470f
-                                               xprt->total_bytes_read);
a3470f
-                        if (ret)
a3470f
-                                goto unlock;
a3470f
-
a3470f
-                        memset (key, 0, sizeof (key));
a3470f
-                        snprintf (key, sizeof (key), "client%d.byteswrite",
a3470f
-                                  count);
a3470f
-                        ret = dict_set_uint64 (dict, key,
a3470f
-                                               xprt->total_bytes_write);
a3470f
-                        if (ret)
a3470f
-                                goto unlock;
a3470f
-
a3470f
-                        memset (key, 0, sizeof (key));
a3470f
-                        snprintf (key, sizeof (key), "client%d.opversion",
a3470f
-                                  count);
a3470f
-                        ret = dict_set_uint32 (dict, key,
a3470f
-                                               peerinfo->max_op_version);
a3470f
-                        if (ret)
a3470f
-                                goto unlock;
a3470f
-
a3470f
-                        count++;
a3470f
+                        if (!strcmp (brickname,
a3470f
+                                     xprt->xl_private->bound_xl->name)) {
a3470f
+                                peerinfo = &xprt->peerinfo;
a3470f
+                                memset (key, 0, sizeof (key));
a3470f
+                                snprintf (key, sizeof (key),
a3470f
+                                          "client%d.hostname",
a3470f
+                                          count);
a3470f
+                                ret = dict_set_str (dict, key,
a3470f
+                                                    peerinfo->identifier);
a3470f
+                                if (ret)
a3470f
+                                        goto unlock;
a3470f
+
a3470f
+                                memset (key, 0, sizeof (key));
a3470f
+                                snprintf (key, sizeof (key),
a3470f
+                                          "client%d.bytesread",
a3470f
+                                          count);
a3470f
+                                ret = dict_set_uint64 (dict, key,
a3470f
+                                                xprt->total_bytes_read);
a3470f
+                                if (ret)
a3470f
+                                        goto unlock;
a3470f
+
a3470f
+                                memset (key, 0, sizeof (key));
a3470f
+                                snprintf (key, sizeof (key),
a3470f
+                                          "client%d.byteswrite",
a3470f
+                                          count);
a3470f
+                                ret = dict_set_uint64 (dict, key,
a3470f
+                                                xprt->total_bytes_write);
a3470f
+                                if (ret)
a3470f
+                                        goto unlock;
a3470f
+
a3470f
+                                memset (key, 0, sizeof (key));
a3470f
+                                snprintf (key, sizeof (key),
a3470f
+                                          "client%d.opversion",
a3470f
+                                          count);
a3470f
+                                ret = dict_set_uint32 (dict, key,
a3470f
+                                                peerinfo->max_op_version);
a3470f
+                                if (ret)
a3470f
+                                        goto unlock;
a3470f
+
a3470f
+
a3470f
+                                count++;
a3470f
+                        }
a3470f
                 }
a3470f
         }
a3470f
 unlock:
a3470f
-- 
a3470f
1.8.3.1
a3470f