From patchwork Thu Jun 1 09:44:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13263290 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 A305EC7EE2F for ; Thu, 1 Jun 2023 09:45:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232910AbjFAJpZ (ORCPT ); Thu, 1 Jun 2023 05:45:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233011AbjFAJpL (ORCPT ); Thu, 1 Jun 2023 05:45:11 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5BA5E95; Thu, 1 Jun 2023 02:45:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=HIEuDOPmFIS+iShTM0mpdBmHQefNMWjqF+6tGPSU4L4=; b=Oiw/hTyUqPPXTx0Bf3107EcQ6q zK8Myc3BfuoouZ6FP2FcFCE2UPjnsFwe77gwuBx5g0J6+dnEzJbln7Rf1t10Jhu0noyEy47TlKzWm QPhsZvqJ2FVQtLzsxm4KvlaGknvgPaF+Qzw/795gSuGPK7BxYqta+lPJ6I0vcceTX9KZ04FKKAiYu JqfQGqR3ldzckXRE6x5K+4mxnFjzrZO/Xj44J/OXxiQLR1NrbHjI/n7QPDAeLI1H5jXBLGBl+wW7J TYLLkW+2TRQ8905Rn8g/jYLmHmqNwLlx6yKTryVpG48OSCVKF6GHdy4csAC4hagX2rDGiXmDyEcld pUWrfNow==; Received: from [2001:4bb8:182:6d06:35f3:1da0:1cc3:d86d] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1q4eri-002lxV-2C; Thu, 01 Jun 2023 09:45:07 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Al Viro , Christian Brauner , "Darrick J. Wong" , Jan Kara , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org Subject: [PATCH 01/16] block: factor out a bd_end_claim helper from blkdev_put Date: Thu, 1 Jun 2023 11:44:44 +0200 Message-Id: <20230601094459.1350643-2-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230601094459.1350643-1-hch@lst.de> References: <20230601094459.1350643-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org Move all the logic to release an exclusive claim into a helper. Signed-off-by: Christoph Hellwig Reviewed-by: Jan Kara Acked-by: Christian Brauner --- block/bdev.c | 63 +++++++++++++++++++++++++++------------------------- 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/block/bdev.c b/block/bdev.c index 21c63bfef3237a..317bfd9cba40fa 100644 --- a/block/bdev.c +++ b/block/bdev.c @@ -589,6 +589,37 @@ void bd_abort_claiming(struct block_device *bdev, void *holder) } EXPORT_SYMBOL(bd_abort_claiming); +static void bd_end_claim(struct block_device *bdev) +{ + struct block_device *whole = bdev_whole(bdev); + bool unblock = false; + + /* + * Release a claim on the device. The holder fields are protected with + * bdev_lock. open_mutex is used to synchronize disk_holder unlinking. + */ + spin_lock(&bdev_lock); + WARN_ON_ONCE(--bdev->bd_holders < 0); + WARN_ON_ONCE(--whole->bd_holders < 0); + if (!bdev->bd_holders) { + bdev->bd_holder = NULL; + if (bdev->bd_write_holder) + unblock = true; + } + if (!whole->bd_holders) + whole->bd_holder = NULL; + spin_unlock(&bdev_lock); + + /* + * If this was the last claim, remove holder link and unblock evpoll if + * it was a write holder. + */ + if (unblock) { + disk_unblock_events(bdev->bd_disk); + bdev->bd_write_holder = false; + } +} + static void blkdev_flush_mapping(struct block_device *bdev) { WARN_ON_ONCE(bdev->bd_holders); @@ -843,36 +874,8 @@ void blkdev_put(struct block_device *bdev, fmode_t mode) sync_blockdev(bdev); mutex_lock(&disk->open_mutex); - if (mode & FMODE_EXCL) { - struct block_device *whole = bdev_whole(bdev); - bool bdev_free; - - /* - * Release a claim on the device. The holder fields - * are protected with bdev_lock. open_mutex is to - * synchronize disk_holder unlinking. - */ - spin_lock(&bdev_lock); - - WARN_ON_ONCE(--bdev->bd_holders < 0); - WARN_ON_ONCE(--whole->bd_holders < 0); - - if ((bdev_free = !bdev->bd_holders)) - bdev->bd_holder = NULL; - if (!whole->bd_holders) - whole->bd_holder = NULL; - - spin_unlock(&bdev_lock); - - /* - * If this was the last claim, remove holder link and - * unblock evpoll if it was a write holder. - */ - if (bdev_free && bdev->bd_write_holder) { - disk_unblock_events(disk); - bdev->bd_write_holder = false; - } - } + if (mode & FMODE_EXCL) + bd_end_claim(bdev); /* * Trigger event checking and tell drivers to flush MEDIA_CHANGE From patchwork Thu Jun 1 09:44:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13263288 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 90E58C77B7E for ; Thu, 1 Jun 2023 09:45:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232622AbjFAJpY (ORCPT ); Thu, 1 Jun 2023 05:45:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233024AbjFAJpP (ORCPT ); Thu, 1 Jun 2023 05:45:15 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E125595; Thu, 1 Jun 2023 02:45:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=EJ0nylZIsQIHOD70DFk2c9TfKIoYn5xl+C0q9q82FOg=; b=Puf6xm1OzqPWYxQIUprINZ3IOl zMmBGi5gqEkYi0jbxBr2V1UYAed9TxYqdYCYoPUeoaaJ7lRFWc3crH14nLC8yW9y2i8JdGKxtoDDk Gv2513xWXMyN6maDtiXqW/OOMWf23Yd1hvup5PyatDpldCvyuxYXQ3dc+PwuM4oFMHpLT6d7qXXh6 c8vI1cdJ0JcQG4Y67hVm4U9znWgLM7hrH/RCCjddzApc5uS5VxrwLnBYXsLHV9uQEP/kFMTs4tmpk IVexAkV/s1hgjMKz5PWMsGDaLLSEwwcWUuKh8xYmm56Q4iJtsolp7WVSzgqs6Ou7SUqMVtXUYMbUF VRPaZPjA==; Received: from [2001:4bb8:182:6d06:35f3:1da0:1cc3:d86d] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1q4ern-002ly1-0t; Thu, 01 Jun 2023 09:45:12 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Al Viro , Christian Brauner , "Darrick J. Wong" , Jan Kara , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org Subject: [PATCH 02/16] block: refactor bd_may_claim Date: Thu, 1 Jun 2023 11:44:45 +0200 Message-Id: <20230601094459.1350643-3-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230601094459.1350643-1-hch@lst.de> References: <20230601094459.1350643-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org The long if/else chain obsfucates the actual logic. Tidy it up to be more structured. Also drop the whole argument, as it can be trivially derived from bdev using bdev_whole, and having the bdev_whole in the function makes it easier to follow. Signed-off-by: Christoph Hellwig Reviewed-by: Jan Kara --- block/bdev.c | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/block/bdev.c b/block/bdev.c index 317bfd9cba40fa..080b5c83bfbc72 100644 --- a/block/bdev.c +++ b/block/bdev.c @@ -463,7 +463,6 @@ long nr_blockdev_pages(void) /** * bd_may_claim - test whether a block device can be claimed * @bdev: block device of interest - * @whole: whole block device containing @bdev, may equal @bdev * @holder: holder trying to claim @bdev * * Test whether @bdev can be claimed by @holder. @@ -474,22 +473,27 @@ long nr_blockdev_pages(void) * RETURNS: * %true if @bdev can be claimed, %false otherwise. */ -static bool bd_may_claim(struct block_device *bdev, struct block_device *whole, - void *holder) +static bool bd_may_claim(struct block_device *bdev, void *holder) { - if (bdev->bd_holder == holder) - return true; /* already a holder */ - else if (bdev->bd_holder != NULL) - return false; /* held by someone else */ - else if (whole == bdev) - return true; /* is a whole device which isn't held */ - - else if (whole->bd_holder == bd_may_claim) - return true; /* is a partition of a device that is being partitioned */ - else if (whole->bd_holder != NULL) - return false; /* is a partition of a held device */ - else - return true; /* is a partition of an un-held device */ + struct block_device *whole = bdev_whole(bdev); + + if (bdev->bd_holder) { + /* + * The same holder can always re-claim. + */ + if (bdev->bd_holder == holder) + return true; + return false; + } + + /* + * If the whole devices holder is set to bd_may_claim, a partition on + * the device is claimed, but not the whole device. + */ + if (whole != bdev && + whole->bd_holder && whole->bd_holder != bd_may_claim) + return false; + return true; } /** @@ -513,7 +517,7 @@ int bd_prepare_to_claim(struct block_device *bdev, void *holder) retry: spin_lock(&bdev_lock); /* if someone else claimed, fail */ - if (!bd_may_claim(bdev, whole, holder)) { + if (!bd_may_claim(bdev, holder)) { spin_unlock(&bdev_lock); return -EBUSY; } @@ -559,7 +563,7 @@ static void bd_finish_claiming(struct block_device *bdev, void *holder) struct block_device *whole = bdev_whole(bdev); spin_lock(&bdev_lock); - BUG_ON(!bd_may_claim(bdev, whole, holder)); + BUG_ON(!bd_may_claim(bdev, holder)); /* * Note that for a whole device bd_holders will be incremented twice, * and bd_holder will be set to bd_may_claim before being set to holder From patchwork Thu Jun 1 09:44:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13263289 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 92FCBC7EE33 for ; Thu, 1 Jun 2023 09:45:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232941AbjFAJp0 (ORCPT ); Thu, 1 Jun 2023 05:45:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233040AbjFAJpU (ORCPT ); Thu, 1 Jun 2023 05:45:20 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 923A995; Thu, 1 Jun 2023 02:45:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=0gTLAUlFe0DX2eUG/rV5llfv74gR91AkuRTXQ7aAQuQ=; b=j9+I37km1dVFzK0pMRVFUutkyM fx91ge5Dkms4bXI2cS2pZNdEUcx41bgMRQ7q4fhg4tItO5gByIT/0UG0hoVoNn3UP8Rlgv7zy9ILR 68zCoxcEg5Aa5WXbZMF+rsOOYvno1nLE1UWDOuzKWG+RRdj3RG5s/HiOGXvtoB4iK+PQ3vPtYxwSc q9O7YaE+SQ3nq5rVKtgogIliYnJqKjxNO+W5wfn+9j4dwhhKhJDWAdrzYRXOTv8HUG24zGgOYLIzG OeJ3+54kBKVlFVbWUQl+lKIYUtyOTU9vrqdfqn42PnR1vgvoJxytsTUU+nedf7IIjj1VnqvHLCHLD VNuzbKsQ==; Received: from [2001:4bb8:182:6d06:35f3:1da0:1cc3:d86d] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1q4ers-002lzB-2y; Thu, 01 Jun 2023 09:45:17 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Al Viro , Christian Brauner , "Darrick J. Wong" , Jan Kara , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org Subject: [PATCH 03/16] block: turn bdev_lock into a mutex Date: Thu, 1 Jun 2023 11:44:46 +0200 Message-Id: <20230601094459.1350643-4-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230601094459.1350643-1-hch@lst.de> References: <20230601094459.1350643-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org There is no reason for this lock to spin, and being able to sleep under it will come in handy soon. Signed-off-by: Christoph Hellwig Reviewed-by: Jan Kara Acked-by: Christian Brauner --- block/bdev.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/block/bdev.c b/block/bdev.c index 080b5c83bfbc72..f5ffcac762e0cd 100644 --- a/block/bdev.c +++ b/block/bdev.c @@ -308,7 +308,7 @@ EXPORT_SYMBOL(thaw_bdev); * pseudo-fs */ -static __cacheline_aligned_in_smp DEFINE_SPINLOCK(bdev_lock); +static __cacheline_aligned_in_smp DEFINE_MUTEX(bdev_lock); static struct kmem_cache * bdev_cachep __read_mostly; static struct inode *bdev_alloc_inode(struct super_block *sb) @@ -467,9 +467,6 @@ long nr_blockdev_pages(void) * * Test whether @bdev can be claimed by @holder. * - * CONTEXT: - * spin_lock(&bdev_lock). - * * RETURNS: * %true if @bdev can be claimed, %false otherwise. */ @@ -477,6 +474,8 @@ static bool bd_may_claim(struct block_device *bdev, void *holder) { struct block_device *whole = bdev_whole(bdev); + lockdep_assert_held(&bdev_lock); + if (bdev->bd_holder) { /* * The same holder can always re-claim. @@ -515,10 +514,10 @@ int bd_prepare_to_claim(struct block_device *bdev, void *holder) if (WARN_ON_ONCE(!holder)) return -EINVAL; retry: - spin_lock(&bdev_lock); + mutex_lock(&bdev_lock); /* if someone else claimed, fail */ if (!bd_may_claim(bdev, holder)) { - spin_unlock(&bdev_lock); + mutex_unlock(&bdev_lock); return -EBUSY; } @@ -528,7 +527,7 @@ int bd_prepare_to_claim(struct block_device *bdev, void *holder) DEFINE_WAIT(wait); prepare_to_wait(wq, &wait, TASK_UNINTERRUPTIBLE); - spin_unlock(&bdev_lock); + mutex_unlock(&bdev_lock); schedule(); finish_wait(wq, &wait); goto retry; @@ -536,7 +535,7 @@ int bd_prepare_to_claim(struct block_device *bdev, void *holder) /* yay, all mine */ whole->bd_claiming = holder; - spin_unlock(&bdev_lock); + mutex_unlock(&bdev_lock); return 0; } EXPORT_SYMBOL_GPL(bd_prepare_to_claim); /* only for the loop driver */ @@ -562,7 +561,7 @@ static void bd_finish_claiming(struct block_device *bdev, void *holder) { struct block_device *whole = bdev_whole(bdev); - spin_lock(&bdev_lock); + mutex_lock(&bdev_lock); BUG_ON(!bd_may_claim(bdev, holder)); /* * Note that for a whole device bd_holders will be incremented twice, @@ -573,7 +572,7 @@ static void bd_finish_claiming(struct block_device *bdev, void *holder) bdev->bd_holders++; bdev->bd_holder = holder; bd_clear_claiming(whole, holder); - spin_unlock(&bdev_lock); + mutex_unlock(&bdev_lock); } /** @@ -587,9 +586,9 @@ static void bd_finish_claiming(struct block_device *bdev, void *holder) */ void bd_abort_claiming(struct block_device *bdev, void *holder) { - spin_lock(&bdev_lock); + mutex_lock(&bdev_lock); bd_clear_claiming(bdev_whole(bdev), holder); - spin_unlock(&bdev_lock); + mutex_unlock(&bdev_lock); } EXPORT_SYMBOL(bd_abort_claiming); @@ -602,7 +601,7 @@ static void bd_end_claim(struct block_device *bdev) * Release a claim on the device. The holder fields are protected with * bdev_lock. open_mutex is used to synchronize disk_holder unlinking. */ - spin_lock(&bdev_lock); + mutex_lock(&bdev_lock); WARN_ON_ONCE(--bdev->bd_holders < 0); WARN_ON_ONCE(--whole->bd_holders < 0); if (!bdev->bd_holders) { @@ -612,7 +611,7 @@ static void bd_end_claim(struct block_device *bdev) } if (!whole->bd_holders) whole->bd_holder = NULL; - spin_unlock(&bdev_lock); + mutex_unlock(&bdev_lock); /* * If this was the last claim, remove holder link and unblock evpoll if From patchwork Thu Jun 1 09:44:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13263291 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 D8FF3C7EE29 for ; Thu, 1 Jun 2023 09:45:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232354AbjFAJp2 (ORCPT ); Thu, 1 Jun 2023 05:45:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232907AbjFAJpZ (ORCPT ); Thu, 1 Jun 2023 05:45:25 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B38695; Thu, 1 Jun 2023 02:45:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=k4kNldVjs7e6baim8DHczVcxxVbNeVcf2VNYa40zrTg=; b=WJB1U3XzmTyXq+NiXj5gLFMAln Yna1szv8xq6MvrjgFSZMKkaciy3Jxq1smAfaFVRHx32tKlYtrzzvvZW/J/02D7Nw0g0OR1DNsNmkF h1stJDzJs9Ms7o3GnN8ShpnZPgqiWNWbyGIax8YjbKhwB0JCGwPOrwXeFmo6O01KZBzoHoSb2hZlf nLyD6xsq8e+6iLDDI5Fqs5pJmqZUciH4o2W6D6uufC6aEBELpHJ5mN+uJ0Et70xvyL4dD7Y66UPBd oNFHS9gqKJ+oVTfJ3nLtGPZBeAmnzclOAEVf3f+NHQX48HhIYBMyyLcmU8PYgxV1Y0rzigouu0wkk Igp8wGfg==; Received: from [2001:4bb8:182:6d06:35f3:1da0:1cc3:d86d] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1q4erx-002lzw-1g; Thu, 01 Jun 2023 09:45:21 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Al Viro , Christian Brauner , "Darrick J. Wong" , Jan Kara , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org Subject: [PATCH 04/16] block: consolidate the shutdown logic in blk_mark_disk_dead and del_gendisk Date: Thu, 1 Jun 2023 11:44:47 +0200 Message-Id: <20230601094459.1350643-5-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230601094459.1350643-1-hch@lst.de> References: <20230601094459.1350643-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org blk_mark_disk_dead does very similar work a a section of del_gendisk: - set the GD_DEAD flag - set the capacity to zero - start a queue drain but del_gendisk also sets QUEUE_FLAG_DYING on the queue if it is owned by the disk, sets the capacity to zero before starting the drain, and both with sending a uevent and kernel message for this fake capacity change. Move the exact logic from the more heavily used del_gendisk into blk_mark_disk_dead and then call blk_mark_disk_dead from del_gendisk. Signed-off-by: Christoph Hellwig Reviewed-by: Jan Kara --- block/genhd.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/block/genhd.c b/block/genhd.c index 3537b7d7c484d7..aa327314905e63 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -572,13 +572,22 @@ EXPORT_SYMBOL(device_add_disk); */ void blk_mark_disk_dead(struct gendisk *disk) { + /* + * Fail any new I/O. + */ set_bit(GD_DEAD, &disk->state); - blk_queue_start_drain(disk->queue); + if (test_bit(GD_OWNS_QUEUE, &disk->state)) + blk_queue_flag_set(QUEUE_FLAG_DYING, disk->queue); /* * Stop buffered writers from dirtying pages that can't be written out. */ - set_capacity_and_notify(disk, 0); + set_capacity(disk, 0); + + /* + * Prevent new I/O from crossing bio_queue_enter(). + */ + blk_queue_start_drain(disk->queue); } EXPORT_SYMBOL_GPL(blk_mark_disk_dead); @@ -620,18 +629,7 @@ void del_gendisk(struct gendisk *disk) fsync_bdev(disk->part0); __invalidate_device(disk->part0, true); - /* - * Fail any new I/O. - */ - set_bit(GD_DEAD, &disk->state); - if (test_bit(GD_OWNS_QUEUE, &disk->state)) - blk_queue_flag_set(QUEUE_FLAG_DYING, q); - set_capacity(disk, 0); - - /* - * Prevent new I/O from crossing bio_queue_enter(). - */ - blk_queue_start_drain(q); + blk_mark_disk_dead(disk); if (!(disk->flags & GENHD_FL_HIDDEN)) { sysfs_remove_link(&disk_to_dev(disk)->kobj, "bdi"); From patchwork Thu Jun 1 09:44:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13263292 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 54570C7EE29 for ; Thu, 1 Jun 2023 09:45:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232960AbjFAJpj (ORCPT ); Thu, 1 Jun 2023 05:45:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232887AbjFAJp3 (ORCPT ); Thu, 1 Jun 2023 05:45:29 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8AB96107; Thu, 1 Jun 2023 02:45:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=FCBrupMSi2gX4xBrWPykUficbuGDQWQogDz/WNYsqZU=; b=cEYDIK7id/fucsksAWexU/ieCz Qin08z4KispC9wOLvMd2ldfFTB3Is8I6MQVjLbhxL8X7JEApZ2KGtZwUI9imTxbi8TZhLd87NrOAG ZNVR0pK5kc3Kik9yz61Qvjlhjbj9AlHPywGmMTRVEsOAXN7roWqbGlrJ09cT0qCwRq/U+UUIC7c8C uMOEpPN5LQ880W7c12lSA8WFNrtIeKDNebSL7LITJUOqoma8bEgIIs9lhlKKVFfpLqZOtJD8GDkut cqk2WTeB1zDx2L+iDOWjZTRCDwWu8Q/L65k7r8U0sf63wlNeSgSlskhZp+4MU7JNO9CKlfPVQn0MB 4PThO84Q==; Received: from [2001:4bb8:182:6d06:35f3:1da0:1cc3:d86d] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1q4es1-002m0W-0J; Thu, 01 Jun 2023 09:45:26 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Al Viro , Christian Brauner , "Darrick J. Wong" , Jan Kara , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org Subject: [PATCH 05/16] block: avoid repeated work in blk_mark_disk_dead Date: Thu, 1 Jun 2023 11:44:48 +0200 Message-Id: <20230601094459.1350643-6-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230601094459.1350643-1-hch@lst.de> References: <20230601094459.1350643-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org Check if GD_DEAD is already set in blk_mark_disk_dead, and don't duplicate the work already done. Signed-off-by: Christoph Hellwig Reviewed-by: Jan Kara Acked-by: Christian Brauner --- block/genhd.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/block/genhd.c b/block/genhd.c index aa327314905e63..6fa926a02d8534 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -575,7 +575,9 @@ void blk_mark_disk_dead(struct gendisk *disk) /* * Fail any new I/O. */ - set_bit(GD_DEAD, &disk->state); + if (test_and_set_bit(GD_DEAD, &disk->state)) + return; + if (test_bit(GD_OWNS_QUEUE, &disk->state)) blk_queue_flag_set(QUEUE_FLAG_DYING, disk->queue); From patchwork Thu Jun 1 09:44:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13263293 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 B6F1BC77B7E for ; Thu, 1 Jun 2023 09:45:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232979AbjFAJpw (ORCPT ); Thu, 1 Jun 2023 05:45:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232952AbjFAJph (ORCPT ); Thu, 1 Jun 2023 05:45:37 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A4F5138; Thu, 1 Jun 2023 02:45:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=YJQybKfCdLCIlGO1r6f0pU+uuBW5OJtJmoC2d/oJamo=; b=JbTNDwZUHQDUcxy8O6bTE5P6Zo gcD1ddqRinuAYUlqbqusDenhM/kdMxPo3rIGWWFdCxm8Zl1XIJGWoT3/4qVNrgUELTp1pxJIi2nkX 855mXrzwH+P5TlO8idl0ODuCqvqPKz+sd0vNhUZVKg7tHEwv0hWvh5xo4nNRmg9RSUV/D+pIoF0e9 5hyuAcIf9Gi5YbWHn6oQpAUwywZe5KrXrKcDVQxroK3ifg26RFm8XJQVH4tLogeog3dTjehwkI+av e/MUBtbi91Dg/QAbQtjEU3vzkp+cOFFAp3ityrixi0wMcOzBY8TczmPLvPivM+X+RBDDtSCmtvNAJ Bdn9F3jg==; Received: from [2001:4bb8:182:6d06:35f3:1da0:1cc3:d86d] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1q4es7-002m2b-0p; Thu, 01 Jun 2023 09:45:32 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Al Viro , Christian Brauner , "Darrick J. Wong" , Jan Kara , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org Subject: [PATCH 06/16] block: unhash the inode earlier in delete_partition Date: Thu, 1 Jun 2023 11:44:49 +0200 Message-Id: <20230601094459.1350643-7-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230601094459.1350643-1-hch@lst.de> References: <20230601094459.1350643-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org Move the call to remove_inode_hash to the beginning of delete_partition, as we want to prevent opening a block_device that is about to be removed ASAP. Signed-off-by: Christoph Hellwig Reviewed-by: Jan Kara --- block/partitions/core.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/block/partitions/core.c b/block/partitions/core.c index 82d26427deae25..9d1debaa5caf9a 100644 --- a/block/partitions/core.c +++ b/block/partitions/core.c @@ -267,6 +267,12 @@ static void delete_partition(struct block_device *part) { lockdep_assert_held(&part->bd_disk->open_mutex); + /* + * Remove the block device from the inode hash, so that it cannot be + * looked up any more even when openers still hold references. + */ + remove_inode_hash(part->bd_inode); + fsync_bdev(part); __invalidate_device(part, true); @@ -274,12 +280,6 @@ static void delete_partition(struct block_device *part) kobject_put(part->bd_holder_dir); device_del(&part->bd_device); - /* - * Remove the block device from the inode hash, so that it cannot be - * looked up any more even when openers still hold references. - */ - remove_inode_hash(part->bd_inode); - put_device(&part->bd_device); } From patchwork Thu Jun 1 09:44:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13263294 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 959E8C77B7E for ; Thu, 1 Jun 2023 09:45:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232967AbjFAJpy (ORCPT ); Thu, 1 Jun 2023 05:45:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232907AbjFAJpw (ORCPT ); Thu, 1 Jun 2023 05:45:52 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B3A19193; Thu, 1 Jun 2023 02:45:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=KBSZP+H+B3VTPJga3uZab9DVq6AzfNWIBlykXT/Wzx0=; b=LYXIF4HcK1/SwO8gYDml1qoGO8 Qfg8n88Pr7TJ4LdfLYHZ6VFL5lDnrTbqE2/IXQFjv1d68yDxHtZQ6E6geFes4yObXvDw2abAWZlxX 3Hdc85DpwvWySKkz0nekueDJT/l/oEOwHRLLWsiuo6rcqqg5HtdpSgJNNlp456fjTggwYd1I83E1j 2uug+cZgWpNyxZm9YcYxwmATLHfOOWdYTj1+hbEaC+SHIuqpjTpTyhefjeUbehv1ZBdp7DCCeLXsH ambjrXEjpP/XmV+I/2DYGheWkpw8hNe0pXPj+MxIoSoGEz9XkqUkw+16YJieXF0ztRXWDXrOAgClB dfpxGX1A==; Received: from [2001:4bb8:182:6d06:35f3:1da0:1cc3:d86d] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1q4esC-002m4j-2p; Thu, 01 Jun 2023 09:45:37 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Al Viro , Christian Brauner , "Darrick J. Wong" , Jan Kara , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org Subject: [PATCH 07/16] block: delete partitions later in del_gendisk Date: Thu, 1 Jun 2023 11:44:50 +0200 Message-Id: <20230601094459.1350643-8-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230601094459.1350643-1-hch@lst.de> References: <20230601094459.1350643-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org Delay dropping the block_devices for partitions in del_gendisk until after the call to blk_mark_disk_dead, so that we can implementat notification of removed devices in blk_mark_disk_dead. This requires splitting a lower-level drop_partition helper out of delete_partition and using that from del_gendisk, while having a common loop for the whole device and partitions that calls remove_inode_hash, fsync_bdev and __invalidate_device before the call to blk_mark_disk_dead. Signed-off-by: Christoph Hellwig Reviewed-by: Jan Kara --- block/blk.h | 2 +- block/genhd.c | 24 +++++++++++++++++++----- block/partitions/core.c | 19 ++++++++++++------- 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/block/blk.h b/block/blk.h index 7ad7cb6ffa0135..9582fcd0df4123 100644 --- a/block/blk.h +++ b/block/blk.h @@ -409,7 +409,7 @@ int bdev_add_partition(struct gendisk *disk, int partno, sector_t start, int bdev_del_partition(struct gendisk *disk, int partno); int bdev_resize_partition(struct gendisk *disk, int partno, sector_t start, sector_t length); -void blk_drop_partitions(struct gendisk *disk); +void drop_partition(struct block_device *part); void bdev_set_nr_sectors(struct block_device *bdev, sector_t sectors); diff --git a/block/genhd.c b/block/genhd.c index 6fa926a02d8534..a668d2f0208766 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -615,6 +615,8 @@ EXPORT_SYMBOL_GPL(blk_mark_disk_dead); void del_gendisk(struct gendisk *disk) { struct request_queue *q = disk->queue; + struct block_device *part; + unsigned long idx; might_sleep(); @@ -623,16 +625,28 @@ void del_gendisk(struct gendisk *disk) disk_del_events(disk); + /* + * Prevent new openers by unlinked the bdev inode, and write out + * dirty data before marking the disk dead and stopping all I/O. + */ mutex_lock(&disk->open_mutex); - remove_inode_hash(disk->part0->bd_inode); - blk_drop_partitions(disk); + xa_for_each(&disk->part_tbl, idx, part) { + remove_inode_hash(part->bd_inode); + fsync_bdev(part); + __invalidate_device(part, true); + } mutex_unlock(&disk->open_mutex); - fsync_bdev(disk->part0); - __invalidate_device(disk->part0, true); - blk_mark_disk_dead(disk); + /* + * Drop all partitions now that the disk is marked dead. + */ + mutex_lock(&disk->open_mutex); + xa_for_each_start(&disk->part_tbl, idx, part, 1) + drop_partition(part); + mutex_unlock(&disk->open_mutex); + if (!(disk->flags & GENHD_FL_HIDDEN)) { sysfs_remove_link(&disk_to_dev(disk)->kobj, "bdi"); diff --git a/block/partitions/core.c b/block/partitions/core.c index 9d1debaa5caf9a..c3c12671a949d2 100644 --- a/block/partitions/core.c +++ b/block/partitions/core.c @@ -263,10 +263,19 @@ const struct device_type part_type = { .uevent = part_uevent, }; -static void delete_partition(struct block_device *part) +void drop_partition(struct block_device *part) { lockdep_assert_held(&part->bd_disk->open_mutex); + xa_erase(&part->bd_disk->part_tbl, part->bd_partno); + kobject_put(part->bd_holder_dir); + + device_del(&part->bd_device); + put_device(&part->bd_device); +} + +static void delete_partition(struct block_device *part) +{ /* * Remove the block device from the inode hash, so that it cannot be * looked up any more even when openers still hold references. @@ -276,11 +285,7 @@ static void delete_partition(struct block_device *part) fsync_bdev(part); __invalidate_device(part, true); - xa_erase(&part->bd_disk->part_tbl, part->bd_partno); - kobject_put(part->bd_holder_dir); - device_del(&part->bd_device); - - put_device(&part->bd_device); + drop_partition(part); } static ssize_t whole_disk_show(struct device *dev, @@ -519,7 +524,7 @@ static bool disk_unlock_native_capacity(struct gendisk *disk) return true; } -void blk_drop_partitions(struct gendisk *disk) +static void blk_drop_partitions(struct gendisk *disk) { struct block_device *part; unsigned long idx; From patchwork Thu Jun 1 09:44:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13263295 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 B0C5AC7EE23 for ; Thu, 1 Jun 2023 09:46:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232957AbjFAJqH (ORCPT ); Thu, 1 Jun 2023 05:46:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232990AbjFAJpw (ORCPT ); Thu, 1 Jun 2023 05:45:52 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D5E219D; Thu, 1 Jun 2023 02:45:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=SUpOllJbKhqT3YEmC3iheCrejbguNofqWimeHbccUMI=; b=tDIBqGXnztSeTBP+Og2j2qkGdU xD32U0OGfPlUajFNjhfv2sYWLAQoUGkY12auIfZ9IcoEslwNDz6C5KFIFm9/1AsiQGfj1m8Hs6a7w lSCFZYneJiWGKURUd8VszaSZdiaWYDLR3IXZBDLKwykXNSupuXPfex3CNyCDfYvHs3nLxnRIO6P2c FvSGmtpWj42L8M528GTP2xwzCZqpYubVuMkY2BHtoxO+oPKn1q+WHzdh+oXdme5L4H90E7G9Bv3Gv dj7DpNkmpwZv7qHD0CDoc8vz8zbNoL8K1Qx+Ecoue6TaokTusC+ViCOpIoCCkDEbwogNhAgVDuPK8 35N5asTw==; Received: from [2001:4bb8:182:6d06:35f3:1da0:1cc3:d86d] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1q4esH-002m5M-2C; Thu, 01 Jun 2023 09:45:42 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Al Viro , Christian Brauner , "Darrick J. Wong" , Jan Kara , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org Subject: [PATCH 08/16] block: remove blk_drop_partitions Date: Thu, 1 Jun 2023 11:44:51 +0200 Message-Id: <20230601094459.1350643-9-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230601094459.1350643-1-hch@lst.de> References: <20230601094459.1350643-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org There is only a single caller left, so fold the loop into that. Signed-off-by: Christoph Hellwig Reviewed-by: Jan Kara --- block/partitions/core.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/block/partitions/core.c b/block/partitions/core.c index c3c12671a949d2..87a21942d60667 100644 --- a/block/partitions/core.c +++ b/block/partitions/core.c @@ -524,17 +524,6 @@ static bool disk_unlock_native_capacity(struct gendisk *disk) return true; } -static void blk_drop_partitions(struct gendisk *disk) -{ - struct block_device *part; - unsigned long idx; - - lockdep_assert_held(&disk->open_mutex); - - xa_for_each_start(&disk->part_tbl, idx, part, 1) - delete_partition(part); -} - static bool blk_add_partition(struct gendisk *disk, struct parsed_partitions *state, int p) { @@ -651,6 +640,8 @@ static int blk_add_partitions(struct gendisk *disk) int bdev_disk_changed(struct gendisk *disk, bool invalidate) { + struct block_device *part; + unsigned long idx; int ret = 0; lockdep_assert_held(&disk->open_mutex); @@ -663,8 +654,9 @@ int bdev_disk_changed(struct gendisk *disk, bool invalidate) return -EBUSY; sync_blockdev(disk->part0); invalidate_bdev(disk->part0); - blk_drop_partitions(disk); + xa_for_each_start(&disk->part_tbl, idx, part, 1) + delete_partition(part); clear_bit(GD_NEED_PART_SCAN, &disk->state); /* From patchwork Thu Jun 1 09:44:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13263297 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 E1DE5C77B7E for ; Thu, 1 Jun 2023 09:46:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232951AbjFAJqL (ORCPT ); Thu, 1 Jun 2023 05:46:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232972AbjFAJp4 (ORCPT ); Thu, 1 Jun 2023 05:45:56 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 363D3D7; Thu, 1 Jun 2023 02:45:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=Mky/OADGaSUd0VNThcAj7LLq+nluqJ+iFz0Z7temPfc=; b=TvcS5RPVSK0Bq1vPyxt/bx8o6r 5IQanFj0rdoBexmAMvU5/9Y8Cpw+RS6iugJdz1u8+dyG0ddTe3heR0fh5F/n4Js7tUCpwG5bHecdJ fIs2jsHOtibbJYF5+fBrWeXr6ceC9xdsENVh1/IhbHrqegyIMm60kpRxR8QAHreEuVzf0T9fenR74 DN5Slr6hwJA/wtzeBIfvfxKJ/h5XvAojndpuXAhasyIvBSnwUeE+2CIVLnx8/RHjXv4sdcxw4ryde m5l/qaznM6wPx2T/ITp0bYtbhUVpZsygXzrI0HyYpS8tBgScNCCqN3VbtPZvaX9C+Dn9i3PE++iml nxWBbOJg==; Received: from [2001:4bb8:182:6d06:35f3:1da0:1cc3:d86d] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1q4esN-002m62-0O; Thu, 01 Jun 2023 09:45:48 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Al Viro , Christian Brauner , "Darrick J. Wong" , Jan Kara , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org Subject: [PATCH 09/16] block: introduce holder ops Date: Thu, 1 Jun 2023 11:44:52 +0200 Message-Id: <20230601094459.1350643-10-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230601094459.1350643-1-hch@lst.de> References: <20230601094459.1350643-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org Add a new blk_holder_ops structure, which is passed to blkdev_get_by_* and installed in the block_device for exclusive claims. It will be used to allow the block layer to call back into the user of the block device for thing like notification of a removed device or a device resize. Signed-off-by: Christoph Hellwig Reviewed-by: Jan Kara --- block/bdev.c | 41 ++++++++++++++++++++--------- block/fops.c | 2 +- block/genhd.c | 6 +++-- block/ioctl.c | 3 ++- drivers/block/drbd/drbd_nl.c | 3 ++- drivers/block/loop.c | 2 +- drivers/block/pktcdvd.c | 5 ++-- drivers/block/rnbd/rnbd-srv.c | 2 +- drivers/block/xen-blkback/xenbus.c | 2 +- drivers/block/zram/zram_drv.c | 2 +- drivers/md/bcache/super.c | 2 +- drivers/md/dm.c | 2 +- drivers/md/md.c | 2 +- drivers/mtd/devices/block2mtd.c | 4 +-- drivers/nvme/target/io-cmd-bdev.c | 2 +- drivers/s390/block/dasd_genhd.c | 2 +- drivers/target/target_core_iblock.c | 2 +- drivers/target/target_core_pscsi.c | 3 ++- fs/btrfs/dev-replace.c | 2 +- fs/btrfs/volumes.c | 6 ++--- fs/erofs/super.c | 2 +- fs/ext4/super.c | 3 ++- fs/f2fs/super.c | 4 +-- fs/jfs/jfs_logmgr.c | 2 +- fs/nfs/blocklayout/dev.c | 5 ++-- fs/nilfs2/super.c | 2 +- fs/ocfs2/cluster/heartbeat.c | 2 +- fs/reiserfs/journal.c | 5 ++-- fs/super.c | 4 +-- fs/xfs/xfs_super.c | 2 +- include/linux/blk_types.h | 2 ++ include/linux/blkdev.h | 11 +++++--- kernel/power/swap.c | 4 +-- mm/swapfile.c | 3 ++- 34 files changed, 90 insertions(+), 56 deletions(-) diff --git a/block/bdev.c b/block/bdev.c index f5ffcac762e0cd..5c46ff10770638 100644 --- a/block/bdev.c +++ b/block/bdev.c @@ -102,7 +102,7 @@ int truncate_bdev_range(struct block_device *bdev, fmode_t mode, * under live filesystem. */ if (!(mode & FMODE_EXCL)) { - int err = bd_prepare_to_claim(bdev, truncate_bdev_range); + int err = bd_prepare_to_claim(bdev, truncate_bdev_range, NULL); if (err) goto invalidate; } @@ -415,6 +415,7 @@ struct block_device *bdev_alloc(struct gendisk *disk, u8 partno) bdev = I_BDEV(inode); mutex_init(&bdev->bd_fsfreeze_mutex); spin_lock_init(&bdev->bd_size_lock); + mutex_init(&bdev->bd_holder_lock); bdev->bd_partno = partno; bdev->bd_inode = inode; bdev->bd_queue = disk->queue; @@ -464,13 +465,15 @@ long nr_blockdev_pages(void) * bd_may_claim - test whether a block device can be claimed * @bdev: block device of interest * @holder: holder trying to claim @bdev + * @hops: holder ops * * Test whether @bdev can be claimed by @holder. * * RETURNS: * %true if @bdev can be claimed, %false otherwise. */ -static bool bd_may_claim(struct block_device *bdev, void *holder) +static bool bd_may_claim(struct block_device *bdev, void *holder, + const struct blk_holder_ops *hops) { struct block_device *whole = bdev_whole(bdev); @@ -480,8 +483,11 @@ static bool bd_may_claim(struct block_device *bdev, void *holder) /* * The same holder can always re-claim. */ - if (bdev->bd_holder == holder) + if (bdev->bd_holder == holder) { + if (WARN_ON_ONCE(bdev->bd_holder_ops != hops)) + return false; return true; + } return false; } @@ -499,6 +505,7 @@ static bool bd_may_claim(struct block_device *bdev, void *holder) * bd_prepare_to_claim - claim a block device * @bdev: block device of interest * @holder: holder trying to claim @bdev + * @hops: holder ops. * * Claim @bdev. This function fails if @bdev is already claimed by another * holder and waits if another claiming is in progress. return, the caller @@ -507,7 +514,8 @@ static bool bd_may_claim(struct block_device *bdev, void *holder) * RETURNS: * 0 if @bdev can be claimed, -EBUSY otherwise. */ -int bd_prepare_to_claim(struct block_device *bdev, void *holder) +int bd_prepare_to_claim(struct block_device *bdev, void *holder, + const struct blk_holder_ops *hops) { struct block_device *whole = bdev_whole(bdev); @@ -516,7 +524,7 @@ int bd_prepare_to_claim(struct block_device *bdev, void *holder) retry: mutex_lock(&bdev_lock); /* if someone else claimed, fail */ - if (!bd_may_claim(bdev, holder)) { + if (!bd_may_claim(bdev, holder, hops)) { mutex_unlock(&bdev_lock); return -EBUSY; } @@ -557,12 +565,13 @@ static void bd_clear_claiming(struct block_device *whole, void *holder) * Finish exclusive open of a block device. Mark the device as exlusively * open by the holder and wake up all waiters for exclusive open to finish. */ -static void bd_finish_claiming(struct block_device *bdev, void *holder) +static void bd_finish_claiming(struct block_device *bdev, void *holder, + const struct blk_holder_ops *hops) { struct block_device *whole = bdev_whole(bdev); mutex_lock(&bdev_lock); - BUG_ON(!bd_may_claim(bdev, holder)); + BUG_ON(!bd_may_claim(bdev, holder, hops)); /* * Note that for a whole device bd_holders will be incremented twice, * and bd_holder will be set to bd_may_claim before being set to holder @@ -570,7 +579,10 @@ static void bd_finish_claiming(struct block_device *bdev, void *holder) whole->bd_holders++; whole->bd_holder = bd_may_claim; bdev->bd_holders++; + mutex_lock(&bdev->bd_holder_lock); bdev->bd_holder = holder; + bdev->bd_holder_ops = hops; + mutex_unlock(&bdev->bd_holder_lock); bd_clear_claiming(whole, holder); mutex_unlock(&bdev_lock); } @@ -605,7 +617,10 @@ static void bd_end_claim(struct block_device *bdev) WARN_ON_ONCE(--bdev->bd_holders < 0); WARN_ON_ONCE(--whole->bd_holders < 0); if (!bdev->bd_holders) { + mutex_lock(&bdev->bd_holder_lock); bdev->bd_holder = NULL; + bdev->bd_holder_ops = NULL; + mutex_unlock(&bdev->bd_holder_lock); if (bdev->bd_write_holder) unblock = true; } @@ -735,6 +750,7 @@ void blkdev_put_no_open(struct block_device *bdev) * @dev: device number of block device to open * @mode: FMODE_* mask * @holder: exclusive holder identifier + * @hops: holder operations * * Open the block device described by device number @dev. If @mode includes * %FMODE_EXCL, the block device is opened with exclusive access. Specifying @@ -751,7 +767,8 @@ void blkdev_put_no_open(struct block_device *bdev) * RETURNS: * Reference to the block_device on success, ERR_PTR(-errno) on failure. */ -struct block_device *blkdev_get_by_dev(dev_t dev, fmode_t mode, void *holder) +struct block_device *blkdev_get_by_dev(dev_t dev, fmode_t mode, void *holder, + const struct blk_holder_ops *hops) { bool unblock_events = true; struct block_device *bdev; @@ -771,7 +788,7 @@ struct block_device *blkdev_get_by_dev(dev_t dev, fmode_t mode, void *holder) disk = bdev->bd_disk; if (mode & FMODE_EXCL) { - ret = bd_prepare_to_claim(bdev, holder); + ret = bd_prepare_to_claim(bdev, holder, hops); if (ret) goto put_blkdev; } @@ -791,7 +808,7 @@ struct block_device *blkdev_get_by_dev(dev_t dev, fmode_t mode, void *holder) if (ret) goto put_module; if (mode & FMODE_EXCL) { - bd_finish_claiming(bdev, holder); + bd_finish_claiming(bdev, holder, hops); /* * Block event polling for write claims if requested. Any write @@ -842,7 +859,7 @@ EXPORT_SYMBOL(blkdev_get_by_dev); * Reference to the block_device on success, ERR_PTR(-errno) on failure. */ struct block_device *blkdev_get_by_path(const char *path, fmode_t mode, - void *holder) + void *holder, const struct blk_holder_ops *hops) { struct block_device *bdev; dev_t dev; @@ -852,7 +869,7 @@ struct block_device *blkdev_get_by_path(const char *path, fmode_t mode, if (error) return ERR_PTR(error); - bdev = blkdev_get_by_dev(dev, mode, holder); + bdev = blkdev_get_by_dev(dev, mode, holder, hops); if (!IS_ERR(bdev) && (mode & FMODE_WRITE) && bdev_read_only(bdev)) { blkdev_put(bdev, mode); return ERR_PTR(-EACCES); diff --git a/block/fops.c b/block/fops.c index b12c4b2a3a69f2..6a3087b750a6cd 100644 --- a/block/fops.c +++ b/block/fops.c @@ -490,7 +490,7 @@ static int blkdev_open(struct inode *inode, struct file *filp) if ((filp->f_flags & O_ACCMODE) == 3) filp->f_mode |= FMODE_WRITE_IOCTL; - bdev = blkdev_get_by_dev(inode->i_rdev, filp->f_mode, filp); + bdev = blkdev_get_by_dev(inode->i_rdev, filp->f_mode, filp, NULL); if (IS_ERR(bdev)) return PTR_ERR(bdev); diff --git a/block/genhd.c b/block/genhd.c index a668d2f0208766..b3bd58e9fbea81 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -370,13 +370,15 @@ int disk_scan_partitions(struct gendisk *disk, fmode_t mode) * scanners. */ if (!(mode & FMODE_EXCL)) { - ret = bd_prepare_to_claim(disk->part0, disk_scan_partitions); + ret = bd_prepare_to_claim(disk->part0, disk_scan_partitions, + NULL); if (ret) return ret; } set_bit(GD_NEED_PART_SCAN, &disk->state); - bdev = blkdev_get_by_dev(disk_devt(disk), mode & ~FMODE_EXCL, NULL); + bdev = blkdev_get_by_dev(disk_devt(disk), mode & ~FMODE_EXCL, NULL, + NULL); if (IS_ERR(bdev)) ret = PTR_ERR(bdev); else diff --git a/block/ioctl.c b/block/ioctl.c index 9c5f637ff153f8..c7d7d4345edb4f 100644 --- a/block/ioctl.c +++ b/block/ioctl.c @@ -454,7 +454,8 @@ static int blkdev_bszset(struct block_device *bdev, fmode_t mode, if (mode & FMODE_EXCL) return set_blocksize(bdev, n); - if (IS_ERR(blkdev_get_by_dev(bdev->bd_dev, mode | FMODE_EXCL, &bdev))) + if (IS_ERR(blkdev_get_by_dev(bdev->bd_dev, mode | FMODE_EXCL, &bdev, + NULL))) return -EBUSY; ret = set_blocksize(bdev, n); blkdev_put(bdev, mode | FMODE_EXCL); diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c index 1a5d3d72d91d27..cab59dab3410aa 100644 --- a/drivers/block/drbd/drbd_nl.c +++ b/drivers/block/drbd/drbd_nl.c @@ -1641,7 +1641,8 @@ static struct block_device *open_backing_dev(struct drbd_device *device, int err = 0; bdev = blkdev_get_by_path(bdev_path, - FMODE_READ | FMODE_WRITE | FMODE_EXCL, claim_ptr); + FMODE_READ | FMODE_WRITE | FMODE_EXCL, + claim_ptr, NULL); if (IS_ERR(bdev)) { drbd_err(device, "open(\"%s\") failed with %ld\n", bdev_path, PTR_ERR(bdev)); diff --git a/drivers/block/loop.c b/drivers/block/loop.c index bc31bb7072a2cb..a73c857f5bfed0 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -1015,7 +1015,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode, * here to avoid changing device under exclusive owner. */ if (!(mode & FMODE_EXCL)) { - error = bd_prepare_to_claim(bdev, loop_configure); + error = bd_prepare_to_claim(bdev, loop_configure, NULL); if (error) goto out_putf; } diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c index d5d7884cedd477..377f8b34535294 100644 --- a/drivers/block/pktcdvd.c +++ b/drivers/block/pktcdvd.c @@ -2125,7 +2125,8 @@ static int pkt_open_dev(struct pktcdvd_device *pd, fmode_t write) * to read/write from/to it. It is already opened in O_NONBLOCK mode * so open should not fail. */ - bdev = blkdev_get_by_dev(pd->bdev->bd_dev, FMODE_READ | FMODE_EXCL, pd); + bdev = blkdev_get_by_dev(pd->bdev->bd_dev, FMODE_READ | FMODE_EXCL, pd, + NULL); if (IS_ERR(bdev)) { ret = PTR_ERR(bdev); goto out; @@ -2530,7 +2531,7 @@ static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev) } } - bdev = blkdev_get_by_dev(dev, FMODE_READ | FMODE_NDELAY, NULL); + bdev = blkdev_get_by_dev(dev, FMODE_READ | FMODE_NDELAY, NULL, NULL); if (IS_ERR(bdev)) return PTR_ERR(bdev); sdev = scsi_device_from_queue(bdev->bd_disk->queue); diff --git a/drivers/block/rnbd/rnbd-srv.c b/drivers/block/rnbd/rnbd-srv.c index 2cfed2e58d646f..cec22bbae2f9a5 100644 --- a/drivers/block/rnbd/rnbd-srv.c +++ b/drivers/block/rnbd/rnbd-srv.c @@ -719,7 +719,7 @@ static int process_msg_open(struct rnbd_srv_session *srv_sess, goto reject; } - bdev = blkdev_get_by_path(full_path, open_flags, THIS_MODULE); + bdev = blkdev_get_by_path(full_path, open_flags, THIS_MODULE, NULL); if (IS_ERR(bdev)) { ret = PTR_ERR(bdev); pr_err("Opening device '%s' on session %s failed, failed to open the block device, err: %d\n", diff --git a/drivers/block/xen-blkback/xenbus.c b/drivers/block/xen-blkback/xenbus.c index 4807af1d580593..43b36da9b3544d 100644 --- a/drivers/block/xen-blkback/xenbus.c +++ b/drivers/block/xen-blkback/xenbus.c @@ -492,7 +492,7 @@ static int xen_vbd_create(struct xen_blkif *blkif, blkif_vdev_t handle, vbd->pdevice = MKDEV(major, minor); bdev = blkdev_get_by_dev(vbd->pdevice, vbd->readonly ? - FMODE_READ : FMODE_WRITE, NULL); + FMODE_READ : FMODE_WRITE, NULL, NULL); if (IS_ERR(bdev)) { pr_warn("xen_vbd_create: device %08x could not be opened\n", diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index b86691d2133ea8..0bc779446c6f8f 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -508,7 +508,7 @@ static ssize_t backing_dev_store(struct device *dev, } bdev = blkdev_get_by_dev(inode->i_rdev, - FMODE_READ | FMODE_WRITE | FMODE_EXCL, zram); + FMODE_READ | FMODE_WRITE | FMODE_EXCL, zram, NULL); if (IS_ERR(bdev)) { err = PTR_ERR(bdev); bdev = NULL; diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c index 7e9d19fd21ddd5..d84c09a73af803 100644 --- a/drivers/md/bcache/super.c +++ b/drivers/md/bcache/super.c @@ -2560,7 +2560,7 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr, err = "failed to open device"; bdev = blkdev_get_by_path(strim(path), FMODE_READ|FMODE_WRITE|FMODE_EXCL, - sb); + sb, NULL); if (IS_ERR(bdev)) { if (bdev == ERR_PTR(-EBUSY)) { dev_t dev; diff --git a/drivers/md/dm.c b/drivers/md/dm.c index 3b694ba3a106e6..d759f8bdb3df2f 100644 --- a/drivers/md/dm.c +++ b/drivers/md/dm.c @@ -746,7 +746,7 @@ static struct table_device *open_table_device(struct mapped_device *md, return ERR_PTR(-ENOMEM); refcount_set(&td->count, 1); - bdev = blkdev_get_by_dev(dev, mode | FMODE_EXCL, _dm_claim_ptr); + bdev = blkdev_get_by_dev(dev, mode | FMODE_EXCL, _dm_claim_ptr, NULL); if (IS_ERR(bdev)) { r = PTR_ERR(bdev); goto out_free_td; diff --git a/drivers/md/md.c b/drivers/md/md.c index 6a559a7e89c07f..fabf9c543735b6 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -3642,7 +3642,7 @@ static struct md_rdev *md_import_device(dev_t newdev, int super_format, int supe rdev->bdev = blkdev_get_by_dev(newdev, FMODE_READ | FMODE_WRITE | FMODE_EXCL, - super_format == -2 ? &claim_rdev : rdev); + super_format == -2 ? &claim_rdev : rdev, NULL); if (IS_ERR(rdev->bdev)) { pr_warn("md: could not open device unknown-block(%u,%u).\n", MAJOR(newdev), MINOR(newdev)); diff --git a/drivers/mtd/devices/block2mtd.c b/drivers/mtd/devices/block2mtd.c index 4cd37ec45762b6..7ac82c6fe35024 100644 --- a/drivers/mtd/devices/block2mtd.c +++ b/drivers/mtd/devices/block2mtd.c @@ -235,7 +235,7 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size, return NULL; /* Get a handle on the device */ - bdev = blkdev_get_by_path(devname, mode, dev); + bdev = blkdev_get_by_path(devname, mode, dev, NULL); #ifndef MODULE /* @@ -257,7 +257,7 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size, devt = name_to_dev_t(devname); if (!devt) continue; - bdev = blkdev_get_by_dev(devt, mode, dev); + bdev = blkdev_get_by_dev(devt, mode, dev, NULL); } #endif diff --git a/drivers/nvme/target/io-cmd-bdev.c b/drivers/nvme/target/io-cmd-bdev.c index c2d6cea0236b0a..9b6d6d85c72544 100644 --- a/drivers/nvme/target/io-cmd-bdev.c +++ b/drivers/nvme/target/io-cmd-bdev.c @@ -85,7 +85,7 @@ int nvmet_bdev_ns_enable(struct nvmet_ns *ns) return -ENOTBLK; ns->bdev = blkdev_get_by_path(ns->device_path, - FMODE_READ | FMODE_WRITE, NULL); + FMODE_READ | FMODE_WRITE, NULL, NULL); if (IS_ERR(ns->bdev)) { ret = PTR_ERR(ns->bdev); if (ret != -ENOTBLK) { diff --git a/drivers/s390/block/dasd_genhd.c b/drivers/s390/block/dasd_genhd.c index 998a961e170417..f21198bc483e1a 100644 --- a/drivers/s390/block/dasd_genhd.c +++ b/drivers/s390/block/dasd_genhd.c @@ -130,7 +130,7 @@ int dasd_scan_partitions(struct dasd_block *block) struct block_device *bdev; int rc; - bdev = blkdev_get_by_dev(disk_devt(block->gdp), FMODE_READ, NULL); + bdev = blkdev_get_by_dev(disk_devt(block->gdp), FMODE_READ, NULL, NULL); if (IS_ERR(bdev)) { DBF_DEV_EVENT(DBF_ERR, block->base, "scan partitions error, blkdev_get returned %ld", diff --git a/drivers/target/target_core_iblock.c b/drivers/target/target_core_iblock.c index cc838ffd129472..a5cbbefa78ee4e 100644 --- a/drivers/target/target_core_iblock.c +++ b/drivers/target/target_core_iblock.c @@ -114,7 +114,7 @@ static int iblock_configure_device(struct se_device *dev) else dev->dev_flags |= DF_READ_ONLY; - bd = blkdev_get_by_path(ib_dev->ibd_udev_path, mode, ib_dev); + bd = blkdev_get_by_path(ib_dev->ibd_udev_path, mode, ib_dev, NULL); if (IS_ERR(bd)) { ret = PTR_ERR(bd); goto out_free_bioset; diff --git a/drivers/target/target_core_pscsi.c b/drivers/target/target_core_pscsi.c index e7425549e39c73..e3494e036c6c85 100644 --- a/drivers/target/target_core_pscsi.c +++ b/drivers/target/target_core_pscsi.c @@ -367,7 +367,8 @@ static int pscsi_create_type_disk(struct se_device *dev, struct scsi_device *sd) * for TYPE_DISK and TYPE_ZBC using supplied udev_path */ bd = blkdev_get_by_path(dev->udev_path, - FMODE_WRITE|FMODE_READ|FMODE_EXCL, pdv); + FMODE_WRITE|FMODE_READ|FMODE_EXCL, pdv, + NULL); if (IS_ERR(bd)) { pr_err("pSCSI: blkdev_get_by_path() failed\n"); scsi_device_put(sd); diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c index 78696d331639bd..4de4984fa99ba3 100644 --- a/fs/btrfs/dev-replace.c +++ b/fs/btrfs/dev-replace.c @@ -258,7 +258,7 @@ static int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info, } bdev = blkdev_get_by_path(device_path, FMODE_WRITE | FMODE_EXCL, - fs_info->bdev_holder); + fs_info->bdev_holder, NULL); if (IS_ERR(bdev)) { btrfs_err(fs_info, "target device %s is invalid!", device_path); return PTR_ERR(bdev); diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 841e799dece51b..784ccc8f6c69c1 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -496,7 +496,7 @@ btrfs_get_bdev_and_sb(const char *device_path, fmode_t flags, void *holder, { int ret; - *bdev = blkdev_get_by_path(device_path, flags, holder); + *bdev = blkdev_get_by_path(device_path, flags, holder, NULL); if (IS_ERR(*bdev)) { ret = PTR_ERR(*bdev); @@ -1377,7 +1377,7 @@ struct btrfs_device *btrfs_scan_one_device(const char *path, fmode_t flags, * values temporarily, as the device paths of the fsid are the only * required information for assembling the volume. */ - bdev = blkdev_get_by_path(path, flags, holder); + bdev = blkdev_get_by_path(path, flags, holder, NULL); if (IS_ERR(bdev)) return ERR_CAST(bdev); @@ -2629,7 +2629,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path return -EROFS; bdev = blkdev_get_by_path(device_path, FMODE_WRITE | FMODE_EXCL, - fs_info->bdev_holder); + fs_info->bdev_holder, NULL); if (IS_ERR(bdev)) return PTR_ERR(bdev); diff --git a/fs/erofs/super.c b/fs/erofs/super.c index 811ab66d805ede..6c263e9cd38b2a 100644 --- a/fs/erofs/super.c +++ b/fs/erofs/super.c @@ -254,7 +254,7 @@ static int erofs_init_device(struct erofs_buf *buf, struct super_block *sb, dif->fscache = fscache; } else if (!sbi->devs->flatdev) { bdev = blkdev_get_by_path(dif->path, FMODE_READ | FMODE_EXCL, - sb->s_type); + sb->s_type, NULL); if (IS_ERR(bdev)) return PTR_ERR(bdev); dif->bdev = bdev; diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 9680fe753e599a..865625089ecca3 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -1103,7 +1103,8 @@ static struct block_device *ext4_blkdev_get(dev_t dev, struct super_block *sb) { struct block_device *bdev; - bdev = blkdev_get_by_dev(dev, FMODE_READ|FMODE_WRITE|FMODE_EXCL, sb); + bdev = blkdev_get_by_dev(dev, FMODE_READ|FMODE_WRITE|FMODE_EXCL, sb, + NULL); if (IS_ERR(bdev)) goto fail; return bdev; diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 9f15b03037dba9..7c34ab082f1382 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -4025,7 +4025,7 @@ static int f2fs_scan_devices(struct f2fs_sb_info *sbi) /* Single zoned block device mount */ FDEV(0).bdev = blkdev_get_by_dev(sbi->sb->s_bdev->bd_dev, - sbi->sb->s_mode, sbi->sb->s_type); + sbi->sb->s_mode, sbi->sb->s_type, NULL); } else { /* Multi-device mount */ memcpy(FDEV(i).path, RDEV(i).path, MAX_PATH_LEN); @@ -4044,7 +4044,7 @@ static int f2fs_scan_devices(struct f2fs_sb_info *sbi) sbi->log_blocks_per_seg) - 1; } FDEV(i).bdev = blkdev_get_by_path(FDEV(i).path, - sbi->sb->s_mode, sbi->sb->s_type); + sbi->sb->s_mode, sbi->sb->s_type, NULL); } if (IS_ERR(FDEV(i).bdev)) return PTR_ERR(FDEV(i).bdev); diff --git a/fs/jfs/jfs_logmgr.c b/fs/jfs/jfs_logmgr.c index 15c645827decae..46d393c8088a74 100644 --- a/fs/jfs/jfs_logmgr.c +++ b/fs/jfs/jfs_logmgr.c @@ -1101,7 +1101,7 @@ int lmLogOpen(struct super_block *sb) */ bdev = blkdev_get_by_dev(sbi->logdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL, - log); + log, NULL); if (IS_ERR(bdev)) { rc = PTR_ERR(bdev); goto free; diff --git a/fs/nfs/blocklayout/dev.c b/fs/nfs/blocklayout/dev.c index fea5f8821da5ef..38b066ca699ed7 100644 --- a/fs/nfs/blocklayout/dev.c +++ b/fs/nfs/blocklayout/dev.c @@ -243,7 +243,7 @@ bl_parse_simple(struct nfs_server *server, struct pnfs_block_dev *d, if (!dev) return -EIO; - bdev = blkdev_get_by_dev(dev, FMODE_READ | FMODE_WRITE, NULL); + bdev = blkdev_get_by_dev(dev, FMODE_READ | FMODE_WRITE, NULL, NULL); if (IS_ERR(bdev)) { printk(KERN_WARNING "pNFS: failed to open device %d:%d (%ld)\n", MAJOR(dev), MINOR(dev), PTR_ERR(bdev)); @@ -312,7 +312,8 @@ bl_open_path(struct pnfs_block_volume *v, const char *prefix) if (!devname) return ERR_PTR(-ENOMEM); - bdev = blkdev_get_by_path(devname, FMODE_READ | FMODE_WRITE, NULL); + bdev = blkdev_get_by_path(devname, FMODE_READ | FMODE_WRITE, NULL, + NULL); if (IS_ERR(bdev)) { pr_warn("pNFS: failed to open device %s (%ld)\n", devname, PTR_ERR(bdev)); diff --git a/fs/nilfs2/super.c b/fs/nilfs2/super.c index 77f1e5778d1c84..91bfbd973d1d53 100644 --- a/fs/nilfs2/super.c +++ b/fs/nilfs2/super.c @@ -1285,7 +1285,7 @@ nilfs_mount(struct file_system_type *fs_type, int flags, if (!(flags & SB_RDONLY)) mode |= FMODE_WRITE; - sd.bdev = blkdev_get_by_path(dev_name, mode, fs_type); + sd.bdev = blkdev_get_by_path(dev_name, mode, fs_type, NULL); if (IS_ERR(sd.bdev)) return ERR_CAST(sd.bdev); diff --git a/fs/ocfs2/cluster/heartbeat.c b/fs/ocfs2/cluster/heartbeat.c index 60b97c92e2b25e..6b13b8c3f2b8af 100644 --- a/fs/ocfs2/cluster/heartbeat.c +++ b/fs/ocfs2/cluster/heartbeat.c @@ -1786,7 +1786,7 @@ static ssize_t o2hb_region_dev_store(struct config_item *item, goto out2; reg->hr_bdev = blkdev_get_by_dev(f.file->f_mapping->host->i_rdev, - FMODE_WRITE | FMODE_READ, NULL); + FMODE_WRITE | FMODE_READ, NULL, NULL); if (IS_ERR(reg->hr_bdev)) { ret = PTR_ERR(reg->hr_bdev); reg->hr_bdev = NULL; diff --git a/fs/reiserfs/journal.c b/fs/reiserfs/journal.c index 4d11d60f493c14..5e4db9a0c8e5a3 100644 --- a/fs/reiserfs/journal.c +++ b/fs/reiserfs/journal.c @@ -2616,7 +2616,7 @@ static int journal_init_dev(struct super_block *super, if (jdev == super->s_dev) blkdev_mode &= ~FMODE_EXCL; journal->j_dev_bd = blkdev_get_by_dev(jdev, blkdev_mode, - journal); + journal, NULL); journal->j_dev_mode = blkdev_mode; if (IS_ERR(journal->j_dev_bd)) { result = PTR_ERR(journal->j_dev_bd); @@ -2632,7 +2632,8 @@ static int journal_init_dev(struct super_block *super, } journal->j_dev_mode = blkdev_mode; - journal->j_dev_bd = blkdev_get_by_path(jdev_name, blkdev_mode, journal); + journal->j_dev_bd = blkdev_get_by_path(jdev_name, blkdev_mode, journal, + NULL); if (IS_ERR(journal->j_dev_bd)) { result = PTR_ERR(journal->j_dev_bd); journal->j_dev_bd = NULL; diff --git a/fs/super.c b/fs/super.c index 34afe411cf2bc3..012ce140080375 100644 --- a/fs/super.c +++ b/fs/super.c @@ -1248,7 +1248,7 @@ int get_tree_bdev(struct fs_context *fc, if (!fc->source) return invalf(fc, "No source specified"); - bdev = blkdev_get_by_path(fc->source, mode, fc->fs_type); + bdev = blkdev_get_by_path(fc->source, mode, fc->fs_type, NULL); if (IS_ERR(bdev)) { errorf(fc, "%s: Can't open blockdev", fc->source); return PTR_ERR(bdev); @@ -1333,7 +1333,7 @@ struct dentry *mount_bdev(struct file_system_type *fs_type, if (!(flags & SB_RDONLY)) mode |= FMODE_WRITE; - bdev = blkdev_get_by_path(dev_name, mode, fs_type); + bdev = blkdev_get_by_path(dev_name, mode, fs_type, NULL); if (IS_ERR(bdev)) return ERR_CAST(bdev); diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c index 7e706255f16502..5684c538eb76dc 100644 --- a/fs/xfs/xfs_super.c +++ b/fs/xfs/xfs_super.c @@ -386,7 +386,7 @@ xfs_blkdev_get( int error = 0; *bdevp = blkdev_get_by_path(name, FMODE_READ|FMODE_WRITE|FMODE_EXCL, - mp); + mp, NULL); if (IS_ERR(*bdevp)) { error = PTR_ERR(*bdevp); xfs_warn(mp, "Invalid device [%s], error=%d", name, error); diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h index 8ef209e3aa96b8..deb69eeab6bd7b 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -55,6 +55,8 @@ struct block_device { struct super_block * bd_super; void * bd_claiming; void * bd_holder; + const struct blk_holder_ops *bd_holder_ops; + struct mutex bd_holder_lock; /* The counter of freeze processes */ int bd_fsfreeze_count; int bd_holders; diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index d89c2da1469872..44f2a8bc57e87a 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1470,10 +1470,15 @@ void blkdev_show(struct seq_file *seqf, off_t offset); #define BLKDEV_MAJOR_MAX 0 #endif +struct blk_holder_ops { +}; + +struct block_device *blkdev_get_by_dev(dev_t dev, fmode_t mode, void *holder, + const struct blk_holder_ops *hops); struct block_device *blkdev_get_by_path(const char *path, fmode_t mode, - void *holder); -struct block_device *blkdev_get_by_dev(dev_t dev, fmode_t mode, void *holder); -int bd_prepare_to_claim(struct block_device *bdev, void *holder); + void *holder, const struct blk_holder_ops *hops); +int bd_prepare_to_claim(struct block_device *bdev, void *holder, + const struct blk_holder_ops *hops); void bd_abort_claiming(struct block_device *bdev, void *holder); void blkdev_put(struct block_device *bdev, fmode_t mode); diff --git a/kernel/power/swap.c b/kernel/power/swap.c index 92e41ed292ada8..801c411530d11c 100644 --- a/kernel/power/swap.c +++ b/kernel/power/swap.c @@ -357,7 +357,7 @@ static int swsusp_swap_check(void) root_swap = res; hib_resume_bdev = blkdev_get_by_dev(swsusp_resume_device, FMODE_WRITE, - NULL); + NULL, NULL); if (IS_ERR(hib_resume_bdev)) return PTR_ERR(hib_resume_bdev); @@ -1524,7 +1524,7 @@ int swsusp_check(void) mode |= FMODE_EXCL; hib_resume_bdev = blkdev_get_by_dev(swsusp_resume_device, - mode, &holder); + mode, &holder, NULL); if (!IS_ERR(hib_resume_bdev)) { set_blocksize(hib_resume_bdev, PAGE_SIZE); clear_page(swsusp_header); diff --git a/mm/swapfile.c b/mm/swapfile.c index 274bbf79748006..cfbcf7d5705f5f 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -2770,7 +2770,8 @@ static int claim_swapfile(struct swap_info_struct *p, struct inode *inode) if (S_ISBLK(inode->i_mode)) { p->bdev = blkdev_get_by_dev(inode->i_rdev, - FMODE_READ | FMODE_WRITE | FMODE_EXCL, p); + FMODE_READ | FMODE_WRITE | FMODE_EXCL, p, + NULL); if (IS_ERR(p->bdev)) { error = PTR_ERR(p->bdev); p->bdev = NULL; From patchwork Thu Jun 1 09:44:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13263296 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 CFE3FC7EE31 for ; Thu, 1 Jun 2023 09:46:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232973AbjFAJqN (ORCPT ); Thu, 1 Jun 2023 05:46:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233009AbjFAJqF (ORCPT ); Thu, 1 Jun 2023 05:46:05 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C954318F; Thu, 1 Jun 2023 02:45:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=uji49NISUXA3b1CGkfgLmKYelXNUqo0hJhPSfZVmd/M=; b=FLD0ugsB345Ynp8E1wqc6OcZmD AETZbquOfDgN12f+OnhaTDBqUokXiLEQuRovE885ijdadyQHIQK3htBhFPRGdNVDV/VWBKkHv3/lu rCSYB+yRNegjmtPoHz5fUfVC261qvoynmPNmO4D1R80mM/68nm8Q83Ny6sMNJ//H/JK2Vn20qS3+e QbayGLNqwu9FTL1YQCjYGwKi3Yj49xJ11pgt5I/9yF3NmxyYHKYLCvKYJ51OEmuY6teP7+tE4UxzQ h/Y6VBTjvadbp2bCfjxOQHN86ti0AbTc9oH4CHd/q9P02I9iQoXTamSN3GErQ8ahmERYpFBPil9Eh nEjlEuzg==; Received: from [2001:4bb8:182:6d06:35f3:1da0:1cc3:d86d] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1q4esU-002m7Z-0y; Thu, 01 Jun 2023 09:45:55 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Al Viro , Christian Brauner , "Darrick J. Wong" , Jan Kara , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org Subject: [PATCH 10/16] block: add a mark_dead holder operation Date: Thu, 1 Jun 2023 11:44:53 +0200 Message-Id: <20230601094459.1350643-11-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230601094459.1350643-1-hch@lst.de> References: <20230601094459.1350643-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org Add a mark_dead method to blk_holder_ops that is called from blk_mark_disk_dead to notify the holder that the block device it is using has been marked dead. Signed-off-by: Christoph Hellwig Reviewed-by: Jan Kara Acked-by: Christian Brauner --- block/genhd.c | 24 ++++++++++++++++++++++++ include/linux/blkdev.h | 1 + 2 files changed, 25 insertions(+) diff --git a/block/genhd.c b/block/genhd.c index b3bd58e9fbea81..a07c4d6a147637 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -565,6 +565,28 @@ int __must_check device_add_disk(struct device *parent, struct gendisk *disk, } EXPORT_SYMBOL(device_add_disk); +static void blk_report_disk_dead(struct gendisk *disk) +{ + struct block_device *bdev; + unsigned long idx; + + rcu_read_lock(); + xa_for_each(&disk->part_tbl, idx, bdev) { + if (!kobject_get_unless_zero(&bdev->bd_device.kobj)) + continue; + rcu_read_unlock(); + + mutex_lock(&bdev->bd_holder_lock); + if (bdev->bd_holder_ops && bdev->bd_holder_ops->mark_dead) + bdev->bd_holder_ops->mark_dead(bdev); + mutex_unlock(&bdev->bd_holder_lock); + + put_device(&bdev->bd_device); + rcu_read_lock(); + } + rcu_read_unlock(); +} + /** * blk_mark_disk_dead - mark a disk as dead * @disk: disk to mark as dead @@ -592,6 +614,8 @@ void blk_mark_disk_dead(struct gendisk *disk) * Prevent new I/O from crossing bio_queue_enter(). */ blk_queue_start_drain(disk->queue); + + blk_report_disk_dead(disk); } EXPORT_SYMBOL_GPL(blk_mark_disk_dead); diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 44f2a8bc57e87a..9e9a9e4edee94b 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1471,6 +1471,7 @@ void blkdev_show(struct seq_file *seqf, off_t offset); #endif struct blk_holder_ops { + void (*mark_dead)(struct block_device *bdev); }; struct block_device *blkdev_get_by_dev(dev_t dev, fmode_t mode, void *holder, From patchwork Thu Jun 1 09:44:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13263298 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 BB8B8C7EE2F for ; Thu, 1 Jun 2023 09:46:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233001AbjFAJqO (ORCPT ); Thu, 1 Jun 2023 05:46:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233015AbjFAJqG (ORCPT ); Thu, 1 Jun 2023 05:46:06 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 969441B3; Thu, 1 Jun 2023 02:46:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=OGA7f031kFADrJGGT06ylVmkFQ8CdWb4JhvLV6YeomQ=; b=QsawpHD8NF4+PPKCXVRh7DGKLz 3TwxbjTUzfhQ4hEcl4N/2yT7/RdlVCczkjdVkXTm6EpLM5QvyEH1dPrySos1uU26P+QTrBm6X3DrI b4yx3C8lhb71we9YluY/4jpyrbZ1yJewvnZQoQ+0TQLY+zeYCV8hsvRXdsO1v27HOo9HT47hVvCwt V7pdE2CU2iqUZtZ7X3WdjoifqMlSQCEaXRB8AMwkAGCRPiHEc+tegq3qajIaZhtZ+VL0lkmTwVYCV TLBW4mftgNPKtggJlIdpPWLmedoJv9xdEw64GlXnOOFWbvi0wulLvQh4fzGjTh/JARTUwm+DF7T/4 jiMzf7XA==; Received: from [2001:4bb8:182:6d06:35f3:1da0:1cc3:d86d] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1q4esY-002m8o-2u; Thu, 01 Jun 2023 09:45:59 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Al Viro , Christian Brauner , "Darrick J. Wong" , Jan Kara , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org Subject: [PATCH 11/16] fs: add a method to shut down the file system Date: Thu, 1 Jun 2023 11:44:54 +0200 Message-Id: <20230601094459.1350643-12-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230601094459.1350643-1-hch@lst.de> References: <20230601094459.1350643-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org Add a new ->shutdown super operation that can be used to tell the file system to shut down, and call it from newly created holder ops when the block device under a file system shuts down. This only covers the main block device for "simple" file systems using get_tree_bdev / mount_bdev. File systems their own get_tree method or opening additional devices will need to set up their own blk_holder_ops. Signed-off-by: Christoph Hellwig Reviewed-by: Christian Brauner Reviewed-by: Jan Kara Reviewed-by: Darrick J. Wong --- fs/super.c | 21 +++++++++++++++++++-- include/linux/fs.h | 1 + 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/fs/super.c b/fs/super.c index 012ce140080375..f127589700ab25 100644 --- a/fs/super.c +++ b/fs/super.c @@ -1206,6 +1206,22 @@ int get_tree_keyed(struct fs_context *fc, EXPORT_SYMBOL(get_tree_keyed); #ifdef CONFIG_BLOCK +static void fs_mark_dead(struct block_device *bdev) +{ + struct super_block *sb; + + sb = get_super(bdev); + if (!sb) + return; + + if (sb->s_op->shutdown) + sb->s_op->shutdown(sb); + drop_super(sb); +} + +static const struct blk_holder_ops fs_holder_ops = { + .mark_dead = fs_mark_dead, +}; static int set_bdev_super(struct super_block *s, void *data) { @@ -1248,7 +1264,8 @@ int get_tree_bdev(struct fs_context *fc, if (!fc->source) return invalf(fc, "No source specified"); - bdev = blkdev_get_by_path(fc->source, mode, fc->fs_type, NULL); + bdev = blkdev_get_by_path(fc->source, mode, fc->fs_type, + &fs_holder_ops); if (IS_ERR(bdev)) { errorf(fc, "%s: Can't open blockdev", fc->source); return PTR_ERR(bdev); @@ -1333,7 +1350,7 @@ struct dentry *mount_bdev(struct file_system_type *fs_type, if (!(flags & SB_RDONLY)) mode |= FMODE_WRITE; - bdev = blkdev_get_by_path(dev_name, mode, fs_type, NULL); + bdev = blkdev_get_by_path(dev_name, mode, fs_type, &fs_holder_ops); if (IS_ERR(bdev)) return ERR_CAST(bdev); diff --git a/include/linux/fs.h b/include/linux/fs.h index 08ba2ae1d3ce97..7b2053649820cc 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1932,6 +1932,7 @@ struct super_operations { struct shrink_control *); long (*free_cached_objects)(struct super_block *, struct shrink_control *); + void (*shutdown)(struct super_block *sb); }; /* From patchwork Thu Jun 1 09:44:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13263299 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 27C89C7EE23 for ; Thu, 1 Jun 2023 09:46:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232881AbjFAJqc (ORCPT ); Thu, 1 Jun 2023 05:46:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232907AbjFAJqL (ORCPT ); Thu, 1 Jun 2023 05:46:11 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB05F1A8; Thu, 1 Jun 2023 02:46:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=ly1OH3STszGSSSQ6fRDIkHpi8u8Y0rhOG+JcBsmb7/Y=; b=fd3FBkPdowM60v6h3B3JoyFAcY 30S8x2OzFvmBaPz+De47fm4gRR+nEgpZed1MGolzmEeyEvPbSp5dEF0hF2nFQ2MYYMmUThDxTJaZ+ Is3EBXoteNbs4J8uI6V7Cr3o7ZzoGQmuMQb8voMgpr3sfL5uJEGnAq4PWRfTKGXPPYfI1jqH2M98m nsj2rIVf8ewnTum1HV/As37yPDmKEx3NEtfWSTcYVRvqv2w05AMruHAkGNbq8KWfJeoq8zsMeBwQ0 pML3uDdg9OTURI4cX2QDNQvMU341f/1BYPSPCLhMo/IegO4iJDnipJyD3Y5hZWn8CoXzJVeJSGhuc KsLw/r2w==; Received: from [2001:4bb8:182:6d06:35f3:1da0:1cc3:d86d] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1q4esf-002m9r-08; Thu, 01 Jun 2023 09:46:06 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Al Viro , Christian Brauner , "Darrick J. Wong" , Jan Kara , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org Subject: [PATCH 12/16] xfs: wire up sops->shutdown Date: Thu, 1 Jun 2023 11:44:55 +0200 Message-Id: <20230601094459.1350643-13-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230601094459.1350643-1-hch@lst.de> References: <20230601094459.1350643-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org Wire up the shutdown method to shut down the file system when the underlying block device is marked dead. Add a new message to clearly distinguish this shutdown reason from other shutdowns. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong --- fs/xfs/xfs_fsops.c | 3 +++ fs/xfs/xfs_mount.h | 4 +++- fs/xfs/xfs_super.c | 8 ++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/fs/xfs/xfs_fsops.c b/fs/xfs/xfs_fsops.c index 13851c0d640bc8..9ebb8333a30800 100644 --- a/fs/xfs/xfs_fsops.c +++ b/fs/xfs/xfs_fsops.c @@ -534,6 +534,9 @@ xfs_do_force_shutdown( } else if (flags & SHUTDOWN_CORRUPT_ONDISK) { tag = XFS_PTAG_SHUTDOWN_CORRUPT; why = "Corruption of on-disk metadata"; + } else if (flags & SHUTDOWN_DEVICE_REMOVED) { + tag = XFS_PTAG_SHUTDOWN_IOERROR; + why = "Block device removal"; } else { tag = XFS_PTAG_SHUTDOWN_IOERROR; why = "Metadata I/O Error"; diff --git a/fs/xfs/xfs_mount.h b/fs/xfs/xfs_mount.h index aaaf5ec13492d2..429a5e12c1036e 100644 --- a/fs/xfs/xfs_mount.h +++ b/fs/xfs/xfs_mount.h @@ -457,12 +457,14 @@ void xfs_do_force_shutdown(struct xfs_mount *mp, uint32_t flags, char *fname, #define SHUTDOWN_FORCE_UMOUNT (1u << 2) /* shutdown from a forced unmount */ #define SHUTDOWN_CORRUPT_INCORE (1u << 3) /* corrupt in-memory structures */ #define SHUTDOWN_CORRUPT_ONDISK (1u << 4) /* corrupt metadata on device */ +#define SHUTDOWN_DEVICE_REMOVED (1u << 5) /* device removed underneath us */ #define XFS_SHUTDOWN_STRINGS \ { SHUTDOWN_META_IO_ERROR, "metadata_io" }, \ { SHUTDOWN_LOG_IO_ERROR, "log_io" }, \ { SHUTDOWN_FORCE_UMOUNT, "force_umount" }, \ - { SHUTDOWN_CORRUPT_INCORE, "corruption" } + { SHUTDOWN_CORRUPT_INCORE, "corruption" }, \ + { SHUTDOWN_DEVICE_REMOVED, "device_removed" } /* * Flags for xfs_mountfs diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c index 5684c538eb76dc..eb469b8f9a0497 100644 --- a/fs/xfs/xfs_super.c +++ b/fs/xfs/xfs_super.c @@ -1159,6 +1159,13 @@ xfs_fs_free_cached_objects( return xfs_reclaim_inodes_nr(XFS_M(sb), sc->nr_to_scan); } +static void +xfs_fs_shutdown( + struct super_block *sb) +{ + xfs_force_shutdown(XFS_M(sb), SHUTDOWN_DEVICE_REMOVED); +} + static const struct super_operations xfs_super_operations = { .alloc_inode = xfs_fs_alloc_inode, .destroy_inode = xfs_fs_destroy_inode, @@ -1172,6 +1179,7 @@ static const struct super_operations xfs_super_operations = { .show_options = xfs_fs_show_options, .nr_cached_objects = xfs_fs_nr_cached_objects, .free_cached_objects = xfs_fs_free_cached_objects, + .shutdown = xfs_fs_shutdown, }; static int From patchwork Thu Jun 1 09:44:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13263300 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 BC19EC77B7E for ; Thu, 1 Jun 2023 09:46:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233009AbjFAJqh (ORCPT ); Thu, 1 Jun 2023 05:46:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233011AbjFAJqQ (ORCPT ); Thu, 1 Jun 2023 05:46:16 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0118A134; Thu, 1 Jun 2023 02:46:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=zztO8WxLu2RClT/8Y5S0j/gxpaEYqpI3KKJwpryT2rg=; b=rfRX7SxcH1Hdnw8ku4tKhidjy0 ywyrIBljbCLRy2e4sRbVz0kh8ljzPMM4ax1zT+tUe7yx1gjxr1ELZ4cHNkKfBi7aFvZwf5WC0xuHJ Cc1TLU+azQGty9t+jFsD+fzt5remWr4lkdNHESN/o2o/jr0h0UzhlUOq/+59RkOZqCpLRHZ/ybSe0 YBAMcmkgDWo6q1s9IcObT0YioJHc8YktwmSjdtb+D29ySmK9DzwWKKsWIlTALeXXhrPxth1oOUvD7 nD2Eh7LSqF2ddMIPJhuVQTNnGxEpW3i36AriC1IhCjOVNC9YDbyB5sdVZAKyLlMyDMPnK8dojMJY5 HmemP0Rg==; Received: from [2001:4bb8:182:6d06:35f3:1da0:1cc3:d86d] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1q4esl-002mAN-0e; Thu, 01 Jun 2023 09:46:12 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Al Viro , Christian Brauner , "Darrick J. Wong" , Jan Kara , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org Subject: [PATCH 13/16] xfs: wire up the ->mark_dead holder operation for log and RT devices Date: Thu, 1 Jun 2023 11:44:56 +0200 Message-Id: <20230601094459.1350643-14-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230601094459.1350643-1-hch@lst.de> References: <20230601094459.1350643-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org Implement a set of holder_ops that shut down the file system when the block device used as log or RT device is removed undeneath the file system. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong --- fs/xfs/xfs_super.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c index eb469b8f9a0497..1b4bd5c88f4a11 100644 --- a/fs/xfs/xfs_super.c +++ b/fs/xfs/xfs_super.c @@ -377,6 +377,17 @@ xfs_setup_dax_always( return 0; } +static void +xfs_bdev_mark_dead( + struct block_device *bdev) +{ + xfs_force_shutdown(bdev->bd_holder, SHUTDOWN_DEVICE_REMOVED); +} + +static const struct blk_holder_ops xfs_holder_ops = { + .mark_dead = xfs_bdev_mark_dead, +}; + STATIC int xfs_blkdev_get( xfs_mount_t *mp, @@ -386,7 +397,7 @@ xfs_blkdev_get( int error = 0; *bdevp = blkdev_get_by_path(name, FMODE_READ|FMODE_WRITE|FMODE_EXCL, - mp, NULL); + mp, &xfs_holder_ops); if (IS_ERR(*bdevp)) { error = PTR_ERR(*bdevp); xfs_warn(mp, "Invalid device [%s], error=%d", name, error); From patchwork Thu Jun 1 09:44:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13263301 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 296BCC7EE2F for ; Thu, 1 Jun 2023 09:46:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233014AbjFAJqi (ORCPT ); Thu, 1 Jun 2023 05:46:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233016AbjFAJqU (ORCPT ); Thu, 1 Jun 2023 05:46:20 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A2E2138; Thu, 1 Jun 2023 02:46:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=Qfuay10AzkmA8DYupLvHg2nTBv/KnX5g5wKQF7ueM4o=; b=cHjl0o/9Srq1e+L+HNiuLViu4O Z5kCmnaomYKlFSR24zlJsKkmY7WFQnpl19MDpA5h+AVV8YfCuKmkHRChRcxDK9Nknm4/jV5OnBC7U R5EG9B1zfnYP/55SzK8WDAg9vMHUimEXq+6OqaztURies2iniANZGUjZYGojAj69UaMYjNWE9iPWm HzluJIiEjHAT+tQHUQ9FoayWZMC6AlC5KJauuhDuTFYj3zG+QCJhEKsnmH5QvWVv3ei4zjYKqcSoM 1JPDjD0K6gvUXvCz2usFFcrKbRQCtOYX6JNKtsDl+TNsatcvdSsaxeGP/MZoWjBdFo0qKYc4aqLzp JvqpETwQ==; Received: from [2001:4bb8:182:6d06:35f3:1da0:1cc3:d86d] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1q4esq-002mBV-1f; Thu, 01 Jun 2023 09:46:17 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Al Viro , Christian Brauner , "Darrick J. Wong" , Jan Kara , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org Subject: [PATCH 14/16] ext4: split ext4_shutdown Date: Thu, 1 Jun 2023 11:44:57 +0200 Message-Id: <20230601094459.1350643-15-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230601094459.1350643-1-hch@lst.de> References: <20230601094459.1350643-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org Split ext4_shutdown into a low-level helper that will be reused for implementing the shutdown super operation and a wrapper for the ioctl handling. Signed-off-by: Christoph Hellwig Reviewed-by: Jan Kara --- fs/ext4/ext4.h | 1 + fs/ext4/ioctl.c | 24 +++++++++++++++--------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 6948d673bba2e8..2d60bbe8d171d9 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -2965,6 +2965,7 @@ int ext4_fileattr_set(struct mnt_idmap *idmap, int ext4_fileattr_get(struct dentry *dentry, struct fileattr *fa); extern void ext4_reset_inode_seed(struct inode *inode); int ext4_update_overhead(struct super_block *sb, bool force); +int ext4_force_shutdown(struct super_block *sb, u32 flags); /* migrate.c */ extern int ext4_ext_migrate(struct inode *); diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c index f9a43015206323..961284cc9b65cc 100644 --- a/fs/ext4/ioctl.c +++ b/fs/ext4/ioctl.c @@ -793,16 +793,9 @@ static int ext4_ioctl_setproject(struct inode *inode, __u32 projid) } #endif -static int ext4_shutdown(struct super_block *sb, unsigned long arg) +int ext4_force_shutdown(struct super_block *sb, u32 flags) { struct ext4_sb_info *sbi = EXT4_SB(sb); - __u32 flags; - - if (!capable(CAP_SYS_ADMIN)) - return -EPERM; - - if (get_user(flags, (__u32 __user *)arg)) - return -EFAULT; if (flags > EXT4_GOING_FLAGS_NOLOGFLUSH) return -EINVAL; @@ -838,6 +831,19 @@ static int ext4_shutdown(struct super_block *sb, unsigned long arg) return 0; } +static int ext4_ioctl_shutdown(struct super_block *sb, unsigned long arg) +{ + u32 flags; + + if (!capable(CAP_SYS_ADMIN)) + return -EPERM; + + if (get_user(flags, (__u32 __user *)arg)) + return -EFAULT; + + return ext4_force_shutdown(sb, flags); +} + struct getfsmap_info { struct super_block *gi_sb; struct fsmap_head __user *gi_data; @@ -1566,7 +1572,7 @@ static long __ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) return ext4_ioctl_get_es_cache(filp, arg); case EXT4_IOC_SHUTDOWN: - return ext4_shutdown(sb, arg); + return ext4_ioctl_shutdown(sb, arg); case FS_IOC_ENABLE_VERITY: if (!ext4_has_feature_verity(sb)) From patchwork Thu Jun 1 09:44:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13263302 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 105C3C7EE29 for ; Thu, 1 Jun 2023 09:46:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233029AbjFAJql (ORCPT ); Thu, 1 Jun 2023 05:46:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233030AbjFAJqZ (ORCPT ); Thu, 1 Jun 2023 05:46:25 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E959A195; Thu, 1 Jun 2023 02:46:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=92H2SuIqaLTdF0yqiMnFtm3c7m1gbxKAE17NACokr8Q=; b=IIgbZyPgdehBxCmCC21JhGrr2t ZNL90glx6BblQPSfM+8aXSfvGcsqfCEwG65nWX1ah8xRfXWhDbDUBhnFjqff5E79C0eF2LEevk7h5 HnzMRwKYNuxyHwC82KU/WveHqpT5R7rRlDTaNylPARjI7eUYsSz2LCBW/FyKjsTXPWq0P3fPFzjlO cXcoRgltFbNP9rH4SnCGouptlcHbkfd/hUl9Ox184mTOmoC1+FwQxiC96BnBVw03X1gzz6H0Xmspd ewHnXNc25B7nfLLnpPYADgQrVggC6I0rnkE5V/Aea9M5x5Uw3j6OqymdZ7pTGXO/Pgj1nCNEqF4w/ HqQywp0g==; Received: from [2001:4bb8:182:6d06:35f3:1da0:1cc3:d86d] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1q4esw-002mDR-1V; Thu, 01 Jun 2023 09:46:23 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Al Viro , Christian Brauner , "Darrick J. Wong" , Jan Kara , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org Subject: [PATCH 15/16] ext4: wire up sops->shutdown Date: Thu, 1 Jun 2023 11:44:58 +0200 Message-Id: <20230601094459.1350643-16-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230601094459.1350643-1-hch@lst.de> References: <20230601094459.1350643-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org Wire up the shutdown method to shut down the file system when the underlying block device is marked dead. Signed-off-by: Christoph Hellwig Reviewed-by: Jan Kara --- fs/ext4/super.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 865625089ecca3..a177a16c4d2fe5 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -1450,6 +1450,11 @@ static void ext4_destroy_inode(struct inode *inode) EXT4_I(inode)->i_reserved_data_blocks); } +static void ext4_shutdown(struct super_block *sb) +{ + ext4_force_shutdown(sb, EXT4_GOING_FLAGS_NOLOGFLUSH); +} + static void init_once(void *foo) { struct ext4_inode_info *ei = foo; @@ -1610,6 +1615,7 @@ static const struct super_operations ext4_sops = { .unfreeze_fs = ext4_unfreeze, .statfs = ext4_statfs, .show_options = ext4_show_options, + .shutdown = ext4_shutdown, #ifdef CONFIG_QUOTA .quota_read = ext4_quota_read, .quota_write = ext4_quota_write, From patchwork Thu Jun 1 09:44:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13263303 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 E5565C7EE2F for ; Thu, 1 Jun 2023 09:46:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232907AbjFAJqp (ORCPT ); Thu, 1 Jun 2023 05:46:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232994AbjFAJqa (ORCPT ); Thu, 1 Jun 2023 05:46:30 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CDE72198; Thu, 1 Jun 2023 02:46:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=U4TjS8hJ35XHd5owLFnLOorlk910Gs34ZQ7m5GZkWrQ=; b=AW37rgIICwNhWS4cQhU/rOeDtl Fc+pKGDwxbMkx0yfrdUfBJETxBAGp2L+FpFX21n05hR40fvZFcvzDwgR4mGclRFIE0HiYAjcr84Mo 2LguJIqCn1sSXXNeRICc/NGz2FRZLPnp/I0ODyqo7Oe3SMAk+CHWSOO9s6xFUWX/RFJRVNFST7RZz WHd/zUQlxakpP9Hs7BFtLb2QUJfHzuBZKfb3uvWFLfFd0glBqTLYSvVh9VN/6S3U3R/flIWQrusGK GzQjiph+NDLg5nzUpREgxdrrLcFZ0C+H657sG2nQdU+xdso6RQIUhbYoqnqINKLbB91BaIeD7V0wP h513/YCA==; Received: from [2001:4bb8:182:6d06:35f3:1da0:1cc3:d86d] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1q4et1-002mEa-0r; Thu, 01 Jun 2023 09:46:27 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Al Viro , Christian Brauner , "Darrick J. Wong" , Jan Kara , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org Subject: [PATCH 16/16] ext4: wire up the ->mark_dead holder operation for log devices Date: Thu, 1 Jun 2023 11:44:59 +0200 Message-Id: <20230601094459.1350643-17-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230601094459.1350643-1-hch@lst.de> References: <20230601094459.1350643-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org Implement a set of holder_ops that shut down the file system when the block device used as log device is removed undeneath the file system. Signed-off-by: Christoph Hellwig Reviewed-by: Jan Kara --- fs/ext4/super.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/fs/ext4/super.c b/fs/ext4/super.c index a177a16c4d2fe5..9070ea9154d727 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -1096,6 +1096,15 @@ void ext4_update_dynamic_rev(struct super_block *sb) */ } +static void ext4_bdev_mark_dead(struct block_device *bdev) +{ + ext4_force_shutdown(bdev->bd_holder, EXT4_GOING_FLAGS_NOLOGFLUSH); +} + +static const struct blk_holder_ops ext4_holder_ops = { + .mark_dead = ext4_bdev_mark_dead, +}; + /* * Open the external journal device */ @@ -1104,7 +1113,7 @@ static struct block_device *ext4_blkdev_get(dev_t dev, struct super_block *sb) struct block_device *bdev; bdev = blkdev_get_by_dev(dev, FMODE_READ|FMODE_WRITE|FMODE_EXCL, sb, - NULL); + &ext4_holder_ops); if (IS_ERR(bdev)) goto fail; return bdev;