diff mbox series

[3/4] md: prevent adding disks with larger logical_block_size to active arrays

Message ID 20250304121918.3159388-4-linan666@huaweicloud.com (mailing list archive)
State New
Headers show
Series bugfix of logical_block_size and make it configurable | expand

Checks

Context Check Description
shin/vmtest-linus-master-PR success PR summary
shin/vmtest-linus-master-VM_Test-0 success Logs for build-kernel

Commit Message

Li Nan March 4, 2025, 12:19 p.m. UTC
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 mbox series

Patch

diff --git a/drivers/md/md.c b/drivers/md/md.c
index cf3d8ff807a7..48c35b6fb52e 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -5854,6 +5854,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);