From 82fc49a0bebf3f05e0584a1ed5cc6bbfd1cbd475 Mon Sep 17 00:00:00 2001 From: Warner Losh Date: Sat, 8 Feb 2025 14:31:07 -0700 Subject: [PATCH] cam/da: Only mark pack as valid if we know the size in daopen Only mark the pack as 'valid' (eg clear the invalid bit) when we know the size of the underlying drive and the periph hasn't been invalidated. Previously, we'd unconditionally clear this bit, but if the size isn't known, no I/O to the drive is possible. Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D48688 --- sys/cam/scsi/scsi_da.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/sys/cam/scsi/scsi_da.c b/sys/cam/scsi/scsi_da.c index 1e685dc2a9e..44dc21d1bc2 100644 --- a/sys/cam/scsi/scsi_da.c +++ b/sys/cam/scsi/scsi_da.c @@ -1803,10 +1803,17 @@ daopen(struct disk *dp) (softc->quirks & DA_Q_NO_PREVENT) == 0) daprevent(periph, PR_PREVENT); - if (error == 0) { + /* + * Only 'validate' the pack if the media size is non-zero and the + * underlying peripheral isn't invalid (the only error != 0 path). + */ + if (error == 0 && softc->params.sectors != 0) softc->flags &= ~DA_FLAG_PACK_INVALID; + else + softc->flags |= DA_FLAG_PACK_INVALID; + + if (error == 0) softc->flags |= DA_FLAG_OPEN; - } da_periph_unhold(periph, DA_REF_OPEN_HOLD); cam_periph_unlock(periph);