Commit 4fe88e43 authored by Daniel Verkamp's avatar Daniel Verkamp
Browse files

nvme_manage: only ask for required info in format



If the selected LBA format does not have metadata, skip the questions
about metadata and protection information.

Change-Id: I3620990eff2f12f2b7df2e8a293314b4001f52b2
Signed-off-by: default avatarDaniel Verkamp <daniel.verkamp@intel.com>
parent 90095a79
Loading
Loading
Loading
Loading
+54 −32
Original line number Diff line number Diff line
@@ -478,6 +478,7 @@ format_nvm(void)
	int					lbaf;
	char					option;
	struct dev				*ctrlr;
	const struct spdk_nvme_ctrlr_data	*cdata;
	struct spdk_nvme_ns			*ns;
	const struct spdk_nvme_ns_data		*nsdata;

@@ -486,16 +487,19 @@ format_nvm(void)
		printf("Invalid controller PCI BDF.\n");
		return;
	}
	if (!ctrlr->cdata->oacs.format) {

	cdata = ctrlr->cdata;

	if (!cdata->oacs.format) {
		printf("Controller does not support Format NVM command\n");
		return;
	}

	if (ctrlr->cdata->fna.format_all_ns) {
	if (cdata->fna.format_all_ns) {
		ns_id = 0xffffffff;
		ns = spdk_nvme_ctrlr_get_ns(ctrlr->ctrlr, 1);
	} else {
		printf("Please Input Namespace ID (1 - %d): \n", ctrlr->cdata->nn);
		printf("Please Input Namespace ID (1 - %d): \n", cdata->nn);
		if (!scanf("%d", &ns_id)) {
			printf("Invalid Namespace ID\n");
			while (getchar() != '\n');
@@ -515,13 +519,34 @@ format_nvm(void)
	printf("Please Input Secure Erase Setting: \n");
	printf("	0: No secure erase operation requested\n");
	printf("	1: User data erase\n");
	if (cdata->fna.crypto_erase_supported) {
		printf("	2: Cryptographic erase\n");
	}
	if (!scanf("%d", &ses)) {
		printf("Invalid Secure Erase Setting\n");
		while (getchar() != '\n');
		return;
	}

	for (i = 0; i <= nsdata->nlbaf; i++) {
		printf("LBA Format #%02d: Data Size: %5d  Metadata Size: %5d\n",
		       i, 1 << nsdata->lbaf[i].lbads, nsdata->lbaf[i].ms);
	}

	printf("Please Input LBA Format Number (0 - %d): \n", nsdata->nlbaf);
	if (!scanf("%d", &lbaf)) {
		printf("Invalid LBA format size\n");
		while (getchar() != '\n');
		return;
	}

	if (lbaf > nsdata->nlbaf) {
		printf("Invalid LBA format number\n");
		while (getchar() != '\n');
		return;
	}

	if (nsdata->lbaf[lbaf].ms) {
		printf("Please Input Protection Information: \n");
		printf("	0: Protection information is not enabled\n");
		printf("	1: Protection information is enabled, Type 1\n");
@@ -533,6 +558,7 @@ format_nvm(void)
			return;
		}

		if (pi) {
			printf("Please Input Protection Information Location: \n");
			printf("	0: Protection information transferred as the last eight bytes of metadata\n");
			printf("	1: Protection information transferred as the first eight bytes of metadata\n");
@@ -541,6 +567,9 @@ format_nvm(void)
				while (getchar() != '\n');
				return;
			}
		} else {
			pil = 0;
		}

		printf("Please Input Metadata Setting: \n");
		printf("	0: Metadata is transferred as part of a separate buffer\n");
@@ -550,17 +579,10 @@ format_nvm(void)
			while (getchar() != '\n');
			return;
		}

	for (i = 0; i <= nsdata->nlbaf; i++) {
		printf("LBA Format #%02d: Data Size: %5d  Metadata Size: %5d\n",
		       i, 1 << nsdata->lbaf[i].lbads, nsdata->lbaf[i].ms);
	}

	printf("Please Input LBA Format Number (0 - %d): \n", nsdata->nlbaf);
	if (!scanf("%d", &lbaf)) {
		printf("Invalid LBA format size\n");
		while (getchar() != '\n');
		return;
	} else {
		ms = 0;
		pi = 0;
		pil = 0;
	}

	printf("Warning: use this utility at your own risk.\n"