]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
fuse: return -ECONNABORTED on /dev/fuse read after abort
authorSzymon Lukasz <noh4hss@gmail.com>
Thu, 9 Nov 2017 20:23:35 +0000 (21:23 +0100)
committerMiklos Szeredi <mszeredi@redhat.com>
Tue, 20 Mar 2018 16:11:44 +0000 (17:11 +0100)
Currently the userspace has no way of knowing whether the fuse
connection ended because of umount or abort via sysfs. It makes it hard
for filesystems to free the mountpoint after abort without worrying
about removing some new mount.

The patch fixes it by returning different errors when userspace reads
from /dev/fuse (-ENODEV for umount and -ECONNABORTED for abort).

Add a new capability flag FUSE_ABORT_ERROR. If set and the connection is
gone because of sysfs abort, reading from the device will return
-ECONNABORTED.

Signed-off-by: Szymon Lukasz <noh4hss@gmail.com>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
fs/fuse/control.c
fs/fuse/cuse.c
fs/fuse/dev.c
fs/fuse/fuse_i.h
fs/fuse/inode.c
include/uapi/linux/fuse.h

index b9ea99c5b5b31948882d37113d520ab9cdcf9564..78fb7a07c5caef72985382588e0a00a2dfd8246e 100644 (file)
@@ -35,7 +35,7 @@ static ssize_t fuse_conn_abort_write(struct file *file, const char __user *buf,
 {
        struct fuse_conn *fc = fuse_ctl_file_conn_get(file);
        if (fc) {
-               fuse_abort_conn(fc);
+               fuse_abort_conn(fc, true);
                fuse_conn_put(fc);
        }
        return count;
index e9e97803442a6dd33421d250068b71eb4dd63241..31d33b69957f327ccc2b28e1864bc9ed47e097e3 100644 (file)
@@ -406,7 +406,7 @@ static void cuse_process_init_reply(struct fuse_conn *fc, struct fuse_req *req)
 err_region:
        unregister_chrdev_region(devt, 1);
 err:
-       fuse_abort_conn(fc);
+       fuse_abort_conn(fc, false);
        goto out;
 }
 
@@ -581,7 +581,7 @@ static ssize_t cuse_class_abort_store(struct device *dev,
 {
        struct cuse_conn *cc = dev_get_drvdata(dev);
 
-       fuse_abort_conn(&cc->fc);
+       fuse_abort_conn(&cc->fc, false);
        return count;
 }
 static DEVICE_ATTR(abort, 0200, NULL, cuse_class_abort_store);
index 5d06384c2cae3c746ef2e2865956ea2871cd1c1c..78b6293bd04d3b240473b3f0301081901d9ec3e3 100644 (file)
@@ -1234,9 +1234,10 @@ static ssize_t fuse_dev_do_read(struct fuse_dev *fud, struct file *file,
        if (err)
                goto err_unlock;
 
-       err = -ENODEV;
-       if (!fiq->connected)
+       if (!fiq->connected) {
+               err = (fc->aborted && fc->abort_err) ? -ECONNABORTED : -ENODEV;
                goto err_unlock;
+       }
 
        if (!list_empty(&fiq->interrupts)) {
                req = list_entry(fiq->interrupts.next, struct fuse_req,
@@ -1287,7 +1288,7 @@ static ssize_t fuse_dev_do_read(struct fuse_dev *fud, struct file *file,
        spin_lock(&fpq->lock);
        clear_bit(FR_LOCKED, &req->flags);
        if (!fpq->connected) {
-               err = -ENODEV;
+               err = (fc->aborted && fc->abort_err) ? -ECONNABORTED : -ENODEV;
                goto out_end;
        }
        if (err) {
@@ -2076,7 +2077,7 @@ static void end_polls(struct fuse_conn *fc)
  * is OK, the request will in that case be removed from the list before we touch
  * it.
  */
-void fuse_abort_conn(struct fuse_conn *fc)
+void fuse_abort_conn(struct fuse_conn *fc, bool is_abort)
 {
        struct fuse_iqueue *fiq = &fc->iq;
 
@@ -2089,6 +2090,7 @@ void fuse_abort_conn(struct fuse_conn *fc)
 
                fc->connected = 0;
                fc->blocked = 0;
+               fc->aborted = is_abort;
                fuse_set_initialized(fc);
                list_for_each_entry(fud, &fc->devices, entry) {
                        struct fuse_pqueue *fpq = &fud->pq;
@@ -2151,7 +2153,7 @@ int fuse_dev_release(struct inode *inode, struct file *file)
                /* Are we the last open device? */
                if (atomic_dec_and_test(&fc->dev_count)) {
                        WARN_ON(fc->iq.fasync != NULL);
-                       fuse_abort_conn(fc);
+                       fuse_abort_conn(fc, false);
                }
                fuse_dev_free(fud);
        }
index c4c093bbf456bff71568876955c52bb74e675d50..7d2e7deea64b62c128fdf2c7b41322f14b134f6f 100644 (file)
@@ -515,6 +515,9 @@ struct fuse_conn {
            abort and device release */
        unsigned connected;
 
+       /** Connection aborted via sysfs */
+       bool aborted;
+
        /** Connection failed (version mismatch).  Cannot race with
            setting other bitfields since it is only set once in INIT
            reply, before any other request, and never cleared */
@@ -526,6 +529,9 @@ struct fuse_conn {
        /** Do readpages asynchronously?  Only set in INIT */
        unsigned async_read:1;
 
+       /** Return an unique read error after abort.  Only set in INIT */
+       unsigned abort_err:1;
+
        /** Do not send separate SETATTR request before open(O_TRUNC)  */
        unsigned atomic_o_trunc:1;
 
@@ -851,7 +857,7 @@ void fuse_request_send_background_locked(struct fuse_conn *fc,
                                         struct fuse_req *req);
 
 /* Abort all requests */
-void fuse_abort_conn(struct fuse_conn *fc);
+void fuse_abort_conn(struct fuse_conn *fc, bool is_abort);
 
 /**
  * Invalidate inode attributes
index 624f18bbfd2b3430e4a5d67c54cf84af4312a440..3c9b675d99dae4848f5d83dbf23784b21749002c 100644 (file)
@@ -371,7 +371,7 @@ void fuse_unlock_inode(struct inode *inode)
 
 static void fuse_umount_begin(struct super_block *sb)
 {
-       fuse_abort_conn(get_fuse_conn_super(sb));
+       fuse_abort_conn(get_fuse_conn_super(sb), false);
 }
 
 static void fuse_send_destroy(struct fuse_conn *fc)
@@ -393,7 +393,7 @@ static void fuse_put_super(struct super_block *sb)
 
        fuse_send_destroy(fc);
 
-       fuse_abort_conn(fc);
+       fuse_abort_conn(fc, false);
        mutex_lock(&fuse_mutex);
        list_del(&fc->entry);
        fuse_ctl_remove_conn(fc);
@@ -918,6 +918,8 @@ static void process_init_reply(struct fuse_conn *fc, struct fuse_req *req)
                                fc->posix_acl = 1;
                                fc->sb->s_xattr = fuse_acl_xattr_handlers;
                        }
+                       if (arg->flags & FUSE_ABORT_ERROR)
+                               fc->abort_err = 1;
                } else {
                        ra_pages = fc->max_read / PAGE_SIZE;
                        fc->no_lock = 1;
@@ -948,7 +950,8 @@ static void fuse_send_init(struct fuse_conn *fc, struct fuse_req *req)
                FUSE_FLOCK_LOCKS | FUSE_HAS_IOCTL_DIR | FUSE_AUTO_INVAL_DATA |
                FUSE_DO_READDIRPLUS | FUSE_READDIRPLUS_AUTO | FUSE_ASYNC_DIO |
                FUSE_WRITEBACK_CACHE | FUSE_NO_OPEN_SUPPORT |
-               FUSE_PARALLEL_DIROPS | FUSE_HANDLE_KILLPRIV | FUSE_POSIX_ACL;
+               FUSE_PARALLEL_DIROPS | FUSE_HANDLE_KILLPRIV | FUSE_POSIX_ACL |
+               FUSE_ABORT_ERROR;
        req->in.h.opcode = FUSE_INIT;
        req->in.numargs = 1;
        req->in.args[0].size = sizeof(*arg);
index 4b5001c57f4642d57559607e1398492f78bf998b..92fa24c24c926554397bc8fd0db0b449d7c55532 100644 (file)
  *  7.26
  *  - add FUSE_HANDLE_KILLPRIV
  *  - add FUSE_POSIX_ACL
+ *
+ *  7.27
+ *  - add FUSE_ABORT_ERROR
  */
 
 #ifndef _LINUX_FUSE_H
 #define FUSE_KERNEL_VERSION 7
 
 /** Minor version number of this interface */
-#define FUSE_KERNEL_MINOR_VERSION 26
+#define FUSE_KERNEL_MINOR_VERSION 27
 
 /** The node ID of the root inode */
 #define FUSE_ROOT_ID 1
@@ -245,6 +248,7 @@ struct fuse_file_lock {
  * FUSE_PARALLEL_DIROPS: allow parallel lookups and readdir
  * FUSE_HANDLE_KILLPRIV: fs handles killing suid/sgid/cap on write/chown/trunc
  * FUSE_POSIX_ACL: filesystem supports posix acls
+ * FUSE_ABORT_ERROR: reading the device after abort returns ECONNABORTED
  */
 #define FUSE_ASYNC_READ                (1 << 0)
 #define FUSE_POSIX_LOCKS       (1 << 1)
@@ -267,6 +271,7 @@ struct fuse_file_lock {
 #define FUSE_PARALLEL_DIROPS    (1 << 18)
 #define FUSE_HANDLE_KILLPRIV   (1 << 19)
 #define FUSE_POSIX_ACL         (1 << 20)
+#define FUSE_ABORT_ERROR       (1 << 21)
 
 /**
  * CUSE INIT request/reply flags