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