Links: https://lore.kernel.org/linux-raid/20250719083119.1068811-1-linan666@xxxxxxxxxxxxxxx/T/#t The kernel supports configuring the logical block size in this patches, and mdadm needs to provide the corresponding parameters. When creating a RAID device, you can specify the logical block size. Signed-by-off: Wu Guanghao <wuguanghao3@xxxxxxxxxx> --- ReadMe.c | 2 ++ mdadm.c | 31 +++++++++++++++++++++++++++++++ mdadm.h | 2 ++ super0.c | 2 ++ super1.c | 2 ++ 5 files changed, 39 insertions(+) diff --git a/ReadMe.c b/ReadMe.c index c2415c26..137a80c9 100644 --- a/ReadMe.c +++ b/ReadMe.c @@ -149,6 +149,7 @@ struct option long_options[] = { {"home-cluster", 1, 0, ClusterName}, {"write-journal", 1, 0, WriteJournal}, {"consistency-policy", 1, 0, 'k'}, + {"logical-block-size", 1, 0, LogicalBlockSize}, /* For assemble */ {"uuid", 1, 0, 'u'}, @@ -331,6 +332,7 @@ char Help_create[] = " --consistency-policy= : Specify the policy that determines how the array\n" " -k : maintains consistency in case of unexpected shutdown.\n" " --write-zeroes : Write zeroes to the disks before creating. This will bypass initial sync.\n" +" --logical-block-size= : Set the logical block size (in Byte) for the RAID.\n" "\n" ; diff --git a/mdadm.c b/mdadm.c index 14649a40..50d39f67 100644 --- a/mdadm.c +++ b/mdadm.c @@ -76,6 +76,32 @@ static mdadm_status_t set_bitmap_value(struct shape *s, struct context *c, char return MDADM_STATUS_ERROR; } +#define BLK_MAX_BLOCK_SIZE 0x10000 /* 64K */ +/* is x a power of 2? */ +#define is_power_of_2(x) ((x) != 0 && (((x) & ((x) - 1)) == 0)) + +static mdadm_status_t set_logical_block_size(struct shape *s, char *optarg) +{ + char *end; + int size = strtol(optarg, &end, 10); + + if (end != optarg + strlen(optarg)) { + pr_err("Logical block size [%s] can't be converted to an integer\n", optarg); + return MDADM_STATUS_ERROR; + } else if (errno == ERANGE) { + pr_err("Logical block size [%s] more than LONG_MAX.\n", optarg); + return MDADM_STATUS_ERROR; + } + + if (size < 512 || size > BLK_MAX_BLOCK_SIZE || !is_power_of_2(size)) { + pr_err("Logical block size [%s] is invalid\n", optarg); + return MDADM_STATUS_ERROR; + } + + s->logical_block_size = size; + return MDADM_STATUS_SUCCESS; +} + static int scan_assemble(struct supertype *ss, struct context *c, struct mddev_ident *ident); @@ -116,6 +142,7 @@ int main(int argc, char *argv[]) .consistency_policy = CONSISTENCY_POLICY_UNKNOWN, .data_offset = INVALID_SECTORS, .btype = BitmapUnknown, + .logical_block_size = 0, }; char sys_hostname[256]; @@ -1185,6 +1212,10 @@ int main(int argc, char *argv[]) exit(2); } continue; + case O(CREATE, LogicalBlockSize): + if (set_logical_block_size(&s, optarg) != MDADM_STATUS_SUCCESS) + exit(2); + continue; } /* We have now processed all the valid options. Anything else is * an error diff --git a/mdadm.h b/mdadm.h index ce9c216b..dada3ff4 100644 --- a/mdadm.h +++ b/mdadm.h @@ -502,6 +502,7 @@ enum special_options { ClusterConfirm, WriteJournal, ConsistencyPolicy, + LogicalBlockSize, }; enum update_opt { @@ -663,6 +664,7 @@ struct shape { unsigned long long data_offset; int consistency_policy; change_dir_t direction; + int logical_block_size; }; /* List of device names - wildcards expanded */ diff --git a/super0.c b/super0.c index 4a462bdc..15a1ac17 100644 --- a/super0.c +++ b/super0.c @@ -830,6 +830,8 @@ static int init_super0(struct supertype *st, mdu_array_info_t *info, sb->layout = info->layout; sb->chunk_size = info->chunk_size; + sb->logical_block_size = s->logical_block_size; + return 1; } diff --git a/super1.c b/super1.c index 84d73573..f783c4a5 100644 --- a/super1.c +++ b/super1.c @@ -1591,6 +1591,8 @@ static int init_super1(struct supertype *st, mdu_array_info_t *info, if (s->consistency_policy == CONSISTENCY_POLICY_PPL) sb->feature_map |= __cpu_to_le32(MD_FEATURE_PPL); + sb->logical_block_size = s->logical_block_size; + return 1; } -- 2.45.2