Add a littler helper to make the somewhat arcane bd_contains checks a little more obvious.
Unified · Split
| @@ -64,7 +64,7 @@ int __blkdev_issue_discard(struct block_device *bdev, sector_t sector, · 63 unmodified lines | ||
| 64 | 64 | return -EINVAL; |
| 65 | 65 | |
| 66 | 66 | /* In case the discard request is in a partition */ |
| 67 | − if (bdev->bd_partno) | |
| 67 | + if (bdev_is_partition(bdev)) | |
| 68 | 68 | part_offset = bdev->bd_part->start_sect; |
| 69 | 69 | |
| 70 | 70 | while (nr_sects) { |
| @@ -23,7 +23,7 @@ static int blkpg_do_ioctl(struct block_device *bdev, · 22 unmodified lines | ||
| 23 | 23 | return -EACCES; |
| 24 | 24 | if (copy_from_user(&p, upart, sizeof(struct blkpg_partition))) |
| 25 | 25 | return -EFAULT; |
| 26 | − if (bdev != bdev->bd_contains) | |
| 26 | + if (bdev_is_partition(bdev)) | |
| 27 | 27 | return -EINVAL; |
| 28 | 28 | |
| 29 | 29 | if (p.pno <= 0) |
| @@ -94,7 +94,7 @@ static int blkdev_reread_part(struct block_device *bdev) · 64 unmodified lines | ||
| 94 | 94 | { |
| 95 | 95 | int ret; |
| 96 | 96 | |
| 97 | − if (!disk_part_scan_enabled(bdev->bd_disk) || bdev != bdev->bd_contains) | |
| 97 | + if (!disk_part_scan_enabled(bdev->bd_disk) || bdev_is_partition(bdev)) | |
| 98 | 98 | return -EINVAL; |
| 99 | 99 | if (!capable(CAP_SYS_ADMIN)) |
| 100 | 100 | return -EACCES; |
| @@ -852,7 +852,7 @@ EXPORT_SYMBOL(scsi_cmd_ioctl); · 851 unmodified lines | ||
| 852 | 852 | |
| 853 | 853 | int scsi_verify_blk_ioctl(struct block_device *bd, unsigned int cmd) |
| 854 | 854 | { |
| 855 | − if (bd && bd == bd->bd_contains) | |
| 855 | + if (bd && !bdev_is_partition(bd)) | |
| 856 | 856 | return 0; |
| 857 | 857 | |
| 858 | 858 | if (capable(CAP_SYS_RAWIO)) |
| @@ -49,7 +49,7 @@ read_val: · 48 unmodified lines | ||
| 49 | 49 | return err >= 0 ? put_user_long(err, arg) : err; |
| 50 | 50 | |
| 51 | 51 | set_val: |
| 52 | − if (bdev != bdev->bd_contains) | |
| 52 | + if (bdev_is_partition(bdev)) | |
| 53 | 53 | err = -EINVAL; |
| 54 | 54 | else { |
| 55 | 55 | if (!capable(CAP_SYS_ADMIN)) |
| @@ -257,7 +257,7 @@ int generic_ide_ioctl(ide_drive_t *drive, struct block_device *bdev, · 201 unmodified lines | ||
| 257 | 257 | switch (cmd) { |
| 258 | 258 | case HDIO_OBSOLETE_IDENTITY: |
| 259 | 259 | case HDIO_GET_IDENTITY: |
| 260 | − if (bdev != bdev->bd_contains) | |
| 260 | + if (bdev_is_partition(bdev)) | |
| 261 | 261 | return -EINVAL; |
| 262 | 262 | return ide_get_identity_ioctl(drive, cmd, argp); |
| 263 | 263 | case HDIO_GET_NICE: |
| @@ -903,7 +903,7 @@ static int device_is_rq_stackable(struct dm_target *ti, struct dm_dev *dev, · 902 unmodified lines | ||
| 903 | 903 | struct request_queue *q = bdev_get_queue(bdev); |
| 904 | 904 | |
| 905 | 905 | /* request-based cannot stack on partitions! */ |
| 906 | − if (bdev != bdev->bd_contains) | |
| 906 | + if (bdev_is_partition(bdev)) | |
| 907 | 907 | return false; |
| 908 | 908 | |
| 909 | 909 | return queue_is_mq(q); |
| @@ -723,7 +723,7 @@ static int mmc_blk_check_blkdev(struct block_device *bdev) · 722 unmodified lines | ||
| 723 | 723 | * whole block device, not on a partition. This prevents overspray |
| 724 | 724 | * between sibling partitions. |
| 725 | 725 | */ |
| 726 | − if ((!capable(CAP_SYS_RAWIO)) || (bdev != bdev->bd_contains)) | |
| 726 | + if (!capable(CAP_SYS_RAWIO) || bdev_is_partition(bdev)) | |
| 727 | 727 | return -EPERM; |
| 728 | 728 | return 0; |
| 729 | 729 | } |
| @@ -277,7 +277,7 @@ dasd_ioctl_format(struct block_device *bdev, void __user *argp) · 276 unmodified lines | ||
| 277 | 277 | dasd_put_device(base); |
| 278 | 278 | return -EFAULT; |
| 279 | 279 | } |
| 280 | − if (bdev != bdev->bd_contains) { | |
| 280 | + if (bdev_is_partition(bdev)) { | |
| 281 | 281 | pr_warn("%s: The specified DASD is a partition and cannot be formatted\n", |
| 282 | 282 | dev_name(&base->cdev->dev)); |
| 283 | 283 | dasd_put_device(base); |
| @@ -304,7 +304,7 @@ static int dasd_ioctl_check_format(struct block_device *bdev, void __user *argp) · 20 unmodified lines | ||
| 304 | 304 | base = dasd_device_from_gendisk(bdev->bd_disk); |
| 305 | 305 | if (!base) |
| 306 | 306 | return -ENODEV; |
| 307 | − if (bdev != bdev->bd_contains) { | |
| 307 | + if (bdev_is_partition(bdev)) { | |
| 308 | 308 | pr_warn("%s: The specified DASD is a partition and cannot be checked\n", |
| 309 | 309 | dev_name(&base->cdev->dev)); |
| 310 | 310 | rc = -EINVAL; |
| @@ -362,7 +362,7 @@ static int dasd_ioctl_release_space(struct block_device *bdev, void __user *argp · 51 unmodified lines | ||
| 362 | 362 | rc = -EROFS; |
| 363 | 363 | goto out_err; |
| 364 | 364 | } |
| 365 | − if (bdev != bdev->bd_contains) { | |
| 365 | + if (bdev_is_partition(bdev)) { | |
| 366 | 366 | pr_warn("%s: The specified DASD is a partition and tracks cannot be released\n", |
| 367 | 367 | dev_name(&base->cdev->dev)); |
| 368 | 368 | rc = -EINVAL; |
| @@ -540,7 +540,7 @@ dasd_ioctl_set_ro(struct block_device *bdev, void __user *argp) · 171 unmodified lines | ||
| 540 | 540 | |
| 541 | 541 | if (!capable(CAP_SYS_ADMIN)) |
| 542 | 542 | return -EACCES; |
| 543 | − if (bdev != bdev->bd_contains) | |
| 543 | + if (bdev_is_partition(bdev)) | |
| 544 | 544 | // ro setting is not allowed for partitions |
| 545 | 545 | return -EINVAL; |
| 546 | 546 | if (get_user(intval, (int __user *)argp)) |
| @@ -170,7 +170,7 @@ nfsd4_block_proc_getdeviceinfo(struct super_block *sb, · 169 unmodified lines | ||
| 170 | 170 | struct nfs4_client *clp, |
| 171 | 171 | struct nfsd4_getdeviceinfo *gdp) |
| 172 | 172 | { |
| 173 | − if (sb->s_bdev != sb->s_bdev->bd_contains) | |
| 173 | + if (bdev_is_partition(sb->s_bdev)) | |
| 174 | 174 | return nfserr_inval; |
| 175 | 175 | return nfserrno(nfsd4_block_get_device_info_simple(sb, gdp)); |
| 176 | 176 | } |
| @@ -382,7 +382,7 @@ nfsd4_scsi_proc_getdeviceinfo(struct super_block *sb, · 205 unmodified lines | ||
| 382 | 382 | struct nfs4_client *clp, |
| 383 | 383 | struct nfsd4_getdeviceinfo *gdp) |
| 384 | 384 | { |
| 385 | − if (sb->s_bdev != sb->s_bdev->bd_contains) | |
| 385 | + if (bdev_is_partition(sb->s_bdev)) | |
| 386 | 386 | return nfserr_inval; |
| 387 | 387 | return nfserrno(nfsd4_block_get_device_info_scsi(sb, clp, gdp)); |
| 388 | 388 | } |
| @@ -1353,6 +1353,11 @@ static inline int sb_issue_zeroout(struct super_block *sb, sector_t block, · 1352 unmodified lines | ||
| 1353 | 1353 | |
| 1354 | 1354 | extern int blk_verify_command(unsigned char *cmd, fmode_t mode); |
| 1355 | 1355 | |
| 1356 | +static inline bool bdev_is_partition(struct block_device *bdev) | |
| 1357 | +{ | |
| 1358 | + return bdev->bd_partno; | |
| 1359 | +} | |
| 1360 | + | |
| 1356 | 1361 | enum blk_default_limits { |
| 1357 | 1362 | BLK_MAX_SEGMENTS = 128, |
| 1358 | 1363 | BLK_SAFE_MAX_SECTORS = 255, |
| @@ -1469,7 +1474,7 @@ static inline int bdev_alignment_offset(struct block_device *bdev) · 110 unmodified lines | ||
| 1469 | 1474 | |
| 1470 | 1475 | if (q->limits.misaligned) |
| 1471 | 1476 | return -1; |
| 1472 | − if (bdev != bdev->bd_contains) | |
| 1477 | + if (bdev_is_partition(bdev)) | |
| 1473 | 1478 | return queue_limit_alignment_offset(&q->limits, |
| 1474 | 1479 | bdev->bd_part->start_sect); |
| 1475 | 1480 | return q->limits.alignment_offset; |
| @@ -1510,7 +1515,7 @@ static inline int bdev_discard_alignment(struct block_device *bdev) · 34 unmodified lines | ||
| 1510 | 1515 | { |
| 1511 | 1516 | struct request_queue *q = bdev_get_queue(bdev); |
| 1512 | 1517 | |
| 1513 | − if (bdev != bdev->bd_contains) | |
| 1518 | + if (bdev_is_partition(bdev)) | |
| 1514 | 1519 | return queue_limit_discard_alignment(&q->limits, |
| 1515 | 1520 | bdev->bd_part->start_sect); |
| 1516 | 1521 | return q->limits.discard_alignment; |
| @@ -527,7 +527,7 @@ static int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev, · 526 unmodified lines | ||
| 527 | 527 | * and scsi-generic block devices we create a temporary new debugfs |
| 528 | 528 | * directory that will be removed once the trace ends. |
| 529 | 529 | */ |
| 530 | − if (bdev && bdev == bdev->bd_contains) | |
| 530 | + if (bdev && !bdev_is_partition(bdev)) | |
| 531 | 531 | dir = q->debugfs_dir; |
| 532 | 532 | else |
| 533 | 533 | bt->dir = dir = debugfs_create_dir(buts->name, blk_debugfs_root); |