From: kn Date: Mon, 29 Aug 2022 18:54:43 +0000 (+0000) Subject: softraid: make verbose messages -n/nowrite aware X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=a129f1317d7010208a741d8c4ee87d77103a5a15;p=openbsd softraid: make verbose messages -n/nowrite aware Using installboot(8) in dry-run mode aka. -vn (verbose + nowrite) and first reading "would install" followed by an "installing" made me uneasy. Luckily, nothing was written in dry-run mode, it's just that the softraid specific code fails to honour -n/nowrite. So make sure it does and pull the printf out of `if (!nowrite)' so we see the "would install" messages in dry-run mode in the first place. Output diff for root on CRYPTO softraid on biosboot(8/amd64) to illustrate: -# installboot -nv sd1 +# ./obj/installboot -nv sd1 would install bootstrap on /dev/rsd1c using first-stage /usr/mdec/biosboot, second-stage /usr/mdec/boot sd1: softraid volume with 1 disk(s) +sd1: would install boot loader on softraid volume /usr/mdec/boot is 6 blocks x 16384 bytes -sd0a: installing boot blocks on /dev/rsd0c, part offset 144 +sd0a: would install boot blocks on /dev/rsd0c, part offset 144 master boot record (MBR) at sector 0 partition 3: type 0xA6 offset 64 size 488392001 /usr/mdec/biosboot will be written at sector 64 OK jsing --- diff --git a/usr.sbin/installboot/efi_softraid.c b/usr.sbin/installboot/efi_softraid.c index 259df18b184..79c46406b9c 100644 --- a/usr.sbin/installboot/efi_softraid.c +++ b/usr.sbin/installboot/efi_softraid.c @@ -1,4 +1,4 @@ -/* $OpenBSD: efi_softraid.c,v 1.1 2022/08/15 17:06:43 kn Exp $ */ +/* $OpenBSD: efi_softraid.c,v 1.2 2022/08/29 18:54:43 kn Exp $ */ /* * Copyright (c) 2012 Joel Sing * Copyright (c) 2022 Klemens Nanni @@ -67,8 +67,8 @@ sr_install_bootblk(int devfd, int vol, int disk) err(1, "open: %s", realdev); if (verbose) - fprintf(stderr, "%s%c: installing boot blocks on %s\n", - bd.bd_vendor, part, realdev); + fprintf(stderr, "%s%c: %s boot blocks on %s\n", bd.bd_vendor, + part, (nowrite ? "would install" : "installing"), realdev); /* Write boot blocks to device. */ md_installboot(diskfd, realdev); diff --git a/usr.sbin/installboot/i386_softraid.c b/usr.sbin/installboot/i386_softraid.c index 4ad11f97a09..b3ff06a6713 100644 --- a/usr.sbin/installboot/i386_softraid.c +++ b/usr.sbin/installboot/i386_softraid.c @@ -1,4 +1,4 @@ -/* $OpenBSD: i386_softraid.c,v 1.18 2021/10/24 21:24:18 deraadt Exp $ */ +/* $OpenBSD: i386_softraid.c,v 1.19 2022/08/29 18:54:43 kn Exp $ */ /* * Copyright (c) 2012 Joel Sing * Copyright (c) 2010 Otto Moerbeek @@ -102,8 +102,9 @@ sr_install_bootblk(int devfd, int vol, int disk) sym_set_value(pbr_symbols, "_p_offset", poffset); if (verbose) - fprintf(stderr, "%s%c: installing boot blocks on %s, " - "part offset %u\n", bd.bd_vendor, part, dev, poffset); + fprintf(stderr, "%s%c: %s boot blocks on %s, part offset %u\n", + bd.bd_vendor, part, + (nowrite ? "would install" : "installing"), dev, poffset); /* Write boot blocks to device. */ write_bootblocks(diskfd, dev, &dl); @@ -172,10 +173,10 @@ sr_install_bootldr(int devfd, char *dev) bb.bb_bootblk = "XXX"; bb.bb_bootblk_size = sizeof("XXX"); strncpy(bb.bb_dev, dev, sizeof(bb.bb_dev)); + if (verbose) + fprintf(stderr, "%s: %s boot loader on softraid volume\n", dev, + (nowrite ? "would install" : "installing")); if (!nowrite) { - if (verbose) - fprintf(stderr, "%s: installing boot loader on " - "softraid volume\n", dev); if (ioctl(devfd, BIOCINSTALLBOOT, &bb) == -1) errx(1, "softraid installboot failed"); sr_status(&bb.bb_bio.bio_status); diff --git a/usr.sbin/installboot/sparc64_softraid.c b/usr.sbin/installboot/sparc64_softraid.c index c1d8f5170de..022b211c436 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.5 2020/06/08 19:17:12 kn Exp $ */ +/* $OpenBSD: sparc64_softraid.c,v 1.6 2022/08/29 18:54:43 kn Exp $ */ /* * Copyright (c) 2012 Joel Sing * @@ -68,8 +68,8 @@ sr_install_bootblk(int devfd, int vol, int disk) err(1, "open: %s", realdev); if (verbose) - fprintf(stderr, "%s%c: installing boot blocks on %s\n", - bd.bd_vendor, part, realdev); + fprintf(stderr, "%s%c: %s boot blocks on %s\n", bd.bd_vendor, + part, (nowrite ? "would install" : "installing"), realdev); /* Write boot blocks to device. */ md_installboot(diskfd, realdev); @@ -91,10 +91,10 @@ sr_install_bootldr(int devfd, char *dev) bb.bb_bootldr = ldrstore; bb.bb_bootldr_size = ldrsize; strncpy(bb.bb_dev, dev, sizeof(bb.bb_dev)); + if (verbose) + fprintf(stderr, "%s: %s boot loader on softraid volume\n", dev, + (nowrite ? "would install" : "installing")); if (!nowrite) { - if (verbose) - fprintf(stderr, "%s: installing boot loader on " - "softraid volume\n", dev); if (ioctl(devfd, BIOCINSTALLBOOT, &bb) == -1) errx(1, "softraid installboot failed"); sr_status(&bb.bb_bio.bio_status);