aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWanpeng Qian <wanpengqian@gmail.com>2025-11-18 10:24:13 -0700
committerColin Percival <cperciva@FreeBSD.org>2025-11-19 13:37:21 -0800
commite4416d1e95c40b772dbb6889f468538f4ea9f711 (patch)
tree5d8793cc912ff64aa1d94bbbdff5e87d15cede59
parentda71efa95d340ca6625a9b1cd9a8ceb6cd199daa (diff)
nvme_sim: signal namespace depature
Signal when the namespace is gone so we can tear down the disk when a nvme drive is removed. Approved by: re (cperciva) Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D33032 (cherry picked from commit 4640f5008922c5b189d2f7b63edf73300277e6df) (cherry picked from commit b7ffac04541f98d3d8c6078092d59f0fed88b1ef)
-rw-r--r--sys/dev/nvme/nvme_sim.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/sys/dev/nvme/nvme_sim.c b/sys/dev/nvme/nvme_sim.c
index a06774a64761..f7fd0cee931b 100644
--- a/sys/dev/nvme/nvme_sim.c
+++ b/sys/dev/nvme/nvme_sim.c
@@ -352,25 +352,35 @@ static void *
nvme_sim_ns_change(struct nvme_namespace *ns, void *sc_arg)
{
struct nvme_sim_softc *sc = sc_arg;
+ struct cam_path *tmppath;
union ccb *ccb;
+ if (xpt_create_path(&tmppath, /*periph*/NULL,
+ cam_sim_path(sc->s_sim), 0, ns->id) != CAM_REQ_CMP) {
+ printf("unable to create path for rescan\n");
+ return (NULL);
+ }
+ /*
+ * If it's gone, then signal that and leave.
+ */
+ if (ns->flags & NVME_NS_GONE) {
+ xpt_async(AC_LOST_DEVICE, tmppath, NULL);
+ xpt_free_path(tmppath);
+ return (sc_arg);
+ }
+
ccb = xpt_alloc_ccb_nowait();
if (ccb == NULL) {
printf("unable to alloc CCB for rescan\n");
return (NULL);
}
+ ccb->ccb_h.path = tmppath;
/*
- * We map the NVMe namespace idea onto the CAM unit LUN. For
- * each new namespace, we create a new CAM path for it. We then
- * rescan the path to get it to enumerate.
+ * We map the NVMe namespace idea onto the CAM unit LUN. For each new
+ * namespace, scan or rescan the path to enumerate it. tmppath freed at
+ * end of scan.
*/
- if (xpt_create_path(&ccb->ccb_h.path, /*periph*/NULL,
- cam_sim_path(sc->s_sim), 0, ns->id) != CAM_REQ_CMP) {
- printf("unable to create path for rescan\n");
- xpt_free_ccb(ccb);
- return (NULL);
- }
xpt_rescan(ccb);
return (sc_arg);