Commit 9b8579e4 authored by Changpeng Liu's avatar Changpeng Liu Committed by Tomasz Zawadzki
Browse files

lib/ublk: add optional user copy control flag to RPC



The UBLK_F_USER_COPY feature is negotiated between kernel `ublk_drv` driver
and ublk target, but users may want to disable this feature even both
side can support it, here we add optional RPC flag to disable this
feature when creating ublk target.

Change-Id: I07d1a26af43ef5a3b990969ebfdd2d3372b2697d
Signed-off-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/23034


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <jim.harris@samsung.com>
Reviewed-by: default avatarShuhei Matsumoto <smatsumoto@nvidia.com>
Community-CI: Mellanox Build Bot
parent 14636419
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -11537,6 +11537,7 @@ ublk_destroy_target in between. It will use current cpumask in SPDK when user do
Name                    | Optional | Type        | Description
----------------------- | -------- | ----------- | -----------
cpumask                 | Optional | string      | Cpumask for ublk target
disable-user-copy       | Optional | boolean     | Disable user copy feature

#### Response

+23 −1
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ static uint32_t g_num_ublk_poll_groups = 0;
static uint32_t g_next_ublk_poll_group = 0;
static uint32_t g_ublks_max = UBLK_DEFAULT_MAX_SUPPORTED_DEVS;
static struct spdk_cpuset g_core_mask;
static bool g_disable_user_copy = false;

struct ublk_queue;
struct ublk_poll_group;
@@ -531,7 +532,9 @@ ublk_ctrl_cmd_get_features(void)
	if (cqe->res == 0) {
		g_ublk_tgt.ioctl_encode = !!(g_ublk_tgt.features & UBLK_F_CMD_IOCTL_ENCODE);
		g_ublk_tgt.user_copy = !!(g_ublk_tgt.features & UBLK_F_USER_COPY);
		g_ublk_tgt.user_copy &= !g_disable_user_copy;
		g_ublk_tgt.user_recovery = !!(g_ublk_tgt.features & UBLK_F_USER_RECOVERY);
		SPDK_NOTICELOG("User Copy %s\n", g_ublk_tgt.user_copy ? "enabled" : "disabled");
	}
	io_uring_cqe_seen(&g_ublk_tgt.ctrl_ring, cqe);

@@ -666,12 +669,21 @@ ublk_poller_register(void *args)
	}
}

struct rpc_create_target {
	bool disable_user_copy;
};

static const struct spdk_json_object_decoder rpc_ublk_create_target[] = {
	{"disable_user_copy", offsetof(struct rpc_create_target, disable_user_copy), spdk_json_decode_bool, true},
};

int
ublk_create_target(const char *cpumask_str)
ublk_create_target(const char *cpumask_str, const struct spdk_json_val *params)
{
	int rc;
	uint32_t i;
	char thread_name[32];
	struct rpc_create_target req = {};
	struct ublk_poll_group *poll_group;

	if (g_ublk_tgt.active == true) {
@@ -684,6 +696,16 @@ ublk_create_target(const char *cpumask_str)
		return rc;
	}

	if (params) {
		if (spdk_json_decode_object_relaxed(params, rpc_ublk_create_target,
						    SPDK_COUNTOF(rpc_ublk_create_target),
						    &req)) {
			SPDK_ERRLOG("spdk_json_decode_object failed\n");
			return -EINVAL;
		}
		g_disable_user_copy = req.disable_user_copy;
	}

	assert(g_ublk_tgt.poll_groups == NULL);
	g_ublk_tgt.poll_groups = calloc(spdk_env_get_core_count(), sizeof(*poll_group));
	if (!g_ublk_tgt.poll_groups) {
+1 −1
Original line number Diff line number Diff line
@@ -54,7 +54,7 @@ extern "C" {

typedef void (*ublk_ctrl_cb)(void *cb_arg, int result);

int ublk_create_target(const char *cpumask_str);
int ublk_create_target(const char *cpumask_str, const struct spdk_json_val *params);
int ublk_destroy_target(spdk_ublk_fini_cb cb_fn, void *cb_arg);
int ublk_start_disk(const char *bdev_name, uint32_t ublk_id,
		    uint32_t num_queues, uint32_t queue_depth,
+4 −4
Original line number Diff line number Diff line
@@ -32,7 +32,7 @@ rpc_ublk_create_target(struct spdk_jsonrpc_request *request, const struct spdk_j
	struct rpc_ublk_create_target req = {};

	if (params != NULL) {
		if (spdk_json_decode_object(params, rpc_ublk_create_target_decoders,
		if (spdk_json_decode_object_relaxed(params, rpc_ublk_create_target_decoders,
						    SPDK_COUNTOF(rpc_ublk_create_target_decoders),
						    &req)) {
			SPDK_ERRLOG("spdk_json_decode_object failed\n");
@@ -40,7 +40,7 @@ rpc_ublk_create_target(struct spdk_jsonrpc_request *request, const struct spdk_j
			goto invalid;
		}
	}
	rc = ublk_create_target(req.cpumask);
	rc = ublk_create_target(req.cpumask, params);
	if (rc != 0) {
		goto invalid;
	}
+3 −1
Original line number Diff line number Diff line
@@ -3,10 +3,12 @@
#  All rights reserved.


def ublk_create_target(client, cpumask=None):
def ublk_create_target(client, cpumask=None, disable_user_copy=None):
    params = {}
    if cpumask:
        params['cpumask'] = cpumask
    if disable_user_copy:
        params['disable_user_copy'] = True
    return client.call('ublk_create_target', params)


Loading