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

block: store a gendisk in struct parsed_partitions

Partition scanning only happens on the whole device, so pass a
struct gendisk instead of the whole device block_device to the scanners.
This allows to simplify printing the device name in various places as the
disk name is available in disk->name.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Link: https://lore.kernel.org/r/20210810154512.1809898-2-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Christoph Hellwig and committed by
Jens Axboe
a08aa9bc 50b4aecf

+52 -73
+2 -2
block/partitions/acorn.c
··· 275 275 /* 276 276 * Work out start of non-adfs partition. 277 277 */ 278 - nr_sects = (state->bdev->bd_inode->i_size >> 9) - start_sect; 278 + nr_sects = get_capacity(state->disk) - start_sect; 279 279 280 280 if (start_sect) { 281 281 switch (id) { ··· 540 540 if (i != 0) { 541 541 sector_t size; 542 542 543 - size = get_capacity(state->bdev->bd_disk); 543 + size = get_capacity(state->disk); 544 544 put_partition(state, slot++, start, size - start); 545 545 strlcat(state->pp_buf, "\n", PAGE_SIZE); 546 546 }
+2 -18
block/partitions/aix.c
··· 67 67 #define LVM_MAXLVS 256 68 68 69 69 /** 70 - * last_lba(): return number of last logical block of device 71 - * @bdev: block device 72 - * 73 - * Description: Returns last LBA value on success, 0 on error. 74 - * This is stored (by sd and ide-geometry) in 75 - * the part[0] entry for this disk, and is the number of 76 - * physical sectors available on the disk. 77 - */ 78 - static u64 last_lba(struct block_device *bdev) 79 - { 80 - if (!bdev || !bdev->bd_inode) 81 - return 0; 82 - return (bdev->bd_inode->i_size >> 9) - 1ULL; 83 - } 84 - 85 - /** 86 70 * read_lba(): Read bytes from disk, starting at given LBA 87 71 * @state 88 72 * @lba 89 73 * @buffer 90 74 * @count 91 75 * 92 - * Description: Reads @count bytes from @state->bdev into @buffer. 76 + * Description: Reads @count bytes from @state->disk into @buffer. 93 77 * Returns number of bytes read on success, 0 on error. 94 78 */ 95 79 static size_t read_lba(struct parsed_partitions *state, u64 lba, u8 *buffer, ··· 81 97 { 82 98 size_t totalreadcount = 0; 83 99 84 - if (!buffer || lba + count / 512 > last_lba(state->bdev)) 100 + if (!buffer || lba + count / 512 > get_capacity(state->disk) - 1ULL) 85 101 return 0; 86 102 87 103 while (count) {
+3 -4
block/partitions/amiga.c
··· 34 34 int start_sect, nr_sects, blk, part, res = 0; 35 35 int blksize = 1; /* Multiplier for disk block size */ 36 36 int slot = 1; 37 - char b[BDEVNAME_SIZE]; 38 37 39 38 for (blk = 0; ; blk++, put_dev_sector(sect)) { 40 39 if (blk == RDB_ALLOCATION_LIMIT) ··· 41 42 data = read_part_sector(state, blk, &sect); 42 43 if (!data) { 43 44 pr_err("Dev %s: unable to read RDB block %d\n", 44 - bdevname(state->bdev, b), blk); 45 + state->disk->disk_name, blk); 45 46 res = -1; 46 47 goto rdb_done; 47 48 } ··· 63 64 } 64 65 65 66 pr_err("Dev %s: RDB in block %d has bad checksum\n", 66 - bdevname(state->bdev, b), blk); 67 + state->disk->disk_name, blk); 67 68 } 68 69 69 70 /* blksize is blocks per 512 byte standard block */ ··· 83 84 data = read_part_sector(state, blk, &sect); 84 85 if (!data) { 85 86 pr_err("Dev %s: unable to read partition block %d\n", 86 - bdevname(state->bdev, b), blk); 87 + state->disk->disk_name, blk); 87 88 res = -1; 88 89 goto rdb_done; 89 90 }
+2 -2
block/partitions/atari.c
··· 47 47 * ATARI partition scheme supports 512 lba only. If this is not 48 48 * the case, bail early to avoid miscalculating hd_size. 49 49 */ 50 - if (bdev_logical_block_size(state->bdev) != 512) 50 + if (queue_logical_block_size(state->disk->queue) != 512) 51 51 return 0; 52 52 53 53 rs = read_part_sector(state, 0, &sect); ··· 55 55 return -1; 56 56 57 57 /* Verify this is an Atari rootsector: */ 58 - hd_size = state->bdev->bd_inode->i_size >> 9; 58 + hd_size = get_capacity(state->disk); 59 59 if (!VALID_PARTITION(&rs->part[0], hd_size) && 60 60 !VALID_PARTITION(&rs->part[1], hd_size) && 61 61 !VALID_PARTITION(&rs->part[2], hd_size) &&
+1 -1
block/partitions/check.h
··· 9 9 * description. 10 10 */ 11 11 struct parsed_partitions { 12 - struct block_device *bdev; 12 + struct gendisk *disk; 13 13 char name[BDEVNAME_SIZE]; 14 14 struct { 15 15 sector_t from;
+2 -4
block/partitions/cmdline.c
··· 380 380 int cmdline_partition(struct parsed_partitions *state) 381 381 { 382 382 sector_t disk_size; 383 - char bdev[BDEVNAME_SIZE]; 384 383 struct cmdline_parts *parts; 385 384 386 385 if (cmdline) { ··· 396 397 if (!bdev_parts) 397 398 return 0; 398 399 399 - bdevname(state->bdev, bdev); 400 - parts = cmdline_parts_find(bdev_parts, bdev); 400 + parts = cmdline_parts_find(bdev_parts, state->disk->disk_name); 401 401 if (!parts) 402 402 return 0; 403 403 404 - disk_size = get_capacity(state->bdev->bd_disk) << 9; 404 + disk_size = get_capacity(state->disk) << 9; 405 405 406 406 cmdline_parts_set(parts, disk_size, state); 407 407 cmdline_parts_verifier(1, state);
+3 -3
block/partitions/core.c
··· 135 135 } 136 136 state->pp_buf[0] = '\0'; 137 137 138 - state->bdev = hd->part0; 138 + state->disk = hd; 139 139 snprintf(state->name, BDEVNAME_SIZE, "%s", hd->disk_name); 140 140 snprintf(state->pp_buf, PAGE_SIZE, " %s:", state->name); 141 141 if (isdigit(state->name[strlen(state->name)-1])) ··· 717 717 718 718 void *read_part_sector(struct parsed_partitions *state, sector_t n, Sector *p) 719 719 { 720 - struct address_space *mapping = state->bdev->bd_inode->i_mapping; 720 + struct address_space *mapping = state->disk->part0->bd_inode->i_mapping; 721 721 struct page *page; 722 722 723 - if (n >= get_capacity(state->bdev->bd_disk)) { 723 + if (n >= get_capacity(state->disk)) { 724 724 state->access_beyond_eod = true; 725 725 return NULL; 726 726 }
+17 -19
block/partitions/efi.c
··· 124 124 125 125 /** 126 126 * last_lba(): return number of last logical block of device 127 - * @bdev: block device 127 + * @disk: block device 128 128 * 129 129 * Description: Returns last LBA value on success, 0 on error. 130 130 * This is stored (by sd and ide-geometry) in 131 131 * the part[0] entry for this disk, and is the number of 132 132 * physical sectors available on the disk. 133 133 */ 134 - static u64 last_lba(struct block_device *bdev) 134 + static u64 last_lba(struct gendisk *disk) 135 135 { 136 - if (!bdev || !bdev->bd_inode) 137 - return 0; 138 - return div_u64(bdev->bd_inode->i_size, 139 - bdev_logical_block_size(bdev)) - 1ULL; 136 + return div_u64(disk->part0->bd_inode->i_size, 137 + queue_logical_block_size(disk->queue)) - 1ULL; 140 138 } 141 139 142 140 static inline int pmbr_part_valid(gpt_mbr_record *part) ··· 229 231 * @buffer: destination buffer 230 232 * @count: bytes to read 231 233 * 232 - * Description: Reads @count bytes from @state->bdev into @buffer. 234 + * Description: Reads @count bytes from @state->disk into @buffer. 233 235 * Returns number of bytes read on success, 0 on error. 234 236 */ 235 237 static size_t read_lba(struct parsed_partitions *state, 236 238 u64 lba, u8 *buffer, size_t count) 237 239 { 238 240 size_t totalreadcount = 0; 239 - struct block_device *bdev = state->bdev; 240 - sector_t n = lba * (bdev_logical_block_size(bdev) / 512); 241 + sector_t n = lba * 242 + (queue_logical_block_size(state->disk->queue) / 512); 241 243 242 - if (!buffer || lba > last_lba(bdev)) 244 + if (!buffer || lba > last_lba(state->disk)) 243 245 return 0; 244 246 245 247 while (count) { ··· 300 302 * @lba: the Logical Block Address of the partition table 301 303 * 302 304 * Description: returns GPT header on success, NULL on error. Allocates 303 - * and fills a GPT header starting at @ from @state->bdev. 305 + * and fills a GPT header starting at @ from @state->disk. 304 306 * Note: remember to free gpt when finished with it. 305 307 */ 306 308 static gpt_header *alloc_read_gpt_header(struct parsed_partitions *state, 307 309 u64 lba) 308 310 { 309 311 gpt_header *gpt; 310 - unsigned ssz = bdev_logical_block_size(state->bdev); 312 + unsigned ssz = queue_logical_block_size(state->disk->queue); 311 313 312 314 gpt = kmalloc(ssz, GFP_KERNEL); 313 315 if (!gpt) ··· 354 356 355 357 /* Check the GUID Partition Table header size is too big */ 356 358 if (le32_to_cpu((*gpt)->header_size) > 357 - bdev_logical_block_size(state->bdev)) { 359 + queue_logical_block_size(state->disk->queue)) { 358 360 pr_debug("GUID Partition Table Header size is too large: %u > %u\n", 359 361 le32_to_cpu((*gpt)->header_size), 360 - bdev_logical_block_size(state->bdev)); 362 + queue_logical_block_size(state->disk->queue)); 361 363 goto fail; 362 364 } 363 365 ··· 393 395 /* Check the first_usable_lba and last_usable_lba are 394 396 * within the disk. 395 397 */ 396 - lastlba = last_lba(state->bdev); 398 + lastlba = last_lba(state->disk); 397 399 if (le64_to_cpu((*gpt)->first_usable_lba) > lastlba) { 398 400 pr_debug("GPT: first_usable_lba incorrect: %lld > %lld\n", 399 401 (unsigned long long)le64_to_cpu((*gpt)->first_usable_lba), ··· 585 587 gpt_header *pgpt = NULL, *agpt = NULL; 586 588 gpt_entry *pptes = NULL, *aptes = NULL; 587 589 legacy_mbr *legacymbr; 588 - sector_t total_sectors = i_size_read(state->bdev->bd_inode) >> 9; 590 + sector_t total_sectors = get_capacity(state->disk); 589 591 u64 lastlba; 590 592 591 593 if (!ptes) 592 594 return 0; 593 595 594 - lastlba = last_lba(state->bdev); 596 + lastlba = last_lba(state->disk); 595 597 if (!force_gpt) { 596 598 /* This will be added to the EFI Spec. per Intel after v1.02. */ 597 599 legacymbr = kzalloc(sizeof(*legacymbr), GFP_KERNEL); ··· 703 705 gpt_header *gpt = NULL; 704 706 gpt_entry *ptes = NULL; 705 707 u32 i; 706 - unsigned ssz = bdev_logical_block_size(state->bdev) / 512; 708 + unsigned ssz = queue_logical_block_size(state->disk->queue) / 512; 707 709 708 710 if (!find_valid_gpt(state, &gpt, &ptes) || !gpt || !ptes) { 709 711 kfree(gpt); ··· 720 722 u64 size = le64_to_cpu(ptes[i].ending_lba) - 721 723 le64_to_cpu(ptes[i].starting_lba) + 1ULL; 722 724 723 - if (!is_pte_valid(&ptes[i], last_lba(state->bdev))) 725 + if (!is_pte_valid(&ptes[i], last_lba(state->disk))) 724 726 continue; 725 727 726 728 put_partition(state, i+1, start * ssz, size * ssz);
+2 -2
block/partitions/ibm.c
··· 290 290 int ibm_partition(struct parsed_partitions *state) 291 291 { 292 292 int (*fn)(struct gendisk *disk, dasd_information2_t *info); 293 - struct block_device *bdev = state->bdev; 294 - struct gendisk *disk = bdev->bd_disk; 293 + struct gendisk *disk = state->disk; 294 + struct block_device *bdev = disk->part0; 295 295 int blocksize, res; 296 296 loff_t i_size, offset, size; 297 297 dasd_information2_t *info;
+9 -9
block/partitions/ldm.c
··· 304 304 } 305 305 } 306 306 307 - num_sects = state->bdev->bd_inode->i_size >> 9; 307 + num_sects = get_capacity(state->disk); 308 308 309 309 if ((ph[0]->config_start > num_sects) || 310 310 ((ph[0]->config_start + ph[0]->config_size) > num_sects)) { ··· 339 339 /** 340 340 * ldm_validate_tocblocks - Validate the table of contents and its backups 341 341 * @state: Partition check state including device holding the LDM Database 342 - * @base: Offset, into @state->bdev, of the database 342 + * @base: Offset, into @state->disk, of the database 343 343 * @ldb: Cache of the database structures 344 344 * 345 345 * Find and compare the four tables of contents of the LDM Database stored on 346 - * @state->bdev and return the parsed information into @toc1. 346 + * @state->disk and return the parsed information into @toc1. 347 347 * 348 348 * The offsets and sizes of the configs are range-checked against a privhead. 349 349 * ··· 486 486 * only likely to happen if the underlying device is strange. If that IS 487 487 * the case we should return zero to let someone else try. 488 488 * 489 - * Return: 'true' @state->bdev is a dynamic disk 490 - * 'false' @state->bdev is not a dynamic disk, or an error occurred 489 + * Return: 'true' @state->disk is a dynamic disk 490 + * 'false' @state->disk is not a dynamic disk, or an error occurred 491 491 */ 492 492 static bool ldm_validate_partition_table(struct parsed_partitions *state) 493 493 { ··· 1340 1340 /** 1341 1341 * ldm_get_vblks - Read the on-disk database of VBLKs into memory 1342 1342 * @state: Partition check state including device holding the LDM Database 1343 - * @base: Offset, into @state->bdev, of the database 1343 + * @base: Offset, into @state->disk, of the database 1344 1344 * @ldb: Cache of the database structures 1345 1345 * 1346 1346 * To use the information from the VBLKs, they need to be read from the disk, ··· 1432 1432 * example, if the device is hda, we would have: hda1: LDM database, hda2, hda3, 1433 1433 * and so on: the actual data containing partitions. 1434 1434 * 1435 - * Return: 1 Success, @state->bdev is a dynamic disk and we handled it 1436 - * 0 Success, @state->bdev is not a dynamic disk 1435 + * Return: 1 Success, @state->disk is a dynamic disk and we handled it 1436 + * 0 Success, @state->disk is not a dynamic disk 1437 1437 * -1 An error occurred before enough information had been read 1438 - * Or @state->bdev is a dynamic disk, but it may be corrupted 1438 + * Or @state->disk is a dynamic disk, but it may be corrupted 1439 1439 */ 1440 1440 int ldm_partition(struct parsed_partitions *state) 1441 1441 {
+1 -1
block/partitions/mac.c
··· 133 133 } 134 134 #ifdef CONFIG_PPC_PMAC 135 135 if (found_root_goodness) 136 - note_bootable_part(state->bdev->bd_dev, found_root, 136 + note_bootable_part(state->disk->part0->bd_dev, found_root, 137 137 found_root_goodness); 138 138 #endif 139 139
+4 -2
block/partitions/msdos.c
··· 135 135 Sector sect; 136 136 unsigned char *data; 137 137 sector_t this_sector, this_size; 138 - sector_t sector_size = bdev_logical_block_size(state->bdev) / 512; 138 + sector_t sector_size; 139 139 int loopct = 0; /* number of links followed 140 140 without finding a data partition */ 141 141 int i; 142 142 143 + sector_size = queue_logical_block_size(state->disk->queue) / 512; 143 144 this_sector = first_sector; 144 145 this_size = first_size; 145 146 ··· 580 579 581 580 int msdos_partition(struct parsed_partitions *state) 582 581 { 583 - sector_t sector_size = bdev_logical_block_size(state->bdev) / 512; 582 + sector_t sector_size; 584 583 Sector sect; 585 584 unsigned char *data; 586 585 struct msdos_partition *p; ··· 588 587 int slot; 589 588 u32 disksig; 590 589 590 + sector_size = queue_logical_block_size(state->disk->queue) / 512; 591 591 data = read_part_sector(state, 0, &sect); 592 592 if (!data) 593 593 return -1;
+2 -3
block/partitions/sgi.c
··· 43 43 Sector sect; 44 44 struct sgi_disklabel *label; 45 45 struct sgi_partition *p; 46 - char b[BDEVNAME_SIZE]; 47 46 48 47 label = read_part_sector(state, 0, &sect); 49 48 if (!label) ··· 51 52 magic = label->magic_mushroom; 52 53 if(be32_to_cpu(magic) != SGI_LABEL_MAGIC) { 53 54 /*printk("Dev %s SGI disklabel: bad magic %08x\n", 54 - bdevname(bdev, b), be32_to_cpu(magic));*/ 55 + state->disk->disk_name, be32_to_cpu(magic));*/ 55 56 put_dev_sector(sect); 56 57 return 0; 57 58 } ··· 62 63 } 63 64 if(csum) { 64 65 printk(KERN_WARNING "Dev %s SGI disklabel: csum bad, label corrupted\n", 65 - bdevname(state->bdev, b)); 66 + state->disk->disk_name); 66 67 put_dev_sector(sect); 67 68 return 0; 68 69 }
+2 -3
block/partitions/sun.c
··· 65 65 } * label; 66 66 struct sun_partition *p; 67 67 unsigned long spc; 68 - char b[BDEVNAME_SIZE]; 69 68 int use_vtoc; 70 69 int nparts; 71 70 ··· 75 76 p = label->partitions; 76 77 if (be16_to_cpu(label->magic) != SUN_LABEL_MAGIC) { 77 78 /* printk(KERN_INFO "Dev %s Sun disklabel: bad magic %04x\n", 78 - bdevname(bdev, b), be16_to_cpu(label->magic)); */ 79 + state->disk->disk_name, be16_to_cpu(label->magic)); */ 79 80 put_dev_sector(sect); 80 81 return 0; 81 82 } ··· 85 86 csum ^= *ush--; 86 87 if (csum) { 87 88 printk("Dev %s Sun disklabel: Csum bad, label corrupted\n", 88 - bdevname(state->bdev, b)); 89 + state->disk->disk_name); 89 90 put_dev_sector(sect); 90 91 return 0; 91 92 }