From nobody Wed Jun 5 20:03:59 2024 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4VvdhH4f63z5M3MZ; Wed, 05 Jun 2024 20:03:59 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4VvdhH2Z77z4jDw; Wed, 5 Jun 2024 20:03:59 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1717617839; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=PPCwrE8b8y9pNNwA5UpIRNrpjgKgkdboFyUa+kgToV8=; b=xBlnmiWhwrsOwxKQrLvCNy7HlQSN+wPx6ZgQhx1EZhLC09zE1vQKpY6Lg2QzNB3he8M7k6 dO2RYiG+oZjYvsc1I+YOJ0/qIvDYxquemGfZ48aWtEwLxMElFzUicMnlSdbLWDJorst75w I+BFzsb9N7IQ/sXNgpn2fCKYpJZxh+J+0vny1EqjtslQkYfcob2WtRuFWTd/cJ+W8/VFK+ wtHIJsP8dU6Y7dxDyNLSfSy/M6HXZPPrtY2a4VpBoiUls/4fhtppZ54F8IoLhzPYlM8L5d 4+EincHtx4A2Ve5Inw5W6KbCfa8Syb9Cq8yJCdbxEoStXm54TxvoO/51RpE1Zw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1717617839; a=rsa-sha256; cv=none; b=gK2uFJfm014py2bmOUimBV1z9RyD4DecikeaNTvP8N3jK59FDtau5bq1qxOGrIvJwxKAg6 fXDwG9C//ySIg+O84beE6C4UfW4vKEjE7hDkYF4mC0imPUhF8W7bb//mBnhjDOuXPI+8D3 z4lQzZ8N6u1J2xA3KcJp8uBA2kdCp6Gh//hVrh/hICqN/qmS8mqSx6os8Ksjj8CkUdn8SD 0T/ZKEAmzW8XJ3Od5Axi3eAWZx30JbQY19SIo27JNg1AtDiNSQzyOo4vg4/ndDSQRHG7sS vJYblfkEM9s3txafKBVkBT/Ku98JXqA6hHftUsCdH+9Rl9tNcFGlkztVus/BbQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1717617839; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=PPCwrE8b8y9pNNwA5UpIRNrpjgKgkdboFyUa+kgToV8=; b=uie9mrgX7wBl8XUXDDRANfjir8zkP3w8qhjevyEivHHEJei07QjIge7Q95FTrUIm4B+Fko XUqFifiZATI1dsd3hxEWz2a7K653pDKdjaWSu7Y8St6mdyrCsmqGvSar8kqWLpcvMG0p7+ unxkmYCrdGwfUip7as3zdHZJoKJwzOSMCGonmeYQ62effKL3+o2+AoiM+2WaRpW1SZkM95 Rnn4BrOV8U98+l2UW4BnN5w76bu/zlZuQ4vgNf5t6wZN0bhB3OorNLS2Qj6T+VTFLbulHd GTfGZjDPWRYvgexwlbuTu8iMrAUd4l+S+2eWvVzb9qmylypqwnhlsw6B4Vv1oQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4VvdhH2BR7zGHK; Wed, 5 Jun 2024 20:03:59 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 455K3xJq011597; Wed, 5 Jun 2024 20:03:59 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 455K3x5q011594; Wed, 5 Jun 2024 20:03:59 GMT (envelope-from git) Date: Wed, 5 Jun 2024 20:03:59 GMT Message-Id: <202406052003.455K3x5q011594@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: John Baldwin Subject: git: 02ddb305cc6d - main - nvmf: Refactor nvmf_add_namespaces to be more generic List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 02ddb305cc6d7fc3964e33985ae89501b99bb05b Auto-Submitted: auto-generated The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=02ddb305cc6d7fc3964e33985ae89501b99bb05b commit 02ddb305cc6d7fc3964e33985ae89501b99bb05b Author: John Baldwin AuthorDate: 2024-06-05 19:51:56 +0000 Commit: John Baldwin CommitDate: 2024-06-05 19:51:56 +0000 nvmf: Refactor nvmf_add_namespaces to be more generic Rename to nvmf_scan_active_namespaces and accept an additional callback function and callback argument. The callback is invoked on each active namespace enumerated by the active namespace list from the IDENTIFY command. Reviewed by: imp Sponsored by: Chelsio Communications Differential Revision: https://reviews.freebsd.org/D45458 --- sys/dev/nvmf/host/nvmf.c | 74 ++++++++++++++++++++++++++++++------------------ 1 file changed, 47 insertions(+), 27 deletions(-) diff --git a/sys/dev/nvmf/host/nvmf.c b/sys/dev/nvmf/host/nvmf.c index e43d438aaa8c..df07d70b6c86 100644 --- a/sys/dev/nvmf/host/nvmf.c +++ b/sys/dev/nvmf/host/nvmf.c @@ -295,9 +295,13 @@ nvmf_establish_connection(struct nvmf_softc *sc, struct nvmf_ivars *ivars) return (0); } +typedef bool nvmf_scan_active_ns_cb(struct nvmf_softc *, uint32_t, + const struct nvme_namespace_data *, void *); + static bool -nvmf_scan_nslist(struct nvmf_softc *sc, struct nvme_ns_list *nslist, - struct nvme_namespace_data *data, uint32_t *nsidp) +nvmf_scan_active_nslist(struct nvmf_softc *sc, struct nvme_ns_list *nslist, + struct nvme_namespace_data *data, uint32_t *nsidp, + nvmf_scan_active_ns_cb *cb, void *cb_arg) { struct nvmf_completion_status status; uint32_t nsid; @@ -333,13 +337,6 @@ nvmf_scan_nslist(struct nvmf_softc *sc, struct nvme_ns_list *nslist, return (true); } - if (sc->ns[nsid - 1] != NULL) { - device_printf(sc->dev, - "duplicate namespace %u in active namespace list\n", - nsid); - return (false); - } - nvmf_status_init(&status); nvmf_status_wait_io(&status); if (!nvmf_cmd_identify_namespace(sc, nsid, data, nvmf_complete, @@ -365,21 +362,9 @@ nvmf_scan_nslist(struct nvmf_softc *sc, struct nvme_ns_list *nslist, return (false); } - /* - * As in nvme_ns_construct, a size of zero indicates an - * invalid namespace. - */ nvme_namespace_data_swapbytes(data); - if (data->nsze == 0) { - device_printf(sc->dev, - "ignoring active namespace %u with zero size\n", - nsid); - continue; - } - - sc->ns[nsid - 1] = nvmf_init_ns(sc, nsid, data); - - nvmf_sim_rescan_ns(sc, nsid); + if (!cb(sc, nsid, data, cb_arg)) + return (false); } MPASS(nsid == nslist->ns[nitems(nslist->ns) - 1] && nsid != 0); @@ -392,22 +377,22 @@ nvmf_scan_nslist(struct nvmf_softc *sc, struct nvme_ns_list *nslist, } static bool -nvmf_add_namespaces(struct nvmf_softc *sc) +nvmf_scan_active_namespaces(struct nvmf_softc *sc, nvmf_scan_active_ns_cb *cb, + void *cb_arg) { struct nvme_namespace_data *data; struct nvme_ns_list *nslist; uint32_t nsid; bool retval; - sc->ns = mallocarray(sc->cdata->nn, sizeof(*sc->ns), M_NVMF, - M_WAITOK | M_ZERO); nslist = malloc(sizeof(*nslist), M_NVMF, M_WAITOK); data = malloc(sizeof(*data), M_NVMF, M_WAITOK); nsid = 0; retval = true; for (;;) { - if (!nvmf_scan_nslist(sc, nslist, data, &nsid)) { + if (!nvmf_scan_active_nslist(sc, nslist, data, &nsid, cb, + cb_arg)) { retval = false; break; } @@ -420,6 +405,41 @@ nvmf_add_namespaces(struct nvmf_softc *sc) return (retval); } +static bool +nvmf_add_ns(struct nvmf_softc *sc, uint32_t nsid, + const struct nvme_namespace_data *data, void *arg __unused) +{ + if (sc->ns[nsid - 1] != NULL) { + device_printf(sc->dev, + "duplicate namespace %u in active namespace list\n", + nsid); + return (false); + } + + /* + * As in nvme_ns_construct, a size of zero indicates an + * invalid namespace. + */ + if (data->nsze == 0) { + device_printf(sc->dev, + "ignoring active namespace %u with zero size\n", nsid); + return (true); + } + + sc->ns[nsid - 1] = nvmf_init_ns(sc, nsid, data); + + nvmf_sim_rescan_ns(sc, nsid); + return (true); +} + +static bool +nvmf_add_namespaces(struct nvmf_softc *sc) +{ + sc->ns = mallocarray(sc->cdata->nn, sizeof(*sc->ns), M_NVMF, + M_WAITOK | M_ZERO); + return (nvmf_scan_active_namespaces(sc, nvmf_add_ns, NULL)); +} + static int nvmf_attach(device_t dev) {