The branch main has been updated by imp:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=4640f5008922c5b189d2f7b63edf73300277e6df

commit 4640f5008922c5b189d2f7b63edf73300277e6df
Author:     Wanpeng Qian <[email protected]>
AuthorDate: 2025-11-18 17:24:13 +0000
Commit:     Warner Losh <[email protected]>
CommitDate: 2025-11-18 21:01:43 +0000

    nvme_sim: signal namespace depature
    
    Signal when the namespace is gone so we can tear down the disk when a
    nvme drive is removed.
    
    Reviewed by:            imp
    Differential Revision:  https://reviews.freebsd.org/D33032
---
 sys/dev/nvme/nvme_sim.c | 28 +++++++++++++++++++---------
 1 file changed, 19 insertions(+), 9 deletions(-)

diff --git a/sys/dev/nvme/nvme_sim.c b/sys/dev/nvme/nvme_sim.c
index 7693aa6d54d3..e015fbe4d072 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);

Reply via email to