Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 12 Aug 2019 19:39:31 +0000 (UTC)
From:      Alexander Motin <mav@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org
Subject:   svn commit: r350946 - in stable/12: sbin/nvmecontrol sys/dev/nvme
Message-ID:  <201908121939.x7CJdVDA089796@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mav
Date: Mon Aug 12 19:39:31 2019
New Revision: 350946
URL: https://svnweb.freebsd.org/changeset/base/350946

Log:
  MFC r350523, r350524: 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.

Added:
  stable/12/sbin/nvmecontrol/nsid.c
     - copied, changed from r350523, head/sbin/nvmecontrol/nsid.c
Modified:
  stable/12/sbin/nvmecontrol/Makefile
  stable/12/sbin/nvmecontrol/devlist.c
  stable/12/sbin/nvmecontrol/firmware.c
  stable/12/sbin/nvmecontrol/format.c
  stable/12/sbin/nvmecontrol/identify.c
  stable/12/sbin/nvmecontrol/identify_ext.c
  stable/12/sbin/nvmecontrol/logpage.c
  stable/12/sbin/nvmecontrol/ns.c
  stable/12/sbin/nvmecontrol/nvmecontrol.8
  stable/12/sbin/nvmecontrol/nvmecontrol.c
  stable/12/sbin/nvmecontrol/nvmecontrol.h
  stable/12/sys/dev/nvme/nvme.h
  stable/12/sys/dev/nvme/nvme_ctrlr.c
  stable/12/sys/dev/nvme/nvme_ns.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sbin/nvmecontrol/Makefile
==============================================================================
--- stable/12/sbin/nvmecontrol/Makefile	Mon Aug 12 19:38:10 2019	(r350945)
+++ stable/12/sbin/nvmecontrol/Makefile	Mon Aug 12 19:39:31 2019	(r350946)
@@ -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: stable/12/sbin/nvmecontrol/devlist.c
==============================================================================
--- stable/12/sbin/nvmecontrol/devlist.c	Mon Aug 12 19:38:10 2019	(r350945)
+++ stable/12/sbin/nvmecontrol/devlist.c	Mon Aug 12 19:39:31 2019	(r350946)
@@ -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: stable/12/sbin/nvmecontrol/firmware.c
==============================================================================
--- stable/12/sbin/nvmecontrol/firmware.c	Mon Aug 12 19:38:10 2019	(r350945)
+++ stable/12/sbin/nvmecontrol/firmware.c	Mon Aug 12 19:39:31 2019	(r350946)
@@ -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: stable/12/sbin/nvmecontrol/format.c
==============================================================================
--- stable/12/sbin/nvmecontrol/format.c	Mon Aug 12 19:38:10 2019	(r350945)
+++ stable/12/sbin/nvmecontrol/format.c	Mon Aug 12 19:39:31 2019	(r350946)
@@ -1,8 +1,7 @@
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
  *
- * Copyright (C) 2018 Alexander Motin <mav@FreeBSD.org>
- * All rights reserved.
+ * Copyright (C) 2018-2019 Alexander Motin <mav@FreeBSD.org>
  *
  * 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: stable/12/sbin/nvmecontrol/identify.c
==============================================================================
--- stable/12/sbin/nvmecontrol/identify.c	Mon Aug 12 19:38:10 2019	(r350945)
+++ stable/12/sbin/nvmecontrol/identify.c	Mon Aug 12 19:39:31 2019	(r350946)
@@ -3,6 +3,7 @@
  *
  * Copyright (C) 2012-2013 Intel Corporation
  * All rights reserved.
+ * Copyright (C) 2018-2019 Alexander Motin <mav@FreeBSD.org>
  *
  * 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: stable/12/sbin/nvmecontrol/identify_ext.c
==============================================================================
--- stable/12/sbin/nvmecontrol/identify_ext.c	Mon Aug 12 19:38:10 2019	(r350945)
+++ stable/12/sbin/nvmecontrol/identify_ext.c	Mon Aug 12 19:39:31 2019	(r350946)
@@ -3,6 +3,7 @@
  *
  * Copyright (C) 2012-2013 Intel Corporation
  * All rights reserved.
+ * Copyright (C) 2018-2019 Alexander Motin <mav@FreeBSD.org>
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions

Modified: stable/12/sbin/nvmecontrol/logpage.c
==============================================================================
--- stable/12/sbin/nvmecontrol/logpage.c	Mon Aug 12 19:38:10 2019	(r350945)
+++ stable/12/sbin/nvmecontrol/logpage.c	Mon Aug 12 19:39:31 2019	(r350946)
@@ -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: stable/12/sbin/nvmecontrol/ns.c
==============================================================================
--- stable/12/sbin/nvmecontrol/ns.c	Mon Aug 12 19:38:10 2019	(r350945)
+++ stable/12/sbin/nvmecontrol/ns.c	Mon Aug 12 19:39:31 2019	(r350946)
@@ -2,7 +2,7 @@
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
  *
  * Copyright (c) 2017 Netflix, Inc
- * Copyright (C) 2018 Alexander Motin <mav@FreeBSD.org>
+ * Copyright (C) 2018-2019 Alexander Motin <mav@FreeBSD.org>
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions

Copied and modified: stable/12/sbin/nvmecontrol/nsid.c (from r350523, head/sbin/nvmecontrol/nsid.c)
==============================================================================
--- head/sbin/nvmecontrol/nsid.c	Thu Aug  1 21:44:07 2019	(r350523, copy source)
+++ stable/12/sbin/nvmecontrol/nsid.c	Mon Aug 12 19:39:31 2019	(r350946)
@@ -39,7 +39,7 @@ __FBSDID("$FreeBSD$");
 
 /* Tables for command line parsing */
 
-static cmd_fn_t nsid;
+static cmd_fn_t gnsid;
 
 static struct nsid_options {
 	const char	*dev;
@@ -54,7 +54,7 @@ static const struct args nsid_args[] = {
 
 static struct cmd nsid_cmd = {
 	.name = "nsid",
-	.fn = nsid,
+	.fn = gnsid,
 	.descr = "Get controller and NSID for namespace",
 	.ctx_size = sizeof(nsid_opt),
 	.opts = NULL,
@@ -64,7 +64,7 @@ static struct cmd nsid_cmd = {
 CMD_COMMAND(nsid_cmd);
 
 static void
-nsid(const struct cmd *f, int argc, char *argv[])
+gnsid(const struct cmd *f, int argc, char *argv[])
 {
 	char		*path;
 	int		fd;

Modified: stable/12/sbin/nvmecontrol/nvmecontrol.8
==============================================================================
--- stable/12/sbin/nvmecontrol/nvmecontrol.8	Mon Aug 12 19:38:10 2019	(r350945)
+++ stable/12/sbin/nvmecontrol/nvmecontrol.8	Mon Aug 12 19:39:31 2019	(r350946)
@@ -1,5 +1,5 @@
 .\"
-.\" Copyright (c) 2018 Alexander Motin <mav@FreeBSD.org>
+.\" Copyright (c) 2018-2019 Alexander Motin <mav@FreeBSD.org>
 .\" 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: stable/12/sbin/nvmecontrol/nvmecontrol.c
==============================================================================
--- stable/12/sbin/nvmecontrol/nvmecontrol.c	Mon Aug 12 19:38:10 2019	(r350945)
+++ stable/12/sbin/nvmecontrol/nvmecontrol.c	Mon Aug 12 19:39:31 2019	(r350946)
@@ -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: stable/12/sbin/nvmecontrol/nvmecontrol.h
==============================================================================
--- stable/12/sbin/nvmecontrol/nvmecontrol.h	Mon Aug 12 19:38:10 2019	(r350945)
+++ stable/12/sbin/nvmecontrol/nvmecontrol.h	Mon Aug 12 19:39:31 2019	(r350946)
@@ -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: stable/12/sys/dev/nvme/nvme.h
==============================================================================
--- stable/12/sys/dev/nvme/nvme.h	Mon Aug 12 19:38:10 2019	(r350945)
+++ stable/12/sys/dev/nvme/nvme.h	Mon Aug 12 19:39:31 2019	(r350946)
@@ -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: stable/12/sys/dev/nvme/nvme_ctrlr.c
==============================================================================
--- stable/12/sys/dev/nvme/nvme_ctrlr.c	Mon Aug 12 19:38:10 2019	(r350945)
+++ stable/12/sys/dev/nvme/nvme_ctrlr.c	Mon Aug 12 19:39:31 2019	(r350946)
@@ -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: stable/12/sys/dev/nvme/nvme_ns.c
==============================================================================
--- stable/12/sys/dev/nvme/nvme_ns.c	Mon Aug 12 19:38:10 2019	(r350945)
+++ stable/12/sys/dev/nvme/nvme_ns.c	Mon Aug 12 19:39:31 2019	(r350946)
@@ -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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201908121939.x7CJdVDA089796>