From 26ce53eaba1cc603bed743660370c90ad92eddc7 Mon Sep 17 00:00:00 2001 From: kn Date: Tue, 8 Nov 2022 12:08:53 +0000 Subject: [PATCH] Make "prepare filesystem" softraid aware, fix arm64 softraid install 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). Fix it in the same spirit the actual "install" already works in softraid.c. This is what mlarkin has already been tested in a combined diff with the MD -> MI softraid merge bits from the previous commit. Works fine on amd64, arm64 and sparc64 upgrades and installations. OK jsing --- regress/usr.sbin/installboot/Makefile | 8 +----- usr.sbin/installboot/installboot.c | 6 +++- usr.sbin/installboot/installboot.h | 3 +- usr.sbin/installboot/softraid.c | 37 ++++++++++++++++++++++++- usr.sbin/installboot/sparc64_softraid.c | 7 +---- 5 files changed, 45 insertions(+), 16 deletions(-) diff --git a/regress/usr.sbin/installboot/Makefile b/regress/usr.sbin/installboot/Makefile index 0526146baff..d48171993bd 100644 --- a/regress/usr.sbin/installboot/Makefile +++ b/regress/usr.sbin/installboot/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.34 2022/10/10 11:06:14 kn Exp $ +# $OpenBSD: Makefile,v 1.35 2022/11/08 12:08:53 kn Exp $ INSTALLBOOT ?= /usr/sbin/installboot DRY_RUN = ${INSTALLBOOT} -n @@ -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 \ diff --git a/usr.sbin/installboot/installboot.c b/usr.sbin/installboot/installboot.c index 824a5ad9179..220fab8900a 100644 --- a/usr.sbin/installboot/installboot.c +++ b/usr.sbin/installboot/installboot.c @@ -1,4 +1,4 @@ -/* $OpenBSD: installboot.c,v 1.15 2022/08/19 08:27:48 kn Exp $ */ +/* $OpenBSD: installboot.c,v 1.16 2022/11/08 12:08:53 kn Exp $ */ /* * Copyright (c) 2012, 2013 Joel Sing @@ -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; } diff --git a/usr.sbin/installboot/installboot.h b/usr.sbin/installboot/installboot.h index d70005d2496..c4c4de7b153 100644 --- a/usr.sbin/installboot/installboot.h +++ b/usr.sbin/installboot/installboot.h @@ -1,4 +1,4 @@ -/* $OpenBSD: installboot.h,v 1.15 2022/11/07 15:56:09 kn Exp $ */ +/* $OpenBSD: installboot.h,v 1.16 2022/11/08 12:08:53 kn Exp $ */ /* * Copyright (c) 2012, 2013 Joel Sing * @@ -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 *); diff --git a/usr.sbin/installboot/softraid.c b/usr.sbin/installboot/softraid.c index 1bb6254631f..8e95e756d12 100644 --- a/usr.sbin/installboot/softraid.c +++ b/usr.sbin/installboot/softraid.c @@ -1,4 +1,4 @@ -/* $OpenBSD: softraid.c,v 1.6 2022/11/07 15:56:09 kn Exp $ */ +/* $OpenBSD: softraid.c,v 1.7 2022/11/08 12:08:53 kn Exp $ */ /* * Copyright (c) 2012 Joel Sing * @@ -26,12 +26,47 @@ #include #include #include +#include #include #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) { diff --git a/usr.sbin/installboot/sparc64_softraid.c b/usr.sbin/installboot/sparc64_softraid.c index c0bf9a834c2..b86db68df40 100644 --- a/usr.sbin/installboot/sparc64_softraid.c +++ b/usr.sbin/installboot/sparc64_softraid.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sparc64_softraid.c,v 1.8 2022/11/07 15:56:09 kn Exp $ */ +/* $OpenBSD: sparc64_softraid.c,v 1.9 2022/11/08 12:08:53 kn Exp $ */ /* * Copyright (c) 2012 Joel Sing * @@ -15,19 +15,14 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include -#include #include #include #include -#include #include -#include #include #include -#include #include #include "installboot.h" -- 2.20.1