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>
This commit is contained in:
parent
250eec9e39
commit
fa01b1e973
|
@ -64,7 +64,7 @@ int __blkdev_issue_discard(struct block_device *bdev, sector_t sector,
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
/* In case the discard request is in a partition */
|
/* In case the discard request is in a partition */
|
||||||
if (bdev->bd_partno)
|
if (bdev_is_partition(bdev))
|
||||||
part_offset = bdev->bd_part->start_sect;
|
part_offset = bdev->bd_part->start_sect;
|
||||||
|
|
||||||
while (nr_sects) {
|
while (nr_sects) {
|
||||||
|
|
|
@ -23,7 +23,7 @@ static int blkpg_do_ioctl(struct block_device *bdev,
|
||||||
return -EACCES;
|
return -EACCES;
|
||||||
if (copy_from_user(&p, upart, sizeof(struct blkpg_partition)))
|
if (copy_from_user(&p, upart, sizeof(struct blkpg_partition)))
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
if (bdev != bdev->bd_contains)
|
if (bdev_is_partition(bdev))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
if (p.pno <= 0)
|
if (p.pno <= 0)
|
||||||
|
@ -94,7 +94,7 @@ static int blkdev_reread_part(struct block_device *bdev)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (!disk_part_scan_enabled(bdev->bd_disk) || bdev != bdev->bd_contains)
|
if (!disk_part_scan_enabled(bdev->bd_disk) || bdev_is_partition(bdev))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
if (!capable(CAP_SYS_ADMIN))
|
if (!capable(CAP_SYS_ADMIN))
|
||||||
return -EACCES;
|
return -EACCES;
|
||||||
|
|
|
@ -852,7 +852,7 @@ EXPORT_SYMBOL(scsi_cmd_ioctl);
|
||||||
|
|
||||||
int scsi_verify_blk_ioctl(struct block_device *bd, unsigned int cmd)
|
int scsi_verify_blk_ioctl(struct block_device *bd, unsigned int cmd)
|
||||||
{
|
{
|
||||||
if (bd && bd == bd->bd_contains)
|
if (bd && !bdev_is_partition(bd))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (capable(CAP_SYS_RAWIO))
|
if (capable(CAP_SYS_RAWIO))
|
||||||
|
|
|
@ -49,7 +49,7 @@ read_val:
|
||||||
return err >= 0 ? put_user_long(err, arg) : err;
|
return err >= 0 ? put_user_long(err, arg) : err;
|
||||||
|
|
||||||
set_val:
|
set_val:
|
||||||
if (bdev != bdev->bd_contains)
|
if (bdev_is_partition(bdev))
|
||||||
err = -EINVAL;
|
err = -EINVAL;
|
||||||
else {
|
else {
|
||||||
if (!capable(CAP_SYS_ADMIN))
|
if (!capable(CAP_SYS_ADMIN))
|
||||||
|
@ -257,7 +257,7 @@ int generic_ide_ioctl(ide_drive_t *drive, struct block_device *bdev,
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case HDIO_OBSOLETE_IDENTITY:
|
case HDIO_OBSOLETE_IDENTITY:
|
||||||
case HDIO_GET_IDENTITY:
|
case HDIO_GET_IDENTITY:
|
||||||
if (bdev != bdev->bd_contains)
|
if (bdev_is_partition(bdev))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
return ide_get_identity_ioctl(drive, cmd, argp);
|
return ide_get_identity_ioctl(drive, cmd, argp);
|
||||||
case HDIO_GET_NICE:
|
case HDIO_GET_NICE:
|
||||||
|
|
|
@ -903,7 +903,7 @@ static int device_is_rq_stackable(struct dm_target *ti, struct dm_dev *dev,
|
||||||
struct request_queue *q = bdev_get_queue(bdev);
|
struct request_queue *q = bdev_get_queue(bdev);
|
||||||
|
|
||||||
/* request-based cannot stack on partitions! */
|
/* request-based cannot stack on partitions! */
|
||||||
if (bdev != bdev->bd_contains)
|
if (bdev_is_partition(bdev))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return queue_is_mq(q);
|
return queue_is_mq(q);
|
||||||
|
|
|
@ -723,7 +723,7 @@ static int mmc_blk_check_blkdev(struct block_device *bdev)
|
||||||
* whole block device, not on a partition. This prevents overspray
|
* whole block device, not on a partition. This prevents overspray
|
||||||
* between sibling partitions.
|
* between sibling partitions.
|
||||||
*/
|
*/
|
||||||
if ((!capable(CAP_SYS_RAWIO)) || (bdev != bdev->bd_contains))
|
if (!capable(CAP_SYS_RAWIO) || bdev_is_partition(bdev))
|
||||||
return -EPERM;
|
return -EPERM;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -277,7 +277,7 @@ dasd_ioctl_format(struct block_device *bdev, void __user *argp)
|
||||||
dasd_put_device(base);
|
dasd_put_device(base);
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
}
|
}
|
||||||
if (bdev != bdev->bd_contains) {
|
if (bdev_is_partition(bdev)) {
|
||||||
pr_warn("%s: The specified DASD is a partition and cannot be formatted\n",
|
pr_warn("%s: The specified DASD is a partition and cannot be formatted\n",
|
||||||
dev_name(&base->cdev->dev));
|
dev_name(&base->cdev->dev));
|
||||||
dasd_put_device(base);
|
dasd_put_device(base);
|
||||||
|
@ -304,7 +304,7 @@ static int dasd_ioctl_check_format(struct block_device *bdev, void __user *argp)
|
||||||
base = dasd_device_from_gendisk(bdev->bd_disk);
|
base = dasd_device_from_gendisk(bdev->bd_disk);
|
||||||
if (!base)
|
if (!base)
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
if (bdev != bdev->bd_contains) {
|
if (bdev_is_partition(bdev)) {
|
||||||
pr_warn("%s: The specified DASD is a partition and cannot be checked\n",
|
pr_warn("%s: The specified DASD is a partition and cannot be checked\n",
|
||||||
dev_name(&base->cdev->dev));
|
dev_name(&base->cdev->dev));
|
||||||
rc = -EINVAL;
|
rc = -EINVAL;
|
||||||
|
@ -362,7 +362,7 @@ static int dasd_ioctl_release_space(struct block_device *bdev, void __user *argp
|
||||||
rc = -EROFS;
|
rc = -EROFS;
|
||||||
goto out_err;
|
goto out_err;
|
||||||
}
|
}
|
||||||
if (bdev != bdev->bd_contains) {
|
if (bdev_is_partition(bdev)) {
|
||||||
pr_warn("%s: The specified DASD is a partition and tracks cannot be released\n",
|
pr_warn("%s: The specified DASD is a partition and tracks cannot be released\n",
|
||||||
dev_name(&base->cdev->dev));
|
dev_name(&base->cdev->dev));
|
||||||
rc = -EINVAL;
|
rc = -EINVAL;
|
||||||
|
@ -540,7 +540,7 @@ dasd_ioctl_set_ro(struct block_device *bdev, void __user *argp)
|
||||||
|
|
||||||
if (!capable(CAP_SYS_ADMIN))
|
if (!capable(CAP_SYS_ADMIN))
|
||||||
return -EACCES;
|
return -EACCES;
|
||||||
if (bdev != bdev->bd_contains)
|
if (bdev_is_partition(bdev))
|
||||||
// ro setting is not allowed for partitions
|
// ro setting is not allowed for partitions
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
if (get_user(intval, (int __user *)argp))
|
if (get_user(intval, (int __user *)argp))
|
||||||
|
|
|
@ -170,7 +170,7 @@ nfsd4_block_proc_getdeviceinfo(struct super_block *sb,
|
||||||
struct nfs4_client *clp,
|
struct nfs4_client *clp,
|
||||||
struct nfsd4_getdeviceinfo *gdp)
|
struct nfsd4_getdeviceinfo *gdp)
|
||||||
{
|
{
|
||||||
if (sb->s_bdev != sb->s_bdev->bd_contains)
|
if (bdev_is_partition(sb->s_bdev))
|
||||||
return nfserr_inval;
|
return nfserr_inval;
|
||||||
return nfserrno(nfsd4_block_get_device_info_simple(sb, gdp));
|
return nfserrno(nfsd4_block_get_device_info_simple(sb, gdp));
|
||||||
}
|
}
|
||||||
|
@ -382,7 +382,7 @@ nfsd4_scsi_proc_getdeviceinfo(struct super_block *sb,
|
||||||
struct nfs4_client *clp,
|
struct nfs4_client *clp,
|
||||||
struct nfsd4_getdeviceinfo *gdp)
|
struct nfsd4_getdeviceinfo *gdp)
|
||||||
{
|
{
|
||||||
if (sb->s_bdev != sb->s_bdev->bd_contains)
|
if (bdev_is_partition(sb->s_bdev))
|
||||||
return nfserr_inval;
|
return nfserr_inval;
|
||||||
return nfserrno(nfsd4_block_get_device_info_scsi(sb, clp, gdp));
|
return nfserrno(nfsd4_block_get_device_info_scsi(sb, clp, gdp));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1353,6 +1353,11 @@ static inline int sb_issue_zeroout(struct super_block *sb, sector_t block,
|
||||||
|
|
||||||
extern int blk_verify_command(unsigned char *cmd, fmode_t mode);
|
extern int blk_verify_command(unsigned char *cmd, fmode_t mode);
|
||||||
|
|
||||||
|
static inline bool bdev_is_partition(struct block_device *bdev)
|
||||||
|
{
|
||||||
|
return bdev->bd_partno;
|
||||||
|
}
|
||||||
|
|
||||||
enum blk_default_limits {
|
enum blk_default_limits {
|
||||||
BLK_MAX_SEGMENTS = 128,
|
BLK_MAX_SEGMENTS = 128,
|
||||||
BLK_SAFE_MAX_SECTORS = 255,
|
BLK_SAFE_MAX_SECTORS = 255,
|
||||||
|
@ -1469,7 +1474,7 @@ static inline int bdev_alignment_offset(struct block_device *bdev)
|
||||||
|
|
||||||
if (q->limits.misaligned)
|
if (q->limits.misaligned)
|
||||||
return -1;
|
return -1;
|
||||||
if (bdev != bdev->bd_contains)
|
if (bdev_is_partition(bdev))
|
||||||
return queue_limit_alignment_offset(&q->limits,
|
return queue_limit_alignment_offset(&q->limits,
|
||||||
bdev->bd_part->start_sect);
|
bdev->bd_part->start_sect);
|
||||||
return q->limits.alignment_offset;
|
return q->limits.alignment_offset;
|
||||||
|
@ -1510,7 +1515,7 @@ static inline int bdev_discard_alignment(struct block_device *bdev)
|
||||||
{
|
{
|
||||||
struct request_queue *q = bdev_get_queue(bdev);
|
struct request_queue *q = bdev_get_queue(bdev);
|
||||||
|
|
||||||
if (bdev != bdev->bd_contains)
|
if (bdev_is_partition(bdev))
|
||||||
return queue_limit_discard_alignment(&q->limits,
|
return queue_limit_discard_alignment(&q->limits,
|
||||||
bdev->bd_part->start_sect);
|
bdev->bd_part->start_sect);
|
||||||
return q->limits.discard_alignment;
|
return q->limits.discard_alignment;
|
||||||
|
|
|
@ -527,7 +527,7 @@ static int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
|
||||||
* and scsi-generic block devices we create a temporary new debugfs
|
* and scsi-generic block devices we create a temporary new debugfs
|
||||||
* directory that will be removed once the trace ends.
|
* directory that will be removed once the trace ends.
|
||||||
*/
|
*/
|
||||||
if (bdev && bdev == bdev->bd_contains)
|
if (bdev && !bdev_is_partition(bdev))
|
||||||
dir = q->debugfs_dir;
|
dir = q->debugfs_dir;
|
||||||
else
|
else
|
||||||
bt->dir = dir = debugfs_create_dir(buts->name, blk_debugfs_root);
|
bt->dir = dir = debugfs_create_dir(buts->name, blk_debugfs_root);
|
||||||
|
|
Loading…
Reference in New Issue