Skip to content

Commit

Permalink
block: Move checking GENHD_FL_NO_PART to bdev_add_partition()
Browse files Browse the repository at this point in the history
Commit 1a721de ("block: don't add or resize partition on the disk
with GENHD_FL_NO_PART") prevented all operations about partitions on disks
with GENHD_FL_NO_PART in blkpg_do_ioctl() since they are meaningless.
However, it changed error code in some scenarios. So move checking
GENHD_FL_NO_PART to bdev_add_partition() to eliminate impact.

Fixes: 1a721de ("block: don't add or resize partition on the disk with GENHD_FL_NO_PART")
Reported-by: Allison Karlitskaya <allison.karlitskaya@redhat.com>
Closes: https://lore.kernel.org/all/CAOYeF9VsmqKMcQjo1k6YkGNujwN-nzfxY17N3F-CMikE1tYp+w@mail.gmail.com/
Signed-off-by: Li Lingfeng <lilingfeng3@huawei.com>
Reviewed-by: Yu Kuai <yukuai3@huawei.com>
Link: https://lore.kernel.org/r/20240118130401.792757-1-lilingfeng@huaweicloud.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
Li Lingfeng authored and Jens Axboe committed Jan 22, 2024
1 parent 6613476 commit 7777f47
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 0 additions & 2 deletions block/ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ static int blkpg_do_ioctl(struct block_device *bdev,
struct blkpg_partition p;
sector_t start, length;

if (disk->flags & GENHD_FL_NO_PART)
return -EINVAL;
if (!capable(CAP_SYS_ADMIN))
return -EACCES;
if (copy_from_user(&p, upart, sizeof(struct blkpg_partition)))
Expand Down
5 changes: 5 additions & 0 deletions block/partitions/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,11 @@ int bdev_add_partition(struct gendisk *disk, int partno, sector_t start,
goto out;
}

if (disk->flags & GENHD_FL_NO_PART) {
ret = -EINVAL;
goto out;
}

if (partition_overlaps(disk, start, length, -1)) {
ret = -EBUSY;
goto out;
Expand Down

0 comments on commit 7777f47

Please sign in to comment.