On Tue, Sep 26, 2023 at 11:19 PM Yu Kuai <yukuai1@xxxxxxxxxxxxxxx> wrote: > > From: Yu Kuai <yukuai3@xxxxxxxxxx> > > Before this patch, the implementation is hacky and hard to understand: > > 1) md_seq_start set pos to 1; > 2) md_seq_show found pos is 1, then print Personalities; > 3) md_seq_next found pos is 1, then it update pos to the first mddev; > 4) md_seq_show found pos is not 1 or 2, show mddev; > 5) md_seq_next found pos is not 1 or 2, update pos to next mddev; > 6) loop 4-5 until the last mddev, then md_seq_next update pos to 2; > 7) md_seq_show found pos is 2, then print unused devices; > 8) md_seq_next found pos is 2, stop; > > This patch remove the magic value and use seq_list_start/next/stop() > directly, and move printing "Personalities" to md_seq_start(), > "unsed devices" to md_seq_stop(): > > 1) md_seq_start print Personalities, and then set pos to first mddev; > 2) md_seq_show show mddev; > 3) md_seq_next update pos to next mddev; > 4) loop 2-3 until the last mddev; > 5) md_seq_stop print unsed devices; > > Signed-off-by: Yu Kuai <yukuai3@xxxxxxxxxx> Just realized this introduced a behavior change: When there is not md devices, before this patch, we have [root@eth50-1 ~]# cat /proc/mdstat Personalities : [raid0] [raid1] [raid10] [raid6] [raid5] [raid4] unused devices: <none> After this patch, "cat /proc/mdstat" returns nothing. This causes some confusion for users who want to read "Personalities" line, for example, the mdadm test suite reads it. I haven't figured out the best fix yet. Thanks, Song