Commit 511adde0 authored by Piotr Pelplinski's avatar Piotr Pelplinski Committed by Daniel Verkamp
Browse files

lvol: add lvs name in rpc calls

parent e5b0dd6e
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -139,12 +139,13 @@ int spdk_lvs_destroy(struct spdk_lvol_store *lvol_store, bool unmap_device,
/**
 * \brief Create lvol on given lvolstore with specified size
 * \param lvs Handle to lvolstore
 * \param name Name of lvol
 * \param sz size of lvol in bytes
 * \param cb_fn Completion callback
 * \param cb_arg Completion callback custom arguments
 * \return error
 */
int spdk_lvol_create(struct spdk_lvol_store *lvs, char *name, uint64_t sz,
int spdk_lvol_create(struct spdk_lvol_store *lvs, const char *name, uint64_t sz,
		     spdk_lvol_op_with_handle_complete cb_fn, void *cb_arg);

/**
@@ -191,6 +192,12 @@ struct spdk_lvol *vbdev_get_lvol_by_name(const char *name);
 * \return Handle to spdk_lvol_store or NULL if not found.
 */
struct spdk_lvol_store *vbdev_get_lvol_store_by_uuid(uuid_t uuid);
/**
 * \brief Search for handle to lvolstore
 * \param name name of lvolstore
 * \return Handle to spdk_lvol_store or NULL if not found.
 */
struct spdk_lvol_store *vbdev_get_lvol_store_by_name(const char *name);
void spdk_lvs_load(struct spdk_bs_dev *bs_dev, spdk_lvs_op_with_handle_complete cb_fn,
		   void *cb_arg);
void spdk_lvol_open(struct spdk_lvol *lvol, spdk_lvol_op_with_handle_complete cb_fn, void *cb_arg);
+40 −19
Original line number Diff line number Diff line
@@ -102,14 +102,14 @@ end:
}

int
vbdev_lvs_create(struct spdk_bdev *base_bdev, uint32_t cluster_sz,
vbdev_lvs_create(struct spdk_bdev *base_bdev, const char *name, uint32_t cluster_sz,
		 spdk_lvs_op_with_handle_complete cb_fn, void *cb_arg)
{
	struct spdk_bs_dev *bs_dev;
	struct spdk_lvs_with_handle_req *lvs_req;
	struct spdk_lvs_opts opts;
	uuid_t uuid;
	int rc;
	int len;

	if (base_bdev == NULL) {
		SPDK_ERRLOG("Bdev does not exist\n");
@@ -121,12 +121,18 @@ vbdev_lvs_create(struct spdk_bdev *base_bdev, uint32_t cluster_sz,
		opts.cluster_sz = cluster_sz;
	}

	/*
	 * This is temporary until the RPCs take a name parameter for creating
	 *  an lvolstore.
	 */
	uuid_generate(uuid);
	uuid_unparse(uuid, opts.name);
	if (name == NULL) {
		SPDK_ERRLOG("missing name param\n");
		return -EINVAL;
	}

	len = strnlen(name, SPDK_LVS_NAME_MAX);

	if (len == 0 || len == SPDK_LVS_NAME_MAX) {
		SPDK_ERRLOG("name must be between 1 and %d characters\n", SPDK_LVS_NAME_MAX - 1);
		return -EINVAL;
	}
	strncpy(opts.name, name, sizeof(opts.name));

	lvs_req = calloc(1, sizeof(*lvs_req));
	if (!lvs_req) {
@@ -286,6 +292,22 @@ vbdev_get_lvol_store_by_uuid(uuid_t uuid)
	return NULL;
}

struct spdk_lvol_store *
vbdev_get_lvol_store_by_name(const char *name)
{
	struct spdk_lvol_store *lvs = NULL;
	struct lvol_store_bdev *lvs_bdev = vbdev_lvol_store_first();

	while (lvs_bdev != NULL) {
		lvs = lvs_bdev->lvs;
		if (strncmp(lvs->name, name, sizeof(lvs->name)) == 0) {
			return lvs;
		}
		lvs_bdev = vbdev_lvol_store_next(lvs_bdev);
	}
	return NULL;
}

struct lvol_store_bdev *
vbdev_get_lvs_bdev_by_lvs(struct spdk_lvol_store *lvs_orig)
{
@@ -356,6 +378,7 @@ _vbdev_lvol_destroy_cb(void *cb_arg, int lvserrno)
	SPDK_INFOLOG(SPDK_TRACE_VBDEV_LVOL, "Lvol destroyed\n");

	spdk_bdev_unregister_done(bdev, lvserrno);
	free(bdev->name);
	free(bdev);
}

@@ -368,6 +391,7 @@ _vbdev_lvol_destroy_after_close_cb(void *cb_arg, int lvserrno)
	if (lvserrno != 0) {
		SPDK_INFOLOG(SPDK_TRACE_VBDEV_LVOL, "Could not close Lvol %s\n", lvol->old_name);
		spdk_bdev_unregister_done(bdev, lvserrno);
		free(bdev->name);
		free(bdev);
		return;
	}
@@ -384,6 +408,7 @@ vbdev_lvol_destruct(void *ctx)
	assert(lvol != NULL);

	if (lvol->close_only) {
		free(lvol->bdev->name);
		free(lvol->bdev);
		spdk_lvol_close(lvol, _vbdev_lvol_close_cb, NULL);
	} else {
@@ -581,7 +606,12 @@ _create_lvol_disk(struct spdk_lvol *lvol)
		return NULL;
	}

	bdev->name = lvol->old_name;
	bdev->name = spdk_sprintf_alloc("%s/%s", lvs_bdev->lvs->name, lvol->name);
	if (bdev->name == NULL) {
		SPDK_ERRLOG("Cannot alloc memory for bdev name\n");
		free(bdev);
		return NULL;
	}
	bdev->product_name = "Logical Volume";
	bdev->write_cache = 1;
	bdev->blocklen = spdk_bs_get_page_size(lvol->lvol_store->blobstore);
@@ -621,13 +651,11 @@ end:
}

int
vbdev_lvol_create(uuid_t uuid, size_t sz,
vbdev_lvol_create(uuid_t uuid, const char *name, size_t sz,
		  spdk_lvol_op_with_handle_complete cb_fn, void *cb_arg)
{
	struct spdk_lvol_with_handle_req *req;
	struct spdk_lvol_store *lvs;
	uuid_t lvol_uuid;
	char name[SPDK_LVOL_NAME_MAX];
	int rc;

	lvs = vbdev_get_lvol_store_by_uuid(uuid);
@@ -642,13 +670,6 @@ vbdev_lvol_create(uuid_t uuid, size_t sz,
	req->cb_fn = cb_fn;
	req->cb_arg = cb_arg;

	/*
	 * This is temporary until the RPCs take a name parameter for creating
	 *  an lvol.
	 */
	uuid_generate(lvol_uuid);
	uuid_unparse(lvol_uuid, name);

	rc = spdk_lvol_create(lvs, name, sz, _vbdev_lvol_create_cb, req);
	if (rc != 0) {
		free(req);
+4 −2
Original line number Diff line number Diff line
@@ -46,12 +46,14 @@ struct lvol_store_bdev {

	TAILQ_ENTRY(lvol_store_bdev)	lvol_stores;
};
int vbdev_lvs_create(struct spdk_bdev *base_bdev, uint32_t cluster_sz,

int vbdev_lvs_create(struct spdk_bdev *base_bdev, const char *name, uint32_t cluster_sz,
		     spdk_lvs_op_with_handle_complete cb_fn, void *cb_arg);
void vbdev_lvs_destruct(struct spdk_lvol_store *lvs, spdk_lvs_op_complete cb_fn, void *cb_arg);
void vbdev_lvs_unload(struct spdk_lvol_store *lvs, spdk_lvs_op_complete cb_fn, void *cb_arg);

int vbdev_lvol_create(uuid_t uuid, size_t sz, spdk_lvol_op_with_handle_complete cb_fn,
int vbdev_lvol_create(uuid_t uuid, const char *name, size_t sz,
		      spdk_lvol_op_with_handle_complete cb_fn,
		      void *cb_arg);

int vbdev_lvol_resize(char *name, size_t sz, spdk_lvol_op_complete cb_fn, void *cb_arg);
+85 −31
Original line number Diff line number Diff line
@@ -41,19 +41,59 @@
SPDK_LOG_REGISTER_TRACE_FLAG("lvolrpc", SPDK_TRACE_LVOL_RPC)

struct rpc_construct_lvol_store {
	char *base_name;
	char *lvs_name;
	char *bdev_name;
	uint32_t cluster_sz;
};

static int
vbdev_get_lvol_store_by_uuid_xor_name(const char *uuid, const char *lvs_name,
				      struct spdk_lvol_store **lvs)
{
	uuid_t lvol_store_uuid;

	if ((uuid == NULL && lvs_name == NULL)) {
		SPDK_INFOLOG(SPDK_TRACE_VBDEV_LVOL, "lvs UUID nor lvs name specified\n");
		return -EINVAL;
	} else if ((uuid && lvs_name)) {
		SPDK_INFOLOG(SPDK_TRACE_VBDEV_LVOL, "both lvs UUID '%s' and lvs name '%s' specified\n", uuid,
			     lvs_name);
		return -EINVAL;
	} else if (uuid) {
		if (uuid_parse(uuid, lvol_store_uuid)) {
			SPDK_INFOLOG(SPDK_TRACE_VBDEV_LVOL, "incorrect UUID '%s'\n", uuid);
			return -EINVAL;
		}

		*lvs = vbdev_get_lvol_store_by_uuid(lvol_store_uuid);

		if (*lvs == NULL) {
			SPDK_INFOLOG(SPDK_TRACE_VBDEV_LVOL, "blobstore with UUID '%p' not found\n", &lvol_store_uuid);
			return -ENODEV;
		}
	} else if (lvs_name) {

		*lvs = vbdev_get_lvol_store_by_name(lvs_name);

		if (*lvs == NULL) {
			SPDK_INFOLOG(SPDK_TRACE_VBDEV_LVOL, "blobstore with name '%s' not found\n", lvs_name);
			return -ENODEV;
		}
	}
	return 0;
}

static void
free_rpc_construct_lvol_store(struct rpc_construct_lvol_store *req)
{
	free(req->base_name);
	free(req->bdev_name);
	free(req->lvs_name);
}

static const struct spdk_json_object_decoder rpc_construct_lvol_store_decoders[] = {
	{"base_name", offsetof(struct rpc_construct_lvol_store, base_name), spdk_json_decode_string},
	{"bdev_name", offsetof(struct rpc_construct_lvol_store, bdev_name), spdk_json_decode_string},
	{"cluster_sz", offsetof(struct rpc_construct_lvol_store, cluster_sz), spdk_json_decode_uint32, true},
	{"lvs_name", offsetof(struct rpc_construct_lvol_store, lvs_name), spdk_json_decode_string},
};

static void
@@ -103,20 +143,26 @@ spdk_rpc_construct_lvol_store(struct spdk_jsonrpc_request *request,
		goto invalid;
	}

	if (req.base_name == NULL) {
		SPDK_ERRLOG("missing name param\n");
	if (req.bdev_name == NULL) {
		SPDK_ERRLOG("missing bdev_name param\n");
		rc = -EINVAL;
		goto invalid;
	}

	bdev = spdk_bdev_get_by_name(req.base_name);
	if (req.lvs_name == NULL) {
		SPDK_ERRLOG("missing lvs_name param\n");
		rc = -EINVAL;
		goto invalid;
	}
	bdev = spdk_bdev_get_by_name(req.bdev_name);
	if (bdev == NULL) {
		SPDK_ERRLOG("bdev '%s' does not exist\n", req.base_name);
		SPDK_ERRLOG("bdev '%s' does not exist\n", req.bdev_name);
		rc = -ENODEV;
		goto invalid;
	}

	rc = vbdev_lvs_create(bdev, req.cluster_sz, _spdk_rpc_lvol_store_construct_cb, request);
	rc = vbdev_lvs_create(bdev, req.lvs_name, req.cluster_sz, _spdk_rpc_lvol_store_construct_cb,
			      request);
	if (rc < 0) {
		goto invalid;
	}
@@ -132,17 +178,20 @@ invalid:
SPDK_RPC_REGISTER("construct_lvol_store", spdk_rpc_construct_lvol_store)

struct rpc_destroy_lvol_store {
	char *lvol_store_uuid;
	char *uuid;
	char *lvs_name;
};

static void
free_rpc_destroy_lvol_store(struct rpc_destroy_lvol_store *req)
{
	free(req->lvol_store_uuid);
	free(req->uuid);
	free(req->lvs_name);
}

static const struct spdk_json_object_decoder rpc_destroy_lvol_store_decoders[] = {
	{"lvol_store_uuid", offsetof(struct rpc_destroy_lvol_store, lvol_store_uuid), spdk_json_decode_string},
	{"uuid", offsetof(struct rpc_destroy_lvol_store, uuid), spdk_json_decode_string, true},
	{"lvs_name", offsetof(struct rpc_destroy_lvol_store, lvs_name), spdk_json_decode_string, true},
};

static void
@@ -175,8 +224,7 @@ spdk_rpc_destroy_lvol_store(struct spdk_jsonrpc_request *request,
			    const struct spdk_json_val *params)
{
	struct rpc_destroy_lvol_store req = {};
	struct spdk_lvol_store *lvs;
	uuid_t lvol_store_uuid;
	struct spdk_lvol_store *lvs = NULL;
	int rc;
	char buf[64];

@@ -188,16 +236,8 @@ spdk_rpc_destroy_lvol_store(struct spdk_jsonrpc_request *request,
		goto invalid;
	}

	if (uuid_parse(req.lvol_store_uuid, lvol_store_uuid)) {
		SPDK_INFOLOG(SPDK_TRACE_LVOL_RPC, "incorrect UUID '%s'\n", req.lvol_store_uuid);
		rc = -EINVAL;
		goto invalid;
	}

	lvs = vbdev_get_lvol_store_by_uuid(lvol_store_uuid);
	if (lvs == NULL) {
		SPDK_INFOLOG(SPDK_TRACE_LVOL_RPC, "blobstore with UUID '%p' not found\n", &lvol_store_uuid);
		rc = -ENODEV;
	rc = vbdev_get_lvol_store_by_uuid_xor_name(req.uuid, req.lvs_name, &lvs);
	if (rc != 0) {
		goto invalid;
	}

@@ -215,18 +255,24 @@ invalid:
SPDK_RPC_REGISTER("destroy_lvol_store", spdk_rpc_destroy_lvol_store)

struct rpc_construct_lvol_bdev {
	char *lvol_store_uuid;
	char *uuid;
	char *lvs_name;
	char *lvol_name;
	uint64_t size;
};

static void
free_rpc_construct_lvol_bdev(struct rpc_construct_lvol_bdev *req)
{
	free(req->lvol_store_uuid);
	free(req->uuid);
	free(req->lvs_name);
	free(req->lvol_name);
}

static const struct spdk_json_object_decoder rpc_construct_lvol_bdev_decoders[] = {
	{"lvol_store_uuid", offsetof(struct rpc_construct_lvol_bdev, lvol_store_uuid), spdk_json_decode_string},
	{"uuid", offsetof(struct rpc_construct_lvol_bdev, uuid), spdk_json_decode_string, true},
	{"lvs_name", offsetof(struct rpc_construct_lvol_bdev, lvs_name), spdk_json_decode_string, true},
	{"lvol_name", offsetof(struct rpc_construct_lvol_bdev, lvol_name), spdk_json_decode_string, true},
	{"size", offsetof(struct rpc_construct_lvol_bdev, size), spdk_json_decode_uint64},
};

@@ -247,7 +293,7 @@ _spdk_rpc_construct_lvol_bdev_cb(void *cb_arg, struct spdk_lvol *lvol, int lvole
	}

	spdk_json_write_array_begin(w);
	spdk_json_write_string(w, lvol->old_name);
	spdk_json_write_string(w, lvol->bdev->name);
	spdk_json_write_array_end(w);
	spdk_jsonrpc_end_result(request, w);
	return;
@@ -262,10 +308,10 @@ spdk_rpc_construct_lvol_bdev(struct spdk_jsonrpc_request *request,
			     const struct spdk_json_val *params)
{
	struct rpc_construct_lvol_bdev req = {};
	uuid_t lvol_store_uuid;
	size_t sz;
	int rc;
	char buf[64];
	struct spdk_lvol_store *lvs = NULL;

	SPDK_INFOLOG(SPDK_TRACE_LVOL_RPC, "Creating blob\n");

@@ -277,15 +323,20 @@ spdk_rpc_construct_lvol_bdev(struct spdk_jsonrpc_request *request,
		goto invalid;
	}

	if (uuid_parse(req.lvol_store_uuid, lvol_store_uuid)) {
		SPDK_INFOLOG(SPDK_TRACE_LVOL_RPC, "incorrect UUID '%s'\n", req.lvol_store_uuid);
	rc = vbdev_get_lvol_store_by_uuid_xor_name(req.uuid, req.lvs_name, &lvs);
	if (rc != 0) {
		goto invalid;
	}

	if (req.lvol_name == NULL) {
		SPDK_INFOLOG(SPDK_TRACE_LVOL_RPC, "no bdev name\n");
		rc = -EINVAL;
		goto invalid;
	}

	sz = (size_t)req.size;

	rc = vbdev_lvol_create(lvol_store_uuid, sz, _spdk_rpc_construct_lvol_bdev_cb, request);
	rc = vbdev_lvol_create(lvs->uuid, req.lvol_name, sz, _spdk_rpc_construct_lvol_bdev_cb, request);
	if (rc < 0) {
		goto invalid;
	}
@@ -421,6 +472,9 @@ spdk_rpc_get_lvol_stores(struct spdk_jsonrpc_request *request,
		spdk_json_write_name(w, "uuid");
		spdk_json_write_string(w, uuid);

		spdk_json_write_name(w, "name");
		spdk_json_write_string(w, lvs_bdev->lvs->name);

		spdk_json_write_name(w, "base_bdev");
		spdk_json_write_string(w, spdk_bdev_get_name(lvs_bdev->bdev));

+1 −1
Original line number Diff line number Diff line
@@ -909,7 +909,7 @@ _spdk_lvol_create_cb(void *cb_arg, spdk_blob_id blobid, int lvolerrno)
}

int
spdk_lvol_create(struct spdk_lvol_store *lvs, char *name, uint64_t sz,
spdk_lvol_create(struct spdk_lvol_store *lvs, const char *name, uint64_t sz,
		 spdk_lvol_op_with_handle_complete cb_fn, void *cb_arg)
{
	struct spdk_lvol_with_handle_req *req;
Loading