summaryrefslogtreecommitdiffstats
path: root/xlators/cluster/dht/src/dht-inode-read.c
diff options
context:
space:
mode:
authorRaghavendra G <rgowdapp@redhat.com>2015-05-28 16:03:12 +0530
committerRaghavendra G <rgowdapp@redhat.com>2015-06-02 22:33:00 -0700
commitb6eda067d2e2a0b56718ea71522f6c7b06a09f13 (patch)
tree82f5909c06abb4fdbb99d11d3fbe3eefea7b8f2c /xlators/cluster/dht/src/dht-inode-read.c
parentb7842d178a6019bc2c14ecaf18ae5438a46bda29 (diff)
cluster/dht: pass a destination subvol to fop2 variants to avoid races.
The destination subvol used in the fop2 variants is either stored in inode-ctx1 or local->cached_subvol. However, it is not guaranteed that a value stored in these locations before invocation of fop2 is still present after the invocation as these locations are shared among different concurrent operations. So, to preserve the atomicity of "check dst-subvol and invoke fop2 variant if dst-subvol found", we pass down the dst-subvol to fop2 variant. This patch also fixes error handling in some fop2 variants. Change-Id: Icc226228a246d3f223e3463519736c4495b364d2 BUG: 1142423 Signed-off-by: Raghavendra G <rgowdapp@redhat.com> Reviewed-on: http://review.gluster.org/10943 Tested-by: NetBSD Build System <jenkins@build.gluster.org> Reviewed-by: N Balachandran <nbalacha@redhat.com>
Diffstat (limited to 'xlators/cluster/dht/src/dht-inode-read.c')
-rw-r--r--xlators/cluster/dht/src/dht-inode-read.c96
1 files changed, 52 insertions, 44 deletions
diff --git a/xlators/cluster/dht/src/dht-inode-read.c b/xlators/cluster/dht/src/dht-inode-read.c
index 896997e67f7..41cffa8ad1d 100644
--- a/xlators/cluster/dht/src/dht-inode-read.c
+++ b/xlators/cluster/dht/src/dht-inode-read.c
@@ -10,13 +10,13 @@
#include "dht-common.h"
-int dht_access2 (xlator_t *this, call_frame_t *frame, int ret);
-int dht_readv2 (xlator_t *this, call_frame_t *frame, int ret);
-int dht_attr2 (xlator_t *this, call_frame_t *frame, int ret);
-int dht_open2 (xlator_t *this, call_frame_t *frame, int ret);
-int dht_flush2 (xlator_t *this, call_frame_t *frame, int ret);
-int dht_lk2 (xlator_t *this, call_frame_t *frame, int ret);
-int dht_fsync2 (xlator_t *this, call_frame_t *frame, int ret);
+int dht_access2 (xlator_t *this, xlator_t *dst_node, call_frame_t *frame);
+int dht_readv2 (xlator_t *this, xlator_t *dst_node, call_frame_t *frame);
+int dht_attr2 (xlator_t *this, xlator_t *dst_node, call_frame_t *frame);
+int dht_open2 (xlator_t *this, xlator_t *dst_node, call_frame_t *frame);
+int dht_flush2 (xlator_t *this, xlator_t *dst_node, call_frame_t *frame);
+int dht_lk2 (xlator_t *this, xlator_t *dst_node, call_frame_t *frame);
+int dht_fsync2 (xlator_t *this, xlator_t *dst_node, call_frame_t *frame);
int
dht_open_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
@@ -53,22 +53,21 @@ out:
}
int
-dht_open2 (xlator_t *this, call_frame_t *frame, int op_ret)
+dht_open2 (xlator_t *this, xlator_t *subvol, call_frame_t *frame)
{
- dht_local_t *local = NULL;
- xlator_t *subvol = NULL;
+ dht_local_t *local = NULL;
int op_errno = EINVAL;
- local = frame->local;
- if (!local)
+ if (!frame || !frame->local)
goto out;
+ local = frame->local;
op_errno = ENOENT;
- if (op_ret)
+
+ if (subvol == NULL)
goto out;
local->call_cnt = 2;
- subvol = local->cached_subvol;
STACK_WIND (frame, dht_open_cbk, subvol, subvol->fops->open,
&local->loc, local->rebalance.flags, local->fd,
@@ -164,7 +163,7 @@ dht_file_attr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
} else {
/* value is already set in fd_ctx, that means no need
to check for whether its complete or not. */
- dht_attr2 (this, frame, 0);
+ dht_attr2 (this, subvol, frame);
return 0;
}
}
@@ -177,10 +176,9 @@ err:
}
int
-dht_attr2 (xlator_t *this, call_frame_t *frame, int op_ret)
+dht_attr2 (xlator_t *this, xlator_t *subvol, call_frame_t *frame)
{
- dht_local_t *local = NULL;
- xlator_t *subvol = NULL;
+ dht_local_t *local = NULL;
int op_errno = EINVAL;
local = frame->local;
@@ -188,10 +186,9 @@ dht_attr2 (xlator_t *this, call_frame_t *frame, int op_ret)
goto out;
op_errno = local->op_errno;
- if (op_ret == -1)
+ if (subvol == NULL)
goto out;
- subvol = local->cached_subvol;
local->call_cnt = 2;
if (local->fop == GF_FOP_FSTAT) {
@@ -201,6 +198,7 @@ dht_attr2 (xlator_t *this, call_frame_t *frame, int op_ret)
STACK_WIND (frame, dht_file_attr_cbk, subvol,
subvol->fops->stat, &local->loc, NULL);
}
+
return 0;
out:
@@ -408,7 +406,7 @@ dht_readv_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
} else {
/* value is already set in fd_ctx, that means no need
to check for whether its complete or not. */
- dht_readv2 (this, frame, 0);
+ dht_readv2 (this, subvol, frame);
return 0;
}
}
@@ -422,10 +420,9 @@ out:
}
int
-dht_readv2 (xlator_t *this, call_frame_t *frame, int op_ret)
+dht_readv2 (xlator_t *this, xlator_t *subvol, call_frame_t *frame)
{
dht_local_t *local = NULL;
- xlator_t *subvol = NULL;
int op_errno = EINVAL;
local = frame->local;
@@ -433,11 +430,10 @@ dht_readv2 (xlator_t *this, call_frame_t *frame, int op_ret)
goto out;
op_errno = local->op_errno;
- if (op_ret == -1)
+ if (subvol == NULL)
goto out;
local->call_cnt = 2;
- subvol = local->cached_subvol;
STACK_WIND (frame, dht_readv_cbk, subvol, subvol->fops->readv,
local->fd, local->rebalance.size, local->rebalance.offset,
@@ -542,10 +538,9 @@ out:
}
int
-dht_access2 (xlator_t *this, call_frame_t *frame, int op_ret)
+dht_access2 (xlator_t *this, xlator_t *subvol, call_frame_t *frame)
{
- dht_local_t *local = NULL;
- xlator_t *subvol = NULL;
+ dht_local_t *local = NULL;
int op_errno = EINVAL;
local = frame->local;
@@ -553,11 +548,10 @@ dht_access2 (xlator_t *this, call_frame_t *frame, int op_ret)
goto out;
op_errno = local->op_errno;
- if (op_ret == -1)
+ if (subvol == NULL)
goto out;
local->call_cnt = 2;
- subvol = local->cached_subvol;
STACK_WIND (frame, dht_access_cbk, subvol, subvol->fops->access,
&local->loc, local->rebalance.flags, NULL);
@@ -631,7 +625,7 @@ dht_flush_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
/* If context is set, then send flush() it to the destination */
dht_inode_ctx_get1 (this, inode, &subvol);
if (subvol) {
- dht_flush2 (this, frame, 0);
+ dht_flush2 (this, subvol, frame);
return 0;
}
@@ -642,17 +636,20 @@ out:
}
int
-dht_flush2 (xlator_t *this, call_frame_t *frame, int op_ret)
+dht_flush2 (xlator_t *this, xlator_t *subvol, call_frame_t *frame)
{
- dht_local_t *local = NULL;
- xlator_t *subvol = NULL;
+ dht_local_t *local = NULL;
+ int32_t op_errno = EINVAL;
+
+ if ((frame == NULL) || (frame->local == NULL))
+ goto out;
local = frame->local;
- dht_inode_ctx_get1 (this, local->fd->inode, &subvol);
+ op_errno = local->op_errno;
- if (!subvol)
- subvol = local->cached_subvol;
+ if (subvol == NULL)
+ goto out;
local->call_cnt = 2; /* This is the second attempt */
@@ -660,6 +657,10 @@ dht_flush2 (xlator_t *this, call_frame_t *frame, int op_ret)
subvol, subvol->fops->flush, local->fd, NULL);
return 0;
+
+out:
+ DHT_STACK_UNWIND (flush, frame, -1, op_errno, NULL);
+ return 0;
}
@@ -753,7 +754,7 @@ dht_fsync_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int op_ret,
if (!ret)
return 0;
} else {
- dht_fsync2 (this, frame, 0);
+ dht_fsync2 (this, subvol, frame);
return 0;
}
@@ -767,16 +768,19 @@ out:
}
int
-dht_fsync2 (xlator_t *this, call_frame_t *frame, int op_ret)
+dht_fsync2 (xlator_t *this, xlator_t *subvol, call_frame_t *frame)
{
- dht_local_t *local = NULL;
- xlator_t *subvol = NULL;
+ dht_local_t *local = NULL;
+ int32_t op_errno = EINVAL;
+
+ if ((frame == NULL) || (frame->local == NULL))
+ goto out;
local = frame->local;
+ op_errno = local->op_errno;
- dht_inode_ctx_get1 (this, local->fd->inode, &subvol);
- if (!subvol)
- subvol = local->cached_subvol;
+ if (subvol == NULL)
+ goto out;
local->call_cnt = 2; /* This is the second attempt */
@@ -784,6 +788,10 @@ dht_fsync2 (xlator_t *this, call_frame_t *frame, int op_ret)
local->fd, local->rebalance.flags, NULL);
return 0;
+
+out:
+ DHT_STACK_UNWIND (fsync, frame, -1, op_errno, NULL, NULL, NULL);
+ return 0;
}
int