On EFI platforms, 'installboot -p' on a softraid volume will only
prepare the filesysem inside the volume and leave physical softraid
chunks untouched, which leaves you with unbootable chunks.

The current workaround is to prepare chunks manually (see regress).

Here is a fix in the same spirit we already do the actual "install" in
softraid.c.

This is what mlarkin has already been tested in a combined diff with the
MD -> MI softraid merge bits I committed earlier.

Once this is in, all softraid platforms finally work the same in all of
bootloader, kernel and installboot when it comes to softraid boot.

OK?

NB: regress can later be extended to actually check the phsyical disk
    for bootblocks and/or EFI bootloaders being installed to them.

Index: regress/usr.sbin/installboot/Makefile
===================================================================
RCS file: /cvs/src/regress/usr.sbin/installboot/Makefile,v
retrieving revision 1.34
diff -u -p -r1.34 Makefile
--- regress/usr.sbin/installboot/Makefile       10 Oct 2022 11:06:14 -0000      
1.34
+++ regress/usr.sbin/installboot/Makefile       7 Nov 2022 16:58:12 -0000
@@ -100,12 +100,6 @@ REGRESS_TARGETS = prepare
 
 prepare:
        ${SUDO} ${REAL_RUN} -p -- "$$(<${ROOTDEVFILE})"
-.if ${USE_SOFTRAID:L} == "yes"
-       # XXX -p is not yet softraid(4) aware, need to prepare chunks manually
-.  for devfile in ${DISKDEVFILES}
-       ${SUDO} ${REAL_RUN} -p -- "$$(<${devfile})"
-.  endfor
-.endif
 
 REGRESS_TARGETS +=     dry-prepare \
                        dry-default \
Index: usr.sbin/installboot/installboot.c
===================================================================
RCS file: /cvs/src/usr.sbin/installboot/installboot.c,v
retrieving revision 1.15
diff -u -p -r1.15 installboot.c
--- usr.sbin/installboot/installboot.c  19 Aug 2022 08:27:48 -0000      1.15
+++ usr.sbin/installboot/installboot.c  7 Nov 2022 16:58:12 -0000
@@ -91,7 +91,11 @@ main(int argc, char **argv)
                err(1, "open: %s", realdev);
 
        if (prepare) {
+#if SOFTRAID
+               sr_prepareboot(devfd, dev);
+#else
                md_prepareboot(devfd, realdev);
+#endif
                return 0;
        }
 
Index: usr.sbin/installboot/installboot.h
===================================================================
RCS file: /cvs/src/usr.sbin/installboot/installboot.h,v
retrieving revision 1.15
diff -u -p -r1.15 installboot.h
--- usr.sbin/installboot/installboot.h  7 Nov 2022 15:56:09 -0000       1.15
+++ usr.sbin/installboot/installboot.h  7 Nov 2022 16:58:12 -0000
@@ -44,6 +44,7 @@ void  md_installboot(int, char *);
 
 #ifdef SOFTRAID
 int    sr_open_chunk(int, int, int, struct bioc_disk *, char **, char *);
+void   sr_prepareboot(int, char *);
 void   sr_installboot(int, char *);
 void   sr_install_bootblk(int, int, int);
 void   sr_install_bootldr(int, char *);
Index: usr.sbin/installboot/softraid.c
===================================================================
RCS file: /cvs/src/usr.sbin/installboot/softraid.c,v
retrieving revision 1.6
diff -u -p -r1.6 softraid.c
--- usr.sbin/installboot/softraid.c     7 Nov 2022 15:56:09 -0000       1.6
+++ usr.sbin/installboot/softraid.c     7 Nov 2022 16:58:12 -0000
@@ -26,11 +26,46 @@
 #include <fcntl.h>
 #include <stdio.h>
 #include <string.h>
+#include <unistd.h>
 #include <util.h>
 
 #include "installboot.h"
 
 static int sr_volume(int, char *, int *, int *);
+
+static void
+sr_prepare_chunk(int devfd, int vol, int disk)
+{
+       struct bioc_disk bd;
+       char *realdev;
+       char part;
+       int diskfd;
+
+       diskfd = sr_open_chunk(devfd, vol, disk, &bd, &realdev, &part);
+       if (diskfd == -1)
+               return;
+
+       /* Prepare file system on device. */
+       md_prepareboot(diskfd, realdev);
+
+       close(diskfd);
+}
+
+void
+sr_prepareboot(int devfd, char *dev)
+{
+       int     vol = -1, ndisks = 0, disk;
+
+       /* Use the normal process if this is not a softraid volume. */
+       if (!sr_volume(devfd, dev, &vol, &ndisks)) {
+               md_prepareboot(devfd, dev);
+               return;
+       }
+
+       /* Prepare file system on each disk that is part of this volume. */
+       for (disk = 0; disk < ndisks; disk++)
+               sr_prepare_chunk(devfd, vol, disk);
+}
 
 void
 sr_installboot(int devfd, char *dev)
Index: usr.sbin/installboot/sparc64_softraid.c
===================================================================
RCS file: /cvs/src/usr.sbin/installboot/sparc64_softraid.c,v
retrieving revision 1.8
diff -u -p -r1.8 sparc64_softraid.c
--- usr.sbin/installboot/sparc64_softraid.c     7 Nov 2022 15:56:09 -0000       
1.8
+++ usr.sbin/installboot/sparc64_softraid.c     7 Nov 2022 16:58:12 -0000
@@ -15,19 +15,14 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-#include <sys/types.h>
-#include <sys/disklabel.h>
 #include <sys/ioctl.h>
 #include <sys/stat.h>
 
 #include <dev/biovar.h>
-#include <dev/softraidvar.h>
 
 #include <err.h>
-#include <fcntl.h>
 #include <stdio.h>
 #include <string.h>
-#include <util.h>
 #include <unistd.h>
 
 #include "installboot.h"

Reply via email to