From nobody Tue Nov 05 01:29:09 2024 X-Original-To: dev-commits-src-all@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 4Xj9jL1MxDz5cpsq; Tue, 05 Nov 2024 01:29:10 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Xj9jL0grHz4rkJ; Tue, 5 Nov 2024 01:29:10 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730770150; 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=merL+sDpTQar0uMic2Ox9ArV/Q2iKgSCApjfIzgD/Kg=; b=nOh4JDTAMSNECW7wzygAWATfLJkaQe2WyYN6QPLP5XCmFyMY3pfWr6DAag92lmR0INS1K9 xZho6XtPxQifgHgoU1vBPEieVh/oySn1GK9n7TCmzInVNAqcsE+D5CVKa4K1OJb79nFElD t82hgb5zoxt1Hw24fDE7whHYoL29P4MEwP1FCa3R4B16O0CA3T3VJlRzbwakbtp28/2zh1 u3Yv/Hrq75PL80hJrq5r34jJHdsv9gYe2Ch2+cumFKl6SbAJh/h6wzfDSGMDepF1b4uFVY eRN2rT/fHC9AX4mvf/snaMCoJblKf6usbTPugJmAAMB/kW7OrTHLZjTtlCKm6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730770150; 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=merL+sDpTQar0uMic2Ox9ArV/Q2iKgSCApjfIzgD/Kg=; b=X91Y21JfbD9j0y86cdhQWBNRGR6Xj4OUZNtfkG8fv5e8v35RLKTVFbkly1qykE/+lwx+BU FiNgxOm6w4zpBZgEw7hsmw0VN41aye7tHR6i/gHfCjh9YNsqpwmK1PtZmYAXP9069SkX5g 7GuRIZfd1dBqxlIaZhA0zZrWyzSY6i2zEnqD/kWPoIdnMA0PuvDVDJ8MD/xoDJvUkRh+11 TVO6M6AsVZS1VK8pePA9lEQvUnxA1MclisP6Ps3GxY5rKAF+4JsskmpjXw5y5CkJ8ZcW// CYrF9kRPiRexQJy5Y8xUlvcFj5zMQAb9uXsUka/f0fGVBFT1mDRQMKbRGDCQEQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1730770150; a=rsa-sha256; cv=none; b=n7f52bdTR32IaD3GfSfziJtbe8F4MGo6j+Js2gqW+CkeqOJ+3hpFGU7D7M7W/TL4U/X6oX 5rBRViy4pB7AF/Yx9trY/2D66T5dY6RJOMvDT3LxPJ1Zkx9PlieFLsoYtSiV8OJXXdfe0F o4ogfaCKgwI5fuNevnMYz8EyqFPTUBGdiJ7CJPq7UcnoX1yHkm6ADKL8DOqU9moFHeVKxj LkYuGe0gDPmh7ApuM7If4MDQWCyfrqxo+jVvunUehWV/8NTq164h73/XDUWnCryDRtOQKF kpXb3NLTBbQDnslCTRLvtkUhYsJUHyh3ICWSwicR7ssLuOGrZkqgtmiSqZw0rw== 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 4Xj9jK6gcKzwwN; Tue, 5 Nov 2024 01:29:09 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 4A51T9Ib032058; Tue, 5 Nov 2024 01:29:09 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4A51T9uk032055; Tue, 5 Nov 2024 01:29:09 GMT (envelope-from git) Date: Tue, 5 Nov 2024 01:29:09 GMT Message-Id: <202411050129.4A51T9uk032055@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: 9e1db51d4b5f - main - nvmecontrol: Use active nslist to enumerate namespaces List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@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: 9e1db51d4b5fce8a1ea7271018970760e396500c Auto-Submitted: auto-generated The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=9e1db51d4b5fce8a1ea7271018970760e396500c commit 9e1db51d4b5fce8a1ea7271018970760e396500c Author: John Baldwin AuthorDate: 2024-11-05 01:28:40 +0000 Commit: John Baldwin CommitDate: 2024-11-05 01:28:40 +0000 nvmecontrol: Use active nslist to enumerate namespaces Rather than probing all namespace IDs up to cdata.nn for the devlist command, fetch the active namespace list and iterate over that. This can be much quicker on Fabrics controllers which often advertise a large cdata.nn value to support adding additional namespaces at runtime. Reviewed by: chuck Reported by: Neven Z Sponsored by: Chelsio Communications Differential Revision: https://reviews.freebsd.org/D47355 --- sbin/nvmecontrol/devlist.c | 19 ++++++++++++++++--- sbin/nvmecontrol/nvmecontrol.c | 24 ++++++++++++++++++++++++ sbin/nvmecontrol/nvmecontrol.h | 1 + 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/sbin/nvmecontrol/devlist.c b/sbin/nvmecontrol/devlist.c index b2816339bc80..d2386e7ea800 100644 --- a/sbin/nvmecontrol/devlist.c +++ b/sbin/nvmecontrol/devlist.c @@ -116,9 +116,10 @@ static bool scan_controller(int ctrlr) { struct nvme_controller_data cdata; + struct nvme_ns_list nslist; char name[64]; uint8_t mn[64]; - uint32_t i; + uint32_t nsid; int fd, ret; snprintf(name, sizeof(name), "%s%d", NVME_CTRLR_PREFIX, ctrlr); @@ -139,8 +140,20 @@ scan_controller(int ctrlr) nvme_strvis(mn, cdata.mn, sizeof(mn), NVME_MODEL_NUMBER_LENGTH); printf("%6s: %s\n", name, mn); - for (i = 0; i < cdata.nn; i++) { - scan_namespace(fd, ctrlr, i + 1); + nsid = 0; + for (;;) { + if (read_active_namespaces(fd, nsid, &nslist) != 0) + break; + for (u_int i = 0; i < nitems(nslist.ns); i++) { + nsid = nslist.ns[i]; + if (nsid == 0) { + break; + } + + scan_namespace(fd, ctrlr, nsid); + } + if (nsid == 0 || nsid >= NVME_GLOBAL_NAMESPACE_TAG - 1) + break; } close(fd); diff --git a/sbin/nvmecontrol/nvmecontrol.c b/sbin/nvmecontrol/nvmecontrol.c index 8ad9703de9f6..b38fb8038fc3 100644 --- a/sbin/nvmecontrol/nvmecontrol.c +++ b/sbin/nvmecontrol/nvmecontrol.c @@ -142,6 +142,30 @@ read_namespace_data(int fd, uint32_t nsid, struct nvme_namespace_data *nsdata) return (0); } +int +read_active_namespaces(int fd, uint32_t nsid, struct nvme_ns_list *nslist) +{ + struct nvme_pt_command pt; + + memset(&pt, 0, sizeof(pt)); + pt.cmd.opc = NVME_OPC_IDENTIFY; + pt.cmd.nsid = htole32(nsid); + pt.cmd.cdw10 = htole32(2); + pt.buf = nslist; + pt.len = sizeof(*nslist); + pt.is_read = 1; + + if (ioctl(fd, NVME_PASSTHROUGH_CMD, &pt) < 0) + return (errno); + + /* Convert data to host endian */ + nvme_ns_list_swapbytes(nslist); + + if (nvme_completion_is_error(&pt.cpl)) + return (EIO); + return (0); +} + int open_dev(const char *str, int *fd, int write, int exit_on_error) { diff --git a/sbin/nvmecontrol/nvmecontrol.h b/sbin/nvmecontrol/nvmecontrol.h index 394a88608692..968e9c20160e 100644 --- a/sbin/nvmecontrol/nvmecontrol.h +++ b/sbin/nvmecontrol/nvmecontrol.h @@ -81,6 +81,7 @@ int open_dev(const char *str, int *fd, int write, int exit_on_error); void get_nsid(int fd, char **ctrlr_str, uint32_t *nsid); int read_controller_data(int fd, struct nvme_controller_data *cdata); int read_namespace_data(int fd, uint32_t nsid, struct nvme_namespace_data *nsdata); +int read_active_namespaces(int fd, uint32_t nsid, struct nvme_ns_list *nslist); void print_hex(void *data, uint32_t length); void print_namespace(struct nvme_namespace_data *nsdata); void read_logpage(int fd, uint8_t log_page, uint32_t nsid, uint8_t lsp,