summaryrefslogtreecommitdiffstats
path: root/xlators/protocol/client/src/client3_1-fops.c
diff options
context:
space:
mode:
Diffstat (limited to 'xlators/protocol/client/src/client3_1-fops.c')
-rw-r--r--xlators/protocol/client/src/client3_1-fops.c161
1 files changed, 90 insertions, 71 deletions
diff --git a/xlators/protocol/client/src/client3_1-fops.c b/xlators/protocol/client/src/client3_1-fops.c
index d44eb86c46c..76668724b5e 100644
--- a/xlators/protocol/client/src/client3_1-fops.c
+++ b/xlators/protocol/client/src/client3_1-fops.c
@@ -343,12 +343,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;
@@ -379,31 +451,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),
@@ -1980,8 +2035,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;
@@ -1990,7 +2043,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;
@@ -2013,31 +2065,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),
@@ -2479,9 +2515,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;
@@ -2510,28 +2545,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),
@@ -2805,7 +2825,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);
}