From nobody Sun May 10 09:55:52 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3D612C433EF for ; Wed, 11 May 2022 22:36:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348781AbiEKWgp (ORCPT ); Wed, 11 May 2022 18:36:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348805AbiEKWgm (ORCPT ); Wed, 11 May 2022 18:36:42 -0400 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4CA833E9B for ; Wed, 11 May 2022 15:36:41 -0700 (PDT) Received: by mail-pl1-x62b.google.com with SMTP id d22so3198867plr.9 for ; Wed, 11 May 2022 15:36:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3LgIZ0Arn9MkMe+G5lqDiZbm3hHu7bc+acHfe0jeV+M=; b=VDy+LOB5Z24b+YX3YR2qPfyhpZhwjj+zl5gA8W9DjUbiPmsJqFeCNh/FEGU8is2nZS 5T0Gv1b++G/SOWBt0QZk8VTs3b059pW74ffkw7bsAiVHm4MPNXY91nbWtfv4R2tDA8QD 4aUV7TV2Z62wth/sY1QRDONqUhpGeoInAeU4Y= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3LgIZ0Arn9MkMe+G5lqDiZbm3hHu7bc+acHfe0jeV+M=; b=DWSEP1JVFSF5k4e02ryGsA3eBkir09S7H2zsCr1FohCBhIrIFiiTcg4MjQd3g7+FwB SO2SHXw2JwgqwkMKf9y48+XQuvrS8oSrr9uLFYaoFzmbGhKZwvK17th85y/thjPd7lAO YtiHgN7vswxOGTrUfTuHtvn1UsAZYafppknQcFAOLBPvZ05gEBAbtVzupt2KrX7fzD6a UyXuhFN18rwhVDnvZJOoOqowGlROU5XDRVkCjrCpT+z8KApCjqfYhYFIPXJOpcjIbq7A KwqwVV9ZYf5uUxZFYkAYgm+nwvVjl7Uf2k7Jl90csxobXTfxJoya3Nos4VH6j8iRDbDS clYA== X-Gm-Message-State: AOAM531kEPZim0eIbwbCLNjbY86wbqVdcakPYy7UbdPbckLN3amTiAz4 0+BNOyl04qdtTw14douMLncv7w== X-Google-Smtp-Source: ABdhPJx6vfq7aEC09BQ58hiwA5FJut82riYhIGIWThRCuhraVQ0ru9FIWmizgQdmmiA3pDWV6KGEVQ== X-Received: by 2002:a17:90a:bf0a:b0:1db:d98d:7ce9 with SMTP id c10-20020a17090abf0a00b001dbd98d7ce9mr7562374pjs.155.1652308601400; Wed, 11 May 2022 15:36:41 -0700 (PDT) Received: from dlunevwfh.roam.corp.google.com (n122-107-196-14.sbr2.nsw.optusnet.com.au. [122.107.196.14]) by smtp.gmail.com with ESMTPSA id d5-20020a170902c18500b0015e8d4eb1d2sm2391855pld.28.2022.05.11.15.36.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 May 2022 15:36:41 -0700 (PDT) From: Daniil Lunev To: linux-fsdevel@vger.kernel.org Cc: hch@infradead.org, fuse-devel@lists.sourceforge.net, tytso@mit.edu, miklos@szeredi.hu, viro@zeniv.linux.org.uk, linux-kernel@vger.kernel.org, Daniil Lunev Subject: [PATCH v2 1/2] fs/super: function to prevent super re-use Date: Thu, 12 May 2022 08:29:09 +1000 Message-Id: <20220512082832.v2.1.I0e579520b03aa244906b8fe2ef1ec63f2ab7eecf@changeid> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20220511222910.635307-1-dlunev@chromium.org> References: <20220511222910.635307-1-dlunev@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The function is called from generic_shutdown_super upon super destruction, but also can be called by a filesystem during unmount to ensure a new superblock is created upon the next mount. This is necessary for the cases, where force unmount of a filesystem renders superblock disfunctional, in a state that can not be re-used (e.g. FUSE severes the connection of the userspace daemon to the superblock which prevents any further communications between them). Signed-off-by: Daniil Lunev --- Changes in v2: - Remove super from list of superblocks instead of using a flag fs/super.c | 51 ++++++++++++++++++++++++++++++++++++---------- include/linux/fs.h | 1 + 2 files changed, 41 insertions(+), 11 deletions(-) diff --git a/fs/super.c b/fs/super.c index f1d4a193602d6..f23e45434de15 100644 --- a/fs/super.c +++ b/fs/super.c @@ -422,6 +422,45 @@ bool trylock_super(struct super_block *sb) return false; } =20 +/** + * retire_locked_super - prevent superblock from re-use + * @sb: superblock that shouldn't be re-used + * + * retire_locked_super excludes the super from the list of superblocks and + * removes the link between superblock and it bdi. After a call to this + * function, any subsequent mount will allocate a new superblock, even if + * the retired one would have been re-used otherwise. It is safe to call + * the function multiple times for the same superblock, any subsequent + * invocations after the first one have no effect. + */ +static void retire_locked_super(struct super_block *sb) +{ + spin_lock(&sb_lock); + hlist_del_init(&sb->s_instances); + spin_unlock(&sb_lock); + up_write(&sb->s_umount); + if (sb->s_bdi !=3D &noop_backing_dev_info) { + if (sb->s_iflags & SB_I_PERSB_BDI) + bdi_unregister(sb->s_bdi); + bdi_put(sb->s_bdi); + sb->s_bdi =3D &noop_backing_dev_info; + } +} + +/** + * retire_super - prevent superblock from re-use + * @sb: superblock that shouldn't be re-used + * + * Variant of retire_locked_super, except that superblock is *not* locked + * by caller. + */ +void retire_super(struct super_block *sb) +{ + down_write(&sb->s_umount); + retire_locked_super(sb); +} +EXPORT_SYMBOL(retire_super); + /** * generic_shutdown_super - common helper for ->kill_sb() * @sb: superblock to kill @@ -467,17 +506,7 @@ void generic_shutdown_super(struct super_block *sb) sb->s_id); } } - spin_lock(&sb_lock); - /* should be initialized for __put_super_and_need_restart() */ - hlist_del_init(&sb->s_instances); - spin_unlock(&sb_lock); - up_write(&sb->s_umount); - if (sb->s_bdi !=3D &noop_backing_dev_info) { - if (sb->s_iflags & SB_I_PERSB_BDI) - bdi_unregister(sb->s_bdi); - bdi_put(sb->s_bdi); - sb->s_bdi =3D &noop_backing_dev_info; - } + retire_locked_super(sb); } =20 EXPORT_SYMBOL(generic_shutdown_super); diff --git a/include/linux/fs.h b/include/linux/fs.h index bbde95387a23a..dc9151b7f0102 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2424,6 +2424,7 @@ extern struct dentry *mount_nodev(struct file_system_= type *fs_type, int flags, void *data, int (*fill_super)(struct super_block *, void *, int)); extern struct dentry *mount_subtree(struct vfsmount *mnt, const char *path= ); +void retire_super(struct super_block *sb); void generic_shutdown_super(struct super_block *sb); void kill_block_super(struct super_block *sb); void kill_anon_super(struct super_block *sb); --=20 2.31.0 From nobody Sun May 10 09:55:52 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1365FC433EF for ; Wed, 11 May 2022 22:36:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348852AbiEKWgy (ORCPT ); Wed, 11 May 2022 18:36:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47832 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348832AbiEKWgq (ORCPT ); Wed, 11 May 2022 18:36:46 -0400 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1BBBA38795 for ; Wed, 11 May 2022 15:36:46 -0700 (PDT) Received: by mail-pl1-x635.google.com with SMTP id c9so3230673plh.2 for ; Wed, 11 May 2022 15:36:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=si1Rwhr5j9axuLzTcmMSWZj1IF9byAf7FS+JUx2lWqQ=; b=Y1mOoFpuxbMkem3auol/NJSBXB/PCujD/y1PVTZDkChfddxepgxXfoqshDcktwqGpP ARhYZ7veM2ssN8ZclXRl3dw+H03xpWbYiIROWS3VPFrzWnf2UPTo/ZvCBunsjbo0iayU 1kzdoHqbypVeAr1XxsMdL2S/gZSskNsyRZymg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=si1Rwhr5j9axuLzTcmMSWZj1IF9byAf7FS+JUx2lWqQ=; b=MsBQJYIdDmTmnmq6hzTAcnCfH7GRmC7wUD7R0pQGOyYwrluLtPoeWWEYXaqh0CKdYg /cLUtaAWSmwkOWlCH40BFqZ3VQxyFWKssQBAzz5tp02BJg83HIp87w8ScsqAgknMjq33 cIWIx3HV2SN3y1oQtkFMIp25nx15eZff/oI3YG159KclToUHgK5LogfgzSfmd+Zr/r9t ueGuQ5RIglI0opDPCqhX9PEtkdIxq8J/l2sqwCCTQxWa+sWUS4NfWj5OovEB2wcxNlVh X+YdCi0MAQzgNCd5T+1kzm4EW5abKbzwH8JKIDUe8y+UBe0rnsMjj4ISSqdW8kM1BWYL XMfg== X-Gm-Message-State: AOAM5323Wik5CawXNklI1WRfWx6xRoUFM7HrU+L+vKk72wuvnEx7W7DF jyW2Q1PjoBTRqhaLIx79q3WeMg== X-Google-Smtp-Source: ABdhPJzhp1wK1HcHgFgRwXNdOwOYc2AkkaevEP6SkCY6EqKLZyEDAmT5vf1CXRqTBa5UrZOjEt/Liw== X-Received: by 2002:a17:90b:4a08:b0:1dc:6cc1:3d24 with SMTP id kk8-20020a17090b4a0800b001dc6cc13d24mr7728354pjb.131.1652308605699; Wed, 11 May 2022 15:36:45 -0700 (PDT) Received: from dlunevwfh.roam.corp.google.com (n122-107-196-14.sbr2.nsw.optusnet.com.au. [122.107.196.14]) by smtp.gmail.com with ESMTPSA id d5-20020a170902c18500b0015e8d4eb1d2sm2391855pld.28.2022.05.11.15.36.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 May 2022 15:36:45 -0700 (PDT) From: Daniil Lunev To: linux-fsdevel@vger.kernel.org Cc: hch@infradead.org, fuse-devel@lists.sourceforge.net, tytso@mit.edu, miklos@szeredi.hu, viro@zeniv.linux.org.uk, linux-kernel@vger.kernel.org, Daniil Lunev Subject: [PATCH v2 2/2] FUSE: Retire superblock on force unmount Date: Thu, 12 May 2022 08:29:10 +1000 Message-Id: <20220512082832.v2.2.I692165059274c30b59bed56940b54a573ccb46e4@changeid> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20220511222910.635307-1-dlunev@chromium.org> References: <20220511222910.635307-1-dlunev@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Force unmount of FUSE severes the connection with the user space, even if there are still open files. Subsequent remount tries to re-use the superblock held by the open files, which is meaningless in the FUSE case after disconnect - reused super block doesn't have userspace counterpart attached to it and is incapable of doing any IO. Signed-off-by: Daniil Lunev --- Changes in v2: - Use an exported function instead of directly modifying superblock fs/fuse/inode.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c index 8c0665c5dff88..8875361544b2a 100644 --- a/fs/fuse/inode.c +++ b/fs/fuse/inode.c @@ -476,8 +476,11 @@ static void fuse_umount_begin(struct super_block *sb) { struct fuse_conn *fc =3D get_fuse_conn_super(sb); =20 - if (!fc->no_force_umount) - fuse_abort_conn(fc); + if (fc->no_force_umount) + return; + + fuse_abort_conn(fc); + retire_super(sb); } =20 static void fuse_send_destroy(struct fuse_mount *fm) --=20 2.31.0