mirror of
https://github.com/tbsdtv/linux_media.git
synced 2025-07-23 12:43:29 +02:00
block: disallow Persistent Reservation on partitions
Refuse Persistent Reservation operations on partitions as reservation on partitions doesn't make sense. Besides, introduce blkdev_pr_allowed() helper, where more policies could be placed here later. Signed-off-by: Jingbo Xu <jefflexu@linux.alibaba.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Link: https://lore.kernel.org/r/20230613084008.93795-2-jefflexu@linux.alibaba.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
@@ -254,13 +254,25 @@ int blkdev_compat_ptr_ioctl(struct block_device *bdev, blk_mode_t mode,
|
|||||||
EXPORT_SYMBOL(blkdev_compat_ptr_ioctl);
|
EXPORT_SYMBOL(blkdev_compat_ptr_ioctl);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static bool blkdev_pr_allowed(struct block_device *bdev)
|
||||||
|
{
|
||||||
|
/* no sense to make reservations for partitions */
|
||||||
|
if (bdev_is_partition(bdev))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (capable(CAP_SYS_ADMIN))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
static int blkdev_pr_register(struct block_device *bdev,
|
static int blkdev_pr_register(struct block_device *bdev,
|
||||||
struct pr_registration __user *arg)
|
struct pr_registration __user *arg)
|
||||||
{
|
{
|
||||||
const struct pr_ops *ops = bdev->bd_disk->fops->pr_ops;
|
const struct pr_ops *ops = bdev->bd_disk->fops->pr_ops;
|
||||||
struct pr_registration reg;
|
struct pr_registration reg;
|
||||||
|
|
||||||
if (!capable(CAP_SYS_ADMIN))
|
if (!blkdev_pr_allowed(bdev))
|
||||||
return -EPERM;
|
return -EPERM;
|
||||||
if (!ops || !ops->pr_register)
|
if (!ops || !ops->pr_register)
|
||||||
return -EOPNOTSUPP;
|
return -EOPNOTSUPP;
|
||||||
@@ -278,7 +290,7 @@ static int blkdev_pr_reserve(struct block_device *bdev,
|
|||||||
const struct pr_ops *ops = bdev->bd_disk->fops->pr_ops;
|
const struct pr_ops *ops = bdev->bd_disk->fops->pr_ops;
|
||||||
struct pr_reservation rsv;
|
struct pr_reservation rsv;
|
||||||
|
|
||||||
if (!capable(CAP_SYS_ADMIN))
|
if (!blkdev_pr_allowed(bdev))
|
||||||
return -EPERM;
|
return -EPERM;
|
||||||
if (!ops || !ops->pr_reserve)
|
if (!ops || !ops->pr_reserve)
|
||||||
return -EOPNOTSUPP;
|
return -EOPNOTSUPP;
|
||||||
@@ -296,7 +308,7 @@ static int blkdev_pr_release(struct block_device *bdev,
|
|||||||
const struct pr_ops *ops = bdev->bd_disk->fops->pr_ops;
|
const struct pr_ops *ops = bdev->bd_disk->fops->pr_ops;
|
||||||
struct pr_reservation rsv;
|
struct pr_reservation rsv;
|
||||||
|
|
||||||
if (!capable(CAP_SYS_ADMIN))
|
if (!blkdev_pr_allowed(bdev))
|
||||||
return -EPERM;
|
return -EPERM;
|
||||||
if (!ops || !ops->pr_release)
|
if (!ops || !ops->pr_release)
|
||||||
return -EOPNOTSUPP;
|
return -EOPNOTSUPP;
|
||||||
@@ -314,7 +326,7 @@ static int blkdev_pr_preempt(struct block_device *bdev,
|
|||||||
const struct pr_ops *ops = bdev->bd_disk->fops->pr_ops;
|
const struct pr_ops *ops = bdev->bd_disk->fops->pr_ops;
|
||||||
struct pr_preempt p;
|
struct pr_preempt p;
|
||||||
|
|
||||||
if (!capable(CAP_SYS_ADMIN))
|
if (!blkdev_pr_allowed(bdev))
|
||||||
return -EPERM;
|
return -EPERM;
|
||||||
if (!ops || !ops->pr_preempt)
|
if (!ops || !ops->pr_preempt)
|
||||||
return -EOPNOTSUPP;
|
return -EOPNOTSUPP;
|
||||||
@@ -332,7 +344,7 @@ static int blkdev_pr_clear(struct block_device *bdev,
|
|||||||
const struct pr_ops *ops = bdev->bd_disk->fops->pr_ops;
|
const struct pr_ops *ops = bdev->bd_disk->fops->pr_ops;
|
||||||
struct pr_clear c;
|
struct pr_clear c;
|
||||||
|
|
||||||
if (!capable(CAP_SYS_ADMIN))
|
if (!blkdev_pr_allowed(bdev))
|
||||||
return -EPERM;
|
return -EPERM;
|
||||||
if (!ops || !ops->pr_clear)
|
if (!ops || !ops->pr_clear)
|
||||||
return -EOPNOTSUPP;
|
return -EOPNOTSUPP;
|
||||||
|
Reference in New Issue
Block a user