Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 26 Jun 2013 23:20:09 +0000 (UTC)
From:      Jim Harris <jimharris@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r252270 - head/sbin/nvmecontrol
Message-ID:  <201306262320.r5QNK9YB001960@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jimharris
Date: Wed Jun 26 23:20:08 2013
New Revision: 252270
URL: http://svnweb.freebsd.org/changeset/base/252270

Log:
  Create #defines for NVME_CTRLR_PREFIX and NVME_NS_PREFIX for the "nvme"
  and "ns" strings, rather than hardcoding the string values throughout the
  nvmecontrol code base.
  
  Sponsored by:	Intel
  MFC after:	3 days

Modified:
  head/sbin/nvmecontrol/devlist.c
  head/sbin/nvmecontrol/identify.c
  head/sbin/nvmecontrol/nvmecontrol.h

Modified: head/sbin/nvmecontrol/devlist.c
==============================================================================
--- head/sbin/nvmecontrol/devlist.c	Wed Jun 26 23:11:20 2013	(r252269)
+++ head/sbin/nvmecontrol/devlist.c	Wed Jun 26 23:20:08 2013	(r252270)
@@ -78,7 +78,7 @@ devlist(int argc, char *argv[])
 
 	while (1) {
 		ctrlr++;
-		sprintf(name, "nvme%d", ctrlr);
+		sprintf(name, "%s%d", NVME_CTRLR_PREFIX, ctrlr);
 
 		exit_code = open_dev(name, &fd, 0, 0);
 
@@ -95,7 +95,8 @@ devlist(int argc, char *argv[])
 		printf("%6s: %s\n", name, cdata.mn);
 
 		for (i = 0; i < cdata.nn; i++) {
-			sprintf(name, "nvme%dns%d", ctrlr, i+1);
+			sprintf(name, "%s%d%s%d", NVME_CTRLR_PREFIX, ctrlr,
+			    NVME_NS_PREFIX, i+1);
 			read_namespace_data(fd, i+1, &nsdata);
 			printf("  %10s (%lldGB)\n",
 				name,

Modified: head/sbin/nvmecontrol/identify.c
==============================================================================
--- head/sbin/nvmecontrol/identify.c	Wed Jun 26 23:11:20 2013	(r252269)
+++ head/sbin/nvmecontrol/identify.c	Wed Jun 26 23:20:08 2013	(r252270)
@@ -258,7 +258,7 @@ identify_ns(int argc, char *argv[])
 	 *  of the string.  Don't search past 10 characters into the string,
 	 *  otherwise we know it is malformed.
 	 */
-	nsloc = strnstr(argv[optind], "ns", 10);
+	nsloc = strnstr(argv[optind], NVME_NS_PREFIX, 10);
 	if (nsloc != NULL)
 		nsid = strtol(nsloc + 2, NULL, 10);
 	if (nsloc == NULL || (nsid == 0 && errno != 0)) {
@@ -314,7 +314,7 @@ identify(int argc, char *argv[])
 	 * If device node contains "ns", we consider it a namespace,
 	 *  otherwise, consider it a controller.
 	 */
-	if (strstr(target, "ns") == NULL)
+	if (strstr(target, NVME_NS_PREFIX) == NULL)
 		identify_ctrlr(argc, argv);
 	else
 		identify_ns(argc, argv);

Modified: head/sbin/nvmecontrol/nvmecontrol.h
==============================================================================
--- head/sbin/nvmecontrol/nvmecontrol.h	Wed Jun 26 23:11:20 2013	(r252269)
+++ head/sbin/nvmecontrol/nvmecontrol.h	Wed Jun 26 23:20:08 2013	(r252270)
@@ -31,6 +31,9 @@
 
 #include <dev/nvme/nvme.h>
 
+#define NVME_CTRLR_PREFIX	"nvme"
+#define NVME_NS_PREFIX		"ns"
+
 #define DEVLIST_USAGE							       \
 "       nvmecontrol devlist\n"
 



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