summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPranith Kumar Karampuri <pranith.karampuri@phonepe.com>2021-02-03 21:32:45 +0530
committerGitHub <noreply@github.com>2021-02-03 21:32:45 +0530
commit449ef110446891eec44e329dc30112225872bccd (patch)
treea27aae300bbdb404c397bf5f5d49cb84ae7dd341
parent8bc83c331b7dd159f5eb56e0ab5362450d473364 (diff)
downloadglusterfs-449ef110446891eec44e329dc30112225872bccd.tar.gz
glusterfs-449ef110446891eec44e329dc30112225872bccd.tar.xz
glusterfs-449ef110446891eec44e329dc30112225872bccd.zip
cluster/dht: Allow fix-layout only on directories (#2109)
Problem: fix-layout operation assumes that the directory passed is directory i.e. layout->cnt == conf->subvolume_cnt. This will lead to a crash when fix-layout is attempted on a file. Fix: Disallow fix-layout on files fixes: #2107 Change-Id: I2116b8773059f67e3260e9207e20eab3de711417 Signed-off-by: Pranith Kumar K <pranith.karampuri@phonepe.com>
-rw-r--r--tests/bugs/distribute/disallow-fixlayout-on-files.t33
-rw-r--r--xlators/cluster/dht/src/dht-common.c4
2 files changed, 37 insertions, 0 deletions
diff --git a/tests/bugs/distribute/disallow-fixlayout-on-files.t b/tests/bugs/distribute/disallow-fixlayout-on-files.t
new file mode 100644
index 0000000000..df288e0c56
--- /dev/null
+++ b/tests/bugs/distribute/disallow-fixlayout-on-files.t
@@ -0,0 +1,33 @@
+#!/bin/bash
+
+. $(dirname $0)/../../include.rc
+. $(dirname $0)/../../volume.rc
+
+cleanup;
+
+TEST glusterd
+TEST pidof glusterd
+TEST $CLI volume info
+
+#Create a distributed volume
+TEST $CLI volume create $V0 $H0:$B0/${V0}1;
+TEST $CLI volume set $V0 cluster.lookup-optimize off
+TEST $CLI volume start $V0
+
+# Mount FUSE
+TEST glusterfs -s $H0 --volfile-id $V0 $M0
+
+#Create files
+TEST mkdir $M0/foo
+TEST touch $M0/foo/a
+
+EXPECT_WITHIN $UMOUNT_TIMEOUT "Y" force_umount $M0
+TEST $CLI volume add-brick $V0 $H0:$B0/${V0}2
+
+TEST glusterfs -s $H0 --volfile-id $V0 $M0
+TEST setfattr -n distribute.fix.layout -v "yes" $M0
+TEST setfattr -n distribute.fix.layout -v "yes" $M0/foo
+TEST ! setfattr -n distribute.fix.layout -v "yes" $M0/foo/a
+TEST ls $M0 #Test that the mount didn't crash
+
+cleanup;
diff --git a/xlators/cluster/dht/src/dht-common.c b/xlators/cluster/dht/src/dht-common.c
index b16ef8fe6e..d27670d796 100644
--- a/xlators/cluster/dht/src/dht-common.c
+++ b/xlators/cluster/dht/src/dht-common.c
@@ -5907,6 +5907,10 @@ dht_setxattr(call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xattr,
tmp = dict_get(xattr, GF_XATTR_FIX_LAYOUT_KEY);
if (tmp) {
+ if (!IA_ISDIR(loc->inode->ia_type)) {
+ op_errno = ENOTSUP;
+ goto err;
+ }
ret = dict_get_uint32(xattr, "new-commit-hash", &new_hash);
if (ret == 0) {
gf_msg_debug(this->name, 0,