From owner-svn-src-all@freebsd.org Thu Aug 1 21:44:10 2019 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id BDA08A2792; Thu, 1 Aug 2019 21:44:10 +0000 (UTC) (envelope-from mav@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) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4603hp5GHfz4J7r; Thu, 1 Aug 2019 21:44:10 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 7D31820988; Thu, 1 Aug 2019 21:44:10 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x71LiA4N002303; Thu, 1 Aug 2019 21:44:10 GMT (envelope-from mav@FreeBSD.org) Received: (from mav@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x71Li7rN002288; Thu, 1 Aug 2019 21:44:07 GMT (envelope-from mav@FreeBSD.org) Message-Id: <201908012144.x71Li7rN002288@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mav set sender to mav@FreeBSD.org using -f From: Alexander Motin Date: Thu, 1 Aug 2019 21:44:07 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r350523 - in head: sbin/nvmecontrol sys/dev/nvme X-SVN-Group: head X-SVN-Commit-Author: mav X-SVN-Commit-Paths: in head: sbin/nvmecontrol sys/dev/nvme X-SVN-Commit-Revision: 350523 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 Aug 2019 21:44:10 -0000 Author: mav Date: Thu Aug 1 21:44:07 2019 New Revision: 350523 URL: https://svnweb.freebsd.org/changeset/base/350523 Log: Add IOCTL to translate nvdX into nvmeY and NSID. While very useful by itself, it also makes `nvmecontrol` not depend on hardcoded device names parsing, that in its turn makes simple to take nvdX (and potentially any other) device names as arguments. Also added IOCTL bypass from nvdX to respective nvmeYnsZ makes them interchangeable for management purposes. MFC after: 2 weeks Sponsored by: iXsystems, Inc. Added: head/sbin/nvmecontrol/nsid.c (contents, props changed) Modified: head/sbin/nvmecontrol/Makefile head/sbin/nvmecontrol/devlist.c head/sbin/nvmecontrol/firmware.c head/sbin/nvmecontrol/format.c head/sbin/nvmecontrol/identify.c head/sbin/nvmecontrol/identify_ext.c head/sbin/nvmecontrol/logpage.c head/sbin/nvmecontrol/ns.c head/sbin/nvmecontrol/nvmecontrol.8 head/sbin/nvmecontrol/nvmecontrol.c head/sbin/nvmecontrol/nvmecontrol.h head/sys/dev/nvme/nvme.h head/sys/dev/nvme/nvme_ctrlr.c head/sys/dev/nvme/nvme_ns.c Modified: head/sbin/nvmecontrol/Makefile ============================================================================== --- head/sbin/nvmecontrol/Makefile Thu Aug 1 20:36:25 2019 (r350522) +++ head/sbin/nvmecontrol/Makefile Thu Aug 1 21:44:07 2019 (r350523) @@ -3,7 +3,8 @@ PACKAGE=runtime PROG= nvmecontrol SRCS= comnd.c nvmecontrol.c -SRCS+= devlist.c firmware.c format.c identify.c logpage.c ns.c perftest.c power.c reset.c +SRCS+= devlist.c firmware.c format.c identify.c logpage.c ns.c nsid.c +SRCS+= perftest.c power.c reset.c #SRCS+= passthru.c SRCS+= identify_ext.c nvme_util.c nc_util.c MAN= nvmecontrol.8 Modified: head/sbin/nvmecontrol/devlist.c ============================================================================== --- head/sbin/nvmecontrol/devlist.c Thu Aug 1 20:36:25 2019 (r350522) +++ head/sbin/nvmecontrol/devlist.c Thu Aug 1 21:44:07 2019 (r350523) @@ -107,11 +107,11 @@ devlist(const struct cmd *f, int argc, char *argv[]) printf("%6s: %s\n", name, mn); for (i = 0; i < cdata.nn; i++) { - sprintf(name, "%s%d%s%d", NVME_CTRLR_PREFIX, ctrlr, - NVME_NS_PREFIX, i+1); - read_namespace_data(fd, i+1, &nsdata); + read_namespace_data(fd, i + 1, &nsdata); if (nsdata.nsze == 0) continue; + sprintf(name, "%s%d%s%d", NVME_CTRLR_PREFIX, ctrlr, + NVME_NS_PREFIX, i + 1); printf(" %10s (%lldMB)\n", name, nsdata.nsze * Modified: head/sbin/nvmecontrol/firmware.c ============================================================================== --- head/sbin/nvmecontrol/firmware.c Thu Aug 1 20:36:25 2019 (r350522) +++ head/sbin/nvmecontrol/firmware.c Thu Aug 1 21:44:07 2019 (r350523) @@ -224,7 +224,7 @@ firmware(const struct cmd *f, int argc, char *argv[]) int activate_action, reboot_required; char prompt[64]; void *buf = NULL; - int32_t size = 0; + int32_t size = 0, nsid; uint16_t oacs_fw; uint8_t fw_slot1_ro, fw_num_slots; struct nvme_controller_data cdata; @@ -253,10 +253,6 @@ firmware(const struct cmd *f, int argc, char *argv[]) arg_help(argc, argv, f); } - /* Check that a controller (and not a namespace) was specified. */ - if (strstr(opt.dev, NVME_NS_PREFIX) != NULL) - arg_help(argc, argv, f); - if (opt.activate && opt.fw_img == NULL && opt.slot == 0) { fprintf(stderr, "Slot number to activate not specified.\n"); @@ -264,6 +260,14 @@ firmware(const struct cmd *f, int argc, char *argv[]) } open_dev(opt.dev, &fd, 1, 1); + + /* Check that a controller (and not a namespace) was specified. */ + get_nsid(fd, NULL, &nsid); + if (nsid != 0) { + close(fd); + arg_help(argc, argv, f); + } + read_controller_data(fd, &cdata); oacs_fw = (cdata.oacs >> NVME_CTRLR_DATA_OACS_FIRMWARE_SHIFT) & Modified: head/sbin/nvmecontrol/format.c ============================================================================== --- head/sbin/nvmecontrol/format.c Thu Aug 1 20:36:25 2019 (r350522) +++ head/sbin/nvmecontrol/format.c Thu Aug 1 21:44:07 2019 (r350523) @@ -1,8 +1,7 @@ /*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD * - * Copyright (C) 2018 Alexander Motin - * All rights reserved. + * Copyright (C) 2018-2019 Alexander Motin * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -117,7 +116,7 @@ format(const struct cmd *f, int argc, char *argv[]) struct nvme_controller_data cd; struct nvme_namespace_data nsd; struct nvme_pt_command pt; - char path[64]; + char *path; const char *target; uint32_t nsid; int lbaf, ms, pi, pil, ses, fd; @@ -143,18 +142,9 @@ format(const struct cmd *f, int argc, char *argv[]) else ses = opt.ses; - /* - * Check if the specified device node exists before continuing. - * This is a cleaner check for cases where the correct controller - * is specified, but an invalid namespace on that controller. - */ open_dev(target, &fd, 1, 1); - - /* - * If device node contains "ns", we consider it a namespace, - * otherwise, consider it a controller. - */ - if (strstr(target, NVME_NS_PREFIX) == NULL) { + get_nsid(fd, &path, &nsid); + if (nsid == 0) { nsid = NVME_GLOBAL_NAMESPACE_TAG; } else { /* @@ -164,9 +154,9 @@ format(const struct cmd *f, int argc, char *argv[]) * string to get the controller substring and namespace ID. */ close(fd); - parse_ns_str(target, path, &nsid); open_dev(path, &fd, 1, 1); } + free(path); /* Check that controller can execute this command. */ read_controller_data(fd, &cd); Modified: head/sbin/nvmecontrol/identify.c ============================================================================== --- head/sbin/nvmecontrol/identify.c Thu Aug 1 20:36:25 2019 (r350522) +++ head/sbin/nvmecontrol/identify.c Thu Aug 1 21:44:07 2019 (r350523) @@ -3,6 +3,7 @@ * * Copyright (C) 2012-2013 Intel Corporation * All rights reserved. + * Copyright (C) 2018-2019 Alexander Motin * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -44,6 +45,8 @@ __FBSDID("$FreeBSD$"); #include "nvmecontrol.h" #include "nvmecontrol_ext.h" +#define NONE 0xfffffffeu + static struct options { bool hex; bool verbose; @@ -53,7 +56,7 @@ static struct options { .hex = false, .verbose = false, .dev = NULL, - .nsid = 0, + .nsid = NONE, }; void @@ -170,12 +173,11 @@ print_namespace(struct nvme_namespace_data *nsdata) } static void -identify_ctrlr(const struct cmd *f, int argc, char *argv[]) +identify_ctrlr(int fd) { struct nvme_controller_data cdata; - int fd, hexlength; + int hexlength; - open_dev(opt.dev, &fd, 1, 1); read_controller_data(fd, &cdata); close(fd); @@ -189,41 +191,16 @@ identify_ctrlr(const struct cmd *f, int argc, char *ar exit(0); } - if (opt.verbose) { - fprintf(stderr, "-v not currently supported without -x\n"); - arg_help(argc, argv, f); - } - nvme_print_controller(&cdata); exit(0); } static void -identify_ns(const struct cmd *f, int argc, char *argv[]) +identify_ns(int fd, uint32_t nsid) { struct nvme_namespace_data nsdata; - char path[64]; - int fd, hexlength; - uint32_t nsid; + int hexlength; - open_dev(opt.dev, &fd, 1, 1); - if (strstr(opt.dev, NVME_NS_PREFIX) != NULL) { - /* - * Now we know that provided device name is valid, that is - * good for error reporting if specified controller name is - * valid, but namespace ID is not. But we send IDENTIFY - * commands to the controller, not the namespace, since it - * is an admin cmd. The namespace ID will be specified in - * the IDENTIFY command itself. So parse the namespace's - * device node string to get the controller device substring - * and namespace ID. - */ - close(fd); - parse_ns_str(opt.dev, path, &nsid); - open_dev(path, &fd, 1, 1); - } else { - nsid = opt.nsid; - } read_namespace_data(fd, nsid, &nsdata); close(fd); @@ -237,11 +214,6 @@ identify_ns(const struct cmd *f, int argc, char *argv[ exit(0); } - if (opt.verbose) { - fprintf(stderr, "-v not currently supported without -x\n"); - arg_help(argc, argv, f); - } - print_namespace(&nsdata); exit(0); } @@ -249,16 +221,32 @@ identify_ns(const struct cmd *f, int argc, char *argv[ static void identify(const struct cmd *f, int argc, char *argv[]) { + char *path; + int fd; + uint32_t nsid; + arg_parse(argc, argv, f); - /* - * If device node contains "ns" or nsid is specified, we consider - * it a namespace request, otherwise, consider it a controller. - */ - if (strstr(opt.dev, NVME_NS_PREFIX) == NULL && opt.nsid == 0) - identify_ctrlr(f, argc, argv); + open_dev(opt.dev, &fd, 1, 1); + get_nsid(fd, &path, &nsid); + if (nsid != 0) { + /* + * We got namespace device, but we need to send IDENTIFY + * commands to the controller, not the namespace, since it + * is an admin cmd. The namespace ID will be specified in + * the IDENTIFY command itself. + */ + close(fd); + open_dev(path, &fd, 1, 1); + } + free(path); + if (opt.nsid != NONE) + nsid = opt.nsid; + + if (nsid == 0) + identify_ctrlr(fd); else - identify_ns(f, argc, argv); + identify_ns(fd, nsid); } static const struct opts identify_opts[] = { Modified: head/sbin/nvmecontrol/identify_ext.c ============================================================================== --- head/sbin/nvmecontrol/identify_ext.c Thu Aug 1 20:36:25 2019 (r350522) +++ head/sbin/nvmecontrol/identify_ext.c Thu Aug 1 21:44:07 2019 (r350523) @@ -3,6 +3,7 @@ * * Copyright (C) 2012-2013 Intel Corporation * All rights reserved. + * Copyright (C) 2018-2019 Alexander Motin * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions Modified: head/sbin/nvmecontrol/logpage.c ============================================================================== --- head/sbin/nvmecontrol/logpage.c Thu Aug 1 20:36:25 2019 (r350522) +++ head/sbin/nvmecontrol/logpage.c Thu Aug 1 21:44:07 2019 (r350523) @@ -399,8 +399,7 @@ static void logpage(const struct cmd *f, int argc, char *argv[]) { int fd; - bool ns_specified; - char cname[64]; + char *path; uint32_t nsid, size; void *buf; const struct logpage_function *lpf; @@ -421,15 +420,15 @@ logpage(const struct cmd *f, int argc, char *argv[]) fprintf(stderr, "Missing page_id (-p).\n"); arg_help(argc, argv, f); } - if (strstr(opt.dev, NVME_NS_PREFIX) != NULL) { - ns_specified = true; - parse_ns_str(opt.dev, cname, &nsid); - open_dev(cname, &fd, 1, 1); - } else { - ns_specified = false; + open_dev(opt.dev, &fd, 1, 1); + get_nsid(fd, &path, &nsid); + if (nsid == 0) { nsid = NVME_GLOBAL_NAMESPACE_TAG; - open_dev(opt.dev, &fd, 1, 1); + } else { + close(fd); + open_dev(path, &fd, 1, 1); } + free(path); read_controller_data(fd, &cdata); @@ -441,7 +440,7 @@ logpage(const struct cmd *f, int argc, char *argv[]) * supports the SMART/Health information log page on a per * namespace basis. */ - if (ns_specified) { + if (nsid != NVME_GLOBAL_NAMESPACE_TAG) { if (opt.page != NVME_LOG_HEALTH_INFORMATION) errx(1, "log page %d valid only at controller level", opt.page); Modified: head/sbin/nvmecontrol/ns.c ============================================================================== --- head/sbin/nvmecontrol/ns.c Thu Aug 1 20:36:25 2019 (r350522) +++ head/sbin/nvmecontrol/ns.c Thu Aug 1 21:44:07 2019 (r350523) @@ -2,7 +2,7 @@ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD * * Copyright (c) 2017 Netflix, Inc. - * Copyright (C) 2018 Alexander Motin + * Copyright (C) 2018-2019 Alexander Motin * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions Added: head/sbin/nvmecontrol/nsid.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sbin/nvmecontrol/nsid.c Thu Aug 1 21:44:07 2019 (r350523) @@ -0,0 +1,80 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (C) 2019 Alexander Motin + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include + +#include +#include +#include + +#include "nvmecontrol.h" +#include "comnd.h" + +/* Tables for command line parsing */ + +static cmd_fn_t nsid; + +static struct nsid_options { + const char *dev; +} nsid_opt = { + .dev = NULL, +}; + +static const struct args nsid_args[] = { + { arg_string, &nsid_opt.dev, "namespace-id" }, + { arg_none, NULL, NULL }, +}; + +static struct cmd nsid_cmd = { + .name = "nsid", + .fn = nsid, + .descr = "Get controller and NSID for namespace", + .ctx_size = sizeof(nsid_opt), + .opts = NULL, + .args = nsid_args, +}; + +CMD_COMMAND(nsid_cmd); + +static void +nsid(const struct cmd *f, int argc, char *argv[]) +{ + char *path; + int fd; + uint32_t nsid; + + arg_parse(argc, argv, f); + + open_dev(nsid_opt.dev, &fd, 1, 1); + get_nsid(fd, &path, &nsid); + close(fd); + printf("%s\t%u\n", path, nsid); + free(path); +} Modified: head/sbin/nvmecontrol/nvmecontrol.8 ============================================================================== --- head/sbin/nvmecontrol/nvmecontrol.8 Thu Aug 1 20:36:25 2019 (r350522) +++ head/sbin/nvmecontrol/nvmecontrol.8 Thu Aug 1 21:44:07 2019 (r350523) @@ -1,5 +1,5 @@ .\" -.\" Copyright (c) 2018 Alexander Motin +.\" Copyright (c) 2018-2019 Alexander Motin .\" Copyright (c) 2012 Intel Corporation .\" All rights reserved. .\" @@ -34,7 +34,7 @@ .\" .\" $FreeBSD$ .\" -.Dd July 31, 2019 +.Dd August 1, 2019 .Dt NVMECONTROL 8 .Os .Sh NAME @@ -113,6 +113,10 @@ .Op Fl x .Aq Fl n Ar nsid .Aq device id +.Nm +.Ic nsid +.Aq device id +.Aq namespace id .Nm .Ic firmware .Op Fl s Ar slot Modified: head/sbin/nvmecontrol/nvmecontrol.c ============================================================================== --- head/sbin/nvmecontrol/nvmecontrol.c Thu Aug 1 20:36:25 2019 (r350522) +++ head/sbin/nvmecontrol/nvmecontrol.c Thu Aug 1 21:44:07 2019 (r350523) @@ -146,16 +146,6 @@ open_dev(const char *str, int *fd, int show_error, int { char full_path[64]; - if (!strnstr(str, NVME_CTRLR_PREFIX, strlen(NVME_CTRLR_PREFIX))) { - if (show_error) - warnx("controller/namespace ids must begin with '%s'", - NVME_CTRLR_PREFIX); - if (exit_on_error) - exit(1); - else - return (EINVAL); - } - snprintf(full_path, sizeof(full_path), _PATH_DEV"%s", str); *fd = open(full_path, O_RDWR); if (*fd < 0) { @@ -171,26 +161,16 @@ open_dev(const char *str, int *fd, int show_error, int } void -parse_ns_str(const char *ns_str, char *ctrlr_str, uint32_t *nsid) +get_nsid(int fd, char **ctrlr_str, uint32_t *nsid) { - char *nsloc; + struct nvme_get_nsid gnsid; - /* - * Pull the namespace id from the string. +2 skips past the "ns" part - * of the string. Don't search past 10 characters into the string, - * otherwise we know it is malformed. - */ - nsloc = strnstr(ns_str, NVME_NS_PREFIX, 10); - if (nsloc != NULL) - *nsid = strtol(nsloc + 2, NULL, 10); - if (nsloc == NULL || (*nsid == 0 && errno != 0)) - errx(1, "invalid namespace ID '%s'", ns_str); - - /* - * The controller string will include only the nvmX part of the - * nvmeXnsY string. - */ - snprintf(ctrlr_str, nsloc - ns_str + 1, "%s", ns_str); + if (ioctl(fd, NVME_GET_NSID, &gnsid) < 0) + err(1, "NVME_GET_NSID ioctl failed"); + if (ctrlr_str != NULL) + *ctrlr_str = strndup(gnsid.cdev, sizeof(gnsid.cdev)); + if (nsid != NULL) + *nsid = gnsid.nsid; } int Modified: head/sbin/nvmecontrol/nvmecontrol.h ============================================================================== --- head/sbin/nvmecontrol/nvmecontrol.h Thu Aug 1 20:36:25 2019 (r350522) +++ head/sbin/nvmecontrol/nvmecontrol.h Thu Aug 1 21:44:07 2019 (r350523) @@ -69,7 +69,7 @@ void logpage_register(struct logpage_function *p); #define NVME_NS_PREFIX "ns" int open_dev(const char *str, int *fd, int show_error, int exit_on_error); -void parse_ns_str(const char *ns_str, char *ctrlr_str, uint32_t *nsid); +void get_nsid(int fd, char **ctrlr_str, uint32_t *nsid); void read_controller_data(int fd, struct nvme_controller_data *cdata); void read_namespace_data(int fd, uint32_t nsid, struct nvme_namespace_data *nsdata); void print_hex(void *data, uint32_t length); Modified: head/sys/dev/nvme/nvme.h ============================================================================== --- head/sys/dev/nvme/nvme.h Thu Aug 1 20:36:25 2019 (r350522) +++ head/sys/dev/nvme/nvme.h Thu Aug 1 21:44:07 2019 (r350523) @@ -40,6 +40,7 @@ #define NVME_PASSTHROUGH_CMD _IOWR('n', 0, struct nvme_pt_command) #define NVME_RESET_CONTROLLER _IO('n', 1) +#define NVME_GET_NSID _IOR('n', 2, struct nvme_get_nsid) #define NVME_IO_TEST _IOWR('n', 100, struct nvme_io_test) #define NVME_BIO_TEST _IOWR('n', 101, struct nvme_io_test) @@ -1332,6 +1333,11 @@ struct nvme_pt_command { struct mtx * driver_lock; }; +struct nvme_get_nsid { + char cdev[SPECNAMELEN + 1]; + uint32_t nsid; +}; + #define nvme_completion_is_error(cpl) \ (NVME_STATUS_GET_SC((cpl)->status) != 0 || NVME_STATUS_GET_SCT((cpl)->status) != 0) @@ -1340,6 +1346,7 @@ void nvme_strvis(uint8_t *dst, const uint8_t *src, int #ifdef _KERNEL struct bio; +struct thread; struct nvme_namespace; struct nvme_controller; @@ -1429,6 +1436,8 @@ uint32_t nvme_ns_get_stripesize(struct nvme_namespace int nvme_ns_bio_process(struct nvme_namespace *ns, struct bio *bp, nvme_cb_fn_t cb_fn); +int nvme_ns_ioctl_process(struct nvme_namespace *ns, u_long cmd, + caddr_t arg, int flag, struct thread *td); /* * Command building helper functions -- shared with CAM Modified: head/sys/dev/nvme/nvme_ctrlr.c ============================================================================== --- head/sys/dev/nvme/nvme_ctrlr.c Thu Aug 1 20:36:25 2019 (r350522) +++ head/sys/dev/nvme/nvme_ctrlr.c Thu Aug 1 21:44:07 2019 (r350523) @@ -1126,6 +1126,14 @@ nvme_ctrlr_ioctl(struct cdev *cdev, u_long cmd, caddr_ pt = (struct nvme_pt_command *)arg; return (nvme_ctrlr_passthrough_cmd(ctrlr, pt, le32toh(pt->cmd.nsid), 1 /* is_user_buffer */, 1 /* is_admin_cmd */)); + case NVME_GET_NSID: + { + struct nvme_get_nsid *gnsid = (struct nvme_get_nsid *)arg; + strncpy(gnsid->cdev, device_get_nameunit(ctrlr->dev), + sizeof(gnsid->cdev)); + gnsid->nsid = 0; + break; + } default: return (ENOTTY); } Modified: head/sys/dev/nvme/nvme_ns.c ============================================================================== --- head/sys/dev/nvme/nvme_ns.c Thu Aug 1 20:36:25 2019 (r350522) +++ head/sys/dev/nvme/nvme_ns.c Thu Aug 1 21:44:07 2019 (r350523) @@ -82,6 +82,14 @@ nvme_ns_ioctl(struct cdev *cdev, u_long cmd, caddr_t a pt = (struct nvme_pt_command *)arg; return (nvme_ctrlr_passthrough_cmd(ctrlr, pt, ns->id, 1 /* is_user_buffer */, 0 /* is_admin_cmd */)); + case NVME_GET_NSID: + { + struct nvme_get_nsid *gnsid = (struct nvme_get_nsid *)arg; + strncpy(gnsid->cdev, device_get_nameunit(ctrlr->dev), + sizeof(gnsid->cdev)); + gnsid->nsid = ns->id; + break; + } case DIOCGMEDIASIZE: *(off_t *)arg = (off_t)nvme_ns_get_size(ns); break; @@ -481,6 +489,13 @@ nvme_ns_bio_process(struct nvme_namespace *ns, struct } return (err); +} + +int +nvme_ns_ioctl_process(struct nvme_namespace *ns, u_long cmd, caddr_t arg, + int flag, struct thread *td) +{ + return (nvme_ns_ioctl(ns->cdev, cmd, arg, flag, td)); } int