From a0027df9745677df3be816dab4f160a5f682a20c Mon Sep 17 00:00:00 2001
From: Poornima G <pgurusid@redhat.com>
Date: Thu, 25 Aug 2016 15:43:29 +0530
Subject: [PATCH 129/141] md-cache: Process all the cache invalidation flags
Currently, md-cache only processes IATT_UPDATE_FLAGS, UP_XATTR and
UP_XATTR_RM. We also need to process UP_RENAME_FLAGS, UP_FORGET,
UP_PARENT_DENTRY_FLAGS and UP_NLINK_FLAGS. Otherwise the files
unlinked or renamed will not be reflected on other mounts.
Change-Id: Icb8b03da51482c3fc2e2a7292d16d56e11a341d9
BUG: 1284873
Signed-off-by: Poornima G <pgurusid@redhat.com>
Reviewed-on: http://review.gluster.org/15324
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: Raghavendra G <rgowdapp@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/87042
Reviewed-by: Rajesh Joseph <rjoseph@redhat.com>
Tested-by: Rajesh Joseph <rjoseph@redhat.com>
---
tests/bugs/md-cache/bug-1211863_unlink.t | 45 +++++++++++++++++++++++++++
tests/include.rc | 1 +
xlators/performance/md-cache/src/md-cache.c | 43 ++++++++++++++++++++++---
3 files changed, 84 insertions(+), 5 deletions(-)
create mode 100755 tests/bugs/md-cache/bug-1211863_unlink.t
diff --git a/tests/bugs/md-cache/bug-1211863_unlink.t b/tests/bugs/md-cache/bug-1211863_unlink.t
new file mode 100755
index 0000000..f83d3d7
--- /dev/null
+++ b/tests/bugs/md-cache/bug-1211863_unlink.t
@@ -0,0 +1,45 @@
+#!/bin/bash
+
+. $(dirname $0)/../../include.rc
+. $(dirname $0)/../../volume.rc
+
+cleanup;
+
+## Start glusterd
+TEST glusterd;
+
+## Lets create volume
+TEST $CLI volume create $V0 $H0:$B0/${V0}{1,2,3};
+
+## Start the volume
+TEST $CLI volume start $V0
+
+## Enable the upcall xlator, and increase the md-cache timeout to max
+TEST $CLI volume set $V0 features.cache-invalidation on
+TEST $CLI volume set $V0 features.cache-invalidation-timeout 600
+TEST $CLI volume set $V0 performance.cache-invalidation on
+TEST $CLI volume set $V0 performance.md-cache-timeout 600
+TEST $CLI volume set $V0 performance.cache-samba-metadata on
+
+## Create two gluster mounts
+TEST glusterfs --volfile-id=/$V0 --volfile-server=$H0 $M0
+TEST glusterfs --volfile-id=/$V0 --volfile-server=$H0 $M1
+
+## Create files and directories from M0
+TEST mkdir $M0/dir1
+TEST touch $M0/dir1/file{1..5}
+
+## Lookup few files from M1, so that md-cache cahces
+TEST ls -l $M1/dir1/file2
+TEST ls -l $M1/dir1/file3
+
+## Remove the looked up file from M0
+TEST rm $M0/dir1/file2
+TEST mv $M0/dir1/file3 $M0/dir1/file6
+
+## Check if the files are not visible from M0
+EXPECT_WITHIN $MDC_TIMEOUT "N" path_exists $M0/dir1/file2
+EXPECT_WITHIN $MDC_TIMEOUT "N" path_exists $M0/dir1/file3
+EXPECT_WITHIN $MDC_TIMEOUT "Y" path_exists $M0/dir1/file6
+
+cleanup;
diff --git a/tests/include.rc b/tests/include.rc
index e122a0e..44f5798 100644
--- a/tests/include.rc
+++ b/tests/include.rc
@@ -75,6 +75,7 @@ CONFIG_UPDATE_TIMEOUT=5
AUTH_REFRESH_INTERVAL=10
GRAPH_SWITCH_TIMEOUT=10
UNLINK_TIMEOUT=5
+MDC_TIMEOUT=5
LOGDIR=$(gluster --print-logdir)
diff --git a/xlators/performance/md-cache/src/md-cache.c b/xlators/performance/md-cache/src/md-cache.c
index c5d99ba..763428c 100644
--- a/xlators/performance/md-cache/src/md-cache.c
+++ b/xlators/performance/md-cache/src/md-cache.c
@@ -847,6 +847,26 @@ out:
}
+static int
+mdc_update_gfid_stat (xlator_t *this, struct iatt *iatt)
+{
+ int ret = 0;
+ inode_table_t *itable = NULL;
+ inode_t *inode = NULL;
+
+ itable = ((xlator_t *)this->graph->top)->itable;
+ inode = inode_find (itable, iatt->ia_gfid);
+ if (!inode) {
+ ret = -1;
+ goto out;
+ }
+ ret = mdc_inode_iatt_set_validate (this, inode, NULL,
+ iatt);
+out:
+ return ret;
+}
+
+
void
mdc_load_reqs (xlator_t *this, dict_t *dict)
{
@@ -2537,12 +2557,24 @@ mdc_invalidate (xlator_t *this, void *data)
goto out;
}
+ if (up_ci->flags & UP_PARENT_DENTRY_FLAGS) {
+ mdc_update_gfid_stat (this, &up_ci->p_stat);
+ if (up_ci->flags & UP_RENAME_FLAGS)
+ mdc_update_gfid_stat (this, &up_ci->oldp_stat);
+ }
+
+ if ((up_ci->flags & (UP_NLINK | UP_RENAME_FLAGS | UP_FORGET)) ||
+ (up_ci->dict && dict_get (up_ci->dict, MDC_INVALIDATE_IATT))) {
+ mdc_inode_iatt_invalidate (this, inode);
+ mdc_inode_xatt_invalidate (this, inode);
+ INCREMENT_ATOMIC (conf->mdc_counter.lock,
+ conf->mdc_counter.stat_invals);
+ goto out;
+ }
+
if (up_ci->flags & IATT_UPDATE_FLAGS) {
- if (up_ci->dict && dict_get (up_ci->dict, MDC_INVALIDATE_IATT))
- mdc_inode_iatt_invalidate (this, inode);
- else
- ret = mdc_inode_iatt_set_validate (this, inode, NULL,
- &up_ci->stat);
+ ret = mdc_inode_iatt_set_validate (this, inode, NULL,
+ &up_ci->stat);
/* one of the scenarios where ret < 0 is when this invalidate
* is older than the current stat, in that case do not
* update the xattrs as well
@@ -2552,6 +2584,7 @@ mdc_invalidate (xlator_t *this, void *data)
INCREMENT_ATOMIC (conf->mdc_counter.lock,
conf->mdc_counter.stat_invals);
}
+
if (up_ci->flags & UP_XATTR) {
if (up_ci->dict)
ret = mdc_inode_xatt_update (this, inode, up_ci->dict);
--
1.7.1