Blob Blame History Raw
From cd8d8bf659af5c7a159d3c65361fd140909f2232 Mon Sep 17 00:00:00 2001
From: Poornima G <pgurusid@redhat.com>
Date: Fri, 2 Jun 2017 10:05:33 +0530
Subject: [PATCH 502/509] upcall: Update the access time in missing cases

Issue: In fops like rename, link, unlink etc, the parent
dirrs' client access time was not being updated. And in fops like
create, link, symlink etc. the new file/dirs' client access time was
not updated.

Solution: Update the client access time for both parent and new entry.

> Reviewed-on: https://review.gluster.org/17450
> Smoke: Gluster Build System <jenkins@build.gluster.org>
> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
> CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
> Reviewed-by: Niels de Vos <ndevos@redhat.com>
> Signed-off-by: Poornima G <pgurusid@redhat.com>

Change-Id: Id9f63583216ae857f6251dca15797ac66fa85430
BUG: 1450080
Signed-off-by: Poornima G <pgurusid@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/108886
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
---
 tests/bugs/upcall/bug-1458127.t               | 36 ++++++++++++++
 xlators/features/upcall/src/upcall-internal.c |  6 +--
 xlators/features/upcall/src/upcall.c          | 68 ++++++++++++++++++++-------
 xlators/features/upcall/src/upcall.h          |  1 -
 4 files changed, 89 insertions(+), 22 deletions(-)
 create mode 100755 tests/bugs/upcall/bug-1458127.t

diff --git a/tests/bugs/upcall/bug-1458127.t b/tests/bugs/upcall/bug-1458127.t
new file mode 100755
index 0000000..e844f37
--- /dev/null
+++ b/tests/bugs/upcall/bug-1458127.t
@@ -0,0 +1,36 @@
+#!/bin/bash
+
+. $(dirname $0)/../../include.rc
+. $(dirname $0)/../../volume.rc
+
+cleanup;
+
+TEST glusterd
+
+TEST $CLI volume create $V0 $H0:$B0/${V0}{0}
+EXPECT 'Created' volinfo_field $V0 'Status'
+
+TEST $CLI volume set $V0 performance.nl-cache on
+TEST $CLI volume set $V0 nl-cache-positive-entry on
+TEST $CLI volume set $V0 nl-cache-timeout 2
+TEST $CLI volume set $V0 features.cache-invalidation on
+TEST $CLI volume set $V0 features.cache-invalidation-timeout 2
+TEST $CLI volume set $V0 md-cache-timeout 20
+
+TEST $CLI volume start $V0;
+EXPECT 'Started' volinfo_field $V0 'Status';
+
+TEST glusterfs --volfile-id=/$V0 --volfile-server=$H0 $M0
+TEST glusterfs --volfile-id=/$V0 --volfile-server=$H0 $M1
+
+TEST mkdir $M0/dir
+TEST touch $M0/dir/xyz
+#Wait until upcall clears the fact that M0 had accessed dir
+sleep 4
+TEST mv $M0/dir/xyz $M0/dir/xyz1
+TEST ! ls $M0/dir/file1
+TEST touch $M1/dir/file1
+TEST ls $M0/dir/file1
+TEST ls $M0/dir/file1
+
+cleanup;
diff --git a/xlators/features/upcall/src/upcall-internal.c b/xlators/features/upcall/src/upcall-internal.c
index 43a6b20..e577db4 100644
--- a/xlators/features/upcall/src/upcall-internal.c
+++ b/xlators/features/upcall/src/upcall-internal.c
@@ -542,9 +542,7 @@ upcall_cache_invalidate (call_frame_t *frame, xlator_t *this, client_t *client,
                 return;
         }
 
-        up_inode_ctx = ((upcall_local_t *)frame->local)->upcall_inode_ctx;
-
-        if (!up_inode_ctx)
+        if (inode)
                 up_inode_ctx = upcall_inode_ctx_get (inode, this);
 
         if (!up_inode_ctx) {
@@ -559,7 +557,7 @@ upcall_cache_invalidate (call_frame_t *frame, xlator_t *this, client_t *client,
          * invalid till it gets linked to inode table. Read gfid from
          * the stat returned in such cases.
          */
-        if (gf_uuid_is_null (up_inode_ctx->gfid)) {
+        if (gf_uuid_is_null (up_inode_ctx->gfid) && stbuf) {
                 /* That means inode must have been invalid when this inode_ctx
                  * is created. Copy the gfid value from stbuf instead.
                  */
diff --git a/xlators/features/upcall/src/upcall.c b/xlators/features/upcall/src/upcall.c
index abbe3ee..a9d3c8a 100644
--- a/xlators/features/upcall/src/upcall.c
+++ b/xlators/features/upcall/src/upcall.c
@@ -404,6 +404,18 @@ up_rename_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
         upcall_cache_invalidate (frame, this, client, local->inode, flags,
                                  stbuf, postnewparent, postoldparent, NULL);
 
+        flags = UP_UPDATE_CLIENT;
+        upcall_cache_invalidate (frame, this, client,
+                                 local->rename_oldloc.parent, flags,
+                                 postoldparent, NULL, NULL, NULL);
+
+        if (local->rename_oldloc.parent == local->loc.parent)
+                goto out;
+
+        flags = UP_UPDATE_CLIENT;
+        upcall_cache_invalidate (frame, this, client, local->loc.parent,
+                                 flags, postnewparent, NULL, NULL, NULL);
+
 out:
         UPCALL_STACK_UNWIND (rename, frame, op_ret, op_errno,
                              stbuf, preoldparent, postoldparent,
@@ -421,7 +433,7 @@ up_rename (call_frame_t *frame, xlator_t *this,
 
         EXIT_IF_UPCALL_OFF (this, out);
 
-        local = upcall_local_init (frame, this, NULL, NULL, oldloc->inode, NULL);
+        local = upcall_local_init (frame, this, newloc, NULL, oldloc->inode, NULL);
         if (!local) {
                 op_errno = ENOMEM;
                 goto err;
@@ -464,6 +476,10 @@ up_unlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
         upcall_cache_invalidate (frame, this, client, local->inode, flags,
                                  NULL, postparent, NULL, NULL);
 
+        flags = UP_UPDATE_CLIENT;
+        upcall_cache_invalidate (frame, this, client, local->loc.parent,
+                                 flags, postparent, NULL, NULL, NULL);
+
 out:
         UPCALL_STACK_UNWIND (unlink, frame, op_ret, op_errno,
                              preparent, postparent, xdata);
@@ -480,7 +496,7 @@ up_unlink (call_frame_t *frame, xlator_t *this, loc_t *loc, int xflag,
 
         EXIT_IF_UPCALL_OFF (this, out);
 
-        local = upcall_local_init (frame, this, NULL, NULL, loc->inode, NULL);
+        local = upcall_local_init (frame, this, loc, NULL, loc->inode, NULL);
         if (!local) {
                 op_errno = ENOMEM;
                 goto err;
@@ -520,6 +536,10 @@ up_link_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
         upcall_cache_invalidate (frame, this, client, local->inode, flags,
                                  stbuf, postparent, NULL, NULL);
 
+        flags = UP_UPDATE_CLIENT;
+        upcall_cache_invalidate (frame, this, client, local->loc.parent,
+                                 flags, postparent, NULL, NULL, NULL);
+
 out:
         UPCALL_STACK_UNWIND (link, frame, op_ret, op_errno,
                              inode, stbuf, preparent, postparent, xdata);
@@ -536,7 +556,7 @@ up_link (call_frame_t *frame, xlator_t *this, loc_t *oldloc,
 
         EXIT_IF_UPCALL_OFF (this, out);
 
-        local = upcall_local_init (frame, this, NULL, NULL, oldloc->inode, NULL);
+        local = upcall_local_init (frame, this, newloc, NULL, oldloc->inode, NULL);
         if (!local) {
                 op_errno = ENOMEM;
                 goto err;
@@ -578,6 +598,10 @@ up_rmdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
         upcall_cache_invalidate (frame, this, client, local->inode, flags,
                                  NULL, postparent, NULL, NULL);
 
+        flags = UP_UPDATE_CLIENT;
+        upcall_cache_invalidate (frame, this, client, local->loc.parent,
+                                 flags, postparent, NULL, NULL, NULL);
+
 out:
         UPCALL_STACK_UNWIND (rmdir, frame, op_ret, op_errno,
                              preparent, postparent, xdata);
@@ -594,7 +618,7 @@ up_rmdir (call_frame_t *frame, xlator_t *this, loc_t *loc, int flags,
 
         EXIT_IF_UPCALL_OFF (this, out);
 
-        local = upcall_local_init (frame, this, NULL, NULL, loc->inode, NULL);
+        local = upcall_local_init (frame, this, loc, NULL, loc->inode, NULL);
         if (!local) {
                 op_errno = ENOMEM;
                 goto err;
@@ -637,6 +661,10 @@ up_mkdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
         upcall_cache_invalidate (frame, this, client, local->inode, flags,
                                  postparent, NULL, NULL, NULL);
 
+        flags = UP_UPDATE_CLIENT;
+        upcall_cache_invalidate (frame, this, client, local->loc.inode, flags,
+                                 stbuf, NULL, NULL, NULL);
+
 out:
         UPCALL_STACK_UNWIND (mkdir, frame, op_ret, op_errno,
                              inode, stbuf, preparent, postparent, xdata);
@@ -653,7 +681,7 @@ up_mkdir (call_frame_t *frame, xlator_t *this,
 
         EXIT_IF_UPCALL_OFF (this, out);
 
-        local = upcall_local_init (frame, this, NULL, NULL, loc->parent, NULL);
+        local = upcall_local_init (frame, this, loc, NULL, loc->parent, NULL);
         if (!local) {
                 op_errno = ENOMEM;
                 goto err;
@@ -692,12 +720,17 @@ up_create_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
                 goto out;
         }
 
-        /* As its a new file create, no need of sending notification */
-        /* However invalidate parent's entry */
+        /* As its a new file create, no need of sending notification
+         * However invalidate parent's entry and update that fact that the
+         * client has accessed the newly created entry */
         flags = UP_TIMES;
         upcall_cache_invalidate (frame, this, client, local->inode, flags,
                                  postparent, NULL, NULL, NULL);
 
+        flags = UP_UPDATE_CLIENT;
+        upcall_cache_invalidate (frame, this, client, local->loc.inode, flags,
+                                 stbuf, NULL, NULL, NULL);
+
 out:
         UPCALL_STACK_UNWIND (create, frame, op_ret, op_errno, fd,
                              inode, stbuf, preparent, postparent, xdata);
@@ -715,7 +748,7 @@ up_create (call_frame_t *frame, xlator_t *this,
 
         EXIT_IF_UPCALL_OFF (this, out);
 
-        local = upcall_local_init (frame, this, NULL, NULL, loc->parent, NULL);
+        local = upcall_local_init (frame, this, loc, NULL, loc->parent, NULL);
 
         if (!local) {
                 op_errno = ENOMEM;
@@ -1041,6 +1074,10 @@ up_mknod_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
         upcall_cache_invalidate (frame, this, client, local->inode, flags,
                                  postparent, NULL, NULL, NULL);
 
+        flags = UP_UPDATE_CLIENT;
+        upcall_cache_invalidate (frame, this, client, local->loc.inode, flags,
+                                 buf, NULL, NULL, NULL);
+
 out:
         UPCALL_STACK_UNWIND (mknod, frame, op_ret, op_errno, inode, buf,
                              preparent, postparent, xdata);
@@ -1057,7 +1094,7 @@ up_mknod (call_frame_t *frame, xlator_t *this, loc_t *loc,
 
         EXIT_IF_UPCALL_OFF (this, out);
 
-        local = upcall_local_init (frame, this, NULL, NULL, loc->parent, NULL);
+        local = upcall_local_init (frame, this, loc, NULL, loc->parent, NULL);
         if (!local) {
                 op_errno = ENOMEM;
                 goto err;
@@ -1101,6 +1138,10 @@ up_symlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
         upcall_cache_invalidate (frame, this, client, local->inode, flags,
                                  postparent, NULL, NULL, NULL);
 
+        flags = UP_UPDATE_CLIENT;
+        upcall_cache_invalidate (frame, this, client, local->loc.inode, flags,
+                                 buf, NULL, NULL, NULL);
+
 out:
         UPCALL_STACK_UNWIND (symlink, frame, op_ret, op_errno, inode, buf,
                              preparent, postparent, xdata);
@@ -1118,7 +1159,7 @@ up_symlink (call_frame_t   *frame, xlator_t *this,
 
         EXIT_IF_UPCALL_OFF (this, out);
 
-        local = upcall_local_init (frame, this, NULL, NULL, loc->parent, NULL);
+        local = upcall_local_init (frame, this, loc, NULL, loc->parent, NULL);
         if (!local) {
                 op_errno = ENOMEM;
                 goto err;
@@ -1325,10 +1366,6 @@ up_readdirp_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
         upcall_cache_invalidate (frame, this, client, local->inode, flags,
                                  NULL, NULL, NULL, NULL);
 
-        /* upcall_cache_invalidate optimises, by not calling inode_ctx_get
-         * if local->upcall_inode_ctx is set. Hence before processing
-         * the readdir entries unset this */
-        local->upcall_inode_ctx = NULL;
         list_for_each_entry (entry, &entries->list, list) {
                 if (entry->inode == NULL) {
                         continue;
@@ -2263,9 +2300,6 @@ upcall_local_init (call_frame_t *frame, xlator_t *this, loc_t *loc, fd_t *fd,
         if (xattr)
                 local->xattr = dict_copy_with_ref (xattr, NULL);
 
-        /* Shall we get inode_ctx and store it here itself? */
-        local->upcall_inode_ctx = upcall_inode_ctx_get (inode, this);
-
         if (loc)
                 loc_copy (&local->loc, loc);
         if (fd)
diff --git a/xlators/features/upcall/src/upcall.h b/xlators/features/upcall/src/upcall.h
index 4554248..159193f 100644
--- a/xlators/features/upcall/src/upcall.h
+++ b/xlators/features/upcall/src/upcall.h
@@ -83,7 +83,6 @@ struct upcall_local {
          * pointers in 'local' which may get freed
          * in future by other thread
          */
-        upcall_inode_ctx_t *upcall_inode_ctx;
         inode_t   *inode;
         loc_t     rename_oldloc;
         loc_t     loc;  /* required for stat in *xattr_cbk */
-- 
1.8.3.1