Skip to content

Commit fa01b1e

Browse files
Christoph Hellwigaxboe
authored andcommitted
block: add a bdev_is_partition helper
Add a littler helper to make the somewhat arcane bd_contains checks a little more obvious. Signed-off-by: Christoph Hellwig <hch@lst.de> Acked-by: Ulf Hansson <ulf.hansson@linaro.org> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 250eec9 commit fa01b1e

10 files changed

Lines changed: 22 additions & 17 deletions

File tree

‎block/blk-lib.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ int __blkdev_issue_discard(struct block_device *bdev, sector_t sector,
6464
return -EINVAL;
6565

6666
/* In case the discard request is in a partition */
67-
if (bdev->bd_partno)
67+
if (bdev_is_partition(bdev))
6868
part_offset = bdev->bd_part->start_sect;
6969

7070
while (nr_sects) {

‎block/ioctl.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ static int blkpg_do_ioctl(struct block_device *bdev,
2323
return -EACCES;
2424
if (copy_from_user(&p, upart, sizeof(struct blkpg_partition)))
2525
return -EFAULT;
26-
if (bdev != bdev->bd_contains)
26+
if (bdev_is_partition(bdev))
2727
return -EINVAL;
2828

2929
if (p.pno <= 0)
@@ -94,7 +94,7 @@ static int blkdev_reread_part(struct block_device *bdev)
9494
{
9595
int ret;
9696

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))
9898
return -EINVAL;
9999
if (!capable(CAP_SYS_ADMIN))
100100
return -EACCES;

‎block/scsi_ioctl.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,7 @@ EXPORT_SYMBOL(scsi_cmd_ioctl);
852852

853853
int scsi_verify_blk_ioctl(struct block_device *bd, unsigned int cmd)
854854
{
855-
if (bd && bd == bd->bd_contains)
855+
if (bd && !bdev_is_partition(bd))
856856
return 0;
857857

858858
if (capable(CAP_SYS_RAWIO))

‎drivers/ide/ide-ioctls.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ int ide_setting_ioctl(ide_drive_t *drive, struct block_device *bdev,
4949
return err >= 0 ? put_user_long(err, arg) : err;
5050

5151
set_val:
52-
if (bdev != bdev->bd_contains)
52+
if (bdev_is_partition(bdev))
5353
err = -EINVAL;
5454
else {
5555
if (!capable(CAP_SYS_ADMIN))
@@ -257,7 +257,7 @@ int generic_ide_ioctl(ide_drive_t *drive, struct block_device *bdev,
257257
switch (cmd) {
258258
case HDIO_OBSOLETE_IDENTITY:
259259
case HDIO_GET_IDENTITY:
260-
if (bdev != bdev->bd_contains)
260+
if (bdev_is_partition(bdev))
261261
return -EINVAL;
262262
return ide_get_identity_ioctl(drive, cmd, argp);
263263
case HDIO_GET_NICE:

‎drivers/md/dm-table.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,7 @@ static int device_is_rq_stackable(struct dm_target *ti, struct dm_dev *dev,
903903
struct request_queue *q = bdev_get_queue(bdev);
904904

905905
/* request-based cannot stack on partitions! */
906-
if (bdev != bdev->bd_contains)
906+
if (bdev_is_partition(bdev))
907907
return false;
908908

909909
return queue_is_mq(q);

‎drivers/mmc/core/block.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ static int mmc_blk_check_blkdev(struct block_device *bdev)
723723
* whole block device, not on a partition. This prevents overspray
724724
* between sibling partitions.
725725
*/
726-
if ((!capable(CAP_SYS_RAWIO)) || (bdev != bdev->bd_contains))
726+
if (!capable(CAP_SYS_RAWIO) || bdev_is_partition(bdev))
727727
return -EPERM;
728728
return 0;
729729
}

‎drivers/s390/block/dasd_ioctl.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ dasd_ioctl_format(struct block_device *bdev, void __user *argp)
277277
dasd_put_device(base);
278278
return -EFAULT;
279279
}
280-
if (bdev != bdev->bd_contains) {
280+
if (bdev_is_partition(bdev)) {
281281
pr_warn("%s: The specified DASD is a partition and cannot be formatted\n",
282282
dev_name(&base->cdev->dev));
283283
dasd_put_device(base);
@@ -304,7 +304,7 @@ static int dasd_ioctl_check_format(struct block_device *bdev, void __user *argp)
304304
base = dasd_device_from_gendisk(bdev->bd_disk);
305305
if (!base)
306306
return -ENODEV;
307-
if (bdev != bdev->bd_contains) {
307+
if (bdev_is_partition(bdev)) {
308308
pr_warn("%s: The specified DASD is a partition and cannot be checked\n",
309309
dev_name(&base->cdev->dev));
310310
rc = -EINVAL;
@@ -362,7 +362,7 @@ static int dasd_ioctl_release_space(struct block_device *bdev, void __user *argp
362362
rc = -EROFS;
363363
goto out_err;
364364
}
365-
if (bdev != bdev->bd_contains) {
365+
if (bdev_is_partition(bdev)) {
366366
pr_warn("%s: The specified DASD is a partition and tracks cannot be released\n",
367367
dev_name(&base->cdev->dev));
368368
rc = -EINVAL;
@@ -540,7 +540,7 @@ dasd_ioctl_set_ro(struct block_device *bdev, void __user *argp)
540540

541541
if (!capable(CAP_SYS_ADMIN))
542542
return -EACCES;
543-
if (bdev != bdev->bd_contains)
543+
if (bdev_is_partition(bdev))
544544
// ro setting is not allowed for partitions
545545
return -EINVAL;
546546
if (get_user(intval, (int __user *)argp))

‎fs/nfsd/blocklayout.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ nfsd4_block_proc_getdeviceinfo(struct super_block *sb,
170170
struct nfs4_client *clp,
171171
struct nfsd4_getdeviceinfo *gdp)
172172
{
173-
if (sb->s_bdev != sb->s_bdev->bd_contains)
173+
if (bdev_is_partition(sb->s_bdev))
174174
return nfserr_inval;
175175
return nfserrno(nfsd4_block_get_device_info_simple(sb, gdp));
176176
}
@@ -382,7 +382,7 @@ nfsd4_scsi_proc_getdeviceinfo(struct super_block *sb,
382382
struct nfs4_client *clp,
383383
struct nfsd4_getdeviceinfo *gdp)
384384
{
385-
if (sb->s_bdev != sb->s_bdev->bd_contains)
385+
if (bdev_is_partition(sb->s_bdev))
386386
return nfserr_inval;
387387
return nfserrno(nfsd4_block_get_device_info_scsi(sb, clp, gdp));
388388
}

‎include/linux/blkdev.h‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,6 +1353,11 @@ static inline int sb_issue_zeroout(struct super_block *sb, sector_t block,
13531353

13541354
extern int blk_verify_command(unsigned char *cmd, fmode_t mode);
13551355

1356+
static inline bool bdev_is_partition(struct block_device *bdev)
1357+
{
1358+
return bdev->bd_partno;
1359+
}
1360+
13561361
enum blk_default_limits {
13571362
BLK_MAX_SEGMENTS = 128,
13581363
BLK_SAFE_MAX_SECTORS = 255,
@@ -1469,7 +1474,7 @@ static inline int bdev_alignment_offset(struct block_device *bdev)
14691474

14701475
if (q->limits.misaligned)
14711476
return -1;
1472-
if (bdev != bdev->bd_contains)
1477+
if (bdev_is_partition(bdev))
14731478
return queue_limit_alignment_offset(&q->limits,
14741479
bdev->bd_part->start_sect);
14751480
return q->limits.alignment_offset;
@@ -1510,7 +1515,7 @@ static inline int bdev_discard_alignment(struct block_device *bdev)
15101515
{
15111516
struct request_queue *q = bdev_get_queue(bdev);
15121517

1513-
if (bdev != bdev->bd_contains)
1518+
if (bdev_is_partition(bdev))
15141519
return queue_limit_discard_alignment(&q->limits,
15151520
bdev->bd_part->start_sect);
15161521
return q->limits.discard_alignment;

‎kernel/trace/blktrace.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ static int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
527527
* and scsi-generic block devices we create a temporary new debugfs
528528
* directory that will be removed once the trace ends.
529529
*/
530-
if (bdev && bdev == bdev->bd_contains)
530+
if (bdev && !bdev_is_partition(bdev))
531531
dir = q->debugfs_dir;
532532
else
533533
bt->dir = dir = debugfs_create_dir(buts->name, blk_debugfs_root);

0 commit comments

Comments
 (0)