Commit a0c12854 authored by Yash Raj Singh's avatar Yash Raj Singh Committed by Konrad Sztyber
Browse files

bdev/nvme: Make bdev nvme get and set opts APIs public



This patch exposes bdev_nvme_get_opts and bdev_nvme_set_opts APIs.
No changes have been done to the implementation of these functions.

Change-Id: I8498ed81e14abb66283a1608f17bb6bba8e38975
Signed-off-by: default avatarYash Raj Singh <yash.rajsingh@nutanix.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/25406


Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Community-CI: Community CI Samsung <spdk.community.ci.samsung@gmail.com>
Reviewed-by: default avatarJim Harris <jim.harris@nvidia.com>
Community-CI: Mellanox Build Bot
Reviewed-by: default avatarAnkit Kumar <ankit.kumar@samsung.com>
Reviewed-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
parent 53ca6a88
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -16,6 +16,9 @@ to `multipath` field in spdk_bdev_nvme_ctrlr_opts structure passed as a paramete
If multipathing shall be enabled for nvme bdev, `bdev_opts.multipath` shall be set to `true`. When
`bdev_opts.multipath` is set to `false`, failover mode is enabled.

Added public APIs `spdk_bdev_nvme_get_opts` and `spdk_bdev_nvme_set_opts` to get default bdev nvme
options and set them respectively.

### env

Added 3 APIs to handle multiple interrupts for PCI device `spdk_pci_device_enable_interrupts()`,
+30 −0
Original line number Diff line number Diff line
@@ -55,6 +55,13 @@ enum spdk_bdev_timeout_action {
};

struct spdk_bdev_nvme_opts {
	/**
	 * The size of spdk_bdev_nvme_opts according to the caller of this library is used for ABI
	 * compatibility.  The library uses this field to know how many fields in this
	 * structure are valid. And the library will populate any remaining fields with default values.
	 * New added fields should be put at the end of the struct.
	 */
	size_t opts_size;
	enum spdk_bdev_timeout_action action_on_timeout;
	uint32_t keep_alive_timeout_ms;
	uint64_t timeout_us;
@@ -69,6 +76,8 @@ struct spdk_bdev_nvme_opts {
	uint64_t nvme_adminq_poll_period_us;
	uint64_t nvme_ioq_poll_period_us;
	bool delay_cmd_submit;
	/* Hole at bytes 73-75. */
	uint8_t reserved73[3];
	/* The number of attempts per I/O in the bdev layer before an I/O fails. */
	int32_t bdev_retry_count;
	int32_t ctrlr_loss_timeout_sec;
@@ -82,12 +91,17 @@ struct spdk_bdev_nvme_opts {
	bool nvme_error_stat;
	bool io_path_stat;
	bool allow_accel_sequence;
	/* Hole at byte 99. */
	uint8_t reserved99[1];
	uint32_t rdma_srq_size;
	uint32_t rdma_max_cq_size;
	uint16_t rdma_cm_event_timeout_ms;
	/* Hole at byte 110-111. */
	uint8_t reserved110[2];
	uint32_t dhchap_digests;
	uint32_t dhchap_dhgroups;
};
SPDK_STATIC_ASSERT(sizeof(struct spdk_bdev_nvme_opts) == 120, "Incorrect size");

/**
 * Connect to the NVMe controller and populate namespaces as bdevs.
@@ -136,6 +150,22 @@ void spdk_bdev_nvme_set_multipath_policy(const char *name,
 */
void spdk_bdev_nvme_get_default_ctrlr_opts(struct spdk_bdev_nvme_ctrlr_opts *opts);

/**
 * Get the default value for bdev nvme options.
 *
 * \param[out] opts Bdev nvme options object to be filled with default values.
 * \param opts_size Must be set to sizeof(struct spdk_bdev_nvme_opts).
 */
void spdk_bdev_nvme_get_opts(struct spdk_bdev_nvme_opts *opts, size_t opts_size);

/**
 * Set the bdev nvme options.
 *
 * \param opts New value of bdev nvme options to be set.
 * \return 0 on success, negative errno on failure.
 */
int spdk_bdev_nvme_set_opts(const struct spdk_bdev_nvme_opts *opts);

#ifdef __cplusplus
}
#endif
+98 −4
Original line number Diff line number Diff line
@@ -6109,9 +6109,58 @@ bdev_nvme_hotplug(void *arg)
}

void
bdev_nvme_get_opts(struct spdk_bdev_nvme_opts *opts)
spdk_bdev_nvme_get_opts(struct spdk_bdev_nvme_opts *opts, size_t opts_size)
{
	*opts = g_opts;
	if (!opts) {
		SPDK_ERRLOG("opts should not be NULL\n");
		return;
	}

	if (!opts_size) {
		SPDK_ERRLOG("opts_size should not be zero value\n");
		return;
	}

	opts->opts_size = opts_size;

#define SET_FIELD(field, defval) \
		opts->field = SPDK_GET_FIELD(&g_opts, field, defval, opts_size); \

	SET_FIELD(action_on_timeout, 0);
	SET_FIELD(keep_alive_timeout_ms, 0);
	SET_FIELD(timeout_us, 0);
	SET_FIELD(timeout_admin_us, 0);
	SET_FIELD(transport_retry_count, 0);
	SET_FIELD(arbitration_burst, 0);
	SET_FIELD(low_priority_weight, 0);
	SET_FIELD(medium_priority_weight, 0);
	SET_FIELD(high_priority_weight, 0);
	SET_FIELD(io_queue_requests, 0);
	SET_FIELD(nvme_adminq_poll_period_us, 0);
	SET_FIELD(nvme_ioq_poll_period_us, 0);
	SET_FIELD(delay_cmd_submit, 0);
	SET_FIELD(bdev_retry_count, 0);
	SET_FIELD(ctrlr_loss_timeout_sec, 0);
	SET_FIELD(reconnect_delay_sec, 0);
	SET_FIELD(fast_io_fail_timeout_sec, 0);
	SET_FIELD(transport_ack_timeout, 0);
	SET_FIELD(disable_auto_failback, false);
	SET_FIELD(generate_uuids, false);
	SET_FIELD(transport_tos, 0);
	SET_FIELD(nvme_error_stat, false);
	SET_FIELD(io_path_stat, false);
	SET_FIELD(allow_accel_sequence, false);
	SET_FIELD(rdma_srq_size, 0);
	SET_FIELD(rdma_max_cq_size, 0);
	SET_FIELD(rdma_cm_event_timeout_ms, 0);
	SET_FIELD(dhchap_digests, 0);
	SET_FIELD(dhchap_dhgroups, 0);

#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_bdev_nvme_opts) == 120, "Incorrect size");
}

static bool bdev_nvme_check_io_error_resiliency_params(int32_t ctrlr_loss_timeout_sec,
@@ -6142,8 +6191,18 @@ bdev_nvme_validate_opts(const struct spdk_bdev_nvme_opts *opts)
}

int
bdev_nvme_set_opts(const struct spdk_bdev_nvme_opts *opts)
spdk_bdev_nvme_set_opts(const struct spdk_bdev_nvme_opts *opts)
{
	if (!opts) {
		SPDK_ERRLOG("opts cannot be NULL\n");
		return -1;
	}

	if (!opts->opts_size) {
		SPDK_ERRLOG("opts_size inside opts cannot be zero value\n");
		return -1;
	}

	int ret;

	ret = bdev_nvme_validate_opts(opts);
@@ -6181,7 +6240,42 @@ bdev_nvme_set_opts(const struct spdk_bdev_nvme_opts *opts)
		}
	}

	g_opts = *opts;
#define SET_FIELD(field, defval) \
		g_opts.field = SPDK_GET_FIELD(opts, field, defval, opts->opts_size); \

	SET_FIELD(action_on_timeout, 0);
	SET_FIELD(keep_alive_timeout_ms, 0);
	SET_FIELD(timeout_us, 0);
	SET_FIELD(timeout_admin_us, 0);
	SET_FIELD(transport_retry_count, 0);
	SET_FIELD(arbitration_burst, 0);
	SET_FIELD(low_priority_weight, 0);
	SET_FIELD(medium_priority_weight, 0);
	SET_FIELD(high_priority_weight, 0);
	SET_FIELD(io_queue_requests, 0);
	SET_FIELD(nvme_adminq_poll_period_us, 0);
	SET_FIELD(nvme_ioq_poll_period_us, 0);
	SET_FIELD(delay_cmd_submit, 0);
	SET_FIELD(bdev_retry_count, 0);
	SET_FIELD(ctrlr_loss_timeout_sec, 0);
	SET_FIELD(reconnect_delay_sec, 0);
	SET_FIELD(fast_io_fail_timeout_sec, 0);
	SET_FIELD(transport_ack_timeout, 0);
	SET_FIELD(disable_auto_failback, false);
	SET_FIELD(generate_uuids, false);
	SET_FIELD(transport_tos, 0);
	SET_FIELD(nvme_error_stat, false);
	SET_FIELD(io_path_stat, false);
	SET_FIELD(allow_accel_sequence, false);
	SET_FIELD(rdma_srq_size, 0);
	SET_FIELD(rdma_max_cq_size, 0);
	SET_FIELD(rdma_cm_event_timeout_ms, 0);
	SET_FIELD(dhchap_digests, 0);
	SET_FIELD(dhchap_dhgroups, 0);

	g_opts.opts_size = opts->opts_size;

#undef SET_FIELD

	return 0;
}
+0 −2
Original line number Diff line number Diff line
@@ -283,8 +283,6 @@ struct nvme_ns *nvme_ctrlr_get_first_active_ns(struct nvme_ctrlr *nvme_ctrlr);
struct nvme_ns *nvme_ctrlr_get_next_active_ns(struct nvme_ctrlr *nvme_ctrlr, struct nvme_ns *ns);

struct spdk_nvme_qpair *bdev_nvme_get_io_qpair(struct spdk_io_channel *ctrlr_io_ch);
void bdev_nvme_get_opts(struct spdk_bdev_nvme_opts *opts);
int bdev_nvme_set_opts(const struct spdk_bdev_nvme_opts *opts);
int bdev_nvme_set_hotplug(bool enabled, uint64_t period_us, spdk_msg_fn cb, void *cb_ctx);

int bdev_nvme_start_discovery(struct spdk_nvme_transport_id *trid, const char *base_name,
+3 −3
Original line number Diff line number Diff line
@@ -147,7 +147,7 @@ rpc_bdev_nvme_set_options(struct spdk_jsonrpc_request *request,
	struct spdk_bdev_nvme_opts opts;
	int rc;

	bdev_nvme_get_opts(&opts);
	spdk_bdev_nvme_get_opts(&opts, sizeof(opts));
	if (params && spdk_json_decode_object(params, rpc_bdev_nvme_options_decoders,
					      SPDK_COUNTOF(rpc_bdev_nvme_options_decoders),
					      &opts)) {
@@ -157,7 +157,7 @@ rpc_bdev_nvme_set_options(struct spdk_jsonrpc_request *request,
		return;
	}

	rc = bdev_nvme_set_opts(&opts);
	rc = spdk_bdev_nvme_set_opts(&opts);
	if (rc == -EPERM) {
		spdk_jsonrpc_send_error_response(request, -EPERM,
						 "RPC not permitted with nvme controllers already attached");
@@ -2653,7 +2653,7 @@ rpc_bdev_nvme_get_path_iostat(struct spdk_jsonrpc_request *request,
	uint32_t num_paths = 0, i = 0;
	int rc;

	bdev_nvme_get_opts(&opts);
	spdk_bdev_nvme_get_opts(&opts, sizeof(opts));
	if (!opts.io_path_stat) {
		SPDK_ERRLOG("RPC not enabled if enable_io_path_stat is false\n");
		spdk_jsonrpc_send_error_response(request, -EPERM,
Loading