fuse: misc cleanups
* fuse_file_alloc() was structured in weird way. The success path was split between else block and code following the block. Restructure the code such that it's easier to read and modify. * Unindent success path of fuse_release_common() to ease future changes. Signed-off-by: Tejun Heo <tj@kernel.org> Signed-off-by: Miklos Szeredi <mszeredi@suse.cz>
This commit is contained in:
parent
fd9db72977
commit
6b2db28a7a
|
@ -49,22 +49,26 @@ static int fuse_send_open(struct inode *inode, struct file *file, int isdir,
|
||||||
struct fuse_file *fuse_file_alloc(struct fuse_conn *fc)
|
struct fuse_file *fuse_file_alloc(struct fuse_conn *fc)
|
||||||
{
|
{
|
||||||
struct fuse_file *ff;
|
struct fuse_file *ff;
|
||||||
|
|
||||||
ff = kmalloc(sizeof(struct fuse_file), GFP_KERNEL);
|
ff = kmalloc(sizeof(struct fuse_file), GFP_KERNEL);
|
||||||
if (ff) {
|
if (unlikely(!ff))
|
||||||
ff->reserved_req = fuse_request_alloc();
|
return NULL;
|
||||||
if (!ff->reserved_req) {
|
|
||||||
kfree(ff);
|
ff->reserved_req = fuse_request_alloc();
|
||||||
return NULL;
|
if (unlikely(!ff->reserved_req)) {
|
||||||
} else {
|
kfree(ff);
|
||||||
INIT_LIST_HEAD(&ff->write_entry);
|
return NULL;
|
||||||
atomic_set(&ff->count, 0);
|
|
||||||
spin_lock(&fc->lock);
|
|
||||||
ff->kh = ++fc->khctr;
|
|
||||||
spin_unlock(&fc->lock);
|
|
||||||
}
|
|
||||||
RB_CLEAR_NODE(&ff->polled_node);
|
|
||||||
init_waitqueue_head(&ff->poll_wait);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
INIT_LIST_HEAD(&ff->write_entry);
|
||||||
|
atomic_set(&ff->count, 0);
|
||||||
|
RB_CLEAR_NODE(&ff->polled_node);
|
||||||
|
init_waitqueue_head(&ff->poll_wait);
|
||||||
|
|
||||||
|
spin_lock(&fc->lock);
|
||||||
|
ff->kh = ++fc->khctr;
|
||||||
|
spin_unlock(&fc->lock);
|
||||||
|
|
||||||
return ff;
|
return ff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,34 +162,37 @@ void fuse_release_fill(struct fuse_file *ff, u64 nodeid, int flags, int opcode)
|
||||||
|
|
||||||
int fuse_release_common(struct inode *inode, struct file *file, int isdir)
|
int fuse_release_common(struct inode *inode, struct file *file, int isdir)
|
||||||
{
|
{
|
||||||
struct fuse_file *ff = file->private_data;
|
struct fuse_conn *fc;
|
||||||
if (ff) {
|
struct fuse_file *ff;
|
||||||
struct fuse_conn *fc = get_fuse_conn(inode);
|
struct fuse_req *req;
|
||||||
struct fuse_req *req = ff->reserved_req;
|
|
||||||
|
|
||||||
fuse_release_fill(ff, get_node_id(inode), file->f_flags,
|
ff = file->private_data;
|
||||||
isdir ? FUSE_RELEASEDIR : FUSE_RELEASE);
|
if (unlikely(!ff))
|
||||||
|
return 0; /* return value is ignored by VFS */
|
||||||
|
|
||||||
/* Hold vfsmount and dentry until release is finished */
|
fc = get_fuse_conn(inode);
|
||||||
req->misc.release.vfsmount = mntget(file->f_path.mnt);
|
req = ff->reserved_req;
|
||||||
req->misc.release.dentry = dget(file->f_path.dentry);
|
|
||||||
|
|
||||||
spin_lock(&fc->lock);
|
fuse_release_fill(ff, get_node_id(inode), file->f_flags,
|
||||||
list_del(&ff->write_entry);
|
isdir ? FUSE_RELEASEDIR : FUSE_RELEASE);
|
||||||
if (!RB_EMPTY_NODE(&ff->polled_node))
|
|
||||||
rb_erase(&ff->polled_node, &fc->polled_files);
|
|
||||||
spin_unlock(&fc->lock);
|
|
||||||
|
|
||||||
wake_up_interruptible_sync(&ff->poll_wait);
|
/* Hold vfsmount and dentry until release is finished */
|
||||||
/*
|
req->misc.release.vfsmount = mntget(file->f_path.mnt);
|
||||||
* Normally this will send the RELEASE request,
|
req->misc.release.dentry = dget(file->f_path.dentry);
|
||||||
* however if some asynchronous READ or WRITE requests
|
|
||||||
* are outstanding, the sending will be delayed
|
|
||||||
*/
|
|
||||||
fuse_file_put(ff);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Return value is ignored by VFS */
|
spin_lock(&fc->lock);
|
||||||
|
list_del(&ff->write_entry);
|
||||||
|
if (!RB_EMPTY_NODE(&ff->polled_node))
|
||||||
|
rb_erase(&ff->polled_node, &fc->polled_files);
|
||||||
|
spin_unlock(&fc->lock);
|
||||||
|
|
||||||
|
wake_up_interruptible_sync(&ff->poll_wait);
|
||||||
|
/*
|
||||||
|
* Normally this will send the RELEASE request, however if
|
||||||
|
* some asynchronous READ or WRITE requests are outstanding,
|
||||||
|
* the sending will be delayed.
|
||||||
|
*/
|
||||||
|
fuse_file_put(ff);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue