diff options
| author | Abdelkader Boudih <seuros@FreeBSD.org> | 2026-09-25 21:42:23 +0000 |
|---|---|---|
| committer | Abdelkader Boudih <seuros@FreeBSD.org> | 2026-09-25 21:42:23 +0000 |
| commit | 130739e33acc1b55f6da297fdebb693d9d8feea8 (patch) | |
| tree | d1e16cee2d76faabc6587442ef9e8c41d6eb44cd | |
| parent | 92dec9201bf9759fc760da49a175fc99f3277c6c (diff) | |
nvmf: factor out the pending request abort loop
The routine is entered with the namespace lock held and drops it before
completing the requests, which preserves the existing locking.
Reviewed by: imp, adrian
Differential Revision: https://reviews.freebsd.org/D60019
| -rw-r--r-- | sys/dev/nvmf/host/nvmf_ns.c | 33 |
1 files changed, 14 insertions, 19 deletions
diff --git a/sys/dev/nvmf/host/nvmf_ns.c b/sys/dev/nvmf/host/nvmf_ns.c index 572649870e05..12db071b891b 100644 --- a/sys/dev/nvmf/host/nvmf_ns.c +++ b/sys/dev/nvmf/host/nvmf_ns.c @@ -433,14 +433,15 @@ nvmf_reconnect_ns(struct nvmf_namespace *ns) } } -void -nvmf_shutdown_ns(struct nvmf_namespace *ns) +/* Called with ns->lock held; drops it. */ +static void +nvmf_ns_abort_pending_bios(struct nvmf_namespace *ns) { TAILQ_HEAD(, bio) bios; struct bio *bio; - mtx_lock(&ns->lock); - ns->shutdown = true; + mtx_assert(&ns->lock, MA_OWNED); + TAILQ_INIT(&bios); TAILQ_CONCAT(&bios, &ns->pending_bios, bio_queue); mtx_unlock(&ns->lock); @@ -456,11 +457,16 @@ nvmf_shutdown_ns(struct nvmf_namespace *ns) } void -nvmf_destroy_ns(struct nvmf_namespace *ns) +nvmf_shutdown_ns(struct nvmf_namespace *ns) { - TAILQ_HEAD(, bio) bios; - struct bio *bio; + mtx_lock(&ns->lock); + ns->shutdown = true; + nvmf_ns_abort_pending_bios(ns); +} +void +nvmf_destroy_ns(struct nvmf_namespace *ns) +{ if (ns->cdev->si_drv2 != NULL) destroy_dev(ns->cdev->si_drv2); destroy_dev(ns->cdev); @@ -477,18 +483,7 @@ nvmf_destroy_ns(struct nvmf_namespace *ns) } /* Abort any pending I/O requests. */ - TAILQ_INIT(&bios); - TAILQ_CONCAT(&bios, &ns->pending_bios, bio_queue); - mtx_unlock(&ns->lock); - - while (!TAILQ_EMPTY(&bios)) { - bio = TAILQ_FIRST(&bios); - TAILQ_REMOVE(&bios, bio, bio_queue); - bio->bio_error = ECONNABORTED; - bio->bio_flags |= BIO_ERROR; - bio->bio_resid = bio->bio_bcount; - biodone(bio); - } + nvmf_ns_abort_pending_bios(ns); mtx_destroy(&ns->lock); free(ns, M_NVMF); |
