From 6703faca9af788e7ad087c8433d6a4dd65a3fa04 Mon Sep 17 00:00:00 2001
From: Poornima G <pgurusid@redhat.com>
Date: Tue, 16 May 2017 19:25:20 +0530
Subject: [PATCH 465/473] nl-cache: In case of nameless operations do not cache
Issue:
In nameless lookup/other fops, parent inode will be NULL, when we try
to add the cache to the NULL inode, it causes a crash.
Hence handle the scenario of nameless fops, and do not cache/serve
the nameless fops.
>Reviewed-on: https://review.gluster.org/17316
>Smoke: Gluster Build System <jenkins@build.gluster.org>
>NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
>Reviewed-by: Pranith Kumar Karampuri <pkarampu@redhat.com>
>CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
>(cherry picked from commit 284cd8851bfe60984d2f11b5c52fe3204ff43b06)
Change-Id: I3b90f882ac89e6aaf3419db89e6f890797f37700
BUG: 1450904
Signed-off-by: Poornima G <pgurusid@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/106935
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
---
libglusterfs/src/xlator.c | 15 +++++++++++++++
libglusterfs/src/xlator.h | 1 +
tests/bugs/nl-cache/bug-1451588.t | 25 +++++++++++++++++++++++++
xlators/performance/nl-cache/src/nl-cache.c | 11 +++++++----
4 files changed, 48 insertions(+), 4 deletions(-)
create mode 100755 tests/bugs/nl-cache/bug-1451588.t
diff --git a/libglusterfs/src/xlator.c b/libglusterfs/src/xlator.c
index 6e3ff51..dc5cfaa 100644
--- a/libglusterfs/src/xlator.c
+++ b/libglusterfs/src/xlator.c
@@ -1011,6 +1011,21 @@ out:
return ret;
}
+
+gf_boolean_t
+loc_is_nameless (loc_t *loc)
+{
+ gf_boolean_t ret = _gf_false;
+
+ GF_VALIDATE_OR_GOTO ("xlator", loc, out);
+
+ if ((!loc->parent && gf_uuid_is_null (loc->pargfid)) || !loc->name)
+ ret = _gf_true;
+out:
+ return ret;
+}
+
+
int
xlator_destroy (xlator_t *xl)
{
diff --git a/libglusterfs/src/xlator.h b/libglusterfs/src/xlator.h
index c5b0516..508146f 100644
--- a/libglusterfs/src/xlator.h
+++ b/libglusterfs/src/xlator.h
@@ -1026,6 +1026,7 @@ void loc_pargfid (loc_t *loc, uuid_t pargfid);
char* loc_gfid_utoa (loc_t *loc);
gf_boolean_t loc_is_root (loc_t *loc);
int32_t loc_build_child (loc_t *child, loc_t *parent, char *name);
+gf_boolean_t loc_is_nameless (loc_t *loc);
int xlator_mem_acct_init (xlator_t *xl, int num_types);
int is_gf_log_command (xlator_t *trans, const char *name, char *value);
int glusterd_check_log_level (const char *value);
diff --git a/tests/bugs/nl-cache/bug-1451588.t b/tests/bugs/nl-cache/bug-1451588.t
new file mode 100755
index 0000000..cf07d04
--- /dev/null
+++ b/tests/bugs/nl-cache/bug-1451588.t
@@ -0,0 +1,25 @@
+#!/bin/bash
+
+. $(dirname $0)/../../include.rc
+. $(dirname $0)/../../volume.rc
+
+cleanup;
+
+TEST glusterd
+
+TEST $CLI volume create $V0 $H0:$B0/${V0}{0..4}
+EXPECT 'Created' volinfo_field $V0 'Status'
+
+TEST $CLI volume set $V0 performance.nl-cache on
+TEST $CLI volume set $V0 features.cache-invalidation on
+TEST $CLI volume set $V0 features.cache-invalidation-timeout 600
+
+TEST $CLI volume start $V0;
+EXPECT 'Started' volinfo_field $V0 'Status';
+
+TEST glusterfs --volfile-id=/$V0 --aux-gfid-mount --volfile-server=$H0 $M0
+
+TEST ! stat $M0/.gfid/1901b1a0-c612-46ee-b45a-e8345d5a0b48
+
+cleanup;
+G_TESTDEF_TEST_STATUS_NETBSD7=BAD_TEST,BUG=000000
diff --git a/xlators/performance/nl-cache/src/nl-cache.c b/xlators/performance/nl-cache/src/nl-cache.c
index 26c09d7..8a130dc 100644
--- a/xlators/performance/nl-cache/src/nl-cache.c
+++ b/xlators/performance/nl-cache/src/nl-cache.c
@@ -198,6 +198,8 @@ nlc_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
local = frame->local;
conf = this->private;
+ GF_VALIDATE_OR_GOTO (this->name, local, out);
+
/* Donot add to pe, this may lead to duplicate entry and
* requires search before adding if list of strings */
if (op_ret < 0 && op_errno == ENOENT) {
@@ -205,8 +207,9 @@ nlc_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
GF_ATOMIC_INC (conf->nlc_counter.nlc_miss);
}
+out:
NLC_STACK_UNWIND (lookup, frame, op_ret, op_errno, inode, buf, xdata,
- postparent);
+ postparent);
return 0;
}
@@ -218,15 +221,15 @@ nlc_lookup (call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata)
nlc_conf_t *conf = NULL;
inode_t *inode = NULL;
+ if (loc_is_nameless (loc))
+ goto wind;
+
local = nlc_local_init (frame, this, GF_FOP_LOOKUP, loc, NULL);
if (!local)
goto err;
conf = this->private;
- if ((!loc->parent && gf_uuid_is_null (loc->pargfid)) || !loc->name)
- goto wind;
-
inode = inode_grep (loc->inode->table, loc->parent, loc->name);
if (inode) {
inode_unref (inode);
--
1.8.3.1