Commit e6d053e7 authored by Jim Harris's avatar Jim Harris
Browse files

lvol: add lvol unique name



Add a name to each lvol which is persisted as a blob
xattr.  lvol names must be unique within its
lvolstore.

While here, fix a few lvol_ut issues that were caught
as part of testing the lvol unique names.  Also fix
a couple of tests that registered the wrong string
name with CUnit.

Signed-off-by: default avatarJim Harris <james.r.harris@intel.com>
Change-Id: I6d24d241e8f52158d14886f928d41823bbc93fa9

Reviewed-on: https://review.gerrithub.io/383567


Tested-by: default avatarSPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: default avatarDaniel Verkamp <daniel.verkamp@intel.com>
parent c6f1d129
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ struct spdk_lvol;

/* Must include null terminator. */
#define SPDK_LVS_NAME_MAX	64
#define SPDK_LVOL_NAME_MAX	64

struct spdk_lvs_opts {
	uint32_t	cluster_sz;
@@ -68,7 +69,7 @@ int spdk_lvs_init(struct spdk_bs_dev *bs_dev, struct spdk_lvs_opts *o,
int spdk_lvs_unload(struct spdk_lvol_store *lvol_store, spdk_lvs_op_complete cb_fn, void *cb_arg);
int spdk_lvs_destroy(struct spdk_lvol_store *lvol_store, bool unmap_device,
		     spdk_lvs_op_complete cb_fn, void *cb_arg);
int spdk_lvol_create(struct spdk_lvol_store *lvs, uint64_t sz,
int spdk_lvol_create(struct spdk_lvol_store *lvs, char *name, uint64_t sz,
		     spdk_lvol_op_with_handle_complete cb_fn, void *cb_arg);
void spdk_lvol_destroy(struct spdk_lvol *lvol, spdk_lvol_op_complete cb_fn, void *cb_arg);
void spdk_lvol_close(struct spdk_lvol *lvol, spdk_lvol_op_complete cb_fn, void *cb_arg);
+1 −0
Original line number Diff line number Diff line
@@ -97,6 +97,7 @@ struct spdk_lvol {
	uint64_t			num_clusters;
	spdk_blob_id			blob_id;
	char				*old_name;
	char				name[SPDK_LVOL_NAME_MAX];
	bool				close_only;
	struct spdk_bdev		*bdev;
	int				ref_count;
+10 −1
Original line number Diff line number Diff line
@@ -574,6 +574,8 @@ vbdev_lvol_create(uuid_t uuid, size_t sz,
{
	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);
@@ -588,7 +590,14 @@ vbdev_lvol_create(uuid_t uuid, size_t sz,
	req->cb_fn = cb_fn;
	req->cb_arg = cb_arg;

	rc = spdk_lvol_create(lvs, sz, _vbdev_lvol_create_cb, req);
	/*
	 * 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);
	}
+28 −2
Original line number Diff line number Diff line
@@ -842,6 +842,13 @@ _spdk_lvol_create_open_cb(void *cb_arg, struct spdk_blob *blob, int lvolerrno)
		goto invalid;
	}

	lvolerrno = spdk_blob_md_set_xattr(blob, "name", lvol->name,
					   strnlen(lvol->name, SPDK_LVOL_NAME_MAX) + 1);
	if (lvolerrno < 0) {
		spdk_bs_md_close_blob(&blob, _spdk_lvol_destroy_cb, lvol);
		goto invalid;
	}

	TAILQ_INSERT_TAIL(&lvol->lvol_store->lvols, lvol, link);

	spdk_bs_md_sync_blob(blob, _spdk_lvol_sync_cb, req);
@@ -874,18 +881,36 @@ _spdk_lvol_create_cb(void *cb_arg, spdk_blob_id blobid, int lvolerrno)
}

int
spdk_lvol_create(struct spdk_lvol_store *lvs, uint64_t sz,
spdk_lvol_create(struct spdk_lvol_store *lvs, char *name, uint64_t sz,
		 spdk_lvol_op_with_handle_complete cb_fn, void *cb_arg)
{
	struct spdk_lvol_with_handle_req *req;
	struct spdk_blob_store *bs;
	struct spdk_lvol *lvol;
	struct spdk_lvol *lvol, *tmp;
	uint64_t num_clusters, free_clusters;

	if (lvs == NULL) {
		SPDK_ERRLOG("lvol store does not exist\n");
		return -ENODEV;
	}

	if (name == NULL || strnlen(name, SPDK_LVS_NAME_MAX) == 0) {
		SPDK_ERRLOG("No name specified.\n");
		return -EINVAL;
	}

	if (strnlen(name, SPDK_LVOL_NAME_MAX) == SPDK_LVOL_NAME_MAX) {
		SPDK_ERRLOG("Name has no null terminator.\n");
		return -EINVAL;
	}

	TAILQ_FOREACH(tmp, &lvs->lvols, link) {
		if (!strncmp(name, tmp->name, SPDK_LVOL_NAME_MAX)) {
			SPDK_ERRLOG("lvol with name %s already exists\n", name);
			return -EINVAL;
		}
	}

	bs = lvs->blobstore;

	num_clusters = divide_round_up(sz, spdk_bs_get_cluster_size(bs));
@@ -914,6 +939,7 @@ spdk_lvol_create(struct spdk_lvol_store *lvs, uint64_t sz,
	lvol->lvol_store = lvs;
	lvol->num_clusters = num_clusters;
	lvol->close_only = false;
	strncpy(lvol->name, name, SPDK_LVS_NAME_MAX);
	req->lvol = lvol;

	spdk_bs_md_create_blob(lvs->blobstore, _spdk_lvol_create_cb, req);
+2 −2
Original line number Diff line number Diff line
@@ -381,8 +381,8 @@ _lvol_create(struct spdk_lvol_store *lvs)
}

int
spdk_lvol_create(struct spdk_lvol_store *lvs, size_t sz, spdk_lvol_op_with_handle_complete cb_fn,
		 void *cb_arg)
spdk_lvol_create(struct spdk_lvol_store *lvs, char *name, size_t sz,
		 spdk_lvol_op_with_handle_complete cb_fn, void *cb_arg)
{
	struct spdk_lvol *lvol;

Loading