Commit 0c8dcbb2 authored by Pawel Baldysiak's avatar Pawel Baldysiak Committed by Tomasz Zawadzki
Browse files

nvmf_tgt: Add passthru support for sanitize OPC



Add handler to passthru sanitize OPC cmds to underlying dev.
It is disabled by default, can be enabled by RPC.
It uses already existing generic passthru handler,
which makes sure that ctrlr-scope admin cmds are passthru
only for subsystem with single namespace.

Change-Id: I8e123c1050bafceb174fa0d76c1e3d903216aaf3
Signed-off-by: default avatarPawel Baldysiak <pawel.baldysiak@dell.com>
Reviewed-on: https://review.spdk.io/c/spdk/spdk/+/26459


Reviewed-by: default avatarAleksey Marchuk <alexeymar@nvidia.com>
Community-CI: Mellanox Build Bot
Reviewed-by: default avatarJim Harris <jim.harris@nvidia.com>
Tested-by: default avatarSPDK Automated Test System <spdkbot@gmail.com>
parent 18192cd4
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -8590,6 +8590,7 @@ have been initialized.
 identify_ctrlr   | Optional   | bool   | If true, enables custom identify handler that reports some identify attributes from the underlying NVMe drive
 get_log_page     | Optional   | bool   | If true, enables passthru get log page command handlers for underlying NVMe drive (for non-fabrics related log pages)
 get_set_features | Optional   | bool   | If true, enables passthru get/set_feature OPC handlers for underlying NVMe drive
 sanitize         | Optional   | bool   | If true, enables passthru sanitize OPC handlers for underlying NVMe drive
 vendor_specific  | Optional   | bool   | If true, enables passthru command handlers for underlying NVMe drive for vendor specific cmds (OPCs: 0xC0-0xFF)

#### Example
+1 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ struct spdk_nvmf_admin_passthru_conf {
	bool identify_ctrlr;
	bool get_log_page;
	bool get_set_features;
	bool sanitize;
	bool vendor_specific;
};

+1 −0
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ static const struct spdk_json_object_decoder admin_passthru_decoder[] = {
	{"identify_ctrlr", offsetof(struct spdk_nvmf_admin_passthru_conf, identify_ctrlr), spdk_json_decode_bool, true},
	{"get_log_page", offsetof(struct spdk_nvmf_admin_passthru_conf, get_log_page), spdk_json_decode_bool, true},
	{"get_set_features", offsetof(struct spdk_nvmf_admin_passthru_conf, get_set_features), spdk_json_decode_bool, true},
	{"sanitize", offsetof(struct spdk_nvmf_admin_passthru_conf, sanitize), spdk_json_decode_bool, true},
	{"vendor_specific", offsetof(struct spdk_nvmf_admin_passthru_conf, vendor_specific), spdk_json_decode_bool, true},
};

+14 −0
Original line number Diff line number Diff line
@@ -58,6 +58,7 @@ struct spdk_nvmf_tgt_conf g_spdk_nvmf_tgt_conf = {
	.admin_passthru.identify_ctrlr = false,
	.admin_passthru.get_log_page = false,
	.admin_passthru.get_set_features = false,
	.admin_passthru.sanitize = false,
	.admin_passthru.vendor_specific = false
};

@@ -414,6 +415,10 @@ fixup_get_cmds_and_effects_log_page(struct spdk_nvmf_request *req)
			nvmf_log_data.admin_cmds_supported[i] = nvme_log_data.admin_cmds_supported[i];
		}
	}
	if (g_spdk_nvmf_tgt_conf.admin_passthru.sanitize) {
		nvmf_log_data.admin_cmds_supported[SPDK_NVME_OPC_SANITIZE] =
			nvme_log_data.admin_cmds_supported[SPDK_NVME_OPC_SANITIZE];
	}

	/* Copy the fixed SPDK struct to the request */
	spdk_nvmf_request_copy_from_buf(req, (uint8_t *) &nvmf_log_data + offset, datalen);
@@ -542,6 +547,9 @@ fixup_identify_ctrlr(struct spdk_nvmf_request *req)
		nvmf_cdata.elpe = nvme_cdata.elpe;
		nvmf_cdata.pels = nvme_cdata.pels;
	}
	if (g_spdk_nvmf_tgt_conf.admin_passthru.sanitize) {
		nvmf_cdata.sanicap = nvme_cdata.sanicap;
	}

	/* Copy the fixed up data back to the response */
	spdk_nvmf_request_copy_from_buf(req, &nvmf_cdata, datalen);
@@ -690,6 +698,10 @@ nvmf_tgt_advance_state(void)
				spdk_nvmf_set_custom_admin_cmd_hdlr(SPDK_NVME_OPC_SET_FEATURES, nvmf_custom_set_features);
				spdk_nvmf_set_custom_admin_cmd_hdlr(SPDK_NVME_OPC_GET_FEATURES, nvmf_custom_get_features);
			}
			if (g_spdk_nvmf_tgt_conf.admin_passthru.sanitize) {
				SPDK_NOTICELOG("Custom sanitize command handlers enabled\n");
				spdk_nvmf_set_custom_admin_cmd_hdlr(SPDK_NVME_OPC_SANITIZE, nvmf_custom_admin_no_cb_hdlr);
			}
			if (g_spdk_nvmf_tgt_conf.admin_passthru.vendor_specific) {
				int i;
				SPDK_NOTICELOG("Custom vendor specific commands handlers enabled\n");
@@ -814,6 +826,8 @@ nvmf_subsystem_write_config_json(struct spdk_json_write_ctx *w)
				   g_spdk_nvmf_tgt_conf.admin_passthru.get_log_page);
	spdk_json_write_named_bool(w, "get_set_features",
				   g_spdk_nvmf_tgt_conf.admin_passthru.get_set_features);
	spdk_json_write_named_bool(w, "sanitize",
				   g_spdk_nvmf_tgt_conf.admin_passthru.sanitize);
	spdk_json_write_named_bool(w, "vendor_specific",
				   g_spdk_nvmf_tgt_conf.admin_passthru.vendor_specific);
	spdk_json_write_object_end(w);
+2 −2
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@ def add_parser(subparsers):
            print('WARNING: -i|--passthru-identify-ctrlr is deprecated, please use -p|--passthru-admin-cmds identify_ctrlr.',
                  file=sys.stderr)
            admin_cmd_passthru.append('identify_ctrlr')
        all_admin_cmd_passthru = ('identify_ctrlr', 'get_log_page', 'get_set_features', 'vendor_specific')
        all_admin_cmd_passthru = ('identify_ctrlr', 'get_log_page', 'get_set_features', 'sanitize', 'vendor_specific')
        if 'all' in admin_cmd_passthru:
            admin_cmd_passthru = {cmd: True for cmd in all_admin_cmd_passthru}
        else:
@@ -42,7 +42,7 @@ def add_parser(subparsers):
    when the controller has a single namespace that is an NVMe bdev (deprecated)""", action='store_true')
    p.add_argument('-p', '--passthru-admin-cmds', help="""Comma-separated list of admin commands to be passthru
                   when the controller has a single namespace that is an NVMe bdev.
                   Available options are: all, identify_ctrlr, get_log_page, get_set_features, vendor_specific""",
                   Available options are: all, identify_ctrlr, get_log_page, get_set_features, sanitize, vendor_specific""",
                   type=lambda d: d.split(','))
    p.add_argument('-m', '--poll-groups-mask', help='Set cpumask for NVMf poll groups (optional)', type=str)
    p.add_argument('-d', '--discovery-filter', help="""Set discovery filter (optional), possible values are: `match_any` (default) or