aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWarner Losh <imp@FreeBSD.org>2026-03-03 17:59:36 +0000
committerWarner Losh <imp@FreeBSD.org>2026-03-03 17:59:36 +0000
commit628d7a3270b64b6c7fae3b0c98068c670162a154 (patch)
treee15ac5a70996a510e7ef6e983160f0c6e682613f
parent5c2186b992546bce212dfad3e49012f4c69c2d0c (diff)
nda: AC_GETDEV_CHANGED calls media chanaged for sectorsize change
When the sector size changes, we assume it's new media. When the mediasize changes, we'll just resize the disk (we get called for both events). When neither have changed, don't call either. Some NVMe drives (but not all) post a async event on page 4 with the sector size changes via a FORMAT command. We'll notice the new media right away, rather than the next device open. As a practical effect, this just means that certain geom operations will see it sooner. Since most drive interaction goes through open, that will catch those drives that do not post this event well enough. Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D55521
-rw-r--r--sys/cam/nvme/nvme_da.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/sys/cam/nvme/nvme_da.c b/sys/cam/nvme/nvme_da.c
index 2e8e376f985d..a1114ffe8a44 100644
--- a/sys/cam/nvme/nvme_da.c
+++ b/sys/cam/nvme/nvme_da.c
@@ -432,7 +432,7 @@ ndaclose(struct disk *dp)
("nda %d outstanding commands", softc->outstanding_cmds));
cam_periph_unlock(periph);
cam_periph_release(periph);
- return (0);
+ return (0);
}
static void
@@ -760,17 +760,23 @@ ndaasync(void *callback_arg, uint32_t code, struct cam_path *path, void *arg)
}
case AC_GETDEV_CHANGED:
{
- int error;
+ off_t mediasize;
+ u_int sectorsize;
softc = periph->softc;
+ mediasize = softc->disk->d_mediasize;
+ sectorsize = softc->disk->d_sectorsize;
ndasetgeom(softc, periph);
- error = disk_resize(softc->disk, M_NOWAIT);
- if (error != 0) {
- xpt_print(periph->path, "disk_resize(9) failed, error = %d\n", error);
- break;
- }
+ /*
+ * If the sectorsize changed, then it's new media. Otherwise if
+ * the media size changed, resize the existing disk. Otherwise
+ * do nothing.
+ */
+ if (sectorsize != softc->disk->d_sectorsize)
+ disk_media_changed(softc->disk, M_WAITOK);
+ else if (mediasize != softc->disk->d_mediasize)
+ disk_resize(softc->disk, M_WAITOK);
break;
-
}
case AC_ADVINFO_CHANGED:
{