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
This commit is contained in:
Jim Harris 2013-06-26 23:20:08 +00:00
parent 7cdb43c490
commit 6420873cd6
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=252270
3 changed files with 8 additions and 4 deletions

View File

@ -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,

View File

@ -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);

View File

@ -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"