|
|
74096c |
From ba23e6d8f4eff11a228816149a8a1ccd6df41146 Mon Sep 17 00:00:00 2001
|
|
|
74096c |
From: Susant Palai <spalai@redhat.com>
|
|
|
74096c |
Date: Fri, 27 Dec 2019 12:06:19 +0530
|
|
|
74096c |
Subject: [PATCH 415/449] dht: Fix stale-layout and create issue
|
|
|
74096c |
|
|
|
74096c |
Problem: With lookup-optimize set to on by default, a client with
|
|
|
74096c |
stale-layout can create a new file on a wrong subvol. This will lead to
|
|
|
74096c |
possible duplicate files if two different clients attempt to create the
|
|
|
74096c |
same file with two different layouts.
|
|
|
74096c |
|
|
|
74096c |
Solution: Send in-memory layout to be cross checked at posix before
|
|
|
74096c |
commiting a "create". In case of a mismatch, sync the client layout with
|
|
|
74096c |
that of the server and attempt the create fop one more time.
|
|
|
74096c |
|
|
|
74096c |
test: Manual, testcase(attached)
|
|
|
74096c |
|
|
|
74096c |
(Backport of https://review.gluster.org/#/c/glusterfs/+/23927/)
|
|
|
74096c |
|
|
|
74096c |
BUG: 1748865
|
|
|
74096c |
Change-Id: I6c82c97418654ae8eb3b81ab65f1247aa4002ceb
|
|
|
74096c |
Signed-off-by: Susant Palai <spalai@redhat.com>
|
|
|
74096c |
Reviewed-on: https://code.engineering.redhat.com/gerrit/202465
|
|
|
74096c |
Tested-by: RHGS Build Bot <nigelb@redhat.com>
|
|
|
74096c |
Reviewed-by: Mohit Agrawal <moagrawa@redhat.com>
|
|
|
74096c |
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
|
|
|
74096c |
---
|
|
|
74096c |
tests/bugs/distribute/bug-1786679.t | 69 +++++++++++
|
|
|
74096c |
xlators/cluster/dht/src/dht-common.c | 147 ++++++++++++++++++++---
|
|
|
74096c |
xlators/cluster/dht/src/dht-common.h | 6 +
|
|
|
74096c |
xlators/protocol/client/src/client-rpc-fops_v2.c | 9 +-
|
|
|
74096c |
xlators/storage/posix/src/posix-entry-ops.c | 29 ++++-
|
|
|
74096c |
xlators/storage/posix/src/posix-helpers.c | 76 ++++++++++++
|
|
|
74096c |
xlators/storage/posix/src/posix.h | 4 +
|
|
|
74096c |
7 files changed, 321 insertions(+), 19 deletions(-)
|
|
|
74096c |
create mode 100755 tests/bugs/distribute/bug-1786679.t
|
|
|
74096c |
|
|
|
74096c |
diff --git a/tests/bugs/distribute/bug-1786679.t b/tests/bugs/distribute/bug-1786679.t
|
|
|
74096c |
new file mode 100755
|
|
|
74096c |
index 0000000..219ce51
|
|
|
74096c |
--- /dev/null
|
|
|
74096c |
+++ b/tests/bugs/distribute/bug-1786679.t
|
|
|
74096c |
@@ -0,0 +1,69 @@
|
|
|
74096c |
+#!/bin/bash
|
|
|
74096c |
+
|
|
|
74096c |
+SCRIPT_TIMEOUT=250
|
|
|
74096c |
+
|
|
|
74096c |
+. $(dirname $0)/../../include.rc
|
|
|
74096c |
+. $(dirname $0)/../../volume.rc
|
|
|
74096c |
+. $(dirname $0)/../../dht.rc
|
|
|
74096c |
+
|
|
|
74096c |
+
|
|
|
74096c |
+# create 2 subvols
|
|
|
74096c |
+# create a dir
|
|
|
74096c |
+# create a file
|
|
|
74096c |
+# change layout
|
|
|
74096c |
+# remove the file
|
|
|
74096c |
+# execute create from a different mount
|
|
|
74096c |
+# Without the patch, the file will be present on both of the bricks
|
|
|
74096c |
+
|
|
|
74096c |
+cleanup
|
|
|
74096c |
+
|
|
|
74096c |
+function get_layout () {
|
|
|
74096c |
+
|
|
|
74096c |
+layout=`getfattr -n trusted.glusterfs.dht -e hex $1 2>&1 | grep dht | gawk -F"=" '{print $2}'`
|
|
|
74096c |
+
|
|
|
74096c |
+echo $layout
|
|
|
74096c |
+
|
|
|
74096c |
+}
|
|
|
74096c |
+
|
|
|
74096c |
+function set_layout()
|
|
|
74096c |
+{
|
|
|
74096c |
+ setfattr -n "trusted.glusterfs.dht" -v $1 $2
|
|
|
74096c |
+}
|
|
|
74096c |
+
|
|
|
74096c |
+TEST glusterd
|
|
|
74096c |
+TEST pidof glusterd
|
|
|
74096c |
+
|
|
|
74096c |
+BRICK1=$B0/${V0}-0
|
|
|
74096c |
+BRICK2=$B0/${V0}-1
|
|
|
74096c |
+
|
|
|
74096c |
+TEST $CLI volume create $V0 $H0:$BRICK1 $H0:$BRICK2
|
|
|
74096c |
+TEST $CLI volume start $V0
|
|
|
74096c |
+
|
|
|
74096c |
+# Mount FUSE and create symlink
|
|
|
74096c |
+TEST glusterfs -s $H0 --volfile-id $V0 $M0
|
|
|
74096c |
+TEST mkdir $M0/dir
|
|
|
74096c |
+TEST touch $M0/dir/file
|
|
|
74096c |
+TEST ! stat "$BRICK1/dir/file"
|
|
|
74096c |
+TEST stat "$BRICK2/dir/file"
|
|
|
74096c |
+
|
|
|
74096c |
+layout1="$(get_layout "$BRICK1/dir")"
|
|
|
74096c |
+layout2="$(get_layout "$BRICK2/dir")"
|
|
|
74096c |
+
|
|
|
74096c |
+TEST set_layout $layout1 "$BRICK2/dir"
|
|
|
74096c |
+TEST set_layout $layout2 "$BRICK1/dir"
|
|
|
74096c |
+
|
|
|
74096c |
+TEST rm $M0/dir/file -f
|
|
|
74096c |
+TEST gluster v set $V0 client-log-level DEBUG
|
|
|
74096c |
+
|
|
|
74096c |
+#Without the patch in place, this client will create the file in $BRICK2
|
|
|
74096c |
+#which will lead to two files being on both the bricks when a new client
|
|
|
74096c |
+#create the file with the same name
|
|
|
74096c |
+TEST touch $M0/dir/file
|
|
|
74096c |
+
|
|
|
74096c |
+TEST glusterfs -s $H0 --volfile-id $V0 $M1
|
|
|
74096c |
+TEST touch $M1/dir/file
|
|
|
74096c |
+
|
|
|
74096c |
+TEST stat "$BRICK1/dir/file"
|
|
|
74096c |
+TEST ! stat "$BRICK2/dir/file"
|
|
|
74096c |
+
|
|
|
74096c |
+cleanup
|
|
|
74096c |
diff --git a/xlators/cluster/dht/src/dht-common.c b/xlators/cluster/dht/src/dht-common.c
|
|
|
74096c |
index 7890e7a..6aa18f3 100644
|
|
|
74096c |
--- a/xlators/cluster/dht/src/dht-common.c
|
|
|
74096c |
+++ b/xlators/cluster/dht/src/dht-common.c
|
|
|
74096c |
@@ -8262,6 +8262,11 @@ dht_create_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int op_ret,
|
|
|
74096c |
xlator_t *prev = NULL;
|
|
|
74096c |
int ret = -1;
|
|
|
74096c |
dht_local_t *local = NULL;
|
|
|
74096c |
+ gf_boolean_t parent_layout_changed = _gf_false;
|
|
|
74096c |
+ char pgfid[GF_UUID_BUF_SIZE] = {0};
|
|
|
74096c |
+ xlator_t *subvol = NULL;
|
|
|
74096c |
+
|
|
|
74096c |
+ local = frame->local;
|
|
|
74096c |
|
|
|
74096c |
local = frame->local;
|
|
|
74096c |
if (!local) {
|
|
|
74096c |
@@ -8270,8 +8275,69 @@ dht_create_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int op_ret,
|
|
|
74096c |
goto out;
|
|
|
74096c |
}
|
|
|
74096c |
|
|
|
74096c |
- if (op_ret == -1)
|
|
|
74096c |
+ if (op_ret == -1) {
|
|
|
74096c |
+ local->op_errno = op_errno;
|
|
|
74096c |
+ parent_layout_changed = (xdata &&
|
|
|
74096c |
+ dict_get(xdata, GF_PREOP_CHECK_FAILED))
|
|
|
74096c |
+ ? _gf_true
|
|
|
74096c |
+ : _gf_false;
|
|
|
74096c |
+
|
|
|
74096c |
+ if (parent_layout_changed) {
|
|
|
74096c |
+ if (local && local->lock[0].layout.parent_layout.locks) {
|
|
|
74096c |
+ /* Returning failure as the layout could not be fixed even under
|
|
|
74096c |
+ * the lock */
|
|
|
74096c |
+ goto out;
|
|
|
74096c |
+ }
|
|
|
74096c |
+
|
|
|
74096c |
+ gf_uuid_unparse(local->loc.parent->gfid, pgfid);
|
|
|
74096c |
+ gf_msg(this->name, GF_LOG_INFO, 0, DHT_MSG_PARENT_LAYOUT_CHANGED,
|
|
|
74096c |
+ "create (%s/%s) (path: %s): parent layout "
|
|
|
74096c |
+ "changed. Attempting a layout refresh and then a "
|
|
|
74096c |
+ "retry",
|
|
|
74096c |
+ pgfid, local->loc.name, local->loc.path);
|
|
|
74096c |
+
|
|
|
74096c |
+ /*
|
|
|
74096c |
+ dht_refresh_layout needs directory info in local->loc.Hence,
|
|
|
74096c |
+ storing the parent_loc in local->loc and storing the create
|
|
|
74096c |
+ context in local->loc2. We will restore this information in
|
|
|
74096c |
+ dht_creation_do.
|
|
|
74096c |
+ */
|
|
|
74096c |
+
|
|
|
74096c |
+ loc_wipe(&local->loc2);
|
|
|
74096c |
+
|
|
|
74096c |
+ ret = loc_copy(&local->loc2, &local->loc);
|
|
|
74096c |
+ if (ret) {
|
|
|
74096c |
+ gf_msg(this->name, GF_LOG_ERROR, ENOMEM, DHT_MSG_NO_MEMORY,
|
|
|
74096c |
+ "loc_copy failed %s", local->loc.path);
|
|
|
74096c |
+
|
|
|
74096c |
+ goto out;
|
|
|
74096c |
+ }
|
|
|
74096c |
+
|
|
|
74096c |
+ loc_wipe(&local->loc);
|
|
|
74096c |
+
|
|
|
74096c |
+ ret = dht_build_parent_loc(this, &local->loc, &local->loc2,
|
|
|
74096c |
+ &op_errno);
|
|
|
74096c |
+
|
|
|
74096c |
+ if (ret) {
|
|
|
74096c |
+ gf_msg(this->name, GF_LOG_ERROR, ENOMEM, DHT_MSG_LOC_FAILED,
|
|
|
74096c |
+ "parent loc build failed");
|
|
|
74096c |
+ goto out;
|
|
|
74096c |
+ }
|
|
|
74096c |
+
|
|
|
74096c |
+ subvol = dht_subvol_get_hashed(this, &local->loc2);
|
|
|
74096c |
+
|
|
|
74096c |
+ ret = dht_create_lock(frame, subvol);
|
|
|
74096c |
+ if (ret < 0) {
|
|
|
74096c |
+ gf_msg(this->name, GF_LOG_ERROR, 0, DHT_MSG_INODE_LK_ERROR,
|
|
|
74096c |
+ "locking parent failed");
|
|
|
74096c |
+ goto out;
|
|
|
74096c |
+ }
|
|
|
74096c |
+
|
|
|
74096c |
+ return 0;
|
|
|
74096c |
+ }
|
|
|
74096c |
+
|
|
|
74096c |
goto out;
|
|
|
74096c |
+ }
|
|
|
74096c |
|
|
|
74096c |
prev = cookie;
|
|
|
74096c |
|
|
|
74096c |
@@ -8392,6 +8458,8 @@ dht_create_wind_to_avail_subvol(call_frame_t *frame, xlator_t *this,
|
|
|
74096c |
gf_msg_debug(this->name, 0, "creating %s on %s", loc->path,
|
|
|
74096c |
subvol->name);
|
|
|
74096c |
|
|
|
74096c |
+ dht_set_parent_layout_in_dict(loc, this, local);
|
|
|
74096c |
+
|
|
|
74096c |
STACK_WIND_COOKIE(frame, dht_create_cbk, subvol, subvol,
|
|
|
74096c |
subvol->fops->create, loc, flags, mode, umask, fd,
|
|
|
74096c |
params);
|
|
|
74096c |
@@ -8400,10 +8468,6 @@ dht_create_wind_to_avail_subvol(call_frame_t *frame, xlator_t *this,
|
|
|
74096c |
avail_subvol = dht_free_disk_available_subvol(this, subvol, local);
|
|
|
74096c |
|
|
|
74096c |
if (avail_subvol != subvol) {
|
|
|
74096c |
- local->params = dict_ref(params);
|
|
|
74096c |
- local->flags = flags;
|
|
|
74096c |
- local->mode = mode;
|
|
|
74096c |
- local->umask = umask;
|
|
|
74096c |
local->cached_subvol = avail_subvol;
|
|
|
74096c |
local->hashed_subvol = subvol;
|
|
|
74096c |
|
|
|
74096c |
@@ -8419,6 +8483,8 @@ dht_create_wind_to_avail_subvol(call_frame_t *frame, xlator_t *this,
|
|
|
74096c |
gf_msg_debug(this->name, 0, "creating %s on %s", loc->path,
|
|
|
74096c |
subvol->name);
|
|
|
74096c |
|
|
|
74096c |
+ dht_set_parent_layout_in_dict(loc, this, local);
|
|
|
74096c |
+
|
|
|
74096c |
STACK_WIND_COOKIE(frame, dht_create_cbk, subvol, subvol,
|
|
|
74096c |
subvol->fops->create, loc, flags, mode, umask, fd,
|
|
|
74096c |
params);
|
|
|
74096c |
@@ -8680,6 +8746,60 @@ err:
|
|
|
74096c |
}
|
|
|
74096c |
|
|
|
74096c |
int
|
|
|
74096c |
+dht_set_parent_layout_in_dict(loc_t *loc, xlator_t *this, dht_local_t *local)
|
|
|
74096c |
+{
|
|
|
74096c |
+ dht_conf_t *conf = this->private;
|
|
|
74096c |
+ dht_layout_t *parent_layout = NULL;
|
|
|
74096c |
+ int *parent_disk_layout = NULL;
|
|
|
74096c |
+ xlator_t *hashed_subvol = NULL;
|
|
|
74096c |
+ char pgfid[GF_UUID_BUF_SIZE] = {0};
|
|
|
74096c |
+ int ret = 0;
|
|
|
74096c |
+
|
|
|
74096c |
+ gf_uuid_unparse(loc->parent->gfid, pgfid);
|
|
|
74096c |
+
|
|
|
74096c |
+ parent_layout = dht_layout_get(this, loc->parent);
|
|
|
74096c |
+ hashed_subvol = dht_subvol_get_hashed(this, loc);
|
|
|
74096c |
+
|
|
|
74096c |
+ ret = dht_disk_layout_extract_for_subvol(this, parent_layout, hashed_subvol,
|
|
|
74096c |
+ &parent_disk_layout);
|
|
|
74096c |
+ if (ret == -1) {
|
|
|
74096c |
+ gf_msg(this->name, GF_LOG_WARNING, local->op_errno,
|
|
|
74096c |
+ DHT_MSG_PARENT_LAYOUT_CHANGED,
|
|
|
74096c |
+ "%s (%s/%s) (path: %s): "
|
|
|
74096c |
+ "extracting in-memory layout of parent failed. ",
|
|
|
74096c |
+ gf_fop_list[local->fop], pgfid, loc->name, loc->path);
|
|
|
74096c |
+ goto err;
|
|
|
74096c |
+ }
|
|
|
74096c |
+
|
|
|
74096c |
+ ret = dict_set_str_sizen(local->params, GF_PREOP_PARENT_KEY,
|
|
|
74096c |
+ conf->xattr_name);
|
|
|
74096c |
+ if (ret < 0) {
|
|
|
74096c |
+ gf_msg(this->name, GF_LOG_WARNING, local->op_errno,
|
|
|
74096c |
+ DHT_MSG_PARENT_LAYOUT_CHANGED,
|
|
|
74096c |
+ "%s (%s/%s) (path: %s): "
|
|
|
74096c |
+ "setting %s key in params dictionary failed. ",
|
|
|
74096c |
+ gf_fop_list[local->fop], pgfid, loc->name, loc->path,
|
|
|
74096c |
+ GF_PREOP_PARENT_KEY);
|
|
|
74096c |
+ goto err;
|
|
|
74096c |
+ }
|
|
|
74096c |
+
|
|
|
74096c |
+ ret = dict_set_bin(local->params, conf->xattr_name, parent_disk_layout,
|
|
|
74096c |
+ 4 * 4);
|
|
|
74096c |
+ if (ret < 0) {
|
|
|
74096c |
+ gf_msg(this->name, GF_LOG_WARNING, local->op_errno,
|
|
|
74096c |
+ DHT_MSG_PARENT_LAYOUT_CHANGED,
|
|
|
74096c |
+ "%s (%s/%s) (path: %s): "
|
|
|
74096c |
+ "setting parent-layout in params dictionary failed. ",
|
|
|
74096c |
+ gf_fop_list[local->fop], pgfid, loc->name, loc->path);
|
|
|
74096c |
+ goto err;
|
|
|
74096c |
+ }
|
|
|
74096c |
+
|
|
|
74096c |
+err:
|
|
|
74096c |
+ dht_layout_unref(this, parent_layout);
|
|
|
74096c |
+ return ret;
|
|
|
74096c |
+}
|
|
|
74096c |
+
|
|
|
74096c |
+int
|
|
|
74096c |
dht_create(call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags,
|
|
|
74096c |
mode_t mode, mode_t umask, fd_t *fd, dict_t *params)
|
|
|
74096c |
{
|
|
|
74096c |
@@ -8705,6 +8825,11 @@ dht_create(call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags,
|
|
|
74096c |
goto err;
|
|
|
74096c |
}
|
|
|
74096c |
|
|
|
74096c |
+ local->params = dict_ref(params);
|
|
|
74096c |
+ local->flags = flags;
|
|
|
74096c |
+ local->mode = mode;
|
|
|
74096c |
+ local->umask = umask;
|
|
|
74096c |
+
|
|
|
74096c |
if (dht_filter_loc_subvol_key(this, loc, &local->loc, &subvol)) {
|
|
|
74096c |
gf_msg(this->name, GF_LOG_INFO, 0, DHT_MSG_SUBVOL_INFO,
|
|
|
74096c |
"creating %s on %s (got create on %s)", local->loc.path,
|
|
|
74096c |
@@ -8720,10 +8845,6 @@ dht_create(call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags,
|
|
|
74096c |
|
|
|
74096c |
if (hashed_subvol && (hashed_subvol != subvol)) {
|
|
|
74096c |
/* Create the linkto file and then the data file */
|
|
|
74096c |
- local->params = dict_ref(params);
|
|
|
74096c |
- local->flags = flags;
|
|
|
74096c |
- local->mode = mode;
|
|
|
74096c |
- local->umask = umask;
|
|
|
74096c |
local->cached_subvol = subvol;
|
|
|
74096c |
local->hashed_subvol = hashed_subvol;
|
|
|
74096c |
|
|
|
74096c |
@@ -8736,6 +8857,9 @@ dht_create(call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags,
|
|
|
74096c |
* file as we expect a lookup everywhere if there are problems
|
|
|
74096c |
* with the parent layout
|
|
|
74096c |
*/
|
|
|
74096c |
+
|
|
|
74096c |
+ dht_set_parent_layout_in_dict(loc, this, local);
|
|
|
74096c |
+
|
|
|
74096c |
STACK_WIND_COOKIE(frame, dht_create_cbk, subvol, subvol,
|
|
|
74096c |
subvol->fops->create, &local->loc, flags, mode, umask,
|
|
|
74096c |
fd, params);
|
|
|
74096c |
@@ -8787,11 +8911,6 @@ dht_create(call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags,
|
|
|
74096c |
goto err;
|
|
|
74096c |
}
|
|
|
74096c |
|
|
|
74096c |
- local->params = dict_ref(params);
|
|
|
74096c |
- local->flags = flags;
|
|
|
74096c |
- local->mode = mode;
|
|
|
74096c |
- local->umask = umask;
|
|
|
74096c |
-
|
|
|
74096c |
loc_wipe(&local->loc);
|
|
|
74096c |
|
|
|
74096c |
ret = dht_build_parent_loc(this, &local->loc, loc, &op_errno);
|
|
|
74096c |
diff --git a/xlators/cluster/dht/src/dht-common.h b/xlators/cluster/dht/src/dht-common.h
|
|
|
74096c |
index 8e65111..1b3e826 100644
|
|
|
74096c |
--- a/xlators/cluster/dht/src/dht-common.h
|
|
|
74096c |
+++ b/xlators/cluster/dht/src/dht-common.h
|
|
|
74096c |
@@ -1549,4 +1549,10 @@ dht_check_remote_fd_failed_error(dht_local_t *local, int op_ret, int op_errno);
|
|
|
74096c |
int
|
|
|
74096c |
dht_dir_layout_error_check(xlator_t *this, inode_t *inode);
|
|
|
74096c |
|
|
|
74096c |
+int32_t
|
|
|
74096c |
+dht_create_lock(call_frame_t *frame, xlator_t *subvol);
|
|
|
74096c |
+
|
|
|
74096c |
+int
|
|
|
74096c |
+dht_set_parent_layout_in_dict(loc_t *loc, xlator_t *this, dht_local_t *local);
|
|
|
74096c |
+
|
|
|
74096c |
#endif /* _DHT_H */
|
|
|
74096c |
diff --git a/xlators/protocol/client/src/client-rpc-fops_v2.c b/xlators/protocol/client/src/client-rpc-fops_v2.c
|
|
|
74096c |
index 2673b6e..613dda8 100644
|
|
|
74096c |
--- a/xlators/protocol/client/src/client-rpc-fops_v2.c
|
|
|
74096c |
+++ b/xlators/protocol/client/src/client-rpc-fops_v2.c
|
|
|
74096c |
@@ -2094,11 +2094,12 @@ client4_0_create_cbk(struct rpc_req *req, struct iovec *iov, int count,
|
|
|
74096c |
goto out;
|
|
|
74096c |
}
|
|
|
74096c |
|
|
|
74096c |
+ ret = client_post_create_v2(this, &rsp, &stbuf, &preparent, &postparent,
|
|
|
74096c |
+ local, &xdata);
|
|
|
74096c |
+ if (ret < 0)
|
|
|
74096c |
+ goto out;
|
|
|
74096c |
+
|
|
|
74096c |
if (-1 != rsp.op_ret) {
|
|
|
74096c |
- ret = client_post_create_v2(this, &rsp, &stbuf, &preparent, &postparent,
|
|
|
74096c |
- local, &xdata);
|
|
|
74096c |
- if (ret < 0)
|
|
|
74096c |
- goto out;
|
|
|
74096c |
ret = client_add_fd_to_saved_fds(frame->this, fd, &local->loc,
|
|
|
74096c |
local->flags, rsp.fd, 0);
|
|
|
74096c |
if (ret) {
|
|
|
74096c |
diff --git a/xlators/storage/posix/src/posix-entry-ops.c b/xlators/storage/posix/src/posix-entry-ops.c
|
|
|
74096c |
index bea0bbf..65650b3 100644
|
|
|
74096c |
--- a/xlators/storage/posix/src/posix-entry-ops.c
|
|
|
74096c |
+++ b/xlators/storage/posix/src/posix-entry-ops.c
|
|
|
74096c |
@@ -2070,6 +2070,8 @@ posix_create(call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags,
|
|
|
74096c |
gf_boolean_t entry_created = _gf_false, gfid_set = _gf_false;
|
|
|
74096c |
mode_t mode_bit = 0;
|
|
|
74096c |
|
|
|
74096c |
+ dict_t *xdata_rsp = dict_ref(xdata);
|
|
|
74096c |
+
|
|
|
74096c |
DECLARE_OLD_FS_ID_VAR;
|
|
|
74096c |
|
|
|
74096c |
VALIDATE_OR_GOTO(frame, out);
|
|
|
74096c |
@@ -2118,6 +2120,28 @@ posix_create(call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags,
|
|
|
74096c |
was_present = 0;
|
|
|
74096c |
}
|
|
|
74096c |
|
|
|
74096c |
+ if (!was_present) {
|
|
|
74096c |
+ if (posix_is_layout_stale(xdata, par_path, this)) {
|
|
|
74096c |
+ op_ret = -1;
|
|
|
74096c |
+ op_errno = EIO;
|
|
|
74096c |
+ if (!xdata_rsp) {
|
|
|
74096c |
+ xdata_rsp = dict_new();
|
|
|
74096c |
+ if (!xdata_rsp) {
|
|
|
74096c |
+ op_errno = ENOMEM;
|
|
|
74096c |
+ goto out;
|
|
|
74096c |
+ }
|
|
|
74096c |
+ }
|
|
|
74096c |
+
|
|
|
74096c |
+ if (dict_set_int32_sizen(xdata_rsp, GF_PREOP_CHECK_FAILED, 1) ==
|
|
|
74096c |
+ -1) {
|
|
|
74096c |
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_DICT_SET_FAILED,
|
|
|
74096c |
+ "setting key %s in dict failed", GF_PREOP_CHECK_FAILED);
|
|
|
74096c |
+ }
|
|
|
74096c |
+
|
|
|
74096c |
+ goto out;
|
|
|
74096c |
+ }
|
|
|
74096c |
+ }
|
|
|
74096c |
+
|
|
|
74096c |
if (priv->o_direct)
|
|
|
74096c |
_flags |= O_DIRECT;
|
|
|
74096c |
|
|
|
74096c |
@@ -2239,7 +2263,10 @@ out:
|
|
|
74096c |
|
|
|
74096c |
STACK_UNWIND_STRICT(create, frame, op_ret, op_errno, fd,
|
|
|
74096c |
(loc) ? loc->inode : NULL, &stbuf, &preparent,
|
|
|
74096c |
- &postparent, xdata);
|
|
|
74096c |
+ &postparent, xdata_rsp);
|
|
|
74096c |
+
|
|
|
74096c |
+ if (xdata_rsp)
|
|
|
74096c |
+ dict_unref(xdata_rsp);
|
|
|
74096c |
|
|
|
74096c |
return 0;
|
|
|
74096c |
}
|
|
|
74096c |
diff --git a/xlators/storage/posix/src/posix-helpers.c b/xlators/storage/posix/src/posix-helpers.c
|
|
|
74096c |
index 35dd3b6..2c27d22 100644
|
|
|
74096c |
--- a/xlators/storage/posix/src/posix-helpers.c
|
|
|
74096c |
+++ b/xlators/storage/posix/src/posix-helpers.c
|
|
|
74096c |
@@ -3559,3 +3559,79 @@ posix_update_iatt_buf(struct iatt *buf, int fd, char *loc, dict_t *xattr_req)
|
|
|
74096c |
}
|
|
|
74096c |
}
|
|
|
74096c |
}
|
|
|
74096c |
+
|
|
|
74096c |
+gf_boolean_t
|
|
|
74096c |
+posix_is_layout_stale(dict_t *xdata, char *par_path, xlator_t *this)
|
|
|
74096c |
+{
|
|
|
74096c |
+ int op_ret = 0;
|
|
|
74096c |
+ ssize_t size = 0;
|
|
|
74096c |
+ char value_buf[4096] = {
|
|
|
74096c |
+ 0,
|
|
|
74096c |
+ };
|
|
|
74096c |
+ gf_boolean_t have_val = _gf_false;
|
|
|
74096c |
+ data_t *arg_data = NULL;
|
|
|
74096c |
+ char *xattr_name = NULL;
|
|
|
74096c |
+ gf_boolean_t is_stale = _gf_false;
|
|
|
74096c |
+
|
|
|
74096c |
+ op_ret = dict_get_str_sizen(xdata, GF_PREOP_PARENT_KEY, &xattr_name);
|
|
|
74096c |
+ if (xattr_name == NULL) {
|
|
|
74096c |
+ op_ret = 0;
|
|
|
74096c |
+ goto out;
|
|
|
74096c |
+ }
|
|
|
74096c |
+
|
|
|
74096c |
+ arg_data = dict_get(xdata, xattr_name);
|
|
|
74096c |
+ if (!arg_data) {
|
|
|
74096c |
+ op_ret = 0;
|
|
|
74096c |
+ goto out;
|
|
|
74096c |
+ }
|
|
|
74096c |
+
|
|
|
74096c |
+ size = sys_lgetxattr(par_path, xattr_name, value_buf,
|
|
|
74096c |
+ sizeof(value_buf) - 1);
|
|
|
74096c |
+
|
|
|
74096c |
+ if (size >= 0) {
|
|
|
74096c |
+ have_val = _gf_true;
|
|
|
74096c |
+ } else {
|
|
|
74096c |
+ if (errno == ERANGE) {
|
|
|
74096c |
+ gf_msg(this->name, GF_LOG_INFO, errno, P_MSG_PREOP_CHECK_FAILED,
|
|
|
74096c |
+ "getxattr on key (%s) path (%s) failed due to"
|
|
|
74096c |
+ " buffer overflow",
|
|
|
74096c |
+ xattr_name, par_path);
|
|
|
74096c |
+ size = sys_lgetxattr(par_path, xattr_name, NULL, 0);
|
|
|
74096c |
+ }
|
|
|
74096c |
+ if (size < 0) {
|
|
|
74096c |
+ op_ret = -1;
|
|
|
74096c |
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_PREOP_CHECK_FAILED,
|
|
|
74096c |
+ "getxattr on key (%s) failed, path : %s", xattr_name,
|
|
|
74096c |
+ par_path);
|
|
|
74096c |
+ goto out;
|
|
|
74096c |
+ }
|
|
|
74096c |
+ }
|
|
|
74096c |
+
|
|
|
74096c |
+ if (!have_val) {
|
|
|
74096c |
+ size = sys_lgetxattr(par_path, xattr_name, value_buf, size);
|
|
|
74096c |
+ if (size < 0) {
|
|
|
74096c |
+ gf_msg(this->name, GF_LOG_ERROR, errno, P_MSG_PREOP_CHECK_FAILED,
|
|
|
74096c |
+ "getxattr on key (%s) failed (%s)", xattr_name,
|
|
|
74096c |
+ strerror(errno));
|
|
|
74096c |
+ goto out;
|
|
|
74096c |
+ }
|
|
|
74096c |
+ }
|
|
|
74096c |
+
|
|
|
74096c |
+ if ((arg_data->len != size) || (memcmp(arg_data->data, value_buf, size))) {
|
|
|
74096c |
+ gf_msg(this->name, GF_LOG_INFO, EIO, P_MSG_PREOP_CHECK_FAILED,
|
|
|
74096c |
+ "failing preop as on-disk xattr value differs from argument "
|
|
|
74096c |
+ "value for key %s",
|
|
|
74096c |
+ xattr_name);
|
|
|
74096c |
+ op_ret = -1;
|
|
|
74096c |
+ }
|
|
|
74096c |
+
|
|
|
74096c |
+out:
|
|
|
74096c |
+ dict_del_sizen(xdata, xattr_name);
|
|
|
74096c |
+ dict_del_sizen(xdata, GF_PREOP_PARENT_KEY);
|
|
|
74096c |
+
|
|
|
74096c |
+ if (op_ret == -1) {
|
|
|
74096c |
+ is_stale = _gf_true;
|
|
|
74096c |
+ }
|
|
|
74096c |
+
|
|
|
74096c |
+ return is_stale;
|
|
|
74096c |
+}
|
|
|
74096c |
diff --git a/xlators/storage/posix/src/posix.h b/xlators/storage/posix/src/posix.h
|
|
|
74096c |
index dd51062..ac9d83c 100644
|
|
|
74096c |
--- a/xlators/storage/posix/src/posix.h
|
|
|
74096c |
+++ b/xlators/storage/posix/src/posix.h
|
|
|
74096c |
@@ -671,4 +671,8 @@ posix_spawn_ctx_janitor_thread(xlator_t *this);
|
|
|
74096c |
|
|
|
74096c |
void
|
|
|
74096c |
posix_update_iatt_buf(struct iatt *buf, int fd, char *loc, dict_t *xdata);
|
|
|
74096c |
+
|
|
|
74096c |
+gf_boolean_t
|
|
|
74096c |
+posix_is_layout_stale(dict_t *xdata, char *par_path, xlator_t *this);
|
|
|
74096c |
+
|
|
|
74096c |
#endif /* _POSIX_H */
|
|
|
74096c |
--
|
|
|
74096c |
1.8.3.1
|
|
|
74096c |
|