fd: Do fd_bind on successful open
- fd_unref should decrement fd->inode->fd_count only if it is present in the inode's fd list. - successful open/opendir should perform fd_bind. Change-Id: I81dd04f330e2fee86369a6dc7147af44f3d49169 BUG: 1207735 Signed-off-by: Pranith Kumar K <pkarampu@redhat.com> Reviewed-on: http://review.gluster.org/11044 Reviewed-by: Anoop C S <anoopcs@redhat.com> Tested-by: NetBSD Build System <jenkins@build.gluster.org> Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Raghavendra G <rgowdapp@redhat.com>
This commit is contained in:
parent
dedf2bde88
commit
e55579bdb1
@ -468,16 +468,12 @@ __fd_unref (fd_t *fd)
|
||||
|
||||
--fd->refcount;
|
||||
|
||||
if (fd->refcount == 0) {
|
||||
list_del_init (&fd->inode_list);
|
||||
}
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
fd_destroy (fd_t *fd)
|
||||
fd_destroy (fd_t *fd, gf_boolean_t bound)
|
||||
{
|
||||
xlator_t *xl = NULL;
|
||||
int i = 0;
|
||||
@ -525,11 +521,14 @@ fd_destroy (fd_t *fd)
|
||||
LOCK_DESTROY (&fd->lock);
|
||||
|
||||
GF_FREE (fd->_ctx);
|
||||
LOCK (&fd->inode->lock);
|
||||
{
|
||||
fd->inode->fd_count--;
|
||||
if (bound) {
|
||||
/*Decrease the count only after close happens on file*/
|
||||
LOCK (&fd->inode->lock);
|
||||
{
|
||||
fd->inode->fd_count--;
|
||||
}
|
||||
UNLOCK (&fd->inode->lock);
|
||||
}
|
||||
UNLOCK (&fd->inode->lock);
|
||||
inode_unref (fd->inode);
|
||||
fd->inode = NULL;
|
||||
fd_lk_ctx_unref (fd->lk_ctx);
|
||||
@ -543,6 +542,7 @@ void
|
||||
fd_unref (fd_t *fd)
|
||||
{
|
||||
int32_t refcount = 0;
|
||||
gf_boolean_t bound = _gf_false;
|
||||
|
||||
if (!fd) {
|
||||
gf_msg_callingfn ("fd", GF_LOG_ERROR, EINVAL,
|
||||
@ -554,11 +554,18 @@ fd_unref (fd_t *fd)
|
||||
{
|
||||
__fd_unref (fd);
|
||||
refcount = fd->refcount;
|
||||
if (refcount == 0) {
|
||||
if (!list_empty (&fd->inode_list)) {
|
||||
list_del_init (&fd->inode_list);
|
||||
bound = _gf_true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
UNLOCK (&fd->inode->lock);
|
||||
|
||||
if (refcount == 0) {
|
||||
fd_destroy (fd);
|
||||
fd_destroy (fd, bound);
|
||||
}
|
||||
|
||||
return ;
|
||||
|
@ -59,6 +59,8 @@ syncop_dirfd (xlator_t *subvol, loc_t *loc, fd_t **fd, int pid)
|
||||
uuid_utoa (loc->gfid));
|
||||
goto out;
|
||||
#endif /* GF_LINUX_HOST_OS */
|
||||
} else {
|
||||
fd_bind (dirfd);
|
||||
}
|
||||
out:
|
||||
if (ret == 0)
|
||||
|
@ -7307,6 +7307,7 @@ dht_rmdir_opendir_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
|
||||
if (local->op_ret == -1)
|
||||
goto err;
|
||||
|
||||
fd_bind (fd);
|
||||
dict = dict_new ();
|
||||
if (!dict) {
|
||||
local->op_ret = -1;
|
||||
|
@ -504,6 +504,7 @@ __dht_rebalance_create_dst_file (xlator_t *to, xlator_t *from, loc_t *loc, struc
|
||||
}
|
||||
|
||||
|
||||
fd_bind (fd);
|
||||
/*Reason of doing lookup after create again:
|
||||
*In the create, there is some time-gap between opening fd at the
|
||||
*server (posix_layer) and binding it in server (incrementing fd count),
|
||||
@ -777,6 +778,7 @@ __dht_rebalance_open_src_file (xlator_t *from, xlator_t *to, loc_t *loc,
|
||||
goto out;
|
||||
}
|
||||
|
||||
fd_bind (fd);
|
||||
ret = -1;
|
||||
dict = dict_new ();
|
||||
if (!dict)
|
||||
@ -2243,6 +2245,7 @@ gf_defrag_process_dir (xlator_t *this, gf_defrag_info_t *defrag, loc_t *loc,
|
||||
goto out;
|
||||
}
|
||||
|
||||
fd_bind (fd);
|
||||
dir_dfmeta = GF_CALLOC (1, sizeof (*dir_dfmeta),
|
||||
gf_common_mt_pointer);
|
||||
if (!dir_dfmeta) {
|
||||
@ -2543,6 +2546,7 @@ gf_defrag_fix_layout (xlator_t *this, gf_defrag_info_t *defrag, loc_t *loc,
|
||||
goto out;
|
||||
}
|
||||
|
||||
fd_bind (fd);
|
||||
INIT_LIST_HEAD (&entries.list);
|
||||
while ((ret = syncop_readdirp (this, fd, 131072, offset, &entries,
|
||||
NULL, NULL)) != 0)
|
||||
|
@ -244,6 +244,7 @@ dht_rename_opendir_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
|
||||
goto err;
|
||||
}
|
||||
|
||||
fd_bind (fd);
|
||||
STACK_WIND (frame, dht_rename_readdir_cbk,
|
||||
prev->this, prev->this->fops->readdir,
|
||||
local->fd, 4096, 0, NULL);
|
||||
|
@ -881,6 +881,7 @@ int32_t ec_truncate_open_cbk(call_frame_t * frame, void * cookie,
|
||||
int32_t err;
|
||||
|
||||
if (op_ret >= 0) {
|
||||
fd_bind (fd);
|
||||
err = ec_truncate_write(fop->parent, fop->answer->mask);
|
||||
if (err != 0) {
|
||||
fop->error = -err;
|
||||
|
@ -1828,7 +1828,9 @@ static int32_t truncate_begin(call_frame_t *frame,
|
||||
op_ret,
|
||||
op_errno, NULL, NULL, NULL);
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
fd_bind (fd);
|
||||
}
|
||||
/*
|
||||
* crypt_truncate() is implemented via crypt_ftruncate(),
|
||||
* so the crypt xlator does STACK_WIND to itself here
|
||||
@ -3090,7 +3092,7 @@ static int32_t do_linkop(call_frame_t *frame,
|
||||
&lock,
|
||||
NULL);
|
||||
return 0;
|
||||
error:
|
||||
error:
|
||||
unwind_fn(frame);
|
||||
return 0;
|
||||
}
|
||||
@ -3120,11 +3122,14 @@ static int32_t linkop_begin(call_frame_t *frame,
|
||||
unwind_fn = linkop_unwind_dispatch(local->fop);
|
||||
mop = linkop_mtdop_dispatch(local->fop);
|
||||
|
||||
if (op_ret < 0)
|
||||
if (op_ret < 0) {
|
||||
/*
|
||||
* verification failed
|
||||
*/
|
||||
goto error;
|
||||
} else {
|
||||
fd_bind (fd);
|
||||
}
|
||||
|
||||
old_mtd = dict_get(xdata, CRYPTO_FORMAT_PREFIX);
|
||||
if (!old_mtd) {
|
||||
|
@ -773,8 +773,10 @@ mq_dirty_inode_readdir (call_frame_t *frame,
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (local->fd == NULL)
|
||||
if (local->fd == NULL) {
|
||||
fd_bind (fd);
|
||||
local->fd = fd_ref (fd);
|
||||
}
|
||||
|
||||
STACK_WIND (frame,
|
||||
mq_readdir_cbk,
|
||||
@ -3488,6 +3490,7 @@ mq_update_dirty_inode_task (void *opaque)
|
||||
goto out;
|
||||
}
|
||||
|
||||
fd_bind (fd);
|
||||
INIT_LIST_HEAD (&entries.list);
|
||||
while ((ret = syncop_readdirp (this, fd, 131072, offset, &entries,
|
||||
NULL, NULL)) != 0) {
|
||||
|
@ -1240,6 +1240,8 @@ trash_truncate_open_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
|
||||
goto out;
|
||||
}
|
||||
|
||||
fd_bind (fd);
|
||||
|
||||
local->cur_offset = 0;
|
||||
|
||||
STACK_WIND (frame, trash_truncate_readv_cbk,
|
||||
@ -1329,6 +1331,7 @@ trash_truncate_create_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
|
||||
goto out;
|
||||
}
|
||||
|
||||
fd_bind (fd);
|
||||
flags = O_RDONLY;
|
||||
|
||||
/* fd which represents source file for reading and writing from it */
|
||||
|
Loading…
x
Reference in New Issue
Block a user