7f4c2a
From e472b92b2306c37350ca66678d2b642ff510d8b4 Mon Sep 17 00:00:00 2001
7f4c2a
From: Krishnan Parthasarathi <kparthas@redhat.com>
7f4c2a
Date: Fri, 14 Aug 2015 16:01:05 +0530
7f4c2a
Subject: [PATCH 270/279] rpc: add owner xlator argument to rpc_clnt_new
7f4c2a
7f4c2a
        Backport of http://review.gluster.com/11908
7f4c2a
7f4c2a
The @owner argument tells RPC layer the xlator that owns the connection
7f4c2a
and to which xlator THIS needs be set during network notifications like
7f4c2a
CONNECT and DISCONNECT.
7f4c2a
7f4c2a
Code paths that originate from the head of a (volume) graph and use
7f4c2a
STACK_WIND ensure that the RPC local endpoint has the right xlator saved
7f4c2a
in the frame of the call (callback pair). This guarantees that the
7f4c2a
callback is executed in the right xlator context.
7f4c2a
7f4c2a
The client handshake process which includes fetching of brick ports from
7f4c2a
glusterd, setting lk-version on the brick for the session, don't have
7f4c2a
the correct xlator set in their frames. The problem lies with RPC
7f4c2a
notifications. It doesn't have the provision to set THIS with the xlator
7f4c2a
that is registered with the corresponding RPC programs. e.g,
7f4c2a
RPC_CLNT_CONNECT event received by protocol/client doesn't have THIS set
7f4c2a
to its xlator. This implies, call(-callbacks) originating from this
7f4c2a
thread don't have the right xlator set too.
7f4c2a
7f4c2a
The fix would be to save the xlator registered with the RPC connection
7f4c2a
during rpc_clnt_new. e.g, protocol/client's xlator would be saved with
7f4c2a
the RPC connection that it 'owns'. RPC notifications such as CONNECT,
7f4c2a
DISCONNECT, etc inherit THIS from the RPC connection's xlator.
7f4c2a
7f4c2a
BUG: 1235571
7f4c2a
Change-Id: I6138c7f2ffa9a99a15eec020e1f829400b186ce4
7f4c2a
Signed-off-by: Krishnan Parthasarathi <kparthas@redhat.com>
7f4c2a
Reviewed-on: https://code.engineering.redhat.com/gerrit/55164
7f4c2a
Reviewed-by: Raghavendra Gowdappa <rgowdapp@redhat.com>
7f4c2a
Tested-by: Raghavendra Gowdappa <rgowdapp@redhat.com>
7f4c2a
---
7f4c2a
 api/src/glfs-internal.h                            |    1 -
7f4c2a
 api/src/glfs-mgmt.c                                |    2 +-
7f4c2a
 cli/src/cli-quotad-client.c                        |    2 +-
7f4c2a
 cli/src/cli.c                                      |    2 +-
7f4c2a
 glusterfsd/src/glusterfsd-mgmt.c                   |    2 +-
7f4c2a
 libglusterfs/src/globals.h                         |    1 +
7f4c2a
 rpc/rpc-lib/src/rpc-clnt.c                         |   19 ++++++++++++++++++-
7f4c2a
 rpc/rpc-lib/src/rpc-clnt.h                         |    4 +++-
7f4c2a
 .../features/changelog/src/changelog-rpc-common.c  |    2 +-
7f4c2a
 xlators/features/quota/src/quota-enforcer-client.c |    2 +-
7f4c2a
 .../snapview-server/src/snapview-server-mgmt.c     |    2 +-
7f4c2a
 xlators/mgmt/glusterd/src/glusterd-conn-mgmt.c     |    2 +-
7f4c2a
 xlators/mgmt/glusterd/src/glusterd-handler.c       |    2 +-
7f4c2a
 xlators/nfs/server/src/nlm4.c                      |    2 +-
7f4c2a
 xlators/protocol/client/src/client.c               |    2 +-
7f4c2a
 15 files changed, 33 insertions(+), 14 deletions(-)
7f4c2a
7f4c2a
diff --git a/api/src/glfs-internal.h b/api/src/glfs-internal.h
7f4c2a
index 83b4ade..8ff78de 100644
7f4c2a
--- a/api/src/glfs-internal.h
7f4c2a
+++ b/api/src/glfs-internal.h
7f4c2a
@@ -199,7 +199,6 @@ int glfs_first_lookup (xlator_t *subvol);
7f4c2a
 void glfs_process_upcall_event (struct glfs *fs, void *data);
7f4c2a
         GFAPI_PRIVATE(glfs_process_upcall_event, 3.7.0);
7f4c2a
 
7f4c2a
-#define DECLARE_OLD_THIS xlator_t *old_THIS = NULL
7f4c2a
 
7f4c2a
 #define __GLFS_ENTRY_VALIDATE_FS(fs, label)                         \
7f4c2a
 do {                                                                \
7f4c2a
diff --git a/api/src/glfs-mgmt.c b/api/src/glfs-mgmt.c
7f4c2a
index 2159d67..903b102 100644
7f4c2a
--- a/api/src/glfs-mgmt.c
7f4c2a
+++ b/api/src/glfs-mgmt.c
7f4c2a
@@ -868,7 +868,7 @@ glfs_mgmt_init (struct glfs *fs)
7f4c2a
 	if (ret)
7f4c2a
 		goto out;
7f4c2a
 
7f4c2a
-	rpc = rpc_clnt_new (options, ctx, THIS->name, 8);
7f4c2a
+	rpc = rpc_clnt_new (options, THIS, THIS->name, 8);
7f4c2a
 	if (!rpc) {
7f4c2a
 		ret = -1;
7f4c2a
 		gf_msg (THIS->name, GF_LOG_WARNING, 0,
7f4c2a
diff --git a/cli/src/cli-quotad-client.c b/cli/src/cli-quotad-client.c
7f4c2a
index 7c16519..d3a2312 100644
7f4c2a
--- a/cli/src/cli-quotad-client.c
7f4c2a
+++ b/cli/src/cli-quotad-client.c
7f4c2a
@@ -131,7 +131,7 @@ cli_quotad_clnt_init (xlator_t *this, dict_t *options)
7f4c2a
         if (ret)
7f4c2a
                 goto out;
7f4c2a
 
7f4c2a
-        rpc = rpc_clnt_new (options, this->ctx, this->name, 16);
7f4c2a
+        rpc = rpc_clnt_new (options, this, this->name, 16);
7f4c2a
         if (!rpc)
7f4c2a
                 goto out;
7f4c2a
 
7f4c2a
diff --git a/cli/src/cli.c b/cli/src/cli.c
7f4c2a
index 525ec4b..851178b 100644
7f4c2a
--- a/cli/src/cli.c
7f4c2a
+++ b/cli/src/cli.c
7f4c2a
@@ -627,7 +627,7 @@ cli_rpc_init (struct cli_state *state)
7f4c2a
                         goto out;
7f4c2a
         }
7f4c2a
 
7f4c2a
-        rpc = rpc_clnt_new (options, this->ctx, this->name, 16);
7f4c2a
+        rpc = rpc_clnt_new (options, this, this->name, 16);
7f4c2a
         if (!rpc)
7f4c2a
                 goto out;
7f4c2a
 
7f4c2a
diff --git a/glusterfsd/src/glusterfsd-mgmt.c b/glusterfsd/src/glusterfsd-mgmt.c
7f4c2a
index 1cff44b..aa7ee4f 100644
7f4c2a
--- a/glusterfsd/src/glusterfsd-mgmt.c
7f4c2a
+++ b/glusterfsd/src/glusterfsd-mgmt.c
7f4c2a
@@ -2038,7 +2038,7 @@ glusterfs_mgmt_init (glusterfs_ctx_t *ctx)
7f4c2a
         if (ret)
7f4c2a
                 goto out;
7f4c2a
 
7f4c2a
-        rpc = rpc_clnt_new (options, THIS->ctx, THIS->name, 8);
7f4c2a
+        rpc = rpc_clnt_new (options, THIS, THIS->name, 8);
7f4c2a
         if (!rpc) {
7f4c2a
                 ret = -1;
7f4c2a
                 gf_log (THIS->name, GF_LOG_WARNING, "failed to create rpc clnt");
7f4c2a
diff --git a/libglusterfs/src/globals.h b/libglusterfs/src/globals.h
7f4c2a
index 9aca3c3..9579c45 100644
7f4c2a
--- a/libglusterfs/src/globals.h
7f4c2a
+++ b/libglusterfs/src/globals.h
7f4c2a
@@ -68,6 +68,7 @@
7f4c2a
 
7f4c2a
 /* THIS */
7f4c2a
 #define THIS (*__glusterfs_this_location())
7f4c2a
+#define DECLARE_OLD_THIS        xlator_t *old_THIS = THIS
7f4c2a
 
7f4c2a
 xlator_t **__glusterfs_this_location ();
7f4c2a
 xlator_t *glusterfs_this_get ();
7f4c2a
diff --git a/rpc/rpc-lib/src/rpc-clnt.c b/rpc/rpc-lib/src/rpc-clnt.c
7f4c2a
index 5fbe072..1d87866 100644
7f4c2a
--- a/rpc/rpc-lib/src/rpc-clnt.c
7f4c2a
+++ b/rpc/rpc-lib/src/rpc-clnt.c
7f4c2a
@@ -817,6 +817,16 @@ out:
7f4c2a
 static void
7f4c2a
 rpc_clnt_destroy (struct rpc_clnt *rpc);
7f4c2a
 
7f4c2a
+#define RPC_THIS_SAVE(xl) do {                                  \
7f4c2a
+        old_THIS = THIS ;                                       \
7f4c2a
+        if (!old_THIS)                                          \
7f4c2a
+                gf_log_callingfn ("rpc", GF_LOG_CRITICAL,       \
7f4c2a
+                                  "THIS is not initialised.");  \
7f4c2a
+        THIS = xl;                                              \
7f4c2a
+} while (0)
7f4c2a
+
7f4c2a
+#define RPC_THIS_RESTORE        (THIS = old_THIS)
7f4c2a
+
7f4c2a
 int
7f4c2a
 rpc_clnt_notify (rpc_transport_t *trans, void *mydata,
7f4c2a
                  rpc_transport_event_t event, void *data, ...)
7f4c2a
@@ -828,6 +838,7 @@ rpc_clnt_notify (rpc_transport_t *trans, void *mydata,
7f4c2a
         rpc_transport_pollin_t *pollin      = NULL;
7f4c2a
         struct timespec         ts          = {0, };
7f4c2a
         void                   *clnt_mydata = NULL;
7f4c2a
+        DECLARE_OLD_THIS;
7f4c2a
 
7f4c2a
         conn = mydata;
7f4c2a
         if (conn == NULL) {
7f4c2a
@@ -837,6 +848,8 @@ rpc_clnt_notify (rpc_transport_t *trans, void *mydata,
7f4c2a
         if (!clnt)
7f4c2a
                 goto out;
7f4c2a
 
7f4c2a
+        RPC_THIS_SAVE (clnt->owner);
7f4c2a
+
7f4c2a
         switch (event) {
7f4c2a
         case RPC_TRANSPORT_DISCONNECT:
7f4c2a
         {
7f4c2a
@@ -937,6 +950,7 @@ rpc_clnt_notify (rpc_transport_t *trans, void *mydata,
7f4c2a
         }
7f4c2a
 
7f4c2a
 out:
7f4c2a
+        RPC_THIS_RESTORE;
7f4c2a
         return ret;
7f4c2a
 }
7f4c2a
 
7f4c2a
@@ -1041,11 +1055,13 @@ out:
7f4c2a
 }
7f4c2a
 
7f4c2a
 struct rpc_clnt *
7f4c2a
-rpc_clnt_new (dict_t *options, glusterfs_ctx_t *ctx, char *name,
7f4c2a
+rpc_clnt_new (dict_t *options, xlator_t *owner, char *name,
7f4c2a
               uint32_t reqpool_size)
7f4c2a
 {
7f4c2a
         int                    ret  = -1;
7f4c2a
         struct rpc_clnt       *rpc  = NULL;
7f4c2a
+        glusterfs_ctx_t       *ctx  = owner->ctx;
7f4c2a
+
7f4c2a
 
7f4c2a
         rpc = GF_CALLOC (1, sizeof (*rpc), gf_common_mt_rpcclnt_t);
7f4c2a
         if (!rpc) {
7f4c2a
@@ -1054,6 +1070,7 @@ rpc_clnt_new (dict_t *options, glusterfs_ctx_t *ctx, char *name,
7f4c2a
 
7f4c2a
         pthread_mutex_init (&rpc->lock, NULL);
7f4c2a
         rpc->ctx = ctx;
7f4c2a
+        rpc->owner = owner;
7f4c2a
 
7f4c2a
         if (!reqpool_size)
7f4c2a
                 reqpool_size = RPC_CLNT_DEFAULT_REQUEST_COUNT;
7f4c2a
diff --git a/rpc/rpc-lib/src/rpc-clnt.h b/rpc/rpc-lib/src/rpc-clnt.h
7f4c2a
index ee46a9a..6a4bb40 100644
7f4c2a
--- a/rpc/rpc-lib/src/rpc-clnt.h
7f4c2a
+++ b/rpc/rpc-lib/src/rpc-clnt.h
7f4c2a
@@ -188,9 +188,11 @@ typedef struct rpc_clnt {
7f4c2a
         int                   refcount;
7f4c2a
         int                   auth_null;
7f4c2a
         char                  disabled;
7f4c2a
+        xlator_t             *owner;
7f4c2a
 } rpc_clnt_t;
7f4c2a
 
7f4c2a
-struct rpc_clnt *rpc_clnt_new (dict_t *options, glusterfs_ctx_t *ctx,
7f4c2a
+
7f4c2a
+struct rpc_clnt *rpc_clnt_new (dict_t *options, xlator_t *owner,
7f4c2a
                                char *name, uint32_t reqpool_size);
7f4c2a
 
7f4c2a
 int rpc_clnt_start (struct rpc_clnt *rpc);
7f4c2a
diff --git a/xlators/features/changelog/src/changelog-rpc-common.c b/xlators/features/changelog/src/changelog-rpc-common.c
7f4c2a
index de3a730..b3b14fa 100644
7f4c2a
--- a/xlators/features/changelog/src/changelog-rpc-common.c
7f4c2a
+++ b/xlators/features/changelog/src/changelog-rpc-common.c
7f4c2a
@@ -52,7 +52,7 @@ changelog_rpc_client_init (xlator_t *this, void *cbkdata,
7f4c2a
                 goto dealloc_dict;
7f4c2a
         }
7f4c2a
 
7f4c2a
-        rpc = rpc_clnt_new (options, this->ctx, this->name, 16);
7f4c2a
+        rpc = rpc_clnt_new (options, this, this->name, 16);
7f4c2a
         if (!rpc)
7f4c2a
                 goto dealloc_dict;
7f4c2a
 
7f4c2a
diff --git a/xlators/features/quota/src/quota-enforcer-client.c b/xlators/features/quota/src/quota-enforcer-client.c
7f4c2a
index 067db6d..10bd24f 100644
7f4c2a
--- a/xlators/features/quota/src/quota-enforcer-client.c
7f4c2a
+++ b/xlators/features/quota/src/quota-enforcer-client.c
7f4c2a
@@ -453,7 +453,7 @@ quota_enforcer_init (xlator_t *this, dict_t *options)
7f4c2a
         if (ret)
7f4c2a
                 goto out;
7f4c2a
 
7f4c2a
-        rpc = rpc_clnt_new (options, this->ctx, this->name, 16);
7f4c2a
+        rpc = rpc_clnt_new (options, this, this->name, 16);
7f4c2a
         if (!rpc) {
7f4c2a
                 ret = -1;
7f4c2a
                 goto out;
7f4c2a
diff --git a/xlators/features/snapview-server/src/snapview-server-mgmt.c b/xlators/features/snapview-server/src/snapview-server-mgmt.c
7f4c2a
index 0fe3687..4b61326 100644
7f4c2a
--- a/xlators/features/snapview-server/src/snapview-server-mgmt.c
7f4c2a
+++ b/xlators/features/snapview-server/src/snapview-server-mgmt.c
7f4c2a
@@ -85,7 +85,7 @@ svs_mgmt_init (xlator_t *this)
7f4c2a
                 goto out;
7f4c2a
         }
7f4c2a
 
7f4c2a
-        priv->rpc = rpc_clnt_new (options, this->ctx, this->name, 8);
7f4c2a
+        priv->rpc = rpc_clnt_new (options, this, this->name, 8);
7f4c2a
         if (!priv->rpc) {
7f4c2a
                 gf_log (this->name, GF_LOG_ERROR, "failed to initialize RPC");
7f4c2a
                 goto out;
7f4c2a
diff --git a/xlators/mgmt/glusterd/src/glusterd-conn-mgmt.c b/xlators/mgmt/glusterd/src/glusterd-conn-mgmt.c
7f4c2a
index fca9323..607a065 100644
7f4c2a
--- a/xlators/mgmt/glusterd/src/glusterd-conn-mgmt.c
7f4c2a
+++ b/xlators/mgmt/glusterd/src/glusterd-conn-mgmt.c
7f4c2a
@@ -46,7 +46,7 @@ glusterd_conn_init (glusterd_conn_t *conn, char *sockpath,
7f4c2a
                 goto out;
7f4c2a
 
7f4c2a
         /* @options is free'd by rpc_transport when destroyed */
7f4c2a
-        rpc = rpc_clnt_new (options, this->ctx, (char *)svc->name, 16);
7f4c2a
+        rpc = rpc_clnt_new (options, this, (char *)svc->name, 16);
7f4c2a
         if (!rpc) {
7f4c2a
                 ret = -1;
7f4c2a
                 goto out;
7f4c2a
diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c
7f4c2a
index 82bd7b1..ed5d6ff 100644
7f4c2a
--- a/xlators/mgmt/glusterd/src/glusterd-handler.c
7f4c2a
+++ b/xlators/mgmt/glusterd/src/glusterd-handler.c
7f4c2a
@@ -3295,7 +3295,7 @@ glusterd_rpc_create (struct rpc_clnt **rpc,
7f4c2a
         GF_ASSERT (options);
7f4c2a
 
7f4c2a
         /* TODO: is 32 enough? or more ? */
7f4c2a
-        new_rpc = rpc_clnt_new (options, this->ctx, this->name, 16);
7f4c2a
+        new_rpc = rpc_clnt_new (options, this, this->name, 16);
7f4c2a
         if (!new_rpc)
7f4c2a
                 goto out;
7f4c2a
 
7f4c2a
diff --git a/xlators/nfs/server/src/nlm4.c b/xlators/nfs/server/src/nlm4.c
7f4c2a
index a1127a3..ac45b4f 100644
7f4c2a
--- a/xlators/nfs/server/src/nlm4.c
7f4c2a
+++ b/xlators/nfs/server/src/nlm4.c
7f4c2a
@@ -1055,7 +1055,7 @@ nlm4_establish_callback (void *csarg)
7f4c2a
         }
7f4c2a
 
7f4c2a
         /* TODO: is 32 frames in transit enough ? */
7f4c2a
-        rpc_clnt = rpc_clnt_new (options, cs->nfsx->ctx, "NLM-client", 32);
7f4c2a
+        rpc_clnt = rpc_clnt_new (options, cs->nfsx, "NLM-client", 32);
7f4c2a
         if (rpc_clnt == NULL) {
7f4c2a
                 gf_msg (GF_NLM, GF_LOG_ERROR, EINVAL, NFS_MSG_INVALID_ENTRY,
7f4c2a
                         "rpc_clnt NULL");
7f4c2a
diff --git a/xlators/protocol/client/src/client.c b/xlators/protocol/client/src/client.c
7f4c2a
index db7a07a..ccb26dd 100644
7f4c2a
--- a/xlators/protocol/client/src/client.c
7f4c2a
+++ b/xlators/protocol/client/src/client.c
7f4c2a
@@ -2286,7 +2286,7 @@ client_init_rpc (xlator_t *this)
7f4c2a
                 goto out;
7f4c2a
         }
7f4c2a
 
7f4c2a
-        conf->rpc = rpc_clnt_new (this->options, this->ctx, this->name, 0);
7f4c2a
+        conf->rpc = rpc_clnt_new (this->options, this, this->name, 0);
7f4c2a
         if (!conf->rpc) {
7f4c2a
                 gf_msg (this->name, GF_LOG_ERROR, 0, PC_MSG_RPC_INIT_FAILED,
7f4c2a
                         "failed to initialize RPC");
7f4c2a
-- 
7f4c2a
1.7.1
7f4c2a