linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Jens Axboe <axboe@kernel.dk>,
	Stefan Haberland <sth@linux.ibm.com>,
	Jan Hoeppner <hoeppner@linux.ibm.com>
Cc: Tejun Heo <tj@kernel.org>,
	linux-block@vger.kernel.org, linux-s390@vger.kernel.org
Subject: [PATCH 04/11] block: refactor blk_drop_partitions
Date: Tue,  6 Apr 2021 08:22:55 +0200	[thread overview]
Message-ID: <20210406062303.811835-5-hch@lst.de> (raw)
In-Reply-To: <20210406062303.811835-1-hch@lst.de>

Move the busy check and disk-wide sync into the only caller, so that
the remainder can be shared with del_gendisk.  Also pass the gendisk
instead of the bdev as that is all that is needed.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 block/blk.h             |  1 -
 block/genhd.c           | 11 +----------
 block/partitions/core.c | 14 +++-----------
 fs/block_dev.c          |  8 +++++---
 include/linux/genhd.h   |  2 +-
 5 files changed, 10 insertions(+), 26 deletions(-)

diff --git a/block/blk.h b/block/blk.h
index 3b53e44b967e4e..900cb246d5f384 100644
--- a/block/blk.h
+++ b/block/blk.h
@@ -346,7 +346,6 @@ char *disk_name(struct gendisk *hd, int partno, char *buf);
 #define ADDPART_FLAG_NONE	0
 #define ADDPART_FLAG_RAID	1
 #define ADDPART_FLAG_WHOLEDISK	2
-void delete_partition(struct block_device *part);
 int bdev_add_partition(struct block_device *bdev, int partno,
 		sector_t start, sector_t length);
 int bdev_del_partition(struct block_device *bdev, int partno);
diff --git a/block/genhd.c b/block/genhd.c
index 15f99da4543f6d..8303ec67fd7099 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -667,9 +667,6 @@ EXPORT_SYMBOL(device_add_disk_no_queue_reg);
  */
 void del_gendisk(struct gendisk *disk)
 {
-	struct disk_part_iter piter;
-	struct block_device *part;
-
 	might_sleep();
 
 	if (WARN_ON_ONCE(!disk->queue))
@@ -683,13 +680,7 @@ void del_gendisk(struct gendisk *disk)
 	 * disk is marked as dead (GENHD_FL_UP cleared).
 	 */
 	down_write(&bdev_lookup_sem);
-
-	/* invalidate stuff */
-	disk_part_iter_init(&piter, disk, DISK_PITER_INCL_EMPTY);
-	while ((part = disk_part_iter_next(&piter)))
-		delete_partition(part);
-	disk_part_iter_exit(&piter);
-
+	blk_drop_partitions(disk);
 	fsync_bdev(disk->part0);
 	__invalidate_device(disk->part0, true);
 
diff --git a/block/partitions/core.c b/block/partitions/core.c
index 8c173529294081..536f7c5bb0b6d2 100644
--- a/block/partitions/core.c
+++ b/block/partitions/core.c
@@ -285,7 +285,7 @@ struct device_type part_type = {
  * Must be called either with bd_mutex held, before a disk can be opened or
  * after all disk users are gone.
  */
-void delete_partition(struct block_device *part)
+static void delete_partition(struct block_device *part)
 {
 	fsync_bdev(part);
 	__invalidate_device(part, true);
@@ -526,23 +526,15 @@ static bool disk_unlock_native_capacity(struct gendisk *disk)
 	}
 }
 
-int blk_drop_partitions(struct block_device *bdev)
+void blk_drop_partitions(struct gendisk *disk)
 {
 	struct disk_part_iter piter;
 	struct block_device *part;
 
-	if (bdev->bd_part_count)
-		return -EBUSY;
-
-	sync_blockdev(bdev);
-	invalidate_bdev(bdev);
-
-	disk_part_iter_init(&piter, bdev->bd_disk, DISK_PITER_INCL_EMPTY);
+	disk_part_iter_init(&piter, disk, DISK_PITER_INCL_EMPTY);
 	while ((part = disk_part_iter_next(&piter)))
 		delete_partition(part);
 	disk_part_iter_exit(&piter);
-
-	return 0;
 }
 
 static bool blk_add_partition(struct gendisk *disk, struct block_device *bdev,
diff --git a/fs/block_dev.c b/fs/block_dev.c
index 92ed7d5df67744..594a1bee9dd9ac 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -1243,9 +1243,11 @@ int bdev_disk_changed(struct block_device *bdev, bool invalidate)
 	clear_bit(GD_NEED_PART_SCAN, &bdev->bd_disk->state);
 
 rescan:
-	ret = blk_drop_partitions(bdev);
-	if (ret)
-		return ret;
+	if (bdev->bd_part_count)
+		return -EBUSY;
+	sync_blockdev(bdev);
+	invalidate_bdev(bdev);
+	blk_drop_partitions(disk);
 
 	/*
 	 * Historically we only set the capacity to zero for devices that
diff --git a/include/linux/genhd.h b/include/linux/genhd.h
index f364619092cca0..16178a935c4041 100644
--- a/include/linux/genhd.h
+++ b/include/linux/genhd.h
@@ -273,7 +273,7 @@ static inline sector_t get_capacity(struct gendisk *disk)
 
 int bdev_disk_changed(struct block_device *bdev, bool invalidate);
 int blk_add_partitions(struct gendisk *disk, struct block_device *bdev);
-int blk_drop_partitions(struct block_device *bdev);
+void blk_drop_partitions(struct gendisk *disk);
 
 extern struct gendisk *__alloc_disk_node(int minors, int node_id);
 extern void put_disk(struct gendisk *disk);
-- 
2.30.1


  parent reply	other threads:[~2021-04-06  6:23 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-06  6:22 partition iteration simplifications Christoph Hellwig
2021-04-06  6:22 ` [PATCH 01/11] dasd: use bdev_disk_changed instead of blk_drop_partitions Christoph Hellwig
2021-04-08 14:31   ` Stefan Haberland
2021-04-06  6:22 ` [PATCH 02/11] block: remove invalidate_partition Christoph Hellwig
2021-04-06  6:22 ` [PATCH 03/11] block: move more syncing and invalidation to delete_partition Christoph Hellwig
2021-04-06  6:22 ` Christoph Hellwig [this message]
2021-04-06  6:22 ` [PATCH 05/11] block: take bd_mutex around delete_partitions in del_gendisk Christoph Hellwig
2021-04-06  6:22 ` [PATCH 06/11] block: simplify partition removal Christoph Hellwig
2021-04-06  6:22 ` [PATCH 07/11] block: simplify partition_overlaps Christoph Hellwig
2021-04-06  6:22 ` [PATCH 08/11] block: simplify printk_all_partitions Christoph Hellwig
2021-04-06  6:23 ` [PATCH 09/11] block: simplify show_partition Christoph Hellwig
2021-04-06  6:23 ` [PATCH 10/11] block: simplify diskstats_show Christoph Hellwig
2021-04-06  6:23 ` [PATCH 11/11] block: remove disk_part_iter Christoph Hellwig
2021-04-08 16:24 ` partition iteration simplifications Jens Axboe

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=20210406062303.811835-5-hch@lst.de \
    --to=hch@lst.de \
    --cc=axboe@kernel.dk \
    --cc=hoeppner@linux.ibm.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=sth@linux.ibm.com \
    --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).