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