summaryrefslogtreecommitdiffstats
path: root/xlators/protocol/client/src
diff options
context:
space:
mode:
authorRajesh Amaravathi <rajesh@redhat.com>2012-11-15 12:04:34 +0530
committerVijay Bellur <vbellur@redhat.com>2012-11-19 23:30:31 -0800
commitb34235bfee175be1dcaad8056239e69f76ae3e95 (patch)
tree312987d2e5c59de6c61c8064f76480dedc100e63 /xlators/protocol/client/src
parent775626f44f30e38cccd5efcd959b61f4f0f61969 (diff)
protocol/client: Remember the gfid of opened fd
This is needed when the fresh lookup triggers self-heal, gfid won't be present in inode yet. Similar situation happens with Rebalance as it does not perform inode_link. Added similar fix for re-opendir. Removed inode from fdctx and removed some duplication of code. BUG: 826080 Change-Id: I5840b86bf70ef73d40ae899b34a210b2dbcbf91f Signed-off-by: Pranith Kumar K <pranithk@gluster.com> Signed-off-by: Rajesh Amaravathi <rajesh@redhat.com> Reviewed-on: http://review.gluster.org/4192 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Vijay Bellur <vbellur@redhat.com>
Diffstat (limited to 'xlators/protocol/client/src')
-rw-r--r--xlators/protocol/client/src/client-handshake.c54
-rw-r--r--xlators/protocol/client/src/client.h4
-rw-r--r--xlators/protocol/client/src/client3_1-fops.c161
3 files changed, 107 insertions, 112 deletions
diff --git a/xlators/protocol/client/src/client-handshake.c b/xlators/protocol/client/src/client-handshake.c
index 64e0c356db1..404cf99c19d 100644
--- a/xlators/protocol/client/src/client-handshake.c
+++ b/xlators/protocol/client/src/client-handshake.c
@@ -747,7 +747,7 @@ client_reacquire_lock_cbk (struct rpc_req *req, struct iovec *iov,
gf_log (this->name, GF_LOG_DEBUG, "%s type lock reacquired on file "
"with gfid %s from %"PRIu64 " to %"PRIu64,
- get_lk_type (lock.l_type), uuid_utoa (fdctx->inode->gfid),
+ get_lk_type (lock.l_type), uuid_utoa (fdctx->gfid),
lock.l_start, lock.l_start + lock.l_len);
if (clnt_fd_lk_local_unref (this, local) == 0 &&
@@ -799,7 +799,7 @@ _client_reacquire_lock (xlator_t *this, clnt_fd_ctx_t *fdctx)
if (!local) {
gf_log (this->name, GF_LOG_WARNING, "clnt_fd_lk_local_create "
"failed, aborting reacquring of locks on %s.",
- uuid_utoa (fdctx->inode->gfid));
+ uuid_utoa (fdctx->gfid));
clnt_reacquire_lock_error (this, fdctx, conf);
goto out;
}
@@ -825,7 +825,7 @@ _client_reacquire_lock (xlator_t *this, clnt_fd_ctx_t *fdctx)
(void) gf_proto_flock_from_flock (&req.flock,
&flock);
- memcpy (req.gfid, fdctx->inode->gfid, 16);
+ memcpy (req.gfid, fdctx->gfid, 16);
frame = create_frame (this, this->ctx->pool);
if (!frame) {
@@ -844,7 +844,7 @@ _client_reacquire_lock (xlator_t *this, clnt_fd_ctx_t *fdctx)
if (ret) {
gf_log (this->name, GF_LOG_WARNING,
"reacquiring locks failed on file with gfid %s",
- uuid_utoa (fdctx->inode->gfid));
+ uuid_utoa (fdctx->gfid));
break;
}
@@ -1090,34 +1090,25 @@ protocol_client_reopendir (xlator_t *this, clnt_fd_ctx_t *fdctx)
int ret = -1;
gfs3_opendir_req req = {{0,},};
clnt_local_t *local = NULL;
- inode_t *inode = NULL;
- char *path = NULL;
call_frame_t *frame = NULL;
clnt_conf_t *conf = NULL;
if (!this || !fdctx)
goto out;
- inode = fdctx->inode;
conf = this->private;
- ret = inode_path (inode, NULL, &path);
- if (ret < 0) {
- gf_log (this->name, GF_LOG_WARNING,
- "couldn't build path from inode %s",
- uuid_utoa (inode->gfid));
- goto out;
- }
-
local = mem_get0 (this->local_pool);
if (!local) {
ret = -1;
goto out;
}
-
local->fdctx = fdctx;
- local->loc.path = path;
- path = NULL;
+
+ uuid_copy (local->loc.gfid, fdctx->gfid);
+ ret = loc_path (&local->loc, NULL);
+ if (ret < 0)
+ goto out;
frame = create_frame (this, this->ctx->pool);
if (!frame) {
@@ -1125,7 +1116,7 @@ protocol_client_reopendir (xlator_t *this, clnt_fd_ctx_t *fdctx)
goto out;
}
- memcpy (req.gfid, inode->gfid, 16);
+ memcpy (req.gfid, fdctx->gfid, 16);
gf_log (frame->this->name, GF_LOG_DEBUG,
"attempting reopen on %s", local->loc.path);
@@ -1153,8 +1144,6 @@ out:
if (local)
client_local_wipe (local);
- if (path)
- GF_FREE (path);
if ((ret < 0) && this && conf) {
decrement_reopen_fd_count (this, conf);
}
@@ -1169,25 +1158,14 @@ protocol_client_reopen (xlator_t *this, clnt_fd_ctx_t *fdctx)
int ret = -1;
gfs3_open_req req = {{0,},};
clnt_local_t *local = NULL;
- inode_t *inode = NULL;
- char *path = NULL;
call_frame_t *frame = NULL;
clnt_conf_t *conf = NULL;
if (!this || !fdctx)
goto out;
- inode = fdctx->inode;
conf = this->private;
- ret = inode_path (inode, NULL, &path);
- if (ret < 0) {
- gf_log (this->name, GF_LOG_WARNING,
- "couldn't build path from inode %s",
- uuid_utoa (inode->gfid));
- goto out;
- }
-
frame = create_frame (this, this->ctx->pool);
if (!frame) {
ret = -1;
@@ -1201,11 +1179,14 @@ protocol_client_reopen (xlator_t *this, clnt_fd_ctx_t *fdctx)
}
local->fdctx = fdctx;
- local->loc.path = path;
- path = NULL;
+ uuid_copy (local->loc.gfid, fdctx->gfid);
+ ret = loc_path (&local->loc, NULL);
+ if (ret < 0)
+ goto out;
+
frame->local = local;
- memcpy (req.gfid, inode->gfid, 16);
+ memcpy (req.gfid, fdctx->gfid, 16);
req.flags = gf_flags_from_flags (fdctx->flags);
gf_log (frame->this->name, GF_LOG_DEBUG,
@@ -1232,9 +1213,6 @@ out:
if (local)
client_local_wipe (local);
- if (path)
- GF_FREE (path);
-
if ((ret < 0) && this && conf) {
decrement_reopen_fd_count (this, conf);
}
diff --git a/xlators/protocol/client/src/client.h b/xlators/protocol/client/src/client.h
index 64066dd0add..ac999db5a16 100644
--- a/xlators/protocol/client/src/client.h
+++ b/xlators/protocol/client/src/client.h
@@ -116,9 +116,6 @@ typedef struct _client_fd_ctx {
fd's position in the saved_fds list.
*/
int64_t remote_fd;
- inode_t *inode;
- uint64_t ino;
- uint64_t gen;
char is_dir;
char released;
int32_t flags;
@@ -126,6 +123,7 @@ typedef struct _client_fd_ctx {
fd_lk_ctx_t *lk_ctx;
pthread_mutex_t mutex;
lk_heal_state_t lk_heal_state;
+ uuid_t gfid;
struct list_head lock_list; /* List of all granted locks on this fd */
} clnt_fd_ctx_t;
diff --git a/xlators/protocol/client/src/client3_1-fops.c b/xlators/protocol/client/src/client3_1-fops.c
index 78d2504fb04..66751354886 100644
--- a/xlators/protocol/client/src/client3_1-fops.c
+++ b/xlators/protocol/client/src/client3_1-fops.c
@@ -341,12 +341,84 @@ out:
}
int
+_copy_gfid_from_inode_holders (uuid_t gfid, loc_t *loc, fd_t *fd)
+{
+ int ret = 0;
+
+ if (fd && fd->inode && !uuid_is_null (fd->inode->gfid)) {
+ uuid_copy (gfid, fd->inode->gfid);
+ goto out;
+ }
+
+ if (!loc) {
+ GF_ASSERT (0);
+ ret = -1;
+ goto out;
+ }
+
+ if (loc->inode && !uuid_is_null (loc->inode->gfid)) {
+ uuid_copy (gfid, loc->inode->gfid);
+ } else if (!uuid_is_null (loc->gfid)) {
+ uuid_copy (gfid, loc->gfid);
+ } else {
+ GF_ASSERT (0);
+ ret = -1;
+ }
+out:
+ return ret;
+}
+
+int
+client_add_fd_to_saved_fds (xlator_t *this, fd_t *fd, loc_t *loc, int32_t flags,
+ int32_t wbflags, int64_t remote_fd, int is_dir)
+{
+ int ret = 0;
+ uuid_t gfid = {0};
+ clnt_conf_t *conf = NULL;
+ clnt_fd_ctx_t *fdctx = NULL;
+
+ conf = this->private;
+ ret = _copy_gfid_from_inode_holders (gfid, loc, fd);
+ if (ret) {
+ ret = -EINVAL;
+ goto out;
+ }
+
+ fdctx = GF_CALLOC (1, sizeof (*fdctx),
+ gf_client_mt_clnt_fdctx_t);
+ if (!fdctx) {
+ ret = -ENOMEM;
+ goto out;
+ }
+
+ uuid_copy (fdctx->gfid, gfid);
+ fdctx->is_dir = is_dir;
+ fdctx->remote_fd = remote_fd;
+ fdctx->flags = flags;
+ fdctx->wbflags = wbflags;
+ fdctx->lk_ctx = fd_lk_ctx_ref (fd->lk_ctx);
+ fdctx->lk_heal_state = GF_LK_HEAL_DONE;
+
+ INIT_LIST_HEAD (&fdctx->sfd_pos);
+ INIT_LIST_HEAD (&fdctx->lock_list);
+
+ this_fd_set_ctx (fd, this, loc, fdctx);
+
+ pthread_mutex_lock (&conf->lock);
+ {
+ list_add_tail (&fdctx->sfd_pos, &conf->saved_fds);
+ }
+ pthread_mutex_unlock (&conf->lock);
+out:
+ return ret;
+}
+
+int
client3_1_open_cbk (struct rpc_req *req, struct iovec *iov, int count,
void *myframe)
{
clnt_local_t *local = NULL;
clnt_conf_t *conf = NULL;
- clnt_fd_ctx_t *fdctx = NULL;
call_frame_t *frame = NULL;
fd_t *fd = NULL;
int ret = 0;
@@ -377,31 +449,14 @@ client3_1_open_cbk (struct rpc_req *req, struct iovec *iov, int count,
}
if (-1 != rsp.op_ret) {
- fdctx = GF_CALLOC (1, sizeof (*fdctx),
- gf_client_mt_clnt_fdctx_t);
- if (!fdctx) {
+ ret = client_add_fd_to_saved_fds (frame->this, fd, &local->loc,
+ local->flags, local->wbflags,
+ rsp.fd, 0);
+ if (ret) {
rsp.op_ret = -1;
- rsp.op_errno = ENOMEM;
+ rsp.op_errno = -ret;
goto out;
}
-
- fdctx->remote_fd = rsp.fd;
- fdctx->inode = inode_ref (fd->inode);
- fdctx->flags = local->flags;
- fdctx->wbflags = local->wbflags;
- fdctx->lk_ctx = fd_lk_ctx_ref (fd->lk_ctx);
- fdctx->lk_heal_state = GF_LK_HEAL_DONE;
-
- INIT_LIST_HEAD (&fdctx->sfd_pos);
- INIT_LIST_HEAD (&fdctx->lock_list);
-
- this_fd_set_ctx (fd, frame->this, &local->loc, fdctx);
-
- pthread_mutex_lock (&conf->lock);
- {
- list_add_tail (&fdctx->sfd_pos, &conf->saved_fds);
- }
- pthread_mutex_unlock (&conf->lock);
}
GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val),
@@ -1978,8 +2033,6 @@ client3_1_create_cbk (struct rpc_req *req, struct iovec *iov, int count,
struct iatt postparent = {0, };
int32_t ret = -1;
clnt_local_t *local = NULL;
- clnt_conf_t *conf = NULL;
- clnt_fd_ctx_t *fdctx = NULL;
gfs3_create_rsp rsp = {0,};
xlator_t *this = NULL;
dict_t *xdata = NULL;
@@ -1988,7 +2041,6 @@ client3_1_create_cbk (struct rpc_req *req, struct iovec *iov, int count,
frame = myframe;
local = frame->local;
- conf = frame->this->private;
fd = local->fd;
inode = local->loc.inode;
@@ -2011,31 +2063,15 @@ client3_1_create_cbk (struct rpc_req *req, struct iovec *iov, int count,
gf_stat_to_iatt (&rsp.preparent, &preparent);
gf_stat_to_iatt (&rsp.postparent, &postparent);
-
- fdctx = GF_CALLOC (1, sizeof (*fdctx),
- gf_client_mt_clnt_fdctx_t);
- if (!fdctx) {
+ uuid_copy (local->loc.gfid, stbuf.ia_gfid);
+ ret = client_add_fd_to_saved_fds (frame->this, fd, &local->loc,
+ local->flags, 0,
+ rsp.fd, 0);
+ if (ret) {
rsp.op_ret = -1;
- rsp.op_errno = ENOMEM;
+ rsp.op_errno = -ret;
goto out;
}
-
- fdctx->remote_fd = rsp.fd;
- fdctx->inode = inode_ref (inode);
- fdctx->flags = local->flags;
- fdctx->lk_ctx = fd_lk_ctx_ref (fd->lk_ctx);
- fdctx->lk_heal_state = GF_LK_HEAL_DONE;
-
- INIT_LIST_HEAD (&fdctx->sfd_pos);
- INIT_LIST_HEAD (&fdctx->lock_list);
-
- this_fd_set_ctx (fd, frame->this, &local->loc, fdctx);
-
- pthread_mutex_lock (&conf->lock);
- {
- list_add_tail (&fdctx->sfd_pos, &conf->saved_fds);
- }
- pthread_mutex_unlock (&conf->lock);
}
GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val),
@@ -2477,9 +2513,8 @@ client3_1_opendir_cbk (struct rpc_req *req, struct iovec *iov, int count,
{
clnt_local_t *local = NULL;
clnt_conf_t *conf = NULL;
- clnt_fd_ctx_t *fdctx = NULL;
- call_frame_t *frame = NULL;
- fd_t *fd = NULL;
+ call_frame_t *frame = NULL;
+ fd_t *fd = NULL;
int ret = 0;
gfs3_opendir_rsp rsp = {0,};
xlator_t *this = NULL;
@@ -2508,28 +2543,13 @@ client3_1_opendir_cbk (struct rpc_req *req, struct iovec *iov, int count,
}
if (-1 != rsp.op_ret) {
- fdctx = GF_CALLOC (1, sizeof (*fdctx),
- gf_client_mt_clnt_fdctx_t);
- if (!fdctx) {
+ ret = client_add_fd_to_saved_fds (frame->this, fd, &local->loc,
+ 0, 0, rsp.fd, 1);
+ if (ret) {
rsp.op_ret = -1;
- rsp.op_errno = ENOMEM;
+ rsp.op_errno = -ret;
goto out;
}
-
- fdctx->remote_fd = rsp.fd;
- fdctx->inode = inode_ref (fd->inode);
- fdctx->is_dir = 1;
-
- INIT_LIST_HEAD (&fdctx->sfd_pos);
- INIT_LIST_HEAD (&fdctx->lock_list);
-
- this_fd_set_ctx (fd, frame->this, &local->loc, fdctx);
-
- pthread_mutex_lock (&conf->lock);
- {
- list_add_tail (&fdctx->sfd_pos, &conf->saved_fds);
- }
- pthread_mutex_unlock (&conf->lock);
}
GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val),
@@ -2799,7 +2819,6 @@ client_fdctx_destroy (xlator_t *this, clnt_fd_ctx_t *fdctx)
out:
if (fdctx) {
fdctx->remote_fd = -1;
- inode_unref (fdctx->inode);
GF_FREE (fdctx);
}