Skip to content

Commit 267d844

Browse files
author
Miklos Szeredi
committed
fuse: cleanup fuse_file refcounting
struct fuse_file is stored in file->private_data. Make this always be a counting reference for consistency. This also allows fuse_sync_release() to call fuse_file_put() instead of partially duplicating its functionality. Signed-off-by: Miklos Szeredi <[email protected]>
1 parent 2e38bea commit 267d844

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

fs/fuse/dir.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ static int fuse_create_open(struct inode *dir, struct dentry *entry,
473473
if (err) {
474474
fuse_sync_release(ff, flags);
475475
} else {
476-
file->private_data = fuse_file_get(ff);
476+
file->private_data = ff;
477477
fuse_finish_open(inode, file);
478478
}
479479
return err;

fs/fuse/file.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ struct fuse_file *fuse_file_alloc(struct fuse_conn *fc)
5858
}
5959

6060
INIT_LIST_HEAD(&ff->write_entry);
61-
atomic_set(&ff->count, 0);
61+
atomic_set(&ff->count, 1);
6262
RB_CLEAR_NODE(&ff->polled_node);
6363
init_waitqueue_head(&ff->poll_wait);
6464

@@ -75,7 +75,7 @@ void fuse_file_free(struct fuse_file *ff)
7575
kfree(ff);
7676
}
7777

78-
struct fuse_file *fuse_file_get(struct fuse_file *ff)
78+
static struct fuse_file *fuse_file_get(struct fuse_file *ff)
7979
{
8080
atomic_inc(&ff->count);
8181
return ff;
@@ -147,7 +147,7 @@ int fuse_do_open(struct fuse_conn *fc, u64 nodeid, struct file *file,
147147
ff->open_flags &= ~FOPEN_DIRECT_IO;
148148

149149
ff->nodeid = nodeid;
150-
file->private_data = fuse_file_get(ff);
150+
file->private_data = ff;
151151

152152
return 0;
153153
}
@@ -298,13 +298,13 @@ static int fuse_release(struct inode *inode, struct file *file)
298298

299299
void fuse_sync_release(struct fuse_file *ff, int flags)
300300
{
301-
WARN_ON(atomic_read(&ff->count) > 1);
301+
WARN_ON(atomic_read(&ff->count) != 1);
302302
fuse_prepare_release(ff, flags, FUSE_RELEASE);
303-
__set_bit(FR_FORCE, &ff->reserved_req->flags);
304-
__clear_bit(FR_BACKGROUND, &ff->reserved_req->flags);
305-
fuse_request_send(ff->fc, ff->reserved_req);
306-
fuse_put_request(ff->fc, ff->reserved_req);
307-
kfree(ff);
303+
/*
304+
* iput(NULL) is a no-op and since the refcount is 1 and everything's
305+
* synchronous, we are fine with not doing igrab() here"
306+
*/
307+
fuse_file_put(ff, true);
308308
}
309309
EXPORT_SYMBOL_GPL(fuse_sync_release);
310310

fs/fuse/fuse_i.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,6 @@ void fuse_read_fill(struct fuse_req *req, struct file *file,
732732
int fuse_open_common(struct inode *inode, struct file *file, bool isdir);
733733

734734
struct fuse_file *fuse_file_alloc(struct fuse_conn *fc);
735-
struct fuse_file *fuse_file_get(struct fuse_file *ff);
736735
void fuse_file_free(struct fuse_file *ff);
737736
void fuse_finish_open(struct inode *inode, struct file *file);
738737

0 commit comments

Comments
 (0)