From 81d2f9166a86513892803d07ac9b0df4a5b965bb Mon Sep 17 00:00:00 2001 From: miod Date: Sun, 11 Sep 2022 19:34:40 +0000 Subject: [PATCH] Remove the DKF_LABELVALID flag from struct disk. Instead, trust disk drivers to always be able to provide a duid, and keep ignoring whole zero duids. This fixes a race in vnd setup where the disk_attach callback could run before any I/O occurs on the vnd, thus not having a label available yet. noticed by otto@ and kn@; ok kn@ --- sys/dev/softraid.c | 6 ++---- sys/kern/subr_disk.c | 13 ++++++------- sys/sys/disk.h | 3 +-- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/sys/dev/softraid.c b/sys/dev/softraid.c index ebf092a40e5..b243dd3a931 100644 --- a/sys/dev/softraid.c +++ b/sys/dev/softraid.c @@ -1,4 +1,4 @@ -/* $OpenBSD: softraid.c,v 1.426 2022/08/29 19:01:52 stsp Exp $ */ +/* $OpenBSD: softraid.c,v 1.427 2022/09/11 19:34:40 miod Exp $ */ /* * Copyright (c) 2007, 2008, 2009 Marco Peereboom * Copyright (c) 2008 Chris Kuethe @@ -3690,13 +3690,11 @@ sr_ioctl_installboot(struct sr_softc *sc, struct sr_discipline *sd, } } - bzero(duid, sizeof(duid)); TAILQ_FOREACH(dk, &disklist, dk_link) if (!strncmp(dk->dk_name, bb->bb_dev, sizeof(bb->bb_dev))) break; if (dk == NULL || dk->dk_label == NULL || - (dk->dk_flags & DKF_LABELVALID) == 0 || - bcmp(dk->dk_label->d_uid, &duid, sizeof(duid)) == 0) { + duid_iszero(dk->dk_label->d_uid)) { sr_error(sc, "failed to get DUID for softraid volume"); goto done; } diff --git a/sys/kern/subr_disk.c b/sys/kern/subr_disk.c index 6623dd816bc..a387fdc5529 100644 --- a/sys/kern/subr_disk.c +++ b/sys/kern/subr_disk.c @@ -1,4 +1,4 @@ -/* $OpenBSD: subr_disk.c,v 1.261 2022/09/11 11:47:55 krw Exp $ */ +/* $OpenBSD: subr_disk.c,v 1.262 2022/09/11 19:34:40 miod Exp $ */ /* $NetBSD: subr_disk.c,v 1.17 1996/03/16 23:17:08 christos Exp $ */ /* @@ -1130,7 +1130,6 @@ disk_attach_callback(void *xdat) /* Read disklabel. */ if (disk_readlabel(&dl, dk->dk_devno, errbuf, sizeof(errbuf)) == NULL) { enqueue_randomness(dl.d_checksum); - dk->dk_flags |= DKF_LABELVALID; } done: @@ -1449,14 +1448,14 @@ setroot(struct device *bootdv, int part, int exitflags) TAILQ_FOREACH(dk, &disklist, dk_link) if (dk->dk_device == bootdv) break; - if (dk && (dk->dk_flags & DKF_LABELVALID)) + if (dk) bcopy(dk->dk_label->d_uid, bootduid, sizeof(bootduid)); } else if (bootdv == NULL) { /* Locate boot disk based on the provided DUID. */ TAILQ_FOREACH(dk, &disklist, dk_link) if (duid_equal(dk->dk_label->d_uid, bootduid)) break; - if (dk && (dk->dk_flags & DKF_LABELVALID)) + if (dk) bootdv = dk->dk_device; } bcopy(bootduid, rootduid, sizeof(rootduid)); @@ -1570,8 +1569,7 @@ gotswap: if (bootdv->dv_class == DV_DISK) { if (!duid_iszero(rootduid)) { TAILQ_FOREACH(dk, &disklist, dk_link) - if ((dk->dk_flags & DKF_LABELVALID) && - dk->dk_label && duid_equal( + if (dk->dk_label && duid_equal( dk->dk_label->d_uid, rootduid)) break; if (dk == NULL) @@ -1797,7 +1795,8 @@ disk_map(char *path, char *mappath, int size, int flags) mdk = NULL; TAILQ_FOREACH(dk, &disklist, dk_link) { - if ((dk->dk_flags & DKF_LABELVALID) && dk->dk_label && + if (dk->dk_label && + !duid_iszero(dk->dk_label->d_uid) && memcmp(dk->dk_label->d_uid, uid, sizeof(dk->dk_label->d_uid)) == 0) { /* Fail if there are duplicate UIDs! */ diff --git a/sys/sys/disk.h b/sys/sys/disk.h index 4dcd48839f0..a024bb1c4a7 100644 --- a/sys/sys/disk.h +++ b/sys/sys/disk.h @@ -1,4 +1,4 @@ -/* $OpenBSD: disk.h,v 1.36 2017/05/04 22:47:27 deraadt Exp $ */ +/* $OpenBSD: disk.h,v 1.37 2022/09/11 19:34:40 miod Exp $ */ /* $NetBSD: disk.h,v 1.11 1996/04/28 20:22:50 thorpej Exp $ */ /* @@ -83,7 +83,6 @@ struct disk { #define DKF_CONSTRUCTED 0x0001 #define DKF_OPENED 0x0002 #define DKF_NOLABELREAD 0x0004 -#define DKF_LABELVALID 0x0008 /* * Metrics data; note that some metrics may have no meaning -- 2.20.1