提交 ad1eaa53 编写于 作者: C Christoph Hellwig 提交者: Jens Axboe

block: switch disk_part_iter_* to use a struct block_device

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: NChristoph Hellwig <hch@lst.de>
Reviewed-by: NJan Kara <jack@suse.cz>
Reviewed-by: NHannes Reinecke <hare@suse.de>
Signed-off-by: NJens Axboe <axboe@kernel.dk>
上级 71773cf7
...@@ -244,7 +244,7 @@ EXPORT_SYMBOL_GPL(disk_part_iter_init); ...@@ -244,7 +244,7 @@ EXPORT_SYMBOL_GPL(disk_part_iter_init);
* CONTEXT: * CONTEXT:
* Don't care. * 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; struct disk_part_tbl *ptbl;
int inc, end; int inc, end;
...@@ -282,8 +282,9 @@ struct hd_struct *disk_part_iter_next(struct disk_part_iter *piter) ...@@ -282,8 +282,9 @@ struct hd_struct *disk_part_iter_next(struct disk_part_iter *piter)
piter->idx == 0)) piter->idx == 0))
continue; continue;
get_device(part_to_dev(part->bd_part)); piter->part = bdgrab(part);
piter->part = part->bd_part; if (!piter->part)
continue;
piter->idx += inc; piter->idx += inc;
break; break;
} }
...@@ -305,7 +306,8 @@ EXPORT_SYMBOL_GPL(disk_part_iter_next); ...@@ -305,7 +306,8 @@ EXPORT_SYMBOL_GPL(disk_part_iter_next);
*/ */
void disk_part_iter_exit(struct disk_part_iter *piter) void disk_part_iter_exit(struct disk_part_iter *piter)
{ {
disk_put_part(piter->part); if (piter->part)
bdput(piter->part);
piter->part = NULL; piter->part = NULL;
} }
EXPORT_SYMBOL_GPL(disk_part_iter_exit); EXPORT_SYMBOL_GPL(disk_part_iter_exit);
...@@ -346,7 +348,6 @@ struct block_device *disk_map_sector_rcu(struct gendisk *disk, sector_t sector) ...@@ -346,7 +348,6 @@ struct block_device *disk_map_sector_rcu(struct gendisk *disk, sector_t sector)
for (i = 1; i < ptbl->len; i++) { for (i = 1; i < ptbl->len; i++) {
part = rcu_dereference(ptbl->part[i]); part = rcu_dereference(ptbl->part[i]);
if (part && sector_in_part(part, sector)) { if (part && sector_in_part(part, sector)) {
rcu_assign_pointer(ptbl->last_lookup, part); rcu_assign_pointer(ptbl->last_lookup, part);
goto out_unlock; goto out_unlock;
...@@ -647,7 +648,7 @@ static void register_disk(struct device *parent, struct gendisk *disk, ...@@ -647,7 +648,7 @@ static void register_disk(struct device *parent, struct gendisk *disk,
{ {
struct device *ddev = disk_to_dev(disk); struct device *ddev = disk_to_dev(disk);
struct disk_part_iter piter; struct disk_part_iter piter;
struct hd_struct *part; struct block_device *part;
int err; int err;
ddev->parent = parent; ddev->parent = parent;
...@@ -697,7 +698,7 @@ static void register_disk(struct device *parent, struct gendisk *disk, ...@@ -697,7 +698,7 @@ static void register_disk(struct device *parent, struct gendisk *disk,
/* announce possible partitions */ /* announce possible partitions */
disk_part_iter_init(&piter, disk, 0); disk_part_iter_init(&piter, disk, 0);
while ((part = disk_part_iter_next(&piter))) 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); disk_part_iter_exit(&piter);
if (disk->queue->backing_dev_info->dev) { if (disk->queue->backing_dev_info->dev) {
...@@ -837,7 +838,7 @@ static void invalidate_partition(struct block_device *bdev) ...@@ -837,7 +838,7 @@ static void invalidate_partition(struct block_device *bdev)
void del_gendisk(struct gendisk *disk) void del_gendisk(struct gendisk *disk)
{ {
struct disk_part_iter piter; struct disk_part_iter piter;
struct hd_struct *part; struct block_device *part;
might_sleep(); might_sleep();
...@@ -857,8 +858,8 @@ void del_gendisk(struct gendisk *disk) ...@@ -857,8 +858,8 @@ void del_gendisk(struct gendisk *disk)
disk_part_iter_init(&piter, disk, disk_part_iter_init(&piter, disk,
DISK_PITER_INCL_EMPTY | DISK_PITER_REVERSE); DISK_PITER_INCL_EMPTY | DISK_PITER_REVERSE);
while ((part = disk_part_iter_next(&piter))) { while ((part = disk_part_iter_next(&piter))) {
invalidate_partition(part->bdev); invalidate_partition(part);
delete_partition(part); delete_partition(part->bd_part);
} }
disk_part_iter_exit(&piter); disk_part_iter_exit(&piter);
...@@ -977,7 +978,7 @@ void __init printk_all_partitions(void) ...@@ -977,7 +978,7 @@ void __init printk_all_partitions(void)
while ((dev = class_dev_iter_next(&iter))) { while ((dev = class_dev_iter_next(&iter))) {
struct gendisk *disk = dev_to_disk(dev); struct gendisk *disk = dev_to_disk(dev);
struct disk_part_iter piter; struct disk_part_iter piter;
struct hd_struct *part; struct block_device *part;
char name_buf[BDEVNAME_SIZE]; char name_buf[BDEVNAME_SIZE];
char devt_buf[BDEVT_SIZE]; char devt_buf[BDEVT_SIZE];
...@@ -996,14 +997,14 @@ void __init printk_all_partitions(void) ...@@ -996,14 +997,14 @@ void __init printk_all_partitions(void)
*/ */
disk_part_iter_init(&piter, disk, DISK_PITER_INCL_PART0); disk_part_iter_init(&piter, disk, DISK_PITER_INCL_PART0);
while ((part = disk_part_iter_next(&piter))) { 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 ? "" : " ", printk("%s%s %10llu %s %s", is_part0 ? "" : " ",
bdevt_str(part_devt(part), devt_buf), bdevt_str(part->bd_dev, devt_buf),
bdev_nr_sectors(part->bdev) >> 1, bdev_nr_sectors(part) >> 1,
disk_name(disk, part->bdev->bd_partno, name_buf), disk_name(disk, part->bd_partno, name_buf),
part->bdev->bd_meta_info ? part->bd_meta_info ?
part->bdev->bd_meta_info->uuid : ""); part->bd_meta_info->uuid : "");
if (is_part0) { if (is_part0) {
if (dev->parent && dev->parent->driver) if (dev->parent && dev->parent->driver)
printk(" driver: %s\n", printk(" driver: %s\n",
...@@ -1079,7 +1080,7 @@ static int show_partition(struct seq_file *seqf, void *v) ...@@ -1079,7 +1080,7 @@ static int show_partition(struct seq_file *seqf, void *v)
{ {
struct gendisk *sgp = v; struct gendisk *sgp = v;
struct disk_part_iter piter; struct disk_part_iter piter;
struct hd_struct *part; struct block_device *part;
char buf[BDEVNAME_SIZE]; char buf[BDEVNAME_SIZE];
/* Don't show non-partitionable removeable devices or empty devices */ /* Don't show non-partitionable removeable devices or empty devices */
...@@ -1093,9 +1094,9 @@ static int show_partition(struct seq_file *seqf, void *v) ...@@ -1093,9 +1094,9 @@ static int show_partition(struct seq_file *seqf, void *v)
disk_part_iter_init(&piter, sgp, DISK_PITER_INCL_PART0); disk_part_iter_init(&piter, sgp, DISK_PITER_INCL_PART0);
while ((part = disk_part_iter_next(&piter))) while ((part = disk_part_iter_next(&piter)))
seq_printf(seqf, "%4d %7d %10llu %s\n", seq_printf(seqf, "%4d %7d %10llu %s\n",
MAJOR(part_devt(part)), MINOR(part_devt(part)), MAJOR(part->bd_dev), MINOR(part->bd_dev),
bdev_nr_sectors(part->bdev) >> 1, bdev_nr_sectors(part) >> 1,
disk_name(sgp, part->bdev->bd_partno, buf)); disk_name(sgp, part->bd_partno, buf));
disk_part_iter_exit(&piter); disk_part_iter_exit(&piter);
return 0; return 0;
...@@ -1489,7 +1490,7 @@ static int diskstats_show(struct seq_file *seqf, void *v) ...@@ -1489,7 +1490,7 @@ static int diskstats_show(struct seq_file *seqf, void *v)
{ {
struct gendisk *gp = v; struct gendisk *gp = v;
struct disk_part_iter piter; struct disk_part_iter piter;
struct hd_struct *hd; struct block_device *hd;
char buf[BDEVNAME_SIZE]; char buf[BDEVNAME_SIZE];
unsigned int inflight; unsigned int inflight;
struct disk_stats stat; struct disk_stats stat;
...@@ -1504,11 +1505,11 @@ static int diskstats_show(struct seq_file *seqf, void *v) ...@@ -1504,11 +1505,11 @@ static int diskstats_show(struct seq_file *seqf, void *v)
disk_part_iter_init(&piter, gp, DISK_PITER_INCL_EMPTY_PART0); disk_part_iter_init(&piter, gp, DISK_PITER_INCL_EMPTY_PART0);
while ((hd = disk_part_iter_next(&piter))) { 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)) if (queue_is_mq(gp->queue))
inflight = blk_mq_in_flight(gp->queue, hd->bdev); inflight = blk_mq_in_flight(gp->queue, hd);
else else
inflight = part_in_flight(hd->bdev); inflight = part_in_flight(hd);
seq_printf(seqf, "%4d %7d %s " seq_printf(seqf, "%4d %7d %s "
"%lu %lu %lu %u " "%lu %lu %lu %u "
...@@ -1517,8 +1518,8 @@ static int diskstats_show(struct seq_file *seqf, void *v) ...@@ -1517,8 +1518,8 @@ static int diskstats_show(struct seq_file *seqf, void *v)
"%lu %lu %lu %u " "%lu %lu %lu %u "
"%lu %u" "%lu %u"
"\n", "\n",
MAJOR(part_devt(hd)), MINOR(part_devt(hd)), MAJOR(hd->bd_dev), MINOR(hd->bd_dev),
disk_name(gp, hd->bdev->bd_partno, buf), disk_name(gp, hd->bd_partno, buf),
stat.ios[STAT_READ], stat.ios[STAT_READ],
stat.merges[STAT_READ], stat.merges[STAT_READ],
stat.sectors[STAT_READ], stat.sectors[STAT_READ],
...@@ -1673,7 +1674,7 @@ static void set_disk_ro_uevent(struct gendisk *gd, int ro) ...@@ -1673,7 +1674,7 @@ static void set_disk_ro_uevent(struct gendisk *gd, int ro)
void set_disk_ro(struct gendisk *disk, int flag) void set_disk_ro(struct gendisk *disk, int flag)
{ {
struct disk_part_iter piter; struct disk_part_iter piter;
struct hd_struct *part; struct block_device *part;
if (disk->part0->bd_read_only != flag) { if (disk->part0->bd_read_only != flag) {
set_disk_ro_uevent(disk, flag); set_disk_ro_uevent(disk, flag);
...@@ -1682,7 +1683,7 @@ void set_disk_ro(struct gendisk *disk, int flag) ...@@ -1682,7 +1683,7 @@ void set_disk_ro(struct gendisk *disk, int flag)
disk_part_iter_init(&piter, disk, DISK_PITER_INCL_EMPTY); disk_part_iter_init(&piter, disk, DISK_PITER_INCL_EMPTY);
while ((part = disk_part_iter_next(&piter))) while ((part = disk_part_iter_next(&piter)))
part->bdev->bd_read_only = flag; part->bd_read_only = flag;
disk_part_iter_exit(&piter); disk_part_iter_exit(&piter);
} }
......
...@@ -439,15 +439,14 @@ static bool partition_overlaps(struct gendisk *disk, sector_t start, ...@@ -439,15 +439,14 @@ static bool partition_overlaps(struct gendisk *disk, sector_t start,
sector_t length, int skip_partno) sector_t length, int skip_partno)
{ {
struct disk_part_iter piter; struct disk_part_iter piter;
struct hd_struct *part; struct block_device *part;
bool overlap = false; bool overlap = false;
disk_part_iter_init(&piter, disk, DISK_PITER_INCL_EMPTY); disk_part_iter_init(&piter, disk, DISK_PITER_INCL_EMPTY);
while ((part = disk_part_iter_next(&piter))) { while ((part = disk_part_iter_next(&piter))) {
if (part->bdev->bd_partno == skip_partno || if (part->bd_partno == skip_partno ||
start >= part->bdev->bd_start_sect + start >= part->bd_start_sect + bdev_nr_sectors(part) ||
bdev_nr_sectors(part->bdev) || start + length <= part->bd_start_sect)
start + length <= part->bdev->bd_start_sect)
continue; continue;
overlap = true; overlap = true;
break; break;
...@@ -568,7 +567,7 @@ static bool disk_unlock_native_capacity(struct gendisk *disk) ...@@ -568,7 +567,7 @@ static bool disk_unlock_native_capacity(struct gendisk *disk)
int blk_drop_partitions(struct block_device *bdev) int blk_drop_partitions(struct block_device *bdev)
{ {
struct disk_part_iter piter; struct disk_part_iter piter;
struct hd_struct *part; struct block_device *part;
if (bdev->bd_part_count) if (bdev->bd_part_count)
return -EBUSY; return -EBUSY;
...@@ -578,7 +577,7 @@ int blk_drop_partitions(struct block_device *bdev) ...@@ -578,7 +577,7 @@ int blk_drop_partitions(struct block_device *bdev)
disk_part_iter_init(&piter, bdev->bd_disk, DISK_PITER_INCL_EMPTY); disk_part_iter_init(&piter, bdev->bd_disk, DISK_PITER_INCL_EMPTY);
while ((part = disk_part_iter_next(&piter))) while ((part = disk_part_iter_next(&piter)))
delete_partition(part); delete_partition(part->bd_part);
disk_part_iter_exit(&piter); disk_part_iter_exit(&piter);
return 0; return 0;
......
...@@ -432,7 +432,7 @@ dasd_state_ready_to_online(struct dasd_device * device) ...@@ -432,7 +432,7 @@ dasd_state_ready_to_online(struct dasd_device * device)
{ {
struct gendisk *disk; struct gendisk *disk;
struct disk_part_iter piter; struct disk_part_iter piter;
struct hd_struct *part; struct block_device *part;
device->state = DASD_STATE_ONLINE; device->state = DASD_STATE_ONLINE;
if (device->block) { if (device->block) {
...@@ -445,7 +445,7 @@ dasd_state_ready_to_online(struct dasd_device * device) ...@@ -445,7 +445,7 @@ dasd_state_ready_to_online(struct dasd_device * device)
disk = device->block->bdev->bd_disk; disk = device->block->bdev->bd_disk;
disk_part_iter_init(&piter, disk, DISK_PITER_INCL_PART0); disk_part_iter_init(&piter, disk, DISK_PITER_INCL_PART0);
while ((part = disk_part_iter_next(&piter))) 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); disk_part_iter_exit(&piter);
} }
return 0; return 0;
...@@ -459,7 +459,7 @@ static int dasd_state_online_to_ready(struct dasd_device *device) ...@@ -459,7 +459,7 @@ static int dasd_state_online_to_ready(struct dasd_device *device)
int rc; int rc;
struct gendisk *disk; struct gendisk *disk;
struct disk_part_iter piter; struct disk_part_iter piter;
struct hd_struct *part; struct block_device *part;
if (device->discipline->online_to_ready) { if (device->discipline->online_to_ready) {
rc = device->discipline->online_to_ready(device); rc = device->discipline->online_to_ready(device);
...@@ -472,7 +472,7 @@ static int dasd_state_online_to_ready(struct dasd_device *device) ...@@ -472,7 +472,7 @@ static int dasd_state_online_to_ready(struct dasd_device *device)
disk = device->block->bdev->bd_disk; disk = device->block->bdev->bd_disk;
disk_part_iter_init(&piter, disk, DISK_PITER_INCL_PART0); disk_part_iter_init(&piter, disk, DISK_PITER_INCL_PART0);
while ((part = disk_part_iter_next(&piter))) 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); disk_part_iter_exit(&piter);
} }
return 0; return 0;
......
...@@ -244,14 +244,14 @@ static inline void disk_put_part(struct hd_struct *part) ...@@ -244,14 +244,14 @@ static inline void disk_put_part(struct hd_struct *part)
struct disk_part_iter { struct disk_part_iter {
struct gendisk *disk; struct gendisk *disk;
struct hd_struct *part; struct block_device *part;
int idx; int idx;
unsigned int flags; unsigned int flags;
}; };
extern void disk_part_iter_init(struct disk_part_iter *piter, extern void disk_part_iter_init(struct disk_part_iter *piter,
struct gendisk *disk, unsigned int flags); 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 void disk_part_iter_exit(struct disk_part_iter *piter);
extern bool disk_has_partitions(struct gendisk *disk); extern bool disk_has_partitions(struct gendisk *disk);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册