]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
fuse: cleanup fuse_file refcounting
authorMiklos Szeredi <mszeredi@redhat.com>
Wed, 22 Feb 2017 19:08:25 +0000 (20:08 +0100)
committerMiklos Szeredi <mszeredi@redhat.com>
Wed, 22 Feb 2017 19:08:25 +0000 (20:08 +0100)
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 <mszeredi@redhat.com>
fs/fuse/dir.c
fs/fuse/file.c
fs/fuse/fuse_i.h

index 811fd8929a18c1e330316202fd40ac58857ec3c7..e816166ce42fa9778d04224461716e5a83feadbc 100644 (file)
@@ -473,7 +473,7 @@ static int fuse_create_open(struct inode *dir, struct dentry *entry,
        if (err) {
                fuse_sync_release(ff, flags);
        } else {
-               file->private_data = fuse_file_get(ff);
+               file->private_data = ff;
                fuse_finish_open(inode, file);
        }
        return err;
index 5ec5870e423ab5539b7785fe68588660a8375b32..a5f79c59fe1e51b3a3d8724393a54b5424c6b829 100644 (file)
@@ -58,7 +58,7 @@ struct fuse_file *fuse_file_alloc(struct fuse_conn *fc)
        }
 
        INIT_LIST_HEAD(&ff->write_entry);
-       atomic_set(&ff->count, 0);
+       atomic_set(&ff->count, 1);
        RB_CLEAR_NODE(&ff->polled_node);
        init_waitqueue_head(&ff->poll_wait);
 
@@ -75,7 +75,7 @@ void fuse_file_free(struct fuse_file *ff)
        kfree(ff);
 }
 
-struct fuse_file *fuse_file_get(struct fuse_file *ff)
+static struct fuse_file *fuse_file_get(struct fuse_file *ff)
 {
        atomic_inc(&ff->count);
        return ff;
@@ -147,7 +147,7 @@ int fuse_do_open(struct fuse_conn *fc, u64 nodeid, struct file *file,
                ff->open_flags &= ~FOPEN_DIRECT_IO;
 
        ff->nodeid = nodeid;
-       file->private_data = fuse_file_get(ff);
+       file->private_data = ff;
 
        return 0;
 }
@@ -298,13 +298,13 @@ static int fuse_release(struct inode *inode, struct file *file)
 
 void fuse_sync_release(struct fuse_file *ff, int flags)
 {
-       WARN_ON(atomic_read(&ff->count) > 1);
+       WARN_ON(atomic_read(&ff->count) != 1);
        fuse_prepare_release(ff, flags, FUSE_RELEASE);
-       __set_bit(FR_FORCE, &ff->reserved_req->flags);
-       __clear_bit(FR_BACKGROUND, &ff->reserved_req->flags);
-       fuse_request_send(ff->fc, ff->reserved_req);
-       fuse_put_request(ff->fc, ff->reserved_req);
-       kfree(ff);
+       /*
+        * iput(NULL) is a no-op and since the refcount is 1 and everything's
+        * synchronous, we are fine with not doing igrab() here"
+        */
+       fuse_file_put(ff, true);
 }
 EXPORT_SYMBOL_GPL(fuse_sync_release);
 
index 91307940c8ac5e921b08133a04ca0b65283fd308..83f797271aefb4c08d73f037350af6a1d0ab3b4b 100644 (file)
@@ -732,7 +732,6 @@ void fuse_read_fill(struct fuse_req *req, struct file *file,
 int fuse_open_common(struct inode *inode, struct file *file, bool isdir);
 
 struct fuse_file *fuse_file_alloc(struct fuse_conn *fc);
-struct fuse_file *fuse_file_get(struct fuse_file *ff);
 void fuse_file_free(struct fuse_file *ff);
 void fuse_finish_open(struct inode *inode, struct file *file);