Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

block: switch partition lookup to use struct block_device

Use struct block_device to lookup partitions on a disk. This removes
all usage of struct hd_struct from the I/O path.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Jan Kara <jack@suse.cz>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Acked-by: Coly Li <colyli@suse.de> [bcache]
Acked-by: Chao Yu <yuchao0@huawei.com> [f2fs]
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Christoph Hellwig and committed by
Jens Axboe
8446fe92 cb8432d6

+122 -137
+2 -2
block/bio.c
··· 608 608 void guard_bio_eod(struct bio *bio) 609 609 { 610 610 sector_t maxsector; 611 - struct hd_struct *part; 611 + struct block_device *part; 612 612 613 613 rcu_read_lock(); 614 614 part = __disk_get_part(bio->bi_disk, bio->bi_partno); 615 615 if (part) 616 - maxsector = bdev_nr_sectors(part->bdev); 616 + maxsector = bdev_nr_sectors(part); 617 617 else 618 618 maxsector = get_capacity(bio->bi_disk); 619 619 rcu_read_unlock();
+30 -36
block/blk-core.c
··· 666 666 } 667 667 __setup("fail_make_request=", setup_fail_make_request); 668 668 669 - static bool should_fail_request(struct hd_struct *part, unsigned int bytes) 669 + static bool should_fail_request(struct block_device *part, unsigned int bytes) 670 670 { 671 - return part->bdev->bd_make_it_fail && 672 - should_fail(&fail_make_request, bytes); 671 + return part->bd_make_it_fail && should_fail(&fail_make_request, bytes); 673 672 } 674 673 675 674 static int __init fail_make_request_debugfs(void) ··· 683 684 684 685 #else /* CONFIG_FAIL_MAKE_REQUEST */ 685 686 686 - static inline bool should_fail_request(struct hd_struct *part, 687 + static inline bool should_fail_request(struct block_device *part, 687 688 unsigned int bytes) 688 689 { 689 690 return false; ··· 691 692 692 693 #endif /* CONFIG_FAIL_MAKE_REQUEST */ 693 694 694 - static inline bool bio_check_ro(struct bio *bio, struct hd_struct *part) 695 + static inline bool bio_check_ro(struct bio *bio, struct block_device *part) 695 696 { 696 697 const int op = bio_op(bio); 697 698 698 - if (part->bdev->bd_read_only && op_is_write(op)) { 699 + if (part->bd_read_only && op_is_write(op)) { 699 700 char b[BDEVNAME_SIZE]; 700 701 701 702 if (op_is_flush(bio->bi_opf) && !bio_sectors(bio)) ··· 703 704 704 705 WARN_ONCE(1, 705 706 "Trying to write to read-only block-device %s (partno %d)\n", 706 - bio_devname(bio, b), part->partno); 707 + bio_devname(bio, b), part->bd_partno); 707 708 /* Older lvm-tools actually trigger this */ 708 709 return false; 709 710 } ··· 713 714 714 715 static noinline int should_fail_bio(struct bio *bio) 715 716 { 716 - if (should_fail_request(bio->bi_disk->part0->bd_part, 717 - bio->bi_iter.bi_size)) 717 + if (should_fail_request(bio->bi_disk->part0, bio->bi_iter.bi_size)) 718 718 return -EIO; 719 719 return 0; 720 720 } ··· 742 744 */ 743 745 static inline int blk_partition_remap(struct bio *bio) 744 746 { 745 - struct hd_struct *p; 747 + struct block_device *p; 746 748 int ret = -EIO; 747 749 748 750 rcu_read_lock(); ··· 755 757 goto out; 756 758 757 759 if (bio_sectors(bio)) { 758 - if (bio_check_eod(bio, bdev_nr_sectors(p->bdev))) 760 + if (bio_check_eod(bio, bdev_nr_sectors(p))) 759 761 goto out; 760 - bio->bi_iter.bi_sector += p->bdev->bd_start_sect; 761 - trace_block_bio_remap(bio->bi_disk->queue, bio, part_devt(p), 762 + bio->bi_iter.bi_sector += p->bd_start_sect; 763 + trace_block_bio_remap(bio->bi_disk->queue, bio, p->bd_dev, 762 764 bio->bi_iter.bi_sector - 763 - p->bdev->bd_start_sect); 765 + p->bd_start_sect); 764 766 } 765 767 bio->bi_partno = 0; 766 768 ret = 0; ··· 830 832 if (unlikely(blk_partition_remap(bio))) 831 833 goto end_io; 832 834 } else { 833 - if (unlikely(bio_check_ro(bio, bio->bi_disk->part0->bd_part))) 835 + if (unlikely(bio_check_ro(bio, bio->bi_disk->part0))) 834 836 goto end_io; 835 837 if (unlikely(bio_check_eod(bio, get_capacity(bio->bi_disk)))) 836 838 goto end_io; ··· 1202 1204 return ret; 1203 1205 1204 1206 if (rq->rq_disk && 1205 - should_fail_request(rq->rq_disk->part0->bd_part, blk_rq_bytes(rq))) 1207 + should_fail_request(rq->rq_disk->part0, blk_rq_bytes(rq))) 1206 1208 return BLK_STS_IOERR; 1207 1209 1208 1210 if (blk_crypto_insert_cloned_request(rq)) ··· 1261 1263 } 1262 1264 EXPORT_SYMBOL_GPL(blk_rq_err_bytes); 1263 1265 1264 - static void update_io_ticks(struct hd_struct *part, unsigned long now, bool end) 1266 + static void update_io_ticks(struct block_device *part, unsigned long now, 1267 + bool end) 1265 1268 { 1266 1269 unsigned long stamp; 1267 1270 again: 1268 - stamp = READ_ONCE(part->bdev->bd_stamp); 1271 + stamp = READ_ONCE(part->bd_stamp); 1269 1272 if (unlikely(stamp != now)) { 1270 - if (likely(cmpxchg(&part->bdev->bd_stamp, stamp, now) == stamp)) 1273 + if (likely(cmpxchg(&part->bd_stamp, stamp, now) == stamp)) 1271 1274 __part_stat_add(part, io_ticks, end ? now - stamp : 1); 1272 1275 } 1273 - if (part->partno) { 1274 - part = part_to_disk(part)->part0->bd_part; 1276 + if (part->bd_partno) { 1277 + part = bdev_whole(part); 1275 1278 goto again; 1276 1279 } 1277 1280 } ··· 1281 1282 { 1282 1283 if (req->part && blk_do_io_stat(req)) { 1283 1284 const int sgrp = op_stat_group(req_op(req)); 1284 - struct hd_struct *part; 1285 1285 1286 1286 part_stat_lock(); 1287 - part = req->part; 1288 - part_stat_add(part, sectors[sgrp], bytes >> 9); 1287 + part_stat_add(req->part, sectors[sgrp], bytes >> 9); 1289 1288 part_stat_unlock(); 1290 1289 } 1291 1290 } ··· 1298 1301 if (req->part && blk_do_io_stat(req) && 1299 1302 !(req->rq_flags & RQF_FLUSH_SEQ)) { 1300 1303 const int sgrp = op_stat_group(req_op(req)); 1301 - struct hd_struct *part; 1302 1304 1303 1305 part_stat_lock(); 1304 - part = req->part; 1305 - 1306 - update_io_ticks(part, jiffies, true); 1307 - part_stat_inc(part, ios[sgrp]); 1308 - part_stat_add(part, nsecs[sgrp], now - req->start_time_ns); 1306 + update_io_ticks(req->part, jiffies, true); 1307 + part_stat_inc(req->part, ios[sgrp]); 1308 + part_stat_add(req->part, nsecs[sgrp], now - req->start_time_ns); 1309 1309 part_stat_unlock(); 1310 1310 } 1311 1311 } ··· 1319 1325 part_stat_unlock(); 1320 1326 } 1321 1327 1322 - static unsigned long __part_start_io_acct(struct hd_struct *part, 1328 + static unsigned long __part_start_io_acct(struct block_device *part, 1323 1329 unsigned int sectors, unsigned int op) 1324 1330 { 1325 1331 const int sgrp = op_stat_group(op); ··· 1335 1341 return now; 1336 1342 } 1337 1343 1338 - unsigned long part_start_io_acct(struct gendisk *disk, struct hd_struct **part, 1344 + unsigned long part_start_io_acct(struct gendisk *disk, struct block_device **part, 1339 1345 struct bio *bio) 1340 1346 { 1341 1347 *part = disk_map_sector_rcu(disk, bio->bi_iter.bi_sector); ··· 1347 1353 unsigned long disk_start_io_acct(struct gendisk *disk, unsigned int sectors, 1348 1354 unsigned int op) 1349 1355 { 1350 - return __part_start_io_acct(disk->part0->bd_part, sectors, op); 1356 + return __part_start_io_acct(disk->part0, sectors, op); 1351 1357 } 1352 1358 EXPORT_SYMBOL(disk_start_io_acct); 1353 1359 1354 - static void __part_end_io_acct(struct hd_struct *part, unsigned int op, 1360 + static void __part_end_io_acct(struct block_device *part, unsigned int op, 1355 1361 unsigned long start_time) 1356 1362 { 1357 1363 const int sgrp = op_stat_group(op); ··· 1365 1371 part_stat_unlock(); 1366 1372 } 1367 1373 1368 - void part_end_io_acct(struct hd_struct *part, struct bio *bio, 1374 + void part_end_io_acct(struct block_device *part, struct bio *bio, 1369 1375 unsigned long start_time) 1370 1376 { 1371 1377 __part_end_io_acct(part, bio_op(bio), start_time); ··· 1375 1381 void disk_end_io_acct(struct gendisk *disk, unsigned int op, 1376 1382 unsigned long start_time) 1377 1383 { 1378 - __part_end_io_acct(disk->part0->bd_part, op, start_time); 1384 + __part_end_io_acct(disk->part0, op, start_time); 1379 1385 } 1380 1386 EXPORT_SYMBOL(disk_end_io_acct); 1381 1387
+1 -1
block/blk-flush.c
··· 139 139 140 140 static void blk_account_io_flush(struct request *rq) 141 141 { 142 - struct hd_struct *part = rq->rq_disk->part0->bd_part; 142 + struct block_device *part = rq->rq_disk->part0; 143 143 144 144 part_stat_lock(); 145 145 part_stat_inc(part, ios[STAT_FLUSH]);
+5 -4
block/blk-mq.c
··· 95 95 } 96 96 97 97 struct mq_inflight { 98 - struct hd_struct *part; 98 + struct block_device *part; 99 99 unsigned int inflight[2]; 100 100 }; 101 101 ··· 111 111 return true; 112 112 } 113 113 114 - unsigned int blk_mq_in_flight(struct request_queue *q, struct hd_struct *part) 114 + unsigned int blk_mq_in_flight(struct request_queue *q, 115 + struct block_device *part) 115 116 { 116 117 struct mq_inflight mi = { .part = part }; 117 118 ··· 121 120 return mi.inflight[0] + mi.inflight[1]; 122 121 } 123 122 124 - void blk_mq_in_flight_rw(struct request_queue *q, struct hd_struct *part, 125 - unsigned int inflight[2]) 123 + void blk_mq_in_flight_rw(struct request_queue *q, struct block_device *part, 124 + unsigned int inflight[2]) 126 125 { 127 126 struct mq_inflight mi = { .part = part }; 128 127
+4 -3
block/blk-mq.h
··· 182 182 return hctx->nr_ctx && hctx->tags; 183 183 } 184 184 185 - unsigned int blk_mq_in_flight(struct request_queue *q, struct hd_struct *part); 186 - void blk_mq_in_flight_rw(struct request_queue *q, struct hd_struct *part, 187 - unsigned int inflight[2]); 185 + unsigned int blk_mq_in_flight(struct request_queue *q, 186 + struct block_device *part); 187 + void blk_mq_in_flight_rw(struct request_queue *q, struct block_device *part, 188 + unsigned int inflight[2]); 188 189 189 190 static inline void blk_mq_put_dispatch_budget(struct request_queue *q) 190 191 {
+2 -2
block/blk.h
··· 215 215 __elevator_exit(q, e); 216 216 } 217 217 218 - struct hd_struct *__disk_get_part(struct gendisk *disk, int partno); 218 + struct block_device *__disk_get_part(struct gendisk *disk, int partno); 219 219 220 220 ssize_t part_size_show(struct device *dev, struct device_attribute *attr, 221 221 char *buf); ··· 348 348 static inline void blk_queue_free_zone_bitmaps(struct request_queue *q) {} 349 349 #endif 350 350 351 - struct hd_struct *disk_map_sector_rcu(struct gendisk *disk, sector_t sector); 351 + struct block_device *disk_map_sector_rcu(struct gendisk *disk, sector_t sector); 352 352 353 353 int blk_alloc_devt(struct hd_struct *part, dev_t *devt); 354 354 void blk_free_devt(dev_t devt);
+32 -25
block/genhd.c
··· 126 126 } 127 127 } 128 128 129 - static unsigned int part_in_flight(struct hd_struct *part) 129 + static unsigned int part_in_flight(struct block_device *part) 130 130 { 131 131 unsigned int inflight = 0; 132 132 int cpu; ··· 141 141 return inflight; 142 142 } 143 143 144 - static void part_in_flight_rw(struct hd_struct *part, unsigned int inflight[2]) 144 + static void part_in_flight_rw(struct block_device *part, 145 + unsigned int inflight[2]) 145 146 { 146 147 int cpu; 147 148 ··· 158 157 inflight[1] = 0; 159 158 } 160 159 161 - struct hd_struct *__disk_get_part(struct gendisk *disk, int partno) 160 + struct block_device *__disk_get_part(struct gendisk *disk, int partno) 162 161 { 163 162 struct disk_part_tbl *ptbl = rcu_dereference(disk->part_tbl); 164 163 ··· 183 182 */ 184 183 struct hd_struct *disk_get_part(struct gendisk *disk, int partno) 185 184 { 185 + struct block_device *bdev; 186 186 struct hd_struct *part; 187 187 188 188 rcu_read_lock(); 189 - part = __disk_get_part(disk, partno); 190 - if (part) 191 - get_device(part_to_dev(part)); 189 + bdev = __disk_get_part(disk, partno); 190 + if (!bdev) 191 + goto fail; 192 + part = bdev->bd_part; 193 + if (!kobject_get_unless_zero(&part_to_dev(part)->kobj)) 194 + goto fail; 192 195 rcu_read_unlock(); 193 - 194 196 return part; 197 + fail: 198 + rcu_read_unlock(); 199 + return NULL; 195 200 } 196 201 197 202 /** ··· 271 264 272 265 /* iterate to the next partition */ 273 266 for (; piter->idx != end; piter->idx += inc) { 274 - struct hd_struct *part; 267 + struct block_device *part; 275 268 276 269 part = rcu_dereference(ptbl->part[piter->idx]); 277 270 if (!part) 278 271 continue; 279 - if (!bdev_nr_sectors(part->bdev) && 272 + if (!bdev_nr_sectors(part) && 280 273 !(piter->flags & DISK_PITER_INCL_EMPTY) && 281 274 !(piter->flags & DISK_PITER_INCL_EMPTY_PART0 && 282 275 piter->idx == 0)) 283 276 continue; 284 277 285 - get_device(part_to_dev(part)); 286 - piter->part = part; 278 + get_device(part_to_dev(part->bd_part)); 279 + piter->part = part->bd_part; 287 280 piter->idx += inc; 288 281 break; 289 282 } ··· 310 303 } 311 304 EXPORT_SYMBOL_GPL(disk_part_iter_exit); 312 305 313 - static inline int sector_in_part(struct hd_struct *part, sector_t sector) 306 + static inline int sector_in_part(struct block_device *part, sector_t sector) 314 307 { 315 - return part->bdev->bd_start_sect <= sector && 316 - sector < part->bdev->bd_start_sect + bdev_nr_sectors(part->bdev); 308 + return part->bd_start_sect <= sector && 309 + sector < part->bd_start_sect + bdev_nr_sectors(part); 317 310 } 318 311 319 312 /** ··· 331 324 * Found partition on success, part0 is returned if no partition matches 332 325 * or the matched partition is being deleted. 333 326 */ 334 - struct hd_struct *disk_map_sector_rcu(struct gendisk *disk, sector_t sector) 327 + struct block_device *disk_map_sector_rcu(struct gendisk *disk, sector_t sector) 335 328 { 336 329 struct disk_part_tbl *ptbl; 337 - struct hd_struct *part; 330 + struct block_device *part; 338 331 int i; 339 332 340 333 rcu_read_lock(); ··· 353 346 } 354 347 } 355 348 356 - part = disk->part0->bd_part; 349 + part = disk->part0; 357 350 out_unlock: 358 351 rcu_read_unlock(); 359 352 return part; ··· 889 882 kobject_put(disk->part0->bd_holder_dir); 890 883 kobject_put(disk->slave_dir); 891 884 892 - part_stat_set_all(disk->part0->bd_part, 0); 885 + part_stat_set_all(disk->part0, 0); 893 886 disk->part0->bd_stamp = 0; 894 887 if (!sysfs_deprecated) 895 888 sysfs_remove_link(block_depr, dev_name(disk_to_dev(disk))); ··· 1196 1189 1197 1190 part_stat_read_all(p, &stat); 1198 1191 if (queue_is_mq(q)) 1199 - inflight = blk_mq_in_flight(q, p); 1192 + inflight = blk_mq_in_flight(q, p->bdev); 1200 1193 else 1201 - inflight = part_in_flight(p); 1194 + inflight = part_in_flight(p->bdev); 1202 1195 1203 1196 return sprintf(buf, 1204 1197 "%8lu %8lu %8llu %8u " ··· 1238 1231 unsigned int inflight[2]; 1239 1232 1240 1233 if (queue_is_mq(q)) 1241 - blk_mq_in_flight_rw(q, p, inflight); 1234 + blk_mq_in_flight_rw(q, p->bdev, inflight); 1242 1235 else 1243 - part_in_flight_rw(p, inflight); 1236 + part_in_flight_rw(p->bdev, inflight); 1244 1237 1245 1238 return sprintf(buf, "%8u %8u\n", inflight[0], inflight[1]); 1246 1239 } ··· 1513 1506 while ((hd = disk_part_iter_next(&piter))) { 1514 1507 part_stat_read_all(hd, &stat); 1515 1508 if (queue_is_mq(gp->queue)) 1516 - inflight = blk_mq_in_flight(gp->queue, hd); 1509 + inflight = blk_mq_in_flight(gp->queue, hd->bdev); 1517 1510 else 1518 - inflight = part_in_flight(hd); 1511 + inflight = part_in_flight(hd->bdev); 1519 1512 1520 1513 seq_printf(seqf, "%4d %7d %s " 1521 1514 "%lu %lu %lu %u " ··· 1633 1626 goto out_bdput; 1634 1627 1635 1628 ptbl = rcu_dereference_protected(disk->part_tbl, 1); 1636 - rcu_assign_pointer(ptbl->part[0], disk->part0->bd_part); 1629 + rcu_assign_pointer(ptbl->part[0], disk->part0); 1637 1630 1638 1631 disk->minors = minors; 1639 1632 rand_initialize_disk(disk);
+2 -5
block/partitions/core.c
··· 298 298 struct disk_part_tbl *ptbl = 299 299 rcu_dereference_protected(disk->part_tbl, 1); 300 300 301 - /* 302 - * ->part_tbl is referenced in this part's release handler, so 303 - * we have to hold the disk device 304 - */ 305 301 rcu_assign_pointer(ptbl->part[part->partno], NULL); 306 302 rcu_assign_pointer(ptbl->last_lookup, NULL); 303 + 307 304 kobject_put(part->bdev->bd_holder_dir); 308 305 device_del(part_to_dev(part)); 309 306 ··· 418 421 419 422 /* everything is up and running, commence */ 420 423 bdev_add(bdev, devt); 421 - rcu_assign_pointer(ptbl->part[partno], p); 424 + rcu_assign_pointer(ptbl->part[partno], bdev); 422 425 423 426 /* suppress uevent if the disk suppresses it */ 424 427 if (!dev_get_uevent_suppress(ddev))
+1 -1
drivers/block/drbd/drbd_receiver.c
··· 2802 2802 if (c_min_rate == 0) 2803 2803 return false; 2804 2804 2805 - curr_events = (int)part_stat_read_accum(disk->part0->bd_part, sectors) - 2805 + curr_events = (int)part_stat_read_accum(disk->part0, sectors) - 2806 2806 atomic_read(&device->rs_sect_ev); 2807 2807 2808 2808 if (atomic_read(&device->ap_actlog_cnt)
+1 -1
drivers/block/drbd/drbd_worker.c
··· 1679 1679 atomic_set(&device->rs_sect_ev, 0); 1680 1680 device->rs_in_flight = 0; 1681 1681 device->rs_last_events = 1682 - (int)part_stat_read_accum(disk->part0->bd_part, sectors); 1682 + (int)part_stat_read_accum(disk->part0, sectors); 1683 1683 1684 1684 /* Updating the RCU protected object in place is necessary since 1685 1685 this function gets called from atomic context.
+1 -1
drivers/block/zram/zram_drv.c
··· 1687 1687 zram->disksize = 0; 1688 1688 1689 1689 set_capacity_and_notify(zram->disk, 0); 1690 - part_stat_set_all(zram->disk->part0->bd_part, 0); 1690 + part_stat_set_all(zram->disk->part0, 0); 1691 1691 1692 1692 up_write(&zram->init_lock); 1693 1693 /* I/O operation under all of CPU are done so let's free */
+2 -2
drivers/md/bcache/request.c
··· 475 475 unsigned int read_dirty_data:1; 476 476 unsigned int cache_missed:1; 477 477 478 - struct hd_struct *part; 478 + struct block_device *part; 479 479 unsigned long start_time; 480 480 481 481 struct btree_op op; ··· 1073 1073 unsigned long start_time; 1074 1074 bio_end_io_t *bi_end_io; 1075 1075 void *bi_private; 1076 - struct hd_struct *part; 1076 + struct block_device *part; 1077 1077 }; 1078 1078 1079 1079 static void detached_dev_end_io(struct bio *bio)
+2 -2
drivers/md/dm.c
··· 1607 1607 * (by eliminating DM's splitting and just using bio_split) 1608 1608 */ 1609 1609 part_stat_lock(); 1610 - __dm_part_stat_sub(dm_disk(md)->part0->bd_part, 1610 + __dm_part_stat_sub(dm_disk(md)->part0, 1611 1611 sectors[op_stat_group(bio_op(bio))], ci.sector_count); 1612 1612 part_stat_unlock(); 1613 1613 ··· 2242 2242 static bool md_in_flight_bios(struct mapped_device *md) 2243 2243 { 2244 2244 int cpu; 2245 - struct hd_struct *part = dm_disk(md)->part0->bd_part; 2245 + struct block_device *part = dm_disk(md)->part0; 2246 2246 long sum = 0; 2247 2247 2248 2248 for_each_possible_cpu(cpu) {
+2 -2
drivers/md/md.c
··· 464 464 bio_end_io_t *orig_bi_end_io; 465 465 void *orig_bi_private; 466 466 unsigned long start_time; 467 - struct hd_struct *part; 467 + struct block_device *part; 468 468 }; 469 469 470 470 static void md_end_io(struct bio *bio) ··· 8441 8441 rcu_read_lock(); 8442 8442 rdev_for_each_rcu(rdev, mddev) { 8443 8443 struct gendisk *disk = rdev->bdev->bd_disk; 8444 - curr_events = (int)part_stat_read_accum(disk->part0->bd_part, sectors) - 8444 + curr_events = (int)part_stat_read_accum(disk->part0, sectors) - 8445 8445 atomic_read(&disk->sync_io); 8446 8446 /* sync IO will cause sync_io to increase before the disk_stats 8447 8447 * as sync_io is counted when a request starts, and
+10 -10
drivers/nvme/target/admin-cmd.c
··· 89 89 if (!ns->bdev) 90 90 goto out; 91 91 92 - host_reads = part_stat_read(ns->bdev->bd_part, ios[READ]); 93 - data_units_read = DIV_ROUND_UP(part_stat_read(ns->bdev->bd_part, 94 - sectors[READ]), 1000); 95 - host_writes = part_stat_read(ns->bdev->bd_part, ios[WRITE]); 96 - data_units_written = DIV_ROUND_UP(part_stat_read(ns->bdev->bd_part, 97 - sectors[WRITE]), 1000); 92 + host_reads = part_stat_read(ns->bdev, ios[READ]); 93 + data_units_read = 94 + DIV_ROUND_UP(part_stat_read(ns->bdev, sectors[READ]), 1000); 95 + host_writes = part_stat_read(ns->bdev, ios[WRITE]); 96 + data_units_written = 97 + DIV_ROUND_UP(part_stat_read(ns->bdev, sectors[WRITE]), 1000); 98 98 99 99 put_unaligned_le64(host_reads, &slog->host_reads[0]); 100 100 put_unaligned_le64(data_units_read, &slog->data_units_read[0]); ··· 120 120 /* we don't have the right data for file backed ns */ 121 121 if (!ns->bdev) 122 122 continue; 123 - host_reads += part_stat_read(ns->bdev->bd_part, ios[READ]); 123 + host_reads += part_stat_read(ns->bdev, ios[READ]); 124 124 data_units_read += DIV_ROUND_UP( 125 - part_stat_read(ns->bdev->bd_part, sectors[READ]), 1000); 126 - host_writes += part_stat_read(ns->bdev->bd_part, ios[WRITE]); 125 + part_stat_read(ns->bdev, sectors[READ]), 1000); 126 + host_writes += part_stat_read(ns->bdev, ios[WRITE]); 127 127 data_units_written += DIV_ROUND_UP( 128 - part_stat_read(ns->bdev->bd_part, sectors[WRITE]), 1000); 128 + part_stat_read(ns->bdev, sectors[WRITE]), 1000); 129 129 } 130 130 131 131 put_unaligned_le64(host_reads, &slog->host_reads[0]);
+6 -12
fs/ext4/super.c
··· 4048 4048 sbi->s_sb = sb; 4049 4049 sbi->s_inode_readahead_blks = EXT4_DEF_INODE_READAHEAD_BLKS; 4050 4050 sbi->s_sb_block = sb_block; 4051 - if (sb->s_bdev->bd_part) 4052 - sbi->s_sectors_written_start = 4053 - part_stat_read(sb->s_bdev->bd_part, sectors[STAT_WRITE]); 4051 + sbi->s_sectors_written_start = 4052 + part_stat_read(sb->s_bdev, sectors[STAT_WRITE]); 4054 4053 4055 4054 /* Cleanup superblock name */ 4056 4055 strreplace(sb->s_id, '/', '!'); ··· 5508 5509 */ 5509 5510 if (!(sb->s_flags & SB_RDONLY)) 5510 5511 ext4_update_tstamp(es, s_wtime); 5511 - if (sb->s_bdev->bd_part) 5512 - es->s_kbytes_written = 5513 - cpu_to_le64(EXT4_SB(sb)->s_kbytes_written + 5514 - ((part_stat_read(sb->s_bdev->bd_part, 5515 - sectors[STAT_WRITE]) - 5516 - EXT4_SB(sb)->s_sectors_written_start) >> 1)); 5517 - else 5518 - es->s_kbytes_written = 5519 - cpu_to_le64(EXT4_SB(sb)->s_kbytes_written); 5512 + es->s_kbytes_written = 5513 + cpu_to_le64(EXT4_SB(sb)->s_kbytes_written + 5514 + ((part_stat_read(sb->s_bdev, sectors[STAT_WRITE]) - 5515 + EXT4_SB(sb)->s_sectors_written_start) >> 1)); 5520 5516 if (percpu_counter_initialized(&EXT4_SB(sb)->s_freeclusters_counter)) 5521 5517 ext4_free_blocks_count_set(es, 5522 5518 EXT4_C2B(EXT4_SB(sb), percpu_counter_sum_positive(
+2 -8
fs/ext4/sysfs.c
··· 62 62 { 63 63 struct super_block *sb = sbi->s_buddy_cache->i_sb; 64 64 65 - if (!sb->s_bdev->bd_part) 66 - return snprintf(buf, PAGE_SIZE, "0\n"); 67 65 return snprintf(buf, PAGE_SIZE, "%lu\n", 68 - (part_stat_read(sb->s_bdev->bd_part, 69 - sectors[STAT_WRITE]) - 66 + (part_stat_read(sb->s_bdev, sectors[STAT_WRITE]) - 70 67 sbi->s_sectors_written_start) >> 1); 71 68 } 72 69 ··· 71 74 { 72 75 struct super_block *sb = sbi->s_buddy_cache->i_sb; 73 76 74 - if (!sb->s_bdev->bd_part) 75 - return snprintf(buf, PAGE_SIZE, "0\n"); 76 77 return snprintf(buf, PAGE_SIZE, "%llu\n", 77 78 (unsigned long long)(sbi->s_kbytes_written + 78 - ((part_stat_read(sb->s_bdev->bd_part, 79 - sectors[STAT_WRITE]) - 79 + ((part_stat_read(sb->s_bdev, sectors[STAT_WRITE]) - 80 80 EXT4_SB(sb)->s_sectors_written_start) >> 1))); 81 81 } 82 82
+1 -1
fs/f2fs/f2fs.h
··· 1675 1675 * and the return value is in kbytes. s is of struct f2fs_sb_info. 1676 1676 */ 1677 1677 #define BD_PART_WRITTEN(s) \ 1678 - (((u64)part_stat_read((s)->sb->s_bdev->bd_part, sectors[STAT_WRITE]) - \ 1678 + (((u64)part_stat_read((s)->sb->s_bdev, sectors[STAT_WRITE]) - \ 1679 1679 (s)->sectors_written_start) >> 1) 1680 1680 1681 1681 static inline void f2fs_update_time(struct f2fs_sb_info *sbi, int type)
+2 -4
fs/f2fs/super.c
··· 3700 3700 } 3701 3701 3702 3702 /* For write statistics */ 3703 - if (sb->s_bdev->bd_part) 3704 - sbi->sectors_written_start = 3705 - (u64)part_stat_read(sb->s_bdev->bd_part, 3706 - sectors[STAT_WRITE]); 3703 + sbi->sectors_written_start = 3704 + (u64)part_stat_read(sb->s_bdev, sectors[STAT_WRITE]); 3707 3705 3708 3706 /* Read accumulated write IO statistics if exists */ 3709 3707 seg_i = CURSEG_I(sbi, CURSEG_HOT_NODE);
+4 -4
include/linux/blkdev.h
··· 191 191 }; 192 192 193 193 struct gendisk *rq_disk; 194 - struct hd_struct *part; 194 + struct block_device *part; 195 195 #ifdef CONFIG_BLK_RQ_ALLOC_TIME 196 196 /* Time that the first bio started allocating this request. */ 197 197 u64 alloc_time_ns; ··· 1943 1943 void disk_end_io_acct(struct gendisk *disk, unsigned int op, 1944 1944 unsigned long start_time); 1945 1945 1946 - unsigned long part_start_io_acct(struct gendisk *disk, struct hd_struct **part, 1947 - struct bio *bio); 1948 - void part_end_io_acct(struct hd_struct *part, struct bio *bio, 1946 + unsigned long part_start_io_acct(struct gendisk *disk, 1947 + struct block_device **part, struct bio *bio); 1948 + void part_end_io_acct(struct block_device *part, struct bio *bio, 1949 1949 unsigned long start_time); 1950 1950 1951 1951 /**
+2 -2
include/linux/genhd.h
··· 131 131 struct disk_part_tbl { 132 132 struct rcu_head rcu_head; 133 133 int len; 134 - struct hd_struct __rcu *last_lookup; 135 - struct hd_struct __rcu *part[]; 134 + struct block_device __rcu *last_lookup; 135 + struct block_device __rcu *part[]; 136 136 }; 137 137 138 138 struct disk_events;
+8 -9
include/linux/part_stat.h
··· 25 25 #define part_stat_unlock() preempt_enable() 26 26 27 27 #define part_stat_get_cpu(part, field, cpu) \ 28 - (per_cpu_ptr((part)->bdev->bd_stats, (cpu))->field) 28 + (per_cpu_ptr((part)->bd_stats, (cpu))->field) 29 29 30 30 #define part_stat_get(part, field) \ 31 31 part_stat_get_cpu(part, field, smp_processor_id()) 32 32 33 33 #define part_stat_read(part, field) \ 34 34 ({ \ 35 - typeof((part)->bdev->bd_stats->field) res = 0; \ 35 + typeof((part)->bd_stats->field) res = 0; \ 36 36 unsigned int _cpu; \ 37 37 for_each_possible_cpu(_cpu) \ 38 - res += per_cpu_ptr((part)->bdev->bd_stats, _cpu)->field; \ 38 + res += per_cpu_ptr((part)->bd_stats, _cpu)->field; \ 39 39 res; \ 40 40 }) 41 41 42 - static inline void part_stat_set_all(struct hd_struct *part, int value) 42 + static inline void part_stat_set_all(struct block_device *part, int value) 43 43 { 44 44 int i; 45 45 46 46 for_each_possible_cpu(i) 47 - memset(per_cpu_ptr(part->bdev->bd_stats, i), value, 47 + memset(per_cpu_ptr(part->bd_stats, i), value, 48 48 sizeof(struct disk_stats)); 49 49 } 50 50 ··· 54 54 part_stat_read(part, field[STAT_DISCARD])) 55 55 56 56 #define __part_stat_add(part, field, addnd) \ 57 - __this_cpu_add((part)->bdev->bd_stats->field, addnd) 57 + __this_cpu_add((part)->bd_stats->field, addnd) 58 58 59 59 #define part_stat_add(part, field, addnd) do { \ 60 60 __part_stat_add((part), field, addnd); \ 61 - if ((part)->partno) \ 62 - __part_stat_add(part_to_disk((part))->part0->bd_part, \ 63 - field, addnd); \ 61 + if ((part)->bd_partno) \ 62 + __part_stat_add(bdev_whole(part), field, addnd); \ 64 63 } while (0) 65 64 66 65 #define part_stat_dec(part, field) \