Commit ecbceb22 authored by Marcin Spiewak's avatar Marcin Spiewak Committed by Tomasz Zawadzki
Browse files

nvmf: add --ana-state parameter to nvmf_subsystem_add_listener



Currently, when a listener is added to the subsystem, all ANA
(Asymmetric Namespace Access) groups are set to default state
SPDK_NVME_ANA_OPTIMIZED_STATE.
In certain applications, the user may want to submit initial
state for ANA groups during listener creation, and in this case
such a state shall be used as initial one for all ANA groups
created in the listener.

This patch modifies nvmf_subsystem_add_listener RPC call and adds
--ana-state optional parameter to it. If the parameter is present
in RPC nvmf_subsystem_add_listener call, the listener is created
and all 32 ANA groups are initialized to the provided state.
If the parameter is not present, the nvmf_subsystem_add_listener
RPC call works as it did before, and all ANA groups created for
this listener are initialized to SPDK_NVME_ANA_OPTIMIZED_STATE.

The possible values for '--ana-state' (or shortly '-n') are:
--ana-state optimized
--ana-state non_optimized
--ana-state inaccessible

Fixes #3154

Change-Id: I8ce2083698f7dfff44e19d5a5b8a1bcede6b4313
Signed-off-by: default avatarMarcin Spiewak <marcin.spiewak@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/20663


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <jim.harris@samsung.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@nvidia.com>
Reviewed-by: default avatarSebastian Brzezinka <sebastian.brzezinka@intel.com>
Reviewed-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Community-CI: Mellanox Build Bot
parent 91c770a2
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -107,6 +107,8 @@ spdk_nvmf_subsystem_any_listener_allowed()` API fixing the typo.

Added `spdk_nvmf_subsystem_is_discovery()` API to check whether a given susbystem is discovery subsystem.

Added new optional `--ana-state` (or shortly `-n`) parameter to nvmf_subsystem_add_listener RPC call.

### scripts

`setup.sh` now supports interactive mode for device selection and hugepage reservation.
+19 −2
Original line number Diff line number Diff line
@@ -116,8 +116,19 @@ struct spdk_nvmf_listen_opts {
	 */
	bool secure_channel;

	/* Hole at bytes 17-19. */
	uint8_t reserved1[3];

	/**
	 * Asymmetric Namespace Access state
	 * Optional parameter, which defines ANA_STATE that will be set for
	 * all ANA groups in this listener, when the listener is added to the subsystem.
	 * If not specified, SPDK_NVME_ANA_OPTIMIZED_STATE will be set by default.
	 */
	enum spdk_nvme_ana_state ana_state;

} __attribute__((packed));
SPDK_STATIC_ASSERT(sizeof(struct spdk_nvmf_listen_opts) == 17, "Incorrect size");
SPDK_STATIC_ASSERT(sizeof(struct spdk_nvmf_listen_opts) == 24, "Incorrect size");

/**
 * Initialize listen options
@@ -676,8 +687,14 @@ struct spdk_nvmf_listener_opts {

	/* Secure channel parameter used in TCP TLS. */
	bool secure_channel;

	/* Hole at bytes 9-11. */
	uint8_t reserved1[3];

	/* Asymmetric namespace access state */
	enum spdk_nvme_ana_state ana_state;
} __attribute__((packed));
SPDK_STATIC_ASSERT(sizeof(struct spdk_nvmf_listener_opts) == 9, "Incorrect size");
SPDK_STATIC_ASSERT(sizeof(struct spdk_nvmf_listener_opts) == 16, "Incorrect size");

/**
 * Initialize options structure for listener creation.
+3 −2
Original line number Diff line number Diff line
@@ -735,11 +735,12 @@ nvmf_listen_opts_copy(struct spdk_nvmf_listen_opts *opts,

	SET_FIELD(transport_specific);
	SET_FIELD(secure_channel);
	SET_FIELD(ana_state);
#undef SET_FIELD

	/* Do not remove this statement, you should always update this statement when you adding a new field,
	 * and do not forget to add the SET_FIELD statement for your added field. */
	SPDK_STATIC_ASSERT(sizeof(struct spdk_nvmf_listen_opts) == 17, "Incorrect size");
	SPDK_STATIC_ASSERT(sizeof(struct spdk_nvmf_listen_opts) == 24, "Incorrect size");
}

void
@@ -748,7 +749,7 @@ spdk_nvmf_listen_opts_init(struct spdk_nvmf_listen_opts *opts, size_t opts_size)
	struct spdk_nvmf_listen_opts opts_local = {};

	/* local version of opts should have defaults set here */

	opts_local.ana_state = SPDK_NVME_ANA_OPTIMIZED_STATE;
	nvmf_listen_opts_copy(opts, &opts_local, opts_size);
}

+13 −0
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@

static bool g_logged_deprecated_nvmf_get_subsystems = false;

static int rpc_ana_state_parse(const char *str, enum spdk_nvme_ana_state *ana_state);

static int
json_write_hex_str(struct spdk_json_write_ctx *w, const void *data, size_t size)
{
@@ -633,6 +635,7 @@ static const struct spdk_json_object_decoder nvmf_rpc_listener_decoder[] = {
	{"listen_address", offsetof(struct nvmf_rpc_listener_ctx, address), decode_rpc_listen_address},
	{"tgt_name", offsetof(struct nvmf_rpc_listener_ctx, tgt_name), spdk_json_decode_string, true},
	{"secure_channel", offsetof(struct nvmf_rpc_listener_ctx, listener_opts.secure_channel), spdk_json_decode_bool, true},
	{"ana_state", offsetof(struct nvmf_rpc_listener_ctx, ana_state_str), spdk_json_decode_string, true},
};

static void
@@ -896,6 +899,16 @@ rpc_nvmf_subsystem_add_listener(struct spdk_jsonrpc_request *request,
	}
	ctx->opts.secure_channel = ctx->listener_opts.secure_channel;

	if (ctx->ana_state_str) {
		if (rpc_ana_state_parse(ctx->ana_state_str, &ctx->ana_state)) {
			spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
							 "Invalid parameters");
			nvmf_rpc_listener_ctx_free(ctx);
			return;
		}
		ctx->listener_opts.ana_state = ctx->ana_state;
	}

	rc = spdk_nvmf_subsystem_pause(subsystem, 0, nvmf_rpc_listen_paused, ctx);
	if (rc != 0) {
		if (rc == -EBUSY) {
+4 −3
Original line number Diff line number Diff line
@@ -1099,6 +1099,7 @@ spdk_nvmf_subsystem_listener_opts_init(struct spdk_nvmf_listener_opts *opts, siz
	} \

	SET_FIELD(secure_channel, false);
	SET_FIELD(ana_state, SPDK_NVME_ANA_OPTIMIZED_STATE);

#undef FIELD_OK
#undef SET_FIELD
@@ -1125,10 +1126,10 @@ listener_opts_copy(struct spdk_nvmf_listener_opts *src, struct spdk_nvmf_listene
	} \

	SET_FIELD(secure_channel);

	SET_FIELD(ana_state);
	/* We should not remove this statement, but need to update the assert statement
	 * if we add a new field, and also add a corresponding SET_FIELD statement. */
	SPDK_STATIC_ASSERT(sizeof(struct spdk_nvmf_listener_opts) == 9, "Incorrect size");
	SPDK_STATIC_ASSERT(sizeof(struct spdk_nvmf_listener_opts) == 16, "Incorrect size");

#undef SET_FIELD
#undef FIELD_OK
@@ -1221,7 +1222,7 @@ _nvmf_subsystem_add_listener(struct spdk_nvmf_subsystem *subsystem,
	listener->id = id;

	for (i = 0; i < subsystem->max_nsid; i++) {
		listener->ana_state[i] = SPDK_NVME_ANA_OPTIMIZED_STATE;
		listener->ana_state[i] = listener->opts.ana_state;
	}

	if (transport->ops->listen_associate != NULL) {
Loading