From: Alexander Klimov Subject: [patch] [ok?] bioctl: allow -c 1 with only one chunk for degraded arrays To: tech@openbsd.org Date: Fri, 26 Apr 2024 18:04:13 +0200 On 26.04.24 14:47, Stefan Sperling wrote: > I agree that bioctl should allow attaching any volumes in degraded state > at run-time, like it does for RAID 1C. The min_disks check should of > course still apply when a volume is initially created. But this check > needs to be done in the kernel, as bioctl doesn't know the volume's state. Indeed, just lowering a number in /sbin/bioctl wasn't it all for RAID 1. The kernel still complained about too few chunks, so I had to enable such not just for 1C. With the below proper handling in the RAID 1 code I actually got a degraded RAID 1 re-assembled at runtime and could re-build it then. (-R) Ok? --- /usr/src/sbin/bioctl/bioctl.c Fri Apr 26 07:45:28 2024 +++ /usr/src/sbin/bioctl/bioctl.c Fri Apr 26 09:50:47 2024 @@ -851,7 +851,7 @@ min_disks = 2; break; case 1: - min_disks = 2; + min_disks = 1; break; case 5: min_disks = 3; --- /usr/src/sys/dev/softraid.c Fri Apr 26 08:48:23 2024 +++ /usr/src/sys/dev/softraid.c Fri Apr 26 09:52:13 2024 @@ -3411,7 +3411,7 @@ } else { /* Ensure we are assembling the correct # of chunks. */ - if (bc->bc_level == 0x1C && + if ((bc->bc_level == 1 || bc->bc_level == 0x1C) && sd->sd_meta->ssdi.ssd_chunk_no > no_chunk) { sr_warn(sc, "trying to bring up %s degraded", sd->sd_meta->ssd_devname); --- /usr/src/sys/dev/softraid_raid1.c Fri Apr 26 09:40:15 2024 +++ /usr/src/sys/dev/softraid_raid1.c Fri Apr 26 09:47:48 2024 @@ -52,6 +52,8 @@ void sr_raid1_set_chunk_state(struct sr_discipline *, int, int); void sr_raid1_set_vol_state(struct sr_discipline *); +extern int sr_raid1c_add_offline_chunks(struct sr_discipline *, int); + /* Discipline initialisation. */ void sr_raid1_discipline_init(struct sr_discipline *sd) @@ -91,6 +93,15 @@ sr_raid1_assemble(struct sr_discipline *sd, struct bioc_createraid *bc, int no_chunk, void *data) { + int rv; + + /* Create NODEV place-holders for missing chunks. */ + if (no_chunk < sd->sd_meta->ssdi.ssd_chunk_no) { + rv = sr_raid1c_add_offline_chunks(sd, no_chunk); + if (rv) + return (rv); + } + return sr_raid1_init(sd); }