[PATCH v2 1/3] md: prevent adding disks with larger logical_block_size to active arrays

linan666@huaweicloud.com posted 3 patches 2 months, 2 weeks ago
There is a newer version of this series
[PATCH v2 1/3] md: prevent adding disks with larger logical_block_size to active arrays
Posted by linan666@huaweicloud.com 2 months, 2 weeks ago
From: Li Nan <linan122@huawei.com>

When adding a disk to a md array, avoid updating the array's
logical_block_size to match the new disk. This prevents accidental
partition table loss that renders the array unusable.

The later patch will introduce a way to configure the array's
logical_block_size.

Signed-off-by: Li Nan <linan122@huawei.com>
---
 drivers/md/md.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/md/md.c b/drivers/md/md.c
index 0f03b21e66e4..b1fceda89846 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -5841,6 +5841,13 @@ int mddev_stack_new_rdev(struct mddev *mddev, struct md_rdev *rdev)
 	if (mddev_is_dm(mddev))
 		return 0;
 
+	if (queue_logical_block_size(rdev->bdev->bd_disk->queue) >
+	    queue_logical_block_size(mddev->gendisk->queue)) {
+		pr_err("%s: incompatible logical_block_size, can not add\n",
+		       mdname(mddev));
+		return -EINVAL;
+	}
+
 	lim = queue_limits_start_update(mddev->gendisk->queue);
 	queue_limits_stack_bdev(&lim, rdev->bdev, rdev->data_offset,
 				mddev->gendisk->disk_name);
-- 
2.39.2
Re: [PATCH v2 1/3] md: prevent adding disks with larger logical_block_size to active arrays
Posted by Martin K. Petersen 2 months, 1 week ago
> When adding a disk to a md array, avoid updating the array's
> logical_block_size to match the new disk. This prevents accidental
> partition table loss that renders the array unusable.
>
> The later patch will introduce a way to configure the array's
> logical_block_size.

Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>

-- 
Martin K. Petersen