summaryrefslogtreecommitdiffstats
path: root/xlators/features/index/src/index.c
diff options
context:
space:
mode:
authorRavishankar N <ravishankar@redhat.com>2015-12-07 18:03:03 +0530
committerPranith Kumar Karampuri <pkarampu@redhat.com>2015-12-20 20:04:38 -0800
commitd5a9e765543fd6eec5d522e4f3f062bef97aefed (patch)
tree01715711c096da5d6a21b255139b81ad07abbe8d /xlators/features/index/src/index.c
parent9644769ea174646eaf18b8a41873f67928be9c8d (diff)
afr: refresh inode using fstat
For fd based operations (fgetxattr, readv etc.) if an inode refresh is required, do so using fstat instead of lookup. This is because the file might have been deleted by another client before refresh but posix mandates that FOPS using already open fds must still succeed. Change-Id: Id5f71c3af4892b648eb747f363dffe6208e7ac09 BUG: 1285230 Signed-off-by: Ravishankar N <ravishankar@redhat.com> Reviewed-on: http://review.gluster.org/12894 Reviewed-by: Pranith Kumar Karampuri <pkarampu@redhat.com> Tested-by: Gluster Build System <jenkins@build.gluster.com> Tested-by: NetBSD Build System <jenkins@build.gluster.org>
Diffstat (limited to 'xlators/features/index/src/index.c')
-rw-r--r--xlators/features/index/src/index.c65
1 files changed, 53 insertions, 12 deletions
diff --git a/xlators/features/index/src/index.c b/xlators/features/index/src/index.c
index 8350e79c412..6e4071ab539 100644
--- a/xlators/features/index/src/index.c
+++ b/xlators/features/index/src/index.c
@@ -1353,16 +1353,14 @@ out:
return count;
}
-int32_t
-index_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, inode_t *inode,
- struct iatt *buf, dict_t *xdata, struct iatt *postparent)
+dict_t*
+index_fill_link_count (xlator_t *this, dict_t *xdata)
{
- int ret = -1;
- char *dir = NULL;
- index_priv_t *priv = this->private;
- int64_t count = -1;
+ int ret = -1;
+ index_priv_t *priv = NULL;
+ int64_t count = -1;
+ priv = this->private;
xdata = (xdata) ? dict_ref (xdata) : dict_new ();
if (!xdata)
goto out;
@@ -1376,14 +1374,26 @@ index_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
if (count == 0) {
ret = dict_set_int8 (xdata, "link-count", 0);
if (ret < 0)
- goto out;
+ gf_log (this->name, GF_LOG_ERROR,
+ "Unable to set link-count");
} else {
ret = dict_set_int8 (xdata, "link-count", 1);
if (ret < 0)
- goto out;
+ gf_log (this->name, GF_LOG_ERROR,
+ "Unable to set link-count");
}
out:
+ return xdata;
+}
+
+int32_t
+index_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, inode_t *inode,
+ struct iatt *buf, dict_t *xdata, struct iatt *postparent)
+{
+
+ xdata = index_fill_link_count (this, xdata);
STACK_UNWIND_STRICT (lookup, frame, op_ret, op_errno, inode, buf,
xdata, postparent);
if (xdata)
@@ -1418,7 +1428,7 @@ index_lookup (call_frame_t *frame, xlator_t *this,
return 0;
normal:
ret = dict_get_str (xattr_req, "link-count", &flag);
- if (!(ret || strcmp (flag, GF_XATTROP_INDEX_COUNT))) {
+ if ((ret == 0) && (strcmp (flag, GF_XATTROP_INDEX_COUNT) == 0)) {
STACK_WIND (frame, index_lookup_cbk, FIRST_CHILD(this),
FIRST_CHILD(this)->fops->lookup, loc, xattr_req);
} else {
@@ -1430,6 +1440,36 @@ normal:
}
int32_t
+index_fstat_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, struct iatt *buf,
+ dict_t *xdata)
+{
+ xdata = index_fill_link_count (this, xdata);
+ STACK_UNWIND_STRICT (fstat, frame, op_ret, op_errno, buf, xdata);
+ if (xdata)
+ dict_unref (xdata);
+ return 0;
+}
+
+int32_t
+index_fstat (call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *xdata)
+{
+ int ret = -1;
+ char *flag = NULL;
+
+ ret = dict_get_str (xdata, "link-count", &flag);
+ if ((ret == 0) && (strcmp (flag, GF_XATTROP_INDEX_COUNT) == 0)) {
+ STACK_WIND (frame, index_fstat_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->fstat, fd, xdata);
+ } else {
+ STACK_WIND (frame, default_fstat_cbk, FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->fstat, fd, xdata);
+ }
+
+ return 0;
+}
+
+int32_t
index_opendir (call_frame_t *frame, xlator_t *this,
loc_t *loc, fd_t *fd, dict_t *xdata)
{
@@ -1809,7 +1849,8 @@ struct xlator_fops fops = {
.lookup = index_lookup,
.opendir = index_opendir,
.readdir = index_readdir,
- .unlink = index_unlink
+ .unlink = index_unlink,
+ .fstat = index_fstat,
};
struct xlator_dumpops dumpops;