block: Move checking GENHD_FL_NO_PART to bdev_add_partition()
authorLi Lingfeng <lilingfeng3@huawei.com>
Thu, 18 Jan 2024 13:04:01 +0000 (21:04 +0800)
committerJens Axboe <axboe@kernel.dk>
Mon, 22 Jan 2024 16:51:29 +0000 (09:51 -0700)
Commit 1a721de8489f ("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: 1a721de8489f ("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>
block/ioctl.c
block/partitions/core.c

index 9c73a763ef8838953bd1050b505621c39b8d4cdb..438f79c564cfc05d6f525550417eeee93c7b82bb 100644 (file)
@@ -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)))
index cab0d76a828e37eb90e38d91b4e92a61e703717e..5f5ed5c75f04d91d7bc8bf87ff4c9fa685c62318 100644 (file)
@@ -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;