cb8e9e
From 1dde7f9f6a555c7e461ec67ce4f9858ef7decc8d Mon Sep 17 00:00:00 2001
cb8e9e
From: Soumya Koduri <skoduri@redhat.com>
cb8e9e
Date: Thu, 4 Jun 2015 11:25:35 +0530
cb8e9e
Subject: [PATCH 30/57] Upcall/cache-invalidation: Ignore fops with frame->root->client not set
cb8e9e
cb8e9e
This is a backport of the fix reviewed upstream on -
cb8e9e
http://review.gluster.org/10909
cb8e9e
cb8e9e
Server-side internally generated fops like 'quota/marker' will
cb8e9e
not have any client associated with the frame. Hence we need a
cb8e9e
check for clients to be valid before processing for upcall cache
cb8e9e
invalidation. Also fixed an issue with initializing reaper-thread.
cb8e9e
cb8e9e
Added a testcase to test the fix.
cb8e9e
cb8e9e
BUG: 1224183
cb8e9e
Change-Id: I5042238cf52380e06c69adb3bee874df9b445f95
cb8e9e
Signed-off-by: Soumya Koduri <skoduri@redhat.com>
cb8e9e
Reviewed-on: http://review.gluster.org/10909
cb8e9e
Reviewed-by: Kaleb KEITHLEY <kkeithle@redhat.com>
cb8e9e
Reviewed-by: jiffin tony Thottan <jthottan@redhat.com>
cb8e9e
Reviewed-by: Niels de Vos <ndevos@redhat.com>
cb8e9e
Reviewed-on: https://code.engineering.redhat.com/gerrit/50369
cb8e9e
Reviewed-by: Jiffin Thottan <jthottan@redhat.com>
cb8e9e
Tested-by: Niels de Vos <ndevos@redhat.com>
cb8e9e
---
cb8e9e
 tests/bugs/upcall/bug-1227204.t                 |   29 +++++++++++++++++++++++
cb8e9e
 xlators/features/upcall/src/upcall-internal.c   |   25 +++++++++++++++----
cb8e9e
 xlators/features/upcall/src/upcall.c            |    4 ++-
cb8e9e
 xlators/mgmt/glusterd/src/glusterd-volume-set.c |    2 +-
cb8e9e
 4 files changed, 53 insertions(+), 7 deletions(-)
cb8e9e
 create mode 100755 tests/bugs/upcall/bug-1227204.t
cb8e9e
cb8e9e
diff --git a/tests/bugs/upcall/bug-1227204.t b/tests/bugs/upcall/bug-1227204.t
cb8e9e
new file mode 100755
cb8e9e
index 0000000..fc393b1
cb8e9e
--- /dev/null
cb8e9e
+++ b/tests/bugs/upcall/bug-1227204.t
cb8e9e
@@ -0,0 +1,29 @@
cb8e9e
+#!/bin/bash
cb8e9e
+
cb8e9e
+# This regression test tries to ensure that quota limit-usage set work with
cb8e9e
+# features.cache-invalidation on.
cb8e9e
+
cb8e9e
+. $(dirname $0)/../../include.rc
cb8e9e
+. $(dirname $0)/../../volume.rc
cb8e9e
+
cb8e9e
+cleanup;
cb8e9e
+
cb8e9e
+TEST glusterd
cb8e9e
+TEST pidof glusterd;
cb8e9e
+TEST $CLI volume info;
cb8e9e
+
cb8e9e
+TEST $CLI volume create $V0 replica 2 $H0:$B0/${V0}{1,2,3,4,5,6};
cb8e9e
+TEST $CLI volume start $V0;
cb8e9e
+
cb8e9e
+TEST $CLI volume set $V0 features.cache-invalidation on;
cb8e9e
+TEST $CLI volume quota $V0 enable;
cb8e9e
+
cb8e9e
+TEST glusterfs --volfile-id=$V0 --volfile-server=$H0 $M0;
cb8e9e
+
cb8e9e
+TEST mkdir -p $M0/1/2;
cb8e9e
+TEST $CLI volume quota $V0 limit-usage /1/2 100MB 70%;
cb8e9e
+
cb8e9e
+TEST $CLI volume status $V0
cb8e9e
+TEST $CLI volume stop $V0
cb8e9e
+
cb8e9e
+cleanup;
cb8e9e
diff --git a/xlators/features/upcall/src/upcall-internal.c b/xlators/features/upcall/src/upcall-internal.c
cb8e9e
index 19c9f9e..e13097c 100644
cb8e9e
--- a/xlators/features/upcall/src/upcall-internal.c
cb8e9e
+++ b/xlators/features/upcall/src/upcall-internal.c
cb8e9e
@@ -206,10 +206,13 @@ __upcall_inode_ctx_set (inode_t *inode, xlator_t *this)
cb8e9e
         INIT_LIST_HEAD (&inode_ctx->client_list);
cb8e9e
         inode_ctx->destroy = 0;
cb8e9e
 
cb8e9e
-        ret = __inode_ctx_set (inode, this, (uint64_t *) inode_ctx);
cb8e9e
-        if (ret)
cb8e9e
+        ctx = (long) inode_ctx;
cb8e9e
+        ret = __inode_ctx_set (inode, this, &ctx;;
cb8e9e
+        if (ret) {
cb8e9e
                 gf_log (this->name, GF_LOG_DEBUG,
cb8e9e
                         "failed to set inode ctx (%p)", inode);
cb8e9e
+                goto out;
cb8e9e
+        }
cb8e9e
 
cb8e9e
         /* add this inode_ctx to the global list */
cb8e9e
         LOCK (&priv->inode_ctx_lk);
cb8e9e
@@ -241,7 +244,7 @@ __upcall_inode_ctx_get (inode_t *inode, xlator_t *this)
cb8e9e
                         goto out;
cb8e9e
         }
cb8e9e
 
cb8e9e
-        inode_ctx = (upcall_inode_ctx_t *)(long) ctx;
cb8e9e
+        inode_ctx = (upcall_inode_ctx_t *) (long) (ctx);
cb8e9e
 
cb8e9e
 out:
cb8e9e
         return inode_ctx;
cb8e9e
@@ -377,10 +380,10 @@ upcall_cleanup_inode_ctx (xlator_t *this, inode_t *inode)
cb8e9e
                 }
cb8e9e
                 pthread_mutex_unlock (&inode_ctx->client_list_lock);
cb8e9e
 
cb8e9e
-                pthread_mutex_destroy (&inode_ctx->client_list_lock);
cb8e9e
-
cb8e9e
                 /* Mark the inode_ctx to be destroyed */
cb8e9e
                 inode_ctx->destroy = 1;
cb8e9e
+                gf_msg_debug ("upcall", 0, "set upcall_inode_ctx (%p) to destroy mode",
cb8e9e
+                              inode_ctx);
cb8e9e
         }
cb8e9e
 
cb8e9e
 out:
cb8e9e
@@ -422,8 +425,12 @@ upcall_reaper_thread (void *data)
cb8e9e
                         LOCK (&priv->inode_ctx_lk);
cb8e9e
                         {
cb8e9e
                                 /* client list would have been cleaned up*/
cb8e9e
+                                gf_msg_debug ("upcall", 0, "Freeing upcall_inode_ctx (%p)",
cb8e9e
+                                              inode_ctx);
cb8e9e
                                 list_del_init (&inode_ctx->inode_ctx_list);
cb8e9e
+                                pthread_mutex_destroy (&inode_ctx->client_list_lock);
cb8e9e
                                 GF_FREE (inode_ctx);
cb8e9e
+                                inode_ctx = NULL;
cb8e9e
                         }
cb8e9e
                         UNLOCK (&priv->inode_ctx_lk);
cb8e9e
                 }
cb8e9e
@@ -474,6 +481,14 @@ upcall_cache_invalidate (call_frame_t *frame, xlator_t *this, client_t *client,
cb8e9e
         if (!is_cache_invalidation_enabled(this))
cb8e9e
                 return;
cb8e9e
 
cb8e9e
+        /* server-side generated fops like quota/marker will not have any
cb8e9e
+         * client associated with them. Ignore such fops.
cb8e9e
+         */
cb8e9e
+        if (!client) {
cb8e9e
+                gf_msg_debug ("upcall", 0, "Internal fop - client NULL");
cb8e9e
+                return;
cb8e9e
+        }
cb8e9e
+
cb8e9e
         up_inode_ctx = ((upcall_local_t *)frame->local)->upcall_inode_ctx;
cb8e9e
 
cb8e9e
         if (!up_inode_ctx)
cb8e9e
diff --git a/xlators/features/upcall/src/upcall.c b/xlators/features/upcall/src/upcall.c
cb8e9e
index 5f6c29e..331db52 100644
cb8e9e
--- a/xlators/features/upcall/src/upcall.c
cb8e9e
+++ b/xlators/features/upcall/src/upcall.c
cb8e9e
@@ -1581,8 +1581,8 @@ upcall_local_wipe (xlator_t *this, upcall_local_t *local)
cb8e9e
 {
cb8e9e
         if (local) {
cb8e9e
                 inode_unref (local->inode);
cb8e9e
-                mem_put (local);
cb8e9e
                 loc_wipe (&local->rename_oldloc);
cb8e9e
+                mem_put (local);
cb8e9e
         }
cb8e9e
 }
cb8e9e
 
cb8e9e
@@ -1634,6 +1634,7 @@ reconfigure (xlator_t *this, dict_t *options)
cb8e9e
                                 " Disabling cache_invalidation",
cb8e9e
                                 strerror(errno));
cb8e9e
                 }
cb8e9e
+                priv->reaper_init_done = 1;
cb8e9e
         }
cb8e9e
 
cb8e9e
 out:
cb8e9e
@@ -1680,6 +1681,7 @@ init (xlator_t *this)
cb8e9e
                                 " Disabling cache_invalidation",
cb8e9e
                                 strerror(errno));
cb8e9e
                 }
cb8e9e
+                priv->reaper_init_done = 1;
cb8e9e
         }
cb8e9e
 out:
cb8e9e
         if (ret) {
cb8e9e
diff --git a/xlators/mgmt/glusterd/src/glusterd-volume-set.c b/xlators/mgmt/glusterd/src/glusterd-volume-set.c
cb8e9e
index 9b9f544..8dea069 100644
cb8e9e
--- a/xlators/mgmt/glusterd/src/glusterd-volume-set.c
cb8e9e
+++ b/xlators/mgmt/glusterd/src/glusterd-volume-set.c
cb8e9e
@@ -1863,7 +1863,7 @@ struct volopt_map_entry glusterd_volopt_map[] = {
cb8e9e
         /* Upcall translator options */
cb8e9e
         { .key         = "features.cache-invalidation",
cb8e9e
           .voltype     = "features/upcall",
cb8e9e
-          .value      = "off",
cb8e9e
+          .value       = "off",
cb8e9e
           .op_version  = GD_OP_VERSION_3_7_0,
cb8e9e
         },
cb8e9e
         { .key         = "features.cache-invalidation-timeout",
cb8e9e
-- 
cb8e9e
1.7.1
cb8e9e