linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Jens Axboe <axboe@kernel.dk>
Cc: Tejun Heo <tj@kernel.org>, linux-block@vger.kernel.org
Subject: [PATCH 1/4] block: simplify the restart case in __blkdev_get
Date: Thu, 16 Jul 2020 16:33:07 +0200	[thread overview]
Message-ID: <20200716143310.473136-2-hch@lst.de> (raw)
In-Reply-To: <20200716143310.473136-1-hch@lst.de>

Insted of duplicating all the cleanup logic jump to the code that cleans
up anyway, and restart after that.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/block_dev.c | 25 ++++++++++---------------
 1 file changed, 10 insertions(+), 15 deletions(-)

diff --git a/fs/block_dev.c b/fs/block_dev.c
index a36d5b6907ea4e..376832250c8e91 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -1517,7 +1517,7 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)
 	int ret;
 	int partno;
 	int perm = 0;
-	bool first_open = false;
+	bool first_open = false, need_restart;
 
 	if (mode & FMODE_READ)
 		perm |= MAY_READ;
@@ -1533,7 +1533,7 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)
 	}
 
  restart:
-
+	need_restart = false;
 	ret = -ENXIO;
 	disk = bdev_get_gendisk(bdev, &partno);
 	if (!disk)
@@ -1556,19 +1556,12 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)
 			ret = 0;
 			if (disk->fops->open) {
 				ret = disk->fops->open(bdev, mode);
-				if (ret == -ERESTARTSYS) {
-					/* Lost a race with 'disk' being
-					 * deleted, try again.
-					 * See md.c
-					 */
-					disk_put_part(bdev->bd_part);
-					bdev->bd_part = NULL;
-					bdev->bd_disk = NULL;
-					mutex_unlock(&bdev->bd_mutex);
-					disk_unblock_events(disk);
-					put_disk_and_module(disk);
-					goto restart;
-				}
+				/*
+				 * If we lost a race with 'disk' being deleted,
+				 * try again.  See md.c
+				 */
+				if (ret == -ERESTARTSYS)
+					need_restart = true;
 			}
 
 			if (!ret) {
@@ -1647,6 +1640,8 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)
 	mutex_unlock(&bdev->bd_mutex);
 	disk_unblock_events(disk);
 	put_disk_and_module(disk);
+	if (need_restart)
+		goto restart;
  out:
 
 	return ret;
-- 
2.27.0


  reply	other threads:[~2020-07-16 14:33 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-16 14:33 simplify block device claiming (resend) Christoph Hellwig
2020-07-16 14:33 ` Christoph Hellwig [this message]
2020-07-16 14:40   ` [PATCH 1/4] block: simplify the restart case in __blkdev_get Tejun Heo
2020-07-16 17:40   ` Hannes Reinecke
2020-07-16 14:33 ` [PATCH 2/4] block: refactor bd_start_claiming Christoph Hellwig
2020-07-16 14:41   ` Tejun Heo
2020-07-16 17:41   ` Hannes Reinecke
2020-07-16 14:33 ` [PATCH 3/4] block: use bd_prepare_to_claim directly in the loop driver Christoph Hellwig
2020-07-16 17:43   ` Hannes Reinecke
2020-07-16 14:33 ` [PATCH 4/4] block: integrate bd_start_claiming into __blkdev_get Christoph Hellwig
2020-07-16 15:02   ` Tejun Heo
2020-07-16 17:47   ` Hannes Reinecke
2020-07-16 15:37 ` simplify block device claiming (resend) Jens Axboe
  -- strict thread matches above, loose matches on Subject: below --
2020-07-02  8:49 simplify block device claiming Christoph Hellwig
2020-07-02  8:49 ` [PATCH 1/4] block: simplify the restart case in __blkdev_get Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200716143310.473136-2-hch@lst.de \
    --to=hch@lst.de \
    --cc=axboe@kernel.dk \
    --cc=linux-block@vger.kernel.org \
    --cc=tj@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).