From: Christoph Hellwig <hch@lst.de>
To: Jens Axboe <axboe@kernel.dk>
Cc: Tejun Heo <tj@kernel.org>, Josef Bacik <josef@toxicpanda.com>,
Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>,
Coly Li <colyli@suse.de>, Mike Snitzer <snitzer@redhat.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Jan Kara <jack@suse.cz>,
Johannes Thumshirn <johannes.thumshirn@wdc.com>,
dm-devel@redhat.com, Richard Weinberger <richard@nod.at>,
Jan Kara <jack@suse.com>,
linux-block@vger.kernel.org, xen-devel@lists.xenproject.org,
linux-bcache@vger.kernel.org, linux-mtd@lists.infradead.org,
linux-fsdevel@vger.kernel.org, linux-mm@kvack.org
Subject: [PATCH 42/45] block: switch disk_part_iter_* to use a struct block_device
Date: Tue, 24 Nov 2020 14:27:48 +0100 [thread overview]
Message-ID: <20201124132751.3747337-43-hch@lst.de> (raw)
In-Reply-To: <20201124132751.3747337-1-hch@lst.de>
Switch the partition iter infrastructure to iterate over block_device
references instead of hd_struct ones mostly used to get at the
block_device.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
block/genhd.c | 57 +++++++++++++++++++--------------------
block/partitions/core.c | 13 +++++----
drivers/s390/block/dasd.c | 8 +++---
include/linux/genhd.h | 4 +--
4 files changed, 40 insertions(+), 42 deletions(-)
diff --git a/block/genhd.c b/block/genhd.c
index 2985740eab084b..f0bf10192066ac 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -231,7 +231,7 @@ EXPORT_SYMBOL_GPL(disk_part_iter_init);
* CONTEXT:
* Don't care.
*/
-struct hd_struct *disk_part_iter_next(struct disk_part_iter *piter)
+struct block_device *disk_part_iter_next(struct disk_part_iter *piter)
{
struct disk_part_tbl *ptbl;
int inc, end;
@@ -269,8 +269,7 @@ struct hd_struct *disk_part_iter_next(struct disk_part_iter *piter)
piter->idx == 0))
continue;
- get_device(part_to_dev(part->bd_part));
- piter->part = part->bd_part;
+ piter->part = bdgrab(part);
piter->idx += inc;
break;
}
@@ -292,7 +291,8 @@ EXPORT_SYMBOL_GPL(disk_part_iter_next);
*/
void disk_part_iter_exit(struct disk_part_iter *piter)
{
- disk_put_part(piter->part);
+ if (piter->part)
+ bdput(piter->part);
piter->part = NULL;
}
EXPORT_SYMBOL_GPL(disk_part_iter_exit);
@@ -333,7 +333,6 @@ struct block_device *disk_map_sector_rcu(struct gendisk *disk, sector_t sector)
for (i = 1; i < ptbl->len; i++) {
part = rcu_dereference(ptbl->part[i]);
-
if (part && sector_in_part(part, sector)) {
rcu_assign_pointer(ptbl->last_lookup, part);
goto out_unlock;
@@ -634,7 +633,7 @@ static void register_disk(struct device *parent, struct gendisk *disk,
{
struct device *ddev = disk_to_dev(disk);
struct disk_part_iter piter;
- struct hd_struct *part;
+ struct block_device *part;
int err;
ddev->parent = parent;
@@ -684,7 +683,7 @@ static void register_disk(struct device *parent, struct gendisk *disk,
/* announce possible partitions */
disk_part_iter_init(&piter, disk, 0);
while ((part = disk_part_iter_next(&piter)))
- kobject_uevent(&part_to_dev(part)->kobj, KOBJ_ADD);
+ kobject_uevent(bdev_kobj(part), KOBJ_ADD);
disk_part_iter_exit(&piter);
if (disk->queue->backing_dev_info->dev) {
@@ -824,7 +823,7 @@ static void invalidate_partition(struct block_device *bdev)
void del_gendisk(struct gendisk *disk)
{
struct disk_part_iter piter;
- struct hd_struct *part;
+ struct block_device *part;
might_sleep();
@@ -840,8 +839,8 @@ void del_gendisk(struct gendisk *disk)
disk_part_iter_init(&piter, disk,
DISK_PITER_INCL_EMPTY | DISK_PITER_REVERSE);
while ((part = disk_part_iter_next(&piter))) {
- invalidate_partition(part->bdev);
- delete_partition(part);
+ invalidate_partition(part);
+ delete_partition(part->bd_part);
}
disk_part_iter_exit(&piter);
@@ -958,7 +957,7 @@ void __init printk_all_partitions(void)
while ((dev = class_dev_iter_next(&iter))) {
struct gendisk *disk = dev_to_disk(dev);
struct disk_part_iter piter;
- struct hd_struct *part;
+ struct block_device *part;
char name_buf[BDEVNAME_SIZE];
char devt_buf[BDEVT_SIZE];
@@ -977,14 +976,14 @@ void __init printk_all_partitions(void)
*/
disk_part_iter_init(&piter, disk, DISK_PITER_INCL_PART0);
while ((part = disk_part_iter_next(&piter))) {
- bool is_part0 = part == disk->part0->bd_part;
+ bool is_part0 = part == disk->part0;
printk("%s%s %10llu %s %s", is_part0 ? "" : " ",
- bdevt_str(part_devt(part), devt_buf),
- bdev_nr_sectors(part->bdev) >> 1,
- disk_name(disk, part->bdev->bd_partno, name_buf),
- part->bdev->bd_meta_info ?
- part->bdev->bd_meta_info->uuid : "");
+ bdevt_str(part->bd_dev, devt_buf),
+ bdev_nr_sectors(part) >> 1,
+ disk_name(disk, part->bd_partno, name_buf),
+ part->bd_meta_info ?
+ part->bd_meta_info->uuid : "");
if (is_part0) {
if (dev->parent && dev->parent->driver)
printk(" driver: %s\n",
@@ -1060,7 +1059,7 @@ static int show_partition(struct seq_file *seqf, void *v)
{
struct gendisk *sgp = v;
struct disk_part_iter piter;
- struct hd_struct *part;
+ struct block_device *part;
char buf[BDEVNAME_SIZE];
/* Don't show non-partitionable removeable devices or empty devices */
@@ -1074,9 +1073,9 @@ static int show_partition(struct seq_file *seqf, void *v)
disk_part_iter_init(&piter, sgp, DISK_PITER_INCL_PART0);
while ((part = disk_part_iter_next(&piter)))
seq_printf(seqf, "%4d %7d %10llu %s\n",
- MAJOR(part_devt(part)), MINOR(part_devt(part)),
- bdev_nr_sectors(part->bdev) >> 1,
- disk_name(sgp, part->bdev->bd_partno, buf));
+ MAJOR(part->bd_dev), MINOR(part->bd_dev),
+ bdev_nr_sectors(part) >> 1,
+ disk_name(sgp, part->bd_partno, buf));
disk_part_iter_exit(&piter);
return 0;
@@ -1470,7 +1469,7 @@ static int diskstats_show(struct seq_file *seqf, void *v)
{
struct gendisk *gp = v;
struct disk_part_iter piter;
- struct hd_struct *hd;
+ struct block_device *hd;
char buf[BDEVNAME_SIZE];
unsigned int inflight;
struct disk_stats stat;
@@ -1485,11 +1484,11 @@ static int diskstats_show(struct seq_file *seqf, void *v)
disk_part_iter_init(&piter, gp, DISK_PITER_INCL_EMPTY_PART0);
while ((hd = disk_part_iter_next(&piter))) {
- part_stat_read_all(hd, &stat);
+ part_stat_read_all(hd->bd_part, &stat);
if (queue_is_mq(gp->queue))
- inflight = blk_mq_in_flight(gp->queue, hd->bdev);
+ inflight = blk_mq_in_flight(gp->queue, hd);
else
- inflight = part_in_flight(hd->bdev);
+ inflight = part_in_flight(hd);
seq_printf(seqf, "%4d %7d %s "
"%lu %lu %lu %u "
@@ -1498,8 +1497,8 @@ static int diskstats_show(struct seq_file *seqf, void *v)
"%lu %lu %lu %u "
"%lu %u"
"\n",
- MAJOR(part_devt(hd)), MINOR(part_devt(hd)),
- disk_name(gp, hd->bdev->bd_partno, buf),
+ MAJOR(hd->bd_dev), MINOR(hd->bd_dev),
+ disk_name(gp, hd->bd_partno, buf),
stat.ios[STAT_READ],
stat.merges[STAT_READ],
stat.sectors[STAT_READ],
@@ -1654,7 +1653,7 @@ static void set_disk_ro_uevent(struct gendisk *gd, int ro)
void set_disk_ro(struct gendisk *disk, int flag)
{
struct disk_part_iter piter;
- struct hd_struct *part;
+ struct block_device *part;
if (disk->part0->bd_read_only != flag) {
set_disk_ro_uevent(disk, flag);
@@ -1663,7 +1662,7 @@ void set_disk_ro(struct gendisk *disk, int flag)
disk_part_iter_init(&piter, disk, DISK_PITER_INCL_EMPTY);
while ((part = disk_part_iter_next(&piter)))
- part->bdev->bd_read_only = flag;
+ part->bd_read_only = flag;
disk_part_iter_exit(&piter);
}
diff --git a/block/partitions/core.c b/block/partitions/core.c
index 45fed1108d4425..c189ebd4569812 100644
--- a/block/partitions/core.c
+++ b/block/partitions/core.c
@@ -439,15 +439,14 @@ static bool partition_overlaps(struct gendisk *disk, sector_t start,
sector_t length, int skip_partno)
{
struct disk_part_iter piter;
- struct hd_struct *part;
+ struct block_device *part;
bool overlap = false;
disk_part_iter_init(&piter, disk, DISK_PITER_INCL_EMPTY);
while ((part = disk_part_iter_next(&piter))) {
- if (part->bdev->bd_partno == skip_partno ||
- start >= part->bdev->bd_start_sect +
- bdev_nr_sectors(part->bdev) ||
- start + length <= part->bdev->bd_start_sect)
+ if (part->bd_partno == skip_partno ||
+ start >= part->bd_start_sect + bdev_nr_sectors(part) ||
+ start + length <= part->bd_start_sect)
continue;
overlap = true;
break;
@@ -568,7 +567,7 @@ static bool disk_unlock_native_capacity(struct gendisk *disk)
int blk_drop_partitions(struct block_device *bdev)
{
struct disk_part_iter piter;
- struct hd_struct *part;
+ struct block_device *part;
if (bdev->bd_part_count)
return -EBUSY;
@@ -578,7 +577,7 @@ int blk_drop_partitions(struct block_device *bdev)
disk_part_iter_init(&piter, bdev->bd_disk, DISK_PITER_INCL_EMPTY);
while ((part = disk_part_iter_next(&piter)))
- delete_partition(part);
+ delete_partition(part->bd_part);
disk_part_iter_exit(&piter);
return 0;
diff --git a/drivers/s390/block/dasd.c b/drivers/s390/block/dasd.c
index db24e04ee9781e..1825fa8d05a780 100644
--- a/drivers/s390/block/dasd.c
+++ b/drivers/s390/block/dasd.c
@@ -432,7 +432,7 @@ dasd_state_ready_to_online(struct dasd_device * device)
{
struct gendisk *disk;
struct disk_part_iter piter;
- struct hd_struct *part;
+ struct block_device *part;
device->state = DASD_STATE_ONLINE;
if (device->block) {
@@ -445,7 +445,7 @@ dasd_state_ready_to_online(struct dasd_device * device)
disk = device->block->bdev->bd_disk;
disk_part_iter_init(&piter, disk, DISK_PITER_INCL_PART0);
while ((part = disk_part_iter_next(&piter)))
- kobject_uevent(&part_to_dev(part)->kobj, KOBJ_CHANGE);
+ kobject_uevent(bdev_kobj(part), KOBJ_CHANGE);
disk_part_iter_exit(&piter);
}
return 0;
@@ -459,7 +459,7 @@ static int dasd_state_online_to_ready(struct dasd_device *device)
int rc;
struct gendisk *disk;
struct disk_part_iter piter;
- struct hd_struct *part;
+ struct block_device *part;
if (device->discipline->online_to_ready) {
rc = device->discipline->online_to_ready(device);
@@ -472,7 +472,7 @@ static int dasd_state_online_to_ready(struct dasd_device *device)
disk = device->block->bdev->bd_disk;
disk_part_iter_init(&piter, disk, DISK_PITER_INCL_PART0);
while ((part = disk_part_iter_next(&piter)))
- kobject_uevent(&part_to_dev(part)->kobj, KOBJ_CHANGE);
+ kobject_uevent(bdev_kobj(part), KOBJ_CHANGE);
disk_part_iter_exit(&piter);
}
return 0;
diff --git a/include/linux/genhd.h b/include/linux/genhd.h
index afe27a0b8f5dd8..de2ee5ffeefe45 100644
--- a/include/linux/genhd.h
+++ b/include/linux/genhd.h
@@ -245,14 +245,14 @@ static inline void disk_put_part(struct hd_struct *part)
struct disk_part_iter {
struct gendisk *disk;
- struct hd_struct *part;
+ struct block_device *part;
int idx;
unsigned int flags;
};
extern void disk_part_iter_init(struct disk_part_iter *piter,
struct gendisk *disk, unsigned int flags);
-extern struct hd_struct *disk_part_iter_next(struct disk_part_iter *piter);
+struct block_device *disk_part_iter_next(struct disk_part_iter *piter);
extern void disk_part_iter_exit(struct disk_part_iter *piter);
extern bool disk_has_partitions(struct gendisk *disk);
--
2.29.2
next prev parent reply other threads:[~2020-11-24 13:30 UTC|newest]
Thread overview: 91+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-24 13:27 merge struct block_device and struct hd_struct v2 Christoph Hellwig
2020-11-24 13:27 ` [PATCH 01/45] blk-cgroup: fix a hd_struct leak in blkcg_fill_root_iostats Christoph Hellwig
2020-11-25 6:41 ` Hannes Reinecke
2020-11-24 13:27 ` [PATCH 02/45] filemap: consistently use ->f_mapping over ->i_mapping Christoph Hellwig
2020-11-24 13:53 ` Matthew Wilcox
2020-11-25 6:41 ` Hannes Reinecke
2020-11-25 12:16 ` Jan Kara
2020-11-24 13:27 ` [PATCH 03/45] fs: remove get_super_thawed and get_super_exclusive_thawed Christoph Hellwig
2020-11-25 6:42 ` Hannes Reinecke
2020-11-25 12:19 ` Jan Kara
2020-11-24 13:27 ` [PATCH 04/45] fs: simplify freeze_bdev/thaw_bdev Christoph Hellwig
2020-11-25 6:07 ` Chao Yu
2020-11-25 12:29 ` Jan Kara
2020-11-25 16:22 ` Christoph Hellwig
2020-11-24 13:27 ` [PATCH 05/45] mtip32xx: remove the call to fsync_bdev on removal Christoph Hellwig
2020-11-25 12:31 ` Jan Kara
2020-11-24 13:27 ` [PATCH 06/45] zram: remove the claim mechanism Christoph Hellwig
2020-11-25 12:37 ` Jan Kara
2020-11-24 13:27 ` [PATCH 07/45] zram: do not call set_blocksize Christoph Hellwig
2020-11-24 13:27 ` [PATCH 08/45] loop: " Christoph Hellwig
2020-11-25 13:37 ` Jan Kara
2020-11-24 13:27 ` [PATCH 09/45] dm: simplify flush_bio initialization in __send_empty_flush Christoph Hellwig
2020-11-24 13:27 ` [PATCH 10/45] dm: remove the block_device reference in struct mapped_device Christoph Hellwig
2020-11-24 13:27 ` [PATCH 11/45] block: remove a duplicate __disk_get_part prototype Christoph Hellwig
2020-11-24 17:36 ` Tejun Heo
2020-11-24 13:27 ` [PATCH 12/45] block: remove a superflous check in blkpg_do_ioctl Christoph Hellwig
2020-11-24 17:37 ` Tejun Heo
2020-11-25 13:39 ` Jan Kara
2020-11-24 13:27 ` [PATCH 13/45] block: add a bdev_kobj helper Christoph Hellwig
2020-11-24 13:41 ` Coly Li
2020-11-24 17:37 ` Tejun Heo
2020-11-24 13:27 ` [PATCH 14/45] block: use disk_part_iter_exit in disk_part_iter_next Christoph Hellwig
2020-11-24 17:37 ` Tejun Heo
2020-11-24 13:27 ` [PATCH 15/45] block: use put_device in put_disk Christoph Hellwig
2020-11-24 17:37 ` Tejun Heo
2020-11-24 13:27 ` [PATCH 16/45] block: change the hash used for looking up block devices Christoph Hellwig
2020-11-24 17:38 ` Tejun Heo
2020-11-24 13:27 ` [PATCH 17/45] init: refactor name_to_dev_t Christoph Hellwig
2020-11-24 17:38 ` Tejun Heo
2020-11-24 13:27 ` [PATCH 18/45] init: refactor devt_from_partuuid Christoph Hellwig
2020-11-24 17:38 ` Tejun Heo
2020-11-24 13:27 ` [PATCH 19/45] init: cleanup match_dev_by_uuid and match_dev_by_label Christoph Hellwig
2020-11-24 17:39 ` Tejun Heo
2020-11-24 13:27 ` [PATCH 20/45] block: refactor __blkdev_put Christoph Hellwig
2020-11-24 17:41 ` Tejun Heo
2020-11-24 13:27 ` [PATCH 21/45] block: refactor blkdev_get Christoph Hellwig
2020-11-24 18:03 ` Tejun Heo
2020-11-24 13:27 ` [PATCH 22/45] block: opencode devcgroup_inode_permission Christoph Hellwig
2020-11-24 18:05 ` Tejun Heo
2020-11-24 13:27 ` [PATCH 23/45] block: remove i_bdev Christoph Hellwig
2020-11-24 13:38 ` Coly Li
2020-11-24 19:37 ` Tejun Heo
2020-11-25 16:29 ` Christoph Hellwig
2020-11-25 20:19 ` Tejun Heo
2020-11-24 13:27 ` [PATCH 24/45] blk-cgroup: stop abusing get_gendisk Christoph Hellwig
2020-11-24 19:46 ` Tejun Heo
2020-11-24 13:27 ` [PATCH 25/45] block: reference struct block_device from struct hd_struct Christoph Hellwig
2020-11-24 21:18 ` Tejun Heo
[not found] ` <20201125164515.GB1975@lst.de>
[not found] ` <X768hzEnD/ySog5b@mtj.duckdns.org>
2020-11-26 8:16 ` Christoph Hellwig
2020-11-24 13:27 ` [PATCH 26/45] block: remove ->bd_contains Christoph Hellwig
2020-11-24 21:19 ` Tejun Heo
2020-11-24 13:27 ` [PATCH 27/45] block: simplify the block device claiming interface Christoph Hellwig
2020-11-24 21:19 ` Tejun Heo
2020-11-24 13:27 ` [PATCH 28/45] block: simplify part_to_disk Christoph Hellwig
2020-11-24 21:20 ` Tejun Heo
2020-11-24 13:27 ` [PATCH 29/45] block: initialize struct block_device in bdev_alloc Christoph Hellwig
2020-11-24 21:20 ` Tejun Heo
2020-11-24 13:27 ` [PATCH 30/45] block: remove the nr_sects field in struct hd_struct Christoph Hellwig
2020-11-24 13:34 ` Coly Li
2020-11-25 6:10 ` Chao Yu
2020-11-24 13:27 ` [PATCH 31/45] block: move disk stat accounting to struct block_device Christoph Hellwig
2020-11-24 13:27 ` [PATCH 32/45] block: move the start_sect field " Christoph Hellwig
2020-11-24 13:27 ` [PATCH 33/45] block: move the partition_meta_info " Christoph Hellwig
2020-11-24 13:27 ` [PATCH 34/45] block: move holder_dir " Christoph Hellwig
2020-11-24 13:27 ` [PATCH 35/45] block: move make_it_fail " Christoph Hellwig
2020-11-24 13:27 ` [PATCH 36/45] block: move the policy field " Christoph Hellwig
2020-11-24 13:27 ` [PATCH 37/45] block: allocate struct hd_struct as part of struct bdev_inode Christoph Hellwig
2020-11-24 13:27 ` [PATCH 38/45] block: switch partition lookup to use struct block_device Christoph Hellwig
2020-11-24 13:32 ` Coly Li
2020-11-25 6:11 ` Chao Yu
2020-11-24 13:27 ` [PATCH 39/45] block: remove the partno field from struct hd_struct Christoph Hellwig
2020-11-24 13:27 ` [PATCH 40/45] block: pass a block_device to blk_alloc_devt Christoph Hellwig
2020-11-24 13:27 ` [PATCH 41/45] block: pass a block_device to invalidate_partition Christoph Hellwig
2020-11-24 13:27 ` Christoph Hellwig [this message]
2020-11-24 13:27 ` [PATCH 43/45] f2fs: remove a few bd_part checks Christoph Hellwig
2020-11-25 6:12 ` Chao Yu
2020-11-24 13:27 ` [PATCH 44/45] block: merge struct block_device and struct hd_struct Christoph Hellwig
2020-11-24 13:27 ` [PATCH 45/45] block: stop using bdget_disk for partition 0 Christoph Hellwig
2020-11-28 16:14 merge struct block_device and struct hd_struct v4 Christoph Hellwig
2020-11-28 16:15 ` [PATCH 42/45] block: switch disk_part_iter_* to use a struct block_device Christoph Hellwig
2020-11-30 7:50 ` Hannes Reinecke
2020-11-30 10:20 ` Jan Kara
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=20201124132751.3747337-43-hch@lst.de \
--to=hch@lst.de \
--cc=axboe@kernel.dk \
--cc=colyli@suse.de \
--cc=dm-devel@redhat.com \
--cc=gregkh@linuxfoundation.org \
--cc=jack@suse.com \
--cc=jack@suse.cz \
--cc=johannes.thumshirn@wdc.com \
--cc=josef@toxicpanda.com \
--cc=konrad.wilk@oracle.com \
--cc=linux-bcache@vger.kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-mtd@lists.infradead.org \
--cc=richard@nod.at \
--cc=snitzer@redhat.com \
--cc=tj@kernel.org \
--cc=xen-devel@lists.xenproject.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).