History

block: add a bdev_is_partition helper

Add a littler helper to make the somewhat arcane bd_contains checks a little more obvious.

Christoph Hellwig committed 6 years ago

Commit fa01b1e1 parent 250eec910 files · +22 −17Browse files

Unified · Split

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