On Wed, Oct 05, 2022 at 10:31:38AM +0000, Klemens Nanni wrote: > On Sat, Sep 10, 2022 at 02:10:22AM +0000, Klemens Nanni wrote: > > It does not have the prettiest signature, but nicely folds identical > > copies into MI softraid.c, which then allows us to > > - avoid further diverging MD code > > - implement the keydisk fix on tech@ once instead of thrice > > - reuse sr_open_chunk() in an upcoming diff to make -p softraid aware > > > > The last point is especially useful, otherwise I'd have to copy what > > sr_open_chunk() does yet another three times (each *_softraid.c file), > > turning it a much simpler and smaller diff. > > > > This conflicts with the keydisk fix on tech@ > > "Softraid crypto with keydisk and installboot, skip on the same disk". > > The keydisk fix just landed. > > > I've successfully tested the diff below together with the keydisk fix > > as well as the upcoming -p/softraid diff on amd64, arm64 and sparc64. > > mlarking reported success installing root on softraid on arm64 without > manual intervention using the combined diff posted earlier. > > > Feedback? OK? > > Rebased unification diff below without functional changes.
Ping. root on softraid installations on arm64 still fail to boot by default because installboot(8)'s `-p' still ignores softraid(4) chunks. After this merge of common softraid code from MD to MI files, fixing -p for all archs becomes trivial and arm64 installations will finally boot out of the box. Index: efi_softraid.c =================================================================== RCS file: /cvs/src/usr.sbin/installboot/efi_softraid.c,v retrieving revision 1.3 diff -u -p -r1.3 efi_softraid.c --- efi_softraid.c 5 Oct 2022 09:58:43 -0000 1.3 +++ efi_softraid.c 26 Oct 2022 15:19:57 -0000 @@ -16,18 +16,9 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include <sys/types.h> -#include <sys/disklabel.h> -#include <sys/ioctl.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" @@ -40,38 +31,9 @@ sr_install_bootblk(int devfd, int vol, i int diskfd; char part; - /* Get device name for this disk/chunk. */ - memset(&bd, 0, sizeof(bd)); - bd.bd_volid = vol; - bd.bd_diskid = disk; - if (ioctl(devfd, BIOCDISK, &bd) == -1) - err(1, "BIOCDISK"); - - /* Check disk status. */ - if (bd.bd_status != BIOC_SDONLINE && bd.bd_status != BIOC_SDREBUILD) { - fprintf(stderr, "softraid chunk %u not online - skipping...\n", - disk); - return; - } - - /* Keydisks always have a size of zero. */ - if (bd.bd_size == 0) { - fprintf(stderr, "softraid chunk %u is keydisk - skipping...\n", - disk); + diskfd = sr_open_chunk(devfd, vol, disk, &bd, &realdev, &part); + if (diskfd == -1) return; - } - - if (strlen(bd.bd_vendor) < 1) - errx(1, "invalid disk name"); - part = bd.bd_vendor[strlen(bd.bd_vendor) - 1]; - if (part < 'a' || part >= 'a' + MAXPARTITIONS) - errx(1, "invalid partition %c\n", part); - bd.bd_vendor[strlen(bd.bd_vendor) - 1] = '\0'; - - /* Open device. */ - if ((diskfd = opendev(bd.bd_vendor, (nowrite ? O_RDONLY : O_RDWR), - OPENDEV_PART, &realdev)) == -1) - err(1, "open: %s", realdev); if (verbose) fprintf(stderr, "%s%c: %s boot blocks on %s\n", bd.bd_vendor, Index: i386_softraid.c =================================================================== RCS file: /cvs/src/usr.sbin/installboot/i386_softraid.c,v retrieving revision 1.20 diff -u -p -r1.20 i386_softraid.c --- i386_softraid.c 5 Oct 2022 09:58:43 -0000 1.20 +++ i386_softraid.c 26 Oct 2022 15:19:57 -0000 @@ -32,7 +32,6 @@ #include <stdlib.h> #include <string.h> #include <unistd.h> -#include <util.h> #include "installboot.h" #include "i386_installboot.h" @@ -51,38 +50,9 @@ sr_install_bootblk(int devfd, int vol, i char part, efipart; int diskfd; - /* Get device name for this disk/chunk. */ - memset(&bd, 0, sizeof(bd)); - bd.bd_volid = vol; - bd.bd_diskid = disk; - if (ioctl(devfd, BIOCDISK, &bd) == -1) - err(1, "BIOCDISK"); - - /* Check disk status. */ - if (bd.bd_status != BIOC_SDONLINE && bd.bd_status != BIOC_SDREBUILD) { - fprintf(stderr, "softraid chunk %u not online - skipping...\n", - disk); - return; - } - - /* Keydisks always have a size of zero. */ - if (bd.bd_size == 0) { - fprintf(stderr, "softraid chunk %u is keydisk - skipping...\n", - disk); + diskfd = sr_open_chunk(devfd, vol, disk, &bd, &dev, &part); + if (diskfd == -1) return; - } - - if (strlen(bd.bd_vendor) < 1) - errx(1, "invalid disk name"); - part = bd.bd_vendor[strlen(bd.bd_vendor) - 1]; - if (part < 'a' || part >= 'a' + MAXPARTITIONS) - errx(1, "invalid partition %c\n", part); - bd.bd_vendor[strlen(bd.bd_vendor) - 1] = '\0'; - - /* Open this device and check its disklabel. */ - if ((diskfd = opendev(bd.bd_vendor, (nowrite? O_RDONLY:O_RDWR), - OPENDEV_PART, &dev)) == -1) - err(1, "open: %s", dev); /* Get and check disklabel. */ if (ioctl(diskfd, DIOCGDINFO, &dl) == -1) Index: installboot.h =================================================================== RCS file: /cvs/src/usr.sbin/installboot/installboot.h,v retrieving revision 1.14 diff -u -p -r1.14 installboot.h --- installboot.h 3 Feb 2022 10:25:14 -0000 1.14 +++ installboot.h 26 Oct 2022 15:19:57 -0000 @@ -43,6 +43,8 @@ void md_prepareboot(int, char *); 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: softraid.c =================================================================== RCS file: /cvs/src/usr.sbin/installboot/softraid.c,v retrieving revision 1.5 diff -u -p -r1.5 softraid.c --- softraid.c 8 Jun 2020 19:17:12 -0000 1.5 +++ softraid.c 26 Oct 2022 15:19:57 -0000 @@ -15,14 +15,18 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include <sys/types.h> +#include <sys/disklabel.h> #include <sys/dkio.h> #include <sys/ioctl.h> #include <dev/biovar.h> #include <err.h> +#include <fcntl.h> #include <stdio.h> #include <string.h> +#include <util.h> #include "installboot.h" @@ -107,4 +111,47 @@ sr_status(struct bio_status *bs) else exit(1); } +} + +int +sr_open_chunk(int devfd, int vol, int disk, struct bioc_disk *bd, + char **realdev, char *part) +{ + int diskfd; + + /* Get device name for this disk/chunk. */ + memset(bd, 0, sizeof(*bd)); + bd->bd_volid = vol; + bd->bd_diskid = disk; + if (ioctl(devfd, BIOCDISK, bd) == -1) + err(1, "BIOCDISK"); + + /* Check disk status. */ + if (bd->bd_status != BIOC_SDONLINE && + bd->bd_status != BIOC_SDREBUILD) { + fprintf(stderr, "softraid chunk %u not online - skipping...\n", + disk); + return -1; + } + + /* Keydisks always have a size of zero. */ + if (bd->bd_size == 0) { + fprintf(stderr, "softraid chunk %u is keydisk - skipping...\n", + disk); + return -1; + } + + if (strlen(bd->bd_vendor) < 1) + errx(1, "invalid disk name"); + *part = bd->bd_vendor[strlen(bd->bd_vendor) - 1]; + if (*part < 'a' || *part >= 'a' + MAXPARTITIONS) + errx(1, "invalid partition %c\n", *part); + bd->bd_vendor[strlen(bd->bd_vendor) - 1] = '\0'; + + /* Open device. */ + if ((diskfd = opendev(bd->bd_vendor, (nowrite ? O_RDONLY : O_RDWR), + OPENDEV_PART, realdev)) == -1) + err(1, "open: %s", *realdev); + + return diskfd; } Index: sparc64_softraid.c =================================================================== RCS file: /cvs/src/usr.sbin/installboot/sparc64_softraid.c,v retrieving revision 1.7 diff -u -p -r1.7 sparc64_softraid.c --- sparc64_softraid.c 5 Oct 2022 09:58:43 -0000 1.7 +++ sparc64_softraid.c 26 Oct 2022 15:19:57 -0000 @@ -41,38 +41,9 @@ sr_install_bootblk(int devfd, int vol, i int diskfd; char part; - /* Get device name for this disk/chunk. */ - memset(&bd, 0, sizeof(bd)); - bd.bd_volid = vol; - bd.bd_diskid = disk; - if (ioctl(devfd, BIOCDISK, &bd) == -1) - err(1, "BIOCDISK"); - - /* Check disk status. */ - if (bd.bd_status != BIOC_SDONLINE && bd.bd_status != BIOC_SDREBUILD) { - fprintf(stderr, "softraid chunk %u not online - skipping...\n", - disk); + diskfd = sr_open_chunk(devfd, vol, disk, &bd, &realdev, &part); + if (diskfd == -1) return; - } - - /* Keydisks always have a size of zero. */ - if (bd.bd_size == 0) { - fprintf(stderr, "softraid chunk %u is keydisk - skipping...\n", - disk); - return; - } - - if (strlen(bd.bd_vendor) < 1) - errx(1, "invalid disk name"); - part = bd.bd_vendor[strlen(bd.bd_vendor) - 1]; - if (part < 'a' || part >= 'a' + MAXPARTITIONS) - errx(1, "invalid partition %c\n", part); - bd.bd_vendor[strlen(bd.bd_vendor) - 1] = '\0'; - - /* Open device. */ - if ((diskfd = opendev(bd.bd_vendor, (nowrite ? O_RDONLY : O_RDWR), - OPENDEV_PART, &realdev)) == -1) - err(1, "open: %s", realdev); if (verbose) fprintf(stderr, "%s%c: %s boot blocks on %s\n", bd.bd_vendor,