Commit 7809cb41 authored by Artur Paszkiewicz's avatar Artur Paszkiewicz Committed by Jim Harris
Browse files

module/passthru: add uuid option for creating passthru bdev



Change-Id: I1a298161018553feea00248568f2ea786a08ff64
Signed-off-by: default avatarArtur Paszkiewicz <artur.paszkiewicz@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/16157


Reviewed-by: default avatarBen Walker <ben@nvidia.com>
Community-CI: Mellanox Build Bot
Reviewed-by: default avatarShuhei Matsumoto <smatsumoto@nvidia.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
parent ee9fb405
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -6075,6 +6075,7 @@ Name | Optional | Type | Description
----------------------- | -------- | ----------- | -----------
name                    | Required | string      | Bdev name
base_bdev_name          | Required | string      | Base bdev name
uuid                    | Optional | string      | UUID of new bdev

#### Result

+19 −3
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ SPDK_BDEV_MODULE_REGISTER(passthru, &passthru_if)
struct bdev_names {
	char			*vbdev_name;
	char			*bdev_name;
	struct spdk_uuid	uuid;
	TAILQ_ENTRY(bdev_names)	link;
};
static TAILQ_HEAD(, bdev_names) g_bdev_names = TAILQ_HEAD_INITIALIZER(g_bdev_names);
@@ -406,11 +407,19 @@ vbdev_passthru_config_json(struct spdk_json_write_ctx *w)
	struct vbdev_passthru *pt_node;

	TAILQ_FOREACH(pt_node, &g_pt_nodes, link) {
		const struct spdk_uuid *uuid = spdk_bdev_get_uuid(&pt_node->pt_bdev);

		spdk_json_write_object_begin(w);
		spdk_json_write_named_string(w, "method", "bdev_passthru_create");
		spdk_json_write_named_object_begin(w, "params");
		spdk_json_write_named_string(w, "base_bdev_name", spdk_bdev_get_name(pt_node->base_bdev));
		spdk_json_write_named_string(w, "name", spdk_bdev_get_name(&pt_node->pt_bdev));
		if (!spdk_uuid_is_null(uuid)) {
			char uuid_str[SPDK_UUID_STRING_LEN];

			spdk_uuid_fmt_lower(uuid_str, sizeof(uuid_str), uuid);
			spdk_json_write_named_string(w, "uuid", uuid_str);
		}
		spdk_json_write_object_end(w);
		spdk_json_write_object_end(w);
	}
@@ -449,7 +458,8 @@ pt_bdev_ch_destroy_cb(void *io_device, void *ctx_buf)
/* Create the passthru association from the bdev and vbdev name and insert
 * on the global list. */
static int
vbdev_passthru_insert_name(const char *bdev_name, const char *vbdev_name)
vbdev_passthru_insert_name(const char *bdev_name, const char *vbdev_name,
			   const struct spdk_uuid *uuid)
{
	struct bdev_names *name;

@@ -481,6 +491,10 @@ vbdev_passthru_insert_name(const char *bdev_name, const char *vbdev_name)
		return -ENOMEM;
	}

	if (uuid) {
		spdk_uuid_copy(&name->uuid, uuid);
	}

	TAILQ_INSERT_TAIL(&g_bdev_names, name, link);

	return 0;
@@ -612,6 +626,7 @@ vbdev_passthru_register(const char *bdev_name)
			break;
		}
		pt_node->pt_bdev.product_name = "passthru";
		spdk_uuid_copy(&pt_node->pt_bdev.uuid, &name->uuid);

		/* The base bdev that we're attaching to. */
		rc = spdk_bdev_open_ext(bdev_name, true, vbdev_passthru_base_bdev_event_cb,
@@ -701,14 +716,15 @@ vbdev_passthru_register(const char *bdev_name)

/* Create the passthru disk from the given bdev and vbdev name. */
int
bdev_passthru_create_disk(const char *bdev_name, const char *vbdev_name)
bdev_passthru_create_disk(const char *bdev_name, const char *vbdev_name,
			  const struct spdk_uuid *uuid)
{
	int rc;

	/* Insert the bdev name into our global name list even if it doesn't exist yet,
	 * it may show up soon...
	 */
	rc = vbdev_passthru_insert_name(bdev_name, vbdev_name);
	rc = vbdev_passthru_insert_name(bdev_name, vbdev_name, uuid);
	if (rc) {
		return rc;
	}
+3 −1
Original line number Diff line number Diff line
@@ -16,9 +16,11 @@
 *
 * \param bdev_name Bdev on which pass through vbdev will be created.
 * \param vbdev_name Name of the pass through bdev.
 * \param uuid Optional UUID to assign to the pass through bdev.
 * \return 0 on success, other on failure.
 */
int bdev_passthru_create_disk(const char *bdev_name, const char *vbdev_name);
int bdev_passthru_create_disk(const char *bdev_name, const char *vbdev_name,
			      const struct spdk_uuid *uuid);

/**
 * Delete passthru bdev.
+15 −1
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@
struct rpc_bdev_passthru_create {
	char *base_bdev_name;
	char *name;
	char *uuid;
};

/* Free the allocated memory resource after the RPC handling. */
@@ -22,12 +23,14 @@ free_rpc_bdev_passthru_create(struct rpc_bdev_passthru_create *r)
{
	free(r->base_bdev_name);
	free(r->name);
	free(r->uuid);
}

/* Structure to decode the input parameters for this RPC method. */
static const struct spdk_json_object_decoder rpc_bdev_passthru_create_decoders[] = {
	{"base_bdev_name", offsetof(struct rpc_bdev_passthru_create, base_bdev_name), spdk_json_decode_string},
	{"name", offsetof(struct rpc_bdev_passthru_create, name), spdk_json_decode_string},
	{"uuid", offsetof(struct rpc_bdev_passthru_create, uuid), spdk_json_decode_string, true},
};

/* Decode the parameters for this RPC method and properly construct the passthru
@@ -39,6 +42,8 @@ rpc_bdev_passthru_create(struct spdk_jsonrpc_request *request,
{
	struct rpc_bdev_passthru_create req = {NULL};
	struct spdk_json_write_ctx *w;
	struct spdk_uuid *uuid = NULL;
	struct spdk_uuid decoded_uuid;
	int rc;

	if (spdk_json_decode_object(params, rpc_bdev_passthru_create_decoders,
@@ -50,7 +55,16 @@ rpc_bdev_passthru_create(struct spdk_jsonrpc_request *request,
		goto cleanup;
	}

	rc = bdev_passthru_create_disk(req.base_bdev_name, req.name);
	if (req.uuid) {
		if (spdk_uuid_parse(&decoded_uuid, req.uuid)) {
			spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
							 "Failed to parse bdev UUID");
			goto cleanup;
		}
		uuid = &decoded_uuid;
	}

	rc = bdev_passthru_create_disk(req.base_bdev_name, req.name, uuid);
	if (rc != 0) {
		spdk_jsonrpc_send_error_response(request, rc, spdk_strerror(-rc));
		goto cleanup;
+4 −1
Original line number Diff line number Diff line
@@ -1343,12 +1343,13 @@ def bdev_iscsi_delete(client, name):
    return client.call('bdev_iscsi_delete', params)


def bdev_passthru_create(client, base_bdev_name, name):
def bdev_passthru_create(client, base_bdev_name, name, uuid=None):
    """Construct a pass-through block device.

    Args:
        base_bdev_name: name of the existing bdev
        name: name of block device
        uuid: UUID of block device (optional)

    Returns:
        Name of created block device.
@@ -1357,6 +1358,8 @@ def bdev_passthru_create(client, base_bdev_name, name):
        'base_bdev_name': base_bdev_name,
        'name': name,
    }
    if uuid:
        params['uuid'] = uuid
    return client.call('bdev_passthru_create', params)


Loading