From 94253b21f832ff12d1c545c5d87e6bc79465d090 Mon Sep 17 00:00:00 2001
From: Nithya Balachandran <nbalacha@redhat.com>
Date: Mon, 31 Aug 2015 15:52:04 +0530
Subject: [PATCH 319/320] cluster/dht: Don't set posix acls on linkto files
Posix acls on a linkto file change the file's permission
bits and cause DHT to treat it as a non-linkto file.This
happens on the migration failure of a file on which posix
acls were set.
The fix prevents posix acls from being set on a linkto
file and copies them across only after a file has
been successfully migrated.
backport of:
http://review.gluster.org/#/c/12025/
Some tier.t upstream changes have not been merged downstream
so this backport does not include the changes the upstream
patch made to tier.t.
Change-Id: I7380cae9e847785534535c5d306574a231e21a10
BUG: 1234610
Signed-off-by: Nithya Balachandran <nbalacha@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/56696
Reviewed-by: Pranith Kumar Karampuri <pkarampu@redhat.com>
Tested-by: Pranith Kumar Karampuri <pkarampu@redhat.com>
---
tests/bugs/distribute/bug-1247563.t | 57 +++++++++++++++++++++++++++++
xlators/cluster/dht/src/dht-rebalance.c | 34 +++++++++++++++++
xlators/storage/posix/src/posix-helpers.c | 15 ++++++--
xlators/storage/posix/src/posix.c | 11 +++++-
xlators/storage/posix/src/posix.h | 4 +-
5 files changed, 114 insertions(+), 7 deletions(-)
create mode 100644 tests/bugs/distribute/bug-1247563.t
diff --git a/tests/bugs/distribute/bug-1247563.t b/tests/bugs/distribute/bug-1247563.t
new file mode 100644
index 0000000..f7f9258
--- /dev/null
+++ b/tests/bugs/distribute/bug-1247563.t
@@ -0,0 +1,57 @@
+#!/bin/bash
+
+. $(dirname $0)/../../include.rc
+. $(dirname $0)/../../volume.rc
+
+is_sticky_set () {
+ echo $1
+ if [ -k $1 ];
+ then
+ echo "yes"
+ else
+ echo "no"
+ fi
+}
+
+cleanup;
+
+#Basic checks
+TEST glusterd
+TEST pidof glusterd
+TEST $CLI volume info
+
+#Create a distributed volume
+TEST $CLI volume create $V0 $H0:$B0/${V0}{1..3};
+TEST $CLI volume start $V0
+
+# Mount FUSE
+TEST glusterfs --acl -s $H0 --volfile-id $V0 $M0
+
+TEST mkdir $M0/dir1
+
+echo "Testing pacls on rebalance" > $M0/dir1/FILE1
+FPATH1=`find $B0/ -name FILE1`
+
+# Rename the file to create a linkto, for rebalance to
+# act on the file
+
+TEST mv $M0/dir1/FILE1 $M0/dir1/FILE2
+FPATH2=`find $B0/ -perm 1000 -name FILE2`
+
+setfacl -m user:root:rwx $M0/dir1/FILE2
+
+# Run rebalance without the force option to skip
+# the file migration
+TEST $CLI volume rebalance $V0 start
+
+EXPECT_WITHIN $REBALANCE_TIMEOUT "completed" rebalance_status_field $V0
+
+#Check that the file has been skipped,i.e., the linkto still exists
+EXPECT "yes" is_sticky_set $FPATH2
+
+
+#The linkto file should not have any posix acls set
+COUNT=`getfacl $FPATH2 |grep -c "user:root:rwx"`
+EXPECT "0" echo $COUNT
+
+cleanup;
diff --git a/xlators/cluster/dht/src/dht-rebalance.c b/xlators/cluster/dht/src/dht-rebalance.c
index 012d86b..442b46a 100644
--- a/xlators/cluster/dht/src/dht-rebalance.c
+++ b/xlators/cluster/dht/src/dht-rebalance.c
@@ -1196,6 +1196,40 @@ dht_migrate_file (xlator_t *this, loc_t *loc, xlator_t *from, xlator_t *to,
ret = -1;
}
+ /* Posix acls are not set on DHT linkto files as part of the initial
+ * initial xattrs set on the dst file, so these need
+ * to be set on the dst file after the linkto attrs are removed.
+ * TODO: Optimize this.
+ */
+ if (xattr) {
+ dict_unref (xattr);
+ xattr = NULL;
+ }
+
+ ret = syncop_listxattr (from, loc, &xattr, NULL, NULL);
+ if (ret < 0) {
+ gf_msg (this->name, GF_LOG_WARNING, 0,
+ DHT_MSG_MIGRATE_FILE_FAILED,
+ "Migrate file failed:"
+ "%s: failed to get xattr from %s (%s)",
+ loc->path, from->name, strerror (-ret));
+ ret = -1;
+ } else {
+ ret = syncop_setxattr (to, loc, xattr, 0, NULL, NULL);
+ if (ret < 0) {
+ /* Potential problem here where Posix ACLs will
+ * not be set on the target file */
+
+ gf_msg (this->name, GF_LOG_WARNING, 0,
+ DHT_MSG_MIGRATE_FILE_FAILED,
+ "Migrate file failed:"
+ "%s: failed to set xattr on %s (%s)",
+ loc->path, to->name, strerror (-ret));
+ ret = -1;
+ }
+ }
+
+
/* Make the source as a linkfile first before deleting it */
empty_iatt.ia_prot.sticky = 1;
ret = syncop_fsetattr (from, src_fd, &empty_iatt,
diff --git a/xlators/storage/posix/src/posix-helpers.c b/xlators/storage/posix/src/posix-helpers.c
index cae56e7..082e74e 100644
--- a/xlators/storage/posix/src/posix-helpers.c
+++ b/xlators/storage/posix/src/posix-helpers.c
@@ -1072,7 +1072,7 @@ void posix_dump_buffer (xlator_t *this, const char *real_path, const char *key,
int
posix_handle_pair (xlator_t *this, const char *real_path,
- char *key, data_t *value, int flags)
+ char *key, data_t *value, int flags, struct iatt *stbuf)
{
int sys_ret = -1;
int ret = 0;
@@ -1084,7 +1084,12 @@ posix_handle_pair (xlator_t *this, const char *real_path,
ret = posix_set_file_contents (this, real_path, key, value,
flags);
} else if (GF_POSIX_ACL_REQUEST (key)) {
+ if (stbuf && IS_DHT_LINKFILE_MODE (stbuf))
+ goto out;
ret = posix_pacl_set (real_path, key, value->data);
+ } else if (!strncmp(key, POSIX_ACL_ACCESS_XATTR, strlen(key))
+ && stbuf && IS_DHT_LINKFILE_MODE (stbuf)) {
+ goto out;
} else {
sys_ret = sys_lsetxattr (real_path, key, value->data,
value->len, flags);
@@ -1135,7 +1140,7 @@ out:
int
posix_fhandle_pair (xlator_t *this, int fd,
- char *key, data_t *value, int flags)
+ char *key, data_t *value, int flags, struct iatt *stbuf)
{
int sys_ret = -1;
int ret = 0;
@@ -1143,6 +1148,9 @@ posix_fhandle_pair (xlator_t *this, int fd,
if (XATTR_IS_PATHINFO (key)) {
ret = -EACCES;
goto out;
+ } else if (!strncmp(key, POSIX_ACL_ACCESS_XATTR, strlen(key))
+ && stbuf && IS_DHT_LINKFILE_MODE (stbuf)) {
+ goto out;
}
sys_ret = sys_fsetxattr (fd, key, value->data,
@@ -1525,7 +1533,7 @@ _handle_entry_create_keyvalue_pair (dict_t *d, char *k, data_t *v,
}
ret = posix_handle_pair (filler->this, filler->real_path, k, v,
- XATTR_CREATE);
+ XATTR_CREATE, filler->stbuf);
if (ret < 0) {
errno = -ret;
return -1;
@@ -1546,6 +1554,7 @@ posix_entry_create_xattr_set (xlator_t *this, const char *path,
filler.this = this;
filler.real_path = path;
+ filler.stbuf = NULL;
ret = dict_foreach (dict, _handle_entry_create_keyvalue_pair, &filler);
diff --git a/xlators/storage/posix/src/posix.c b/xlators/storage/posix/src/posix.c
index f1ebcc6..f7826fe 100644
--- a/xlators/storage/posix/src/posix.c
+++ b/xlators/storage/posix/src/posix.c
@@ -3198,7 +3198,7 @@ _handle_setxattr_keyvalue_pair (dict_t *d, char *k, data_t *v,
filler = tmp;
return posix_handle_pair (filler->this, filler->real_path, k, v,
- filler->flags);
+ filler->flags, filler->stbuf);
}
#ifdef GF_DARWIN_HOST_OS
@@ -3272,6 +3272,8 @@ posix_setxattr (call_frame_t *frame, xlator_t *this,
goto out;
}
+ posix_pstat(this, loc->gfid, real_path, &stbuf);
+
op_ret = -1;
dict_del (dict, GFID_XATTR_KEY);
@@ -3279,6 +3281,8 @@ posix_setxattr (call_frame_t *frame, xlator_t *this,
filler.real_path = real_path;
filler.this = this;
+ filler.stbuf = &stbuf;
+
#ifdef GF_DARWIN_HOST_OS
filler.flags = map_xattr_flags(flags);
#else
@@ -4443,7 +4447,7 @@ _handle_fsetxattr_keyvalue_pair (dict_t *d, char *k, data_t *v,
filler = tmp;
return posix_fhandle_pair (filler->this, filler->fdnum, k, v,
- filler->flags);
+ filler->flags, filler->stbuf);
}
int32_t
@@ -4476,11 +4480,14 @@ posix_fsetxattr (call_frame_t *frame, xlator_t *this,
}
_fd = pfd->fd;
+ posix_fdstat (this, pfd->fd, &stbuf);
+
dict_del (dict, GFID_XATTR_KEY);
dict_del (dict, GF_XATTR_VOL_ID_KEY);
filler.fdnum = _fd;
filler.this = this;
+ filler.stbuf = &stbuf;
#ifdef GF_DARWIN_HOST_OS
filler.flags = map_xattr_flags(flags);
#else
diff --git a/xlators/storage/posix/src/posix.h b/xlators/storage/posix/src/posix.h
index cf1465a..f8230be 100644
--- a/xlators/storage/posix/src/posix.h
+++ b/xlators/storage/posix/src/posix.h
@@ -207,9 +207,9 @@ int posix_pstat (xlator_t *this, uuid_t gfid, const char *real_path,
dict_t *posix_xattr_fill (xlator_t *this, const char *path, loc_t *loc,
fd_t *fd, int fdnum, dict_t *xattr, struct iatt *buf);
int posix_handle_pair (xlator_t *this, const char *real_path, char *key,
- data_t *value, int flags);
+ data_t *value, int flags, struct iatt *stbuf);
int posix_fhandle_pair (xlator_t *this, int fd, char *key, data_t *value,
- int flags);
+ int flags, struct iatt *stbuf);
void posix_spawn_janitor_thread (xlator_t *this);
int posix_get_file_contents (xlator_t *this, uuid_t pargfid,
const char *name, char **contents);
--
1.7.1