Project

General

Profile

Bug #8495 » nvmeadm_eui64.diff

Moinak Ghosh, 2017-07-14 04:21 PM

View differences:

usr/src/cmd/nvmeadm/nvmeadm.c Wed Jun 14 07:19:18 2017 -0700 → usr/src/cmd/nvmeadm/nvmeadm.c Tue Jul 11 23:15:55 2017 -0700
55 55
	char **npa_argv;
56 56
	char *npa_name;
57 57
	uint32_t npa_nsid;
58
	char npa_eui64[17];
59
	boolean_t npa_eui_set;
58 60
	boolean_t npa_isns;
59 61
	const nvmeadm_cmd_t *npa_cmd;
60 62
	di_node_t npa_node;
......
315 317
			if (tmp != NULL) {
316 318
				unsigned long nsid;
317 319
				*tmp++ = '\0';
320
				nsid = 0;
318 321
				errno = 0;
319
				nsid = strtoul(tmp, NULL, 10);
320
				if (nsid >= UINT32_MAX || errno != 0) {
321
					warn("invalid namespace %s", tmp);
322
					exitcode--;
323
					continue;
324
				}
325
				if (nsid == 0) {
326
					warnx("invalid namespace %s", tmp);
327
					exitcode--;
328
					continue;
322
				npa.npa_eui_set = B_FALSE;
323
				if (strlen(tmp) == 16) {
324
					(void) strlcpy(npa.npa_eui64, tmp, sizeof(npa.npa_eui64));
325
					npa.npa_eui_set = B_TRUE;
326
				} else {
327
					nsid = strtoul(tmp, NULL, 10);
328
					if (nsid >= UINT32_MAX || errno != 0) {
329
						warn("invalid namespace %s", tmp);
330
						exitcode--;
331
						continue;
332
					}
333
					if (nsid == 0) {
334
						warnx("invalid namespace %s", tmp);
335
						exitcode--;
336
						continue;
337
					}
329 338
				}
330 339
				npa.npa_nsid = nsid;
331 340
				npa.npa_isns = B_TRUE;
......
405 414
	free(name);
406 415

  
407 416
	if (npa->npa_isns) {
408
		if (npa->npa_nsid == 0)
417
		if (npa->npa_nsid == 0 && !npa->npa_eui_set)
409 418
			return (B_TRUE);
410
		nsid = strtoul(di_minor_name(npa->npa_minor), NULL, 10);
419

  
420
		if (npa->npa_eui_set) {
421
			if (strcasestr(di_minor_name(npa->npa_minor),
422
			    npa->npa_eui64) == NULL) {
423
				return (B_FALSE);
424
			}
425
		} else {
426
			nsid = strtoul(di_minor_name(npa->npa_minor), NULL, 10);
427
			if (npa->npa_nsid != nsid) {
428
				return (B_FALSE);
429
			}
430
		}
411 431
	}
412 432

  
413
	if (npa->npa_isns && npa->npa_nsid != nsid)
414
		return (B_FALSE);
415

  
416 433
	return (B_TRUE);
417 434
}
418 435

  
......
589 606
static int
590 607
do_identify(int fd, const nvme_process_arg_t *npa)
591 608
{
592
	if (npa->npa_nsid == 0) {
609
	if (npa->npa_nsid == 0 && !npa->npa_eui_set) {
593 610
		nvme_capabilities_t *cap;
594 611

  
595 612
		cap = nvme_capabilities(fd);
......
805 822
	if (npa->npa_argc == 0) {
806 823
		(void) printf("%s: Get Features\n", npa->npa_name);
807 824
		for (feat = &features[0]; feat->f_feature != 0; feat++) {
808
			if ((npa->npa_nsid != 0 &&
825
			if (((npa->npa_nsid != 0 || npa->npa_eui_set) &&
809 826
			    (feat->f_getflags & NVMEADM_NS) == 0) ||
810
			    (npa->npa_nsid == 0 &&
827
			    ((npa->npa_nsid == 0 && !npa->npa_eui_set) &&
811 828
			    (feat->f_getflags & NVMEADM_CTRL) == 0))
812 829
				continue;
813 830

  
......
841 858
			continue;
842 859
		}
843 860

  
844
		if ((npa->npa_nsid != 0 &&
861
		if (((npa->npa_nsid != 0 || npa->npa_eui_set) &&
845 862
		    (feat->f_getflags & NVMEADM_NS) == 0) ||
846
		    (npa->npa_nsid == 0 &&
863
		    ((npa->npa_nsid == 0 && !npa->npa_eui_set)  &&
847 864
		    (feat->f_getflags & NVMEADM_CTRL) == 0)) {
848 865
			warnx("feature %s %s supported for namespaces",
849 866
			    feat->f_name, (feat->f_getflags & NVMEADM_NS) != 0 ?
    (1-1/1)