Skip to content

Commit 4e66c42

Browse files
committed
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/fuse
Pull fuse update from Miklos Szeredi: "A bugfix and cleanups" * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/fuse: fuse: release: private_data cannot be NULL fuse: cleanup fuse_file refcounting fuse: add missing FR_FORCE
2 parents e58bc92 + 9a87ad3 commit 4e66c42

File tree

3 files changed

+13
-18
lines changed

3 files changed

+13
-18
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: 12 additions & 16 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;
@@ -100,6 +100,7 @@ static void fuse_file_put(struct fuse_file *ff, bool sync)
100100
iput(req->misc.release.inode);
101101
fuse_put_request(ff->fc, req);
102102
} else if (sync) {
103+
__set_bit(FR_FORCE, &req->flags);
103104
__clear_bit(FR_BACKGROUND, &req->flags);
104105
fuse_request_send(ff->fc, req);
105106
iput(req->misc.release.inode);
@@ -146,7 +147,7 @@ int fuse_do_open(struct fuse_conn *fc, u64 nodeid, struct file *file,
146147
ff->open_flags &= ~FOPEN_DIRECT_IO;
147148

148149
ff->nodeid = nodeid;
149-
file->private_data = fuse_file_get(ff);
150+
file->private_data = ff;
150151

151152
return 0;
152153
}
@@ -245,14 +246,9 @@ static void fuse_prepare_release(struct fuse_file *ff, int flags, int opcode)
245246

246247
void fuse_release_common(struct file *file, int opcode)
247248
{
248-
struct fuse_file *ff;
249-
struct fuse_req *req;
250-
251-
ff = file->private_data;
252-
if (unlikely(!ff))
253-
return;
249+
struct fuse_file *ff = file->private_data;
250+
struct fuse_req *req = ff->reserved_req;
254251

255-
req = ff->reserved_req;
256252
fuse_prepare_release(ff, file->f_flags, opcode);
257253

258254
if (ff->flock) {
@@ -297,13 +293,13 @@ static int fuse_release(struct inode *inode, struct file *file)
297293

298294
void fuse_sync_release(struct fuse_file *ff, int flags)
299295
{
300-
WARN_ON(atomic_read(&ff->count) > 1);
296+
WARN_ON(atomic_read(&ff->count) != 1);
301297
fuse_prepare_release(ff, flags, FUSE_RELEASE);
302-
__set_bit(FR_FORCE, &ff->reserved_req->flags);
303-
__clear_bit(FR_BACKGROUND, &ff->reserved_req->flags);
304-
fuse_request_send(ff->fc, ff->reserved_req);
305-
fuse_put_request(ff->fc, ff->reserved_req);
306-
kfree(ff);
298+
/*
299+
* iput(NULL) is a no-op and since the refcount is 1 and everything's
300+
* synchronous, we are fine with not doing igrab() here"
301+
*/
302+
fuse_file_put(ff, true);
307303
}
308304
EXPORT_SYMBOL_GPL(fuse_sync_release);
309305

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)