On Sun, Jun 07, 2020 at 03:24:30PM +0200, Klemens Nanni wrote: > On Sun, Jun 07, 2020 at 12:42:57AM +1000, Joel Sing wrote: > > While this works, you would be better off making use of the error > > reporting mechanism that exists. A compile tested only diff for > > the kernel side is below. A diff to installboot would be needed to > > graft some code similar to that in bioctl's bio_status() function. > Thanks, I didn't even look how bioctl(8) does it; that seems better. > > The complete diff for softraid(4), <dev/biovar.h> and installboot(8) > makes sparc64 look like this: > > # ./obj/installboot -v sd2 /usr/mdec/bootblk /ofwboot.big > Using / as root > installing bootstrap on /dev/rsd2c > using first-stage /usr/mdec/bootblk, second-stage /ofwboot.big > boot block is 6882 bytes (14 blocks @ 512 bytes = 7168 bytes) > sd2: softraid volume with 1 disk(s) > sd2: installing boot loader on softraid volume > installboot: boot loader too large (272452 > 163840) > # echo $? > 1 > > I ommitted "is" from the kernel message to stay in line with other > "too large" ones in softraid.c. > > Contrary to bioctl's bio_status(), installboot's new sr_status() uses > warnx(3) for simplicity and put warnings on stderr (where they belong). > > Feedback? OK? Updated diff after the biovar.h commit.
Index: sys/dev/softraid.c =================================================================== RCS file: /cvs/src/sys/dev/softraid.c,v retrieving revision 1.401 diff -u -p -r1.401 softraid.c --- sys/dev/softraid.c 14 Apr 2020 07:38:21 -0000 1.401 +++ sys/dev/softraid.c 7 Jun 2020 11:20:05 -0000 @@ -3704,11 +3704,17 @@ sr_ioctl_installboot(struct sr_softc *sc goto done; } - if (bb->bb_bootblk_size > SR_BOOT_BLOCKS_SIZE * DEV_BSIZE) + if (bb->bb_bootblk_size > SR_BOOT_BLOCKS_SIZE * DEV_BSIZE) { + sr_error(sc, "boot block is too large (%d > %d)", + bb->bb_bootblk_size, SR_BOOT_BLOCKS_SIZE * DEV_BSIZE); goto done; + } - if (bb->bb_bootldr_size > SR_BOOT_LOADER_SIZE * DEV_BSIZE) + if (bb->bb_bootldr_size > SR_BOOT_LOADER_SIZE * DEV_BSIZE) { + sr_error(sc, "boot loader is too large (%d > %d)", + bb->bb_bootldr_size, SR_BOOT_LOADER_SIZE * DEV_BSIZE); goto done; + } secsize = sd->sd_meta->ssdi.ssd_secsize; Index: usr.sbin/installboot/i386_softraid.c =================================================================== RCS file: /cvs/src/usr.sbin/installboot/i386_softraid.c,v retrieving revision 1.15 diff -u -p -r1.15 i386_softraid.c --- usr.sbin/installboot/i386_softraid.c 9 Mar 2020 06:16:56 -0000 1.15 +++ usr.sbin/installboot/i386_softraid.c 7 Jun 2020 12:31:20 -0000 @@ -178,6 +178,7 @@ sr_install_bootldr(int devfd, char *dev) "softraid volume\n", dev); if (ioctl(devfd, BIOCINSTALLBOOT, &bb) == -1) errx(1, "softraid installboot failed"); + sr_status(&bb.bb_bio.bio_status); } /* Index: usr.sbin/installboot/installboot.h =================================================================== RCS file: /cvs/src/usr.sbin/installboot/installboot.h,v retrieving revision 1.11 diff -u -p -r1.11 installboot.h --- usr.sbin/installboot/installboot.h 1 Sep 2018 16:55:29 -0000 1.11 +++ usr.sbin/installboot/installboot.h 7 Jun 2020 11:46:52 -0000 @@ -15,6 +15,8 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include <dev/biovar.h> + #include <stdlib.h> extern int nowrite; @@ -41,4 +43,5 @@ void md_installboot(int, char *); void sr_installboot(int, char *); void sr_install_bootblk(int, int, int); void sr_install_bootldr(int, char *); +void sr_status(struct bio_status *); #endif Index: usr.sbin/installboot/softraid.c =================================================================== RCS file: /cvs/src/usr.sbin/installboot/softraid.c,v retrieving revision 1.4 diff -u -p -r1.4 softraid.c --- usr.sbin/installboot/softraid.c 3 Oct 2015 16:56:52 -0000 1.4 +++ usr.sbin/installboot/softraid.c 7 Jun 2020 13:04:24 -0000 @@ -92,3 +92,19 @@ sr_volume(int devfd, char *dev, int *vol return 1; } + +void +sr_status(struct bio_status *bs) +{ + int i; + + for (i = 0; i < bs->bs_msg_count; i++) + warnx("%s", bs->bs_msgs[i].bm_msg); + + if (bs->bs_status == BIO_STATUS_ERROR) { + if (bs->bs_msg_count == 0) + errx(1, "unknown error"); + else + exit(1); + } +} Index: usr.sbin/installboot/sparc64_softraid.c =================================================================== RCS file: /cvs/src/usr.sbin/installboot/sparc64_softraid.c,v retrieving revision 1.4 diff -u -p -r1.4 sparc64_softraid.c --- usr.sbin/installboot/sparc64_softraid.c 28 Jun 2019 13:32:48 -0000 1.4 +++ usr.sbin/installboot/sparc64_softraid.c 7 Jun 2020 12:31:18 -0000 @@ -97,5 +97,6 @@ sr_install_bootldr(int devfd, char *dev) "softraid volume\n", dev); if (ioctl(devfd, BIOCINSTALLBOOT, &bb) == -1) errx(1, "softraid installboot failed"); + sr_status(&bb.bb_bio.bio_status); } }