From 545a7ce6762a1b3a7b989b43a9d18b5b1b299df0 Mon Sep 17 00:00:00 2001 From: Susant Palai Date: Thu, 18 Jan 2018 13:06:12 +0530 Subject: cluster/dht: avoid overwriting client writes during migration For more details on this issue see https://github.com/gluster/glusterfs/issues/308 Solution: This is a restrictive solution where a file will not be migrated if a client writes to it during the migration. This does not check if the writes from the rebalance and the client actually do overlap. If dht_writev_cbk finds that the file is being migrated (PHASE1) it will set an xattr on the destination file indicating the file was updated by a non-rebalance client. Rebalance checks if any other client has written to the dst file and aborts the file migration if it finds the xattr. updates gluster/glusterfs#308 Change-Id: I73aec28bc9dbb8da57c7425ec88c6b6af0fbc9dd Signed-off-by: Susant Palai Signed-off-by: Raghavendra G Signed-off-by: N Balachandran --- xlators/storage/posix/src/posix-helpers.c | 42 +++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'xlators/storage/posix/src/posix-helpers.c') diff --git a/xlators/storage/posix/src/posix-helpers.c b/xlators/storage/posix/src/posix-helpers.c index 90afced604c..56c9b4afe94 100644 --- a/xlators/storage/posix/src/posix-helpers.c +++ b/xlators/storage/posix/src/posix-helpers.c @@ -2739,3 +2739,45 @@ posix_override_umask (mode_t mode, mode_t mode_bit) gf_msg_debug ("posix", 0, "The value of mode is %u", mode); return mode; } + +int +posix_check_internal_writes (xlator_t *this, fd_t *fd, int sysfd, + dict_t *xdata) +{ + int ret = 0; + size_t xattrsize = 0; + data_t *val = NULL; + + LOCK (&fd->inode->lock); + { + val = dict_get (xdata, GF_PROTECT_FROM_EXTERNAL_WRITES); + if (val) { + ret = sys_fsetxattr (sysfd, + GF_PROTECT_FROM_EXTERNAL_WRITES, + val->data, val->len, 0); + if (ret == -1) { + gf_msg (this->name, GF_LOG_ERROR, + P_MSG_XATTR_FAILED, + errno, "setxattr failed key %s", + GF_PROTECT_FROM_EXTERNAL_WRITES); + } + + goto out; + } + + if (dict_get (xdata, GF_AVOID_OVERWRITE)) { + xattrsize = sys_fgetxattr (sysfd, + GF_PROTECT_FROM_EXTERNAL_WRITES, + NULL, 0); + if ((xattrsize == -1) && ((errno == ENOATTR) || + (errno == ENODATA))) { + ret = 0; + } else { + ret = -1; + } + } + } +out: + UNLOCK (&fd->inode->lock); + return ret; +} -- cgit