From patchwork Thu Nov 9 20:23:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szymon Lukasz X-Patchwork-Id: 10051763 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1ABD260631 for ; Thu, 9 Nov 2017 20:25:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0FEB02B100 for ; Thu, 9 Nov 2017 20:25:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 04A602B110; Thu, 9 Nov 2017 20:25:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A517F2B100 for ; Thu, 9 Nov 2017 20:25:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752684AbdKIUZF (ORCPT ); Thu, 9 Nov 2017 15:25:05 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:48118 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752528AbdKIUZE (ORCPT ); Thu, 9 Nov 2017 15:25:04 -0500 Received: by mail-wm0-f68.google.com with SMTP id b14so4446754wme.2 for ; Thu, 09 Nov 2017 12:25:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=2lOeRU5wlJA6vfPIR2Z25vo1aTL/yJfloG0wIDWmCPc=; b=gczXsjUykLCXkMoSz8o5gJfH6ZHkrjWQRoct3v0MLEp5GThEo/GAiVOczCQQFTFCdh itJwDS7+lc2uErwlTwY0X/+yeImVs4IPMaB6uFJXhgj6i+ko9Mv0WYTRVDFxyxwsVoDl fXQ/4PdbSTlmDpsHgpcxEUhhRM0wgqz/z6s7bk9BdkYDNkDUoFPcpd7T8h8o0iXLqDGx Cc4LdwDnYU2EZM/41iI2cgM9hoS82GNZGh9zWkT/B1TNZaDdLC/Vhyn/c+wMrxlM4bf6 FgQsZmadmMmJEszOcxQwnvuPa+XfnDMEl24Uo4o5YhcqE4G2OVGNV5HxHi1KETHnXNYY J+Ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=2lOeRU5wlJA6vfPIR2Z25vo1aTL/yJfloG0wIDWmCPc=; b=gIm+jQ39DadYpORA9zIy5WBmt6RY1naXj/CaHDSu0GkynQ0PuHm4Ioy/7S758BOfWe i8xjYwvxp9M5CjsOS8ji+BoWfoWYNTluYO7EaMlDI68fE9ORzPvnlL5lECqKwek8Doe2 IjTR/5IC3ZkU53d51PFLb1M1w3rvcscmSvdxqk6SIkOx7YRMBIjpLWEaUQaiyjF2mre/ 2ZcvfU0N0hM/zQQkFcfvc2Qzf9795C5hC9vUsZ+fwoqqVBl6nHVNwQIlqQMVsjk/og1N yWO0itwLNyQyGZ0L/v8H1dxQ8jSSvwUs9MgQEaK8Us6A+PFOGzEwgGH9sctDcc7K3Y11 pPmQ== X-Gm-Message-State: AJaThX6b/F2vkGBNCiQkCzAquAqyDdpsW1IOdxbCkNI6DuYAoUGfWA9X 33vlU9EDV90eGI6S6rTJJls= X-Google-Smtp-Source: AGs4zMZv3lrlszhYse3eJfedXI6hIcKUW9fTM59WcDFqQxIUloNx5+fu3k9WP5Q8WmfsFuYq5JPdxA== X-Received: by 10.28.24.203 with SMTP id 194mr860893wmy.34.1510259102829; Thu, 09 Nov 2017 12:25:02 -0800 (PST) Received: from localhost.localdomain ([185.156.174.155]) by smtp.gmail.com with ESMTPSA id x185sm7775995wmx.12.2017.11.09.12.25.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Nov 2017 12:25:02 -0800 (PST) From: Szymon Lukasz To: Miklos Szeredi Cc: linux-fsdevel@vger.kernel.org, fuse-devel@lists.sourceforge.net, Szymon Lukasz Subject: [PATCH v4] fuse: return -ECONNABORTED on /dev/fuse read after abort Date: Thu, 9 Nov 2017 21:23:35 +0100 Message-Id: <20171109202335.19797-1-noh4hss@gmail.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20171107001638.8947-1-noh4hss@gmail.com> References: <20171107001638.8947-1-noh4hss@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Adds 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 --- fs/fuse/control.c | 2 +- fs/fuse/cuse.c | 4 ++-- fs/fuse/dev.c | 12 +++++++----- fs/fuse/fuse_i.h | 8 +++++++- fs/fuse/inode.c | 9 ++++++--- include/uapi/linux/fuse.h | 7 ++++++- 6 files changed, 29 insertions(+), 13 deletions(-) diff --git a/fs/fuse/control.c b/fs/fuse/control.c index b9ea99c5b5b3..78fb7a07c5ca 100644 --- a/fs/fuse/control.c +++ b/fs/fuse/control.c @@ -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; diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c index e9e97803442a..31d33b69957f 100644 --- a/fs/fuse/cuse.c +++ b/fs/fuse/cuse.c @@ -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); diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c index 13c65dd2d37d..2e1beda0b82b 100644 --- a/fs/fuse/dev.c +++ b/fs/fuse/dev.c @@ -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); } diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h index d5773ca67ad2..2f8a261d8669 100644 --- a/fs/fuse/fuse_i.h +++ b/fs/fuse/fuse_i.h @@ -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 diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c index 94a745acaef8..46a17de24e14 100644 --- a/fs/fuse/inode.c +++ b/fs/fuse/inode.c @@ -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); diff --git a/include/uapi/linux/fuse.h b/include/uapi/linux/fuse.h index 42fa977e3b14..f9b11c43c8f6 100644 --- a/include/uapi/linux/fuse.h +++ b/include/uapi/linux/fuse.h @@ -112,6 +112,9 @@ * 7.26 * - add FUSE_HANDLE_KILLPRIV * - add FUSE_POSIX_ACL + * + * 7.27 + * - add FUSE_ABORT_ERROR */ #ifndef _LINUX_FUSE_H @@ -147,7 +150,7 @@ #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 @@ -244,6 +247,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) @@ -266,6 +270,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