diff options
author | Pranith Kumar Karampuri <pranith.karampuri@phonepe.com> | 2021-02-04 18:29:33 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-04 18:29:33 +0530 |
commit | 228241e9a02d0a40170efd9a877e8476c0ee2dce (patch) | |
tree | 8d9f51698d802693e636b4ca0038b568105e039b | |
parent | c6d4289dad6622e311c312b609a52106909f7d74 (diff) | |
download | glusterfs-228241e9a02d0a40170efd9a877e8476c0ee2dce.tar.gz glusterfs-228241e9a02d0a40170efd9a877e8476c0ee2dce.tar.xz glusterfs-228241e9a02d0a40170efd9a877e8476c0ee2dce.zip |
cluster/dht: Allow fix-layout only on directories (#2109) (#2114)
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.t | 33 | ||||
-rw-r--r-- | xlators/cluster/dht/src/dht-common.c | 4 |
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 2cc3a0d200..7b63bb24ed 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, |