Commit 49121148 authored by Tomasz Zawadzki's avatar Tomasz Zawadzki Committed by Daniel Verkamp
Browse files

lvol: split spdk_lvol_store_req structure into four separate



To increase readability, union in spdk_lvol_store_req is now split
into four separate structures.

As well spdk_bdev from lvs_basic/spdk_lvs_req was removed as it was
not needed.

Signed-off-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
Change-Id: I65c5155f3d15151a97cf8f8e425b26aa1966b677
Reviewed-on: https://review.gerrithub.io/379169


Reviewed-by: default avatarMaciej Szwed <maciej.szwed@intel.com>
Tested-by: default avatarSPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarDaniel Verkamp <daniel.verkamp@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent f76ec3b4
Loading
Loading
Loading
Loading
+20 −25
Original line number Diff line number Diff line
@@ -40,33 +40,28 @@
/* Length of string returned from uuid_unparse() */
#define UUID_STRING_LEN 37

struct spdk_lvol_store_req {
	union {
		struct {
struct spdk_lvs_req {
	spdk_lvs_op_complete    cb_fn;
	void                    *cb_arg;
			struct spdk_bdev	*base_bdev;
		} lvs_basic;
};

struct spdk_lvol_req {
	spdk_lvol_op_complete    cb_fn;
	void                    *cb_arg;
};

		struct {
struct spdk_lvs_with_handle_req {
	spdk_lvs_op_with_handle_complete cb_fn;
	void				*cb_arg;
	struct spdk_lvol_store		*lvol_store;
	struct spdk_bs_dev		*bs_dev;
	struct spdk_bdev		*base_bdev;
		} lvs_handle;

		struct {
			spdk_lvol_op_complete    cb_fn;
			void                    *cb_arg;
		} lvol_basic;
};

		struct {
struct spdk_lvol_with_handle_req {
	spdk_lvol_op_with_handle_complete cb_fn;
	void				*cb_arg;
	struct spdk_lvol		*lvol;
		} lvol_handle;
	} u;
};

struct spdk_lvol_store {
@@ -74,7 +69,7 @@ struct spdk_lvol_store {
	struct spdk_blob_store		*blobstore;
	uuid_t				uuid;
	uint64_t			page_size;
	struct spdk_lvol_store_req *destruct_req;
	struct spdk_lvs_req		*destruct_req;
	TAILQ_HEAD(, spdk_lvol)		lvols;
};

+25 −26
Original line number Diff line number Diff line
@@ -46,10 +46,10 @@ static TAILQ_HEAD(, lvol_store_bdev) g_spdk_lvol_pairs = TAILQ_HEAD_INITIALIZER(
static void
_vbdev_lvs_create_cb(void *cb_arg, struct spdk_lvol_store *lvs, int lvserrno)
{
	struct spdk_lvol_store_req *req = cb_arg;
	struct spdk_bs_dev *bs_dev = req->u.lvs_handle.bs_dev;
	struct spdk_lvs_with_handle_req *req = cb_arg;
	struct spdk_bs_dev *bs_dev = req->bs_dev;
	struct lvol_store_bdev *lvs_bdev;
	struct spdk_bdev *bdev = req->u.lvs_handle.base_bdev;
	struct spdk_bdev *bdev = req->base_bdev;

	if (lvserrno != 0) {
		assert(lvs == NULL);
@@ -73,7 +73,7 @@ _vbdev_lvs_create_cb(void *cb_arg, struct spdk_lvol_store *lvs, int lvserrno)
	SPDK_INFOLOG(SPDK_TRACE_VBDEV_LVOL, "Lvol store bdev inserted\n");

end:
	req->u.lvs_handle.cb_fn(req->u.lvs_handle.cb_arg, lvs, lvserrno);
	req->cb_fn(req->cb_arg, lvs, lvserrno);
	free(req);

	return;
@@ -85,7 +85,7 @@ vbdev_lvs_create(struct spdk_bdev *base_bdev,
		 void *cb_arg)
{
	struct spdk_bs_dev *bs_dev;
	struct spdk_lvol_store_req *lvs_req;
	struct spdk_lvs_with_handle_req *lvs_req;
	int rc;

	lvs_req = calloc(1, sizeof(*lvs_req));
@@ -101,10 +101,10 @@ vbdev_lvs_create(struct spdk_bdev *base_bdev,
		return -ENODEV;
	}

	lvs_req->u.lvs_handle.bs_dev = bs_dev;
	lvs_req->u.lvs_handle.base_bdev = base_bdev;
	lvs_req->u.lvs_handle.cb_fn = cb_fn;
	lvs_req->u.lvs_handle.cb_arg = cb_arg;
	lvs_req->bs_dev = bs_dev;
	lvs_req->base_bdev = base_bdev;
	lvs_req->cb_fn = cb_fn;
	lvs_req->cb_arg = cb_arg;

	rc = spdk_lvs_init(bs_dev, _vbdev_lvs_create_cb, lvs_req);
	if (rc < 0) {
@@ -119,12 +119,12 @@ vbdev_lvs_create(struct spdk_bdev *base_bdev,
static void
_vbdev_lvs_destruct_cb(void *cb_arg, int lvserrno)
{
	struct spdk_lvol_store_req *req = cb_arg;
	struct spdk_lvs_req *req = cb_arg;

	SPDK_INFOLOG(SPDK_TRACE_VBDEV_LVOL, "Lvol store bdev deleted\n");

	if (req->u.lvs_basic.cb_fn != NULL)
		req->u.lvs_basic.cb_fn(req->u.lvs_basic.cb_arg, lvserrno);
	if (req->cb_fn != NULL)
		req->cb_fn(req->cb_arg, lvserrno);
	free(req);
}

@@ -133,7 +133,7 @@ vbdev_lvs_destruct(struct spdk_lvol_store *lvs, spdk_lvs_op_complete cb_fn,
		   void *cb_arg)
{

	struct spdk_lvol_store_req *req;
	struct spdk_lvs_req *req;
	struct lvol_store_bdev *lvs_bdev;
	struct spdk_lvol *lvol, *tmp;

@@ -142,11 +142,10 @@ vbdev_lvs_destruct(struct spdk_lvol_store *lvs, spdk_lvs_op_complete cb_fn,
		SPDK_ERRLOG("Cannot alloc memory for vbdev lvol store request pointer\n");
		return;
	}
	req->u.lvs_basic.cb_fn = cb_fn;
	req->u.lvs_basic.cb_arg = cb_arg;
	req->cb_fn = cb_fn;
	req->cb_arg = cb_arg;

	lvs_bdev = vbdev_get_lvs_bdev_by_lvs(lvs);
	req->u.lvs_basic.base_bdev = lvs_bdev->bdev;
	TAILQ_REMOVE(&g_spdk_lvol_pairs, lvs_bdev, lvol_stores);

	free(lvs_bdev);
@@ -445,7 +444,7 @@ _create_lvol_disk(struct spdk_lvol *lvol)
static void
_vbdev_lvol_create_cb(void *cb_arg, struct spdk_lvol *lvol, int lvolerrno)
{
	struct spdk_lvol_store_req *req = cb_arg;
	struct spdk_lvol_with_handle_req *req = cb_arg;
	struct spdk_bdev *bdev = NULL;

	if (lvolerrno < 0) {
@@ -460,7 +459,7 @@ _vbdev_lvol_create_cb(void *cb_arg, struct spdk_lvol *lvol, int lvolerrno)
	lvol->bdev = bdev;

end:
	req->u.lvol_handle.cb_fn(req->u.lvol_handle.cb_arg, lvol, lvolerrno);
	req->cb_fn(req->cb_arg, lvol, lvolerrno);
	free(req);
}

@@ -468,7 +467,7 @@ int
vbdev_lvol_create(uuid_t uuid, size_t sz,
		  spdk_lvol_op_with_handle_complete cb_fn, void *cb_arg)
{
	struct spdk_lvol_store_req *req;
	struct spdk_lvol_with_handle_req *req;
	struct spdk_lvol_store *lvs;
	int rc;

@@ -481,8 +480,8 @@ vbdev_lvol_create(uuid_t uuid, size_t sz,
	if (req == NULL) {
		return -ENOMEM;
	}
	req->u.lvol_handle.cb_fn = cb_fn;
	req->u.lvol_handle.cb_arg = cb_arg;
	req->cb_fn = cb_fn;
	req->cb_arg = cb_arg;

	rc = spdk_lvol_create(lvs, sz, _vbdev_lvol_create_cb, req);
	if (rc != 0) {
@@ -495,9 +494,9 @@ vbdev_lvol_create(uuid_t uuid, size_t sz,
static void
_vbdev_lvol_resize_cb(void *cb_arg, int lvolerrno)
{
	struct spdk_lvol_store_req *req = cb_arg;
	struct spdk_lvol_req *req = cb_arg;

	req->u.lvol_basic.cb_fn(req->u.lvol_basic.cb_arg,  lvolerrno);
	req->cb_fn(req->cb_arg,  lvolerrno);
	free(req);
}

@@ -505,7 +504,7 @@ int
vbdev_lvol_resize(char *name, size_t sz,
		  spdk_lvol_op_complete cb_fn, void *cb_arg)
{
	struct spdk_lvol_store_req *req;
	struct spdk_lvol_req *req;
	struct spdk_bdev *bdev;
	struct spdk_lvol *lvol;
	struct spdk_lvol_store *lvs;
@@ -537,8 +536,8 @@ vbdev_lvol_resize(char *name, size_t sz,
		cb_fn(cb_arg, -1);
		return -ENOMEM;
	}
	req->u.lvol_basic.cb_fn = cb_fn;
	req->u.lvol_basic.cb_arg = cb_arg;
	req->cb_fn = cb_fn;
	req->cb_arg = cb_arg;

	rc = spdk_lvol_resize(lvol, sz, _vbdev_lvol_resize_cb, req);

+39 −39
Original line number Diff line number Diff line
@@ -44,8 +44,8 @@ SPDK_LOG_REGISTER_TRACE_FLAG("lvol", SPDK_TRACE_LVOL)
static void
_lvs_init_cb(void *cb_arg, struct spdk_blob_store *bs, int lvserrno)
{
	struct spdk_lvol_store_req *lvs_req = cb_arg;
	struct spdk_lvol_store *lvs = lvs_req->u.lvs_handle.lvol_store;
	struct spdk_lvs_with_handle_req *lvs_req = cb_arg;
	struct spdk_lvol_store *lvs = lvs_req->lvol_store;

	if (lvserrno != 0) {
		assert(bs == NULL);
@@ -60,8 +60,8 @@ _lvs_init_cb(void *cb_arg, struct spdk_blob_store *bs, int lvserrno)

		SPDK_INFOLOG(SPDK_TRACE_LVOL, "Lvol store initialized\n");
	}
	assert(lvs_req->u.lvs_handle.cb_fn != NULL);
	lvs_req->u.lvs_handle.cb_fn(lvs_req->u.lvs_handle.cb_arg, lvs, lvserrno);
	assert(lvs_req->cb_fn != NULL);
	lvs_req->cb_fn(lvs_req->cb_arg, lvs, lvserrno);
	free(lvs_req);
}

@@ -70,7 +70,7 @@ spdk_lvs_init(struct spdk_bs_dev *bs_dev, spdk_lvs_op_with_handle_complete cb_fn
	      void *cb_arg)
{
	struct spdk_lvol_store *lvs;
	struct spdk_lvol_store_req *lvs_req;
	struct spdk_lvs_with_handle_req *lvs_req;

	if (bs_dev == NULL) {
		SPDK_ERRLOG("Blobstore device does not exist\n");
@@ -92,9 +92,9 @@ spdk_lvs_init(struct spdk_bs_dev *bs_dev, spdk_lvs_op_with_handle_complete cb_fn
		return -ENOMEM;
	}

	lvs_req->u.lvs_handle.cb_fn = cb_fn;
	lvs_req->u.lvs_handle.cb_arg = cb_arg;
	lvs_req->u.lvs_handle.lvol_store = lvs;
	lvs_req->cb_fn = cb_fn;
	lvs_req->cb_arg = cb_arg;
	lvs_req->lvol_store = lvs;
	lvs->bs_dev = bs_dev;

	SPDK_INFOLOG(SPDK_TRACE_LVOL, "Initializing lvol store\n");
@@ -106,11 +106,11 @@ spdk_lvs_init(struct spdk_bs_dev *bs_dev, spdk_lvs_op_with_handle_complete cb_fn
static void
_lvs_unload_cb(void *cb_arg, int lvserrno)
{
	struct spdk_lvol_store_req *lvs_req = cb_arg;
	struct spdk_lvs_req *lvs_req = cb_arg;

	SPDK_INFOLOG(SPDK_TRACE_LVOL, "Lvol store unloaded\n");
	assert(lvs_req->u.lvs_basic.cb_fn != NULL);
	lvs_req->u.lvs_basic.cb_fn(lvs_req->u.lvs_basic.cb_arg, lvserrno);
	assert(lvs_req->cb_fn != NULL);
	lvs_req->cb_fn(lvs_req->cb_arg, lvserrno);
	free(lvs_req);
}

@@ -118,7 +118,7 @@ int
spdk_lvs_unload(struct spdk_lvol_store *lvs, spdk_lvs_op_complete cb_fn,
		void *cb_arg)
{
	struct spdk_lvol_store_req *lvs_req;
	struct spdk_lvs_req *lvs_req;

	if (lvs == NULL) {
		SPDK_ERRLOG("Lvol store is NULL\n");
@@ -131,8 +131,8 @@ spdk_lvs_unload(struct spdk_lvol_store *lvs, spdk_lvs_op_complete cb_fn,
		return -ENOMEM;
	}

	lvs_req->u.lvs_basic.cb_fn = cb_fn;
	lvs_req->u.lvs_basic.cb_arg = cb_arg;
	lvs_req->cb_fn = cb_fn;
	lvs_req->cb_arg = cb_arg;

	SPDK_INFOLOG(SPDK_TRACE_LVOL, "Unloading lvol store\n");
	spdk_bs_unload(lvs->blobstore, _lvs_unload_cb, lvs_req);
@@ -144,22 +144,22 @@ spdk_lvs_unload(struct spdk_lvol_store *lvs, spdk_lvs_op_complete cb_fn,
static void
_spdk_lvol_return_to_caller(void *cb_arg, int lvolerrno)
{
	struct spdk_lvol_store_req *req = cb_arg;
	struct spdk_lvol_with_handle_req *req = cb_arg;

	assert(req->u.lvol_handle.cb_fn != NULL);
	req->u.lvol_handle.cb_fn(req->u.lvol_handle.cb_arg, req->u.lvol_handle.lvol, lvolerrno);
	assert(req->cb_fn != NULL);
	req->cb_fn(req->cb_arg, req->lvol, lvolerrno);
	free(req);
}

static void
_spdk_lvs_destruct_cb(void *cb_arg, int lvserrno)
{
	struct spdk_lvol_store_req *req = cb_arg;
	struct spdk_lvs_req *req = cb_arg;

	SPDK_INFOLOG(SPDK_TRACE_LVOL, "Lvol store bdev deleted\n");

	if (req->u.lvs_basic.cb_fn != NULL)
		req->u.lvs_basic.cb_fn(req->u.lvs_basic.cb_arg, lvserrno);
	if (req->cb_fn != NULL)
		req->cb_fn(req->cb_arg, lvserrno);
	free(req);
}

@@ -206,9 +206,9 @@ _spdk_lvol_delete_blob_cb(void *cb_arg, int lvolerrno)
static void
_spdk_lvol_create_open_cb(void *cb_arg, struct spdk_blob *blob, int lvolerrno)
{
	struct spdk_lvol_store_req *req = cb_arg;
	struct spdk_lvol_with_handle_req *req = cb_arg;
	spdk_blob_id blob_id = spdk_blob_get_id(blob);
	struct spdk_lvol *lvol = req->u.lvol_handle.lvol;
	struct spdk_lvol *lvol = req->lvol;
	uint64_t cluster_size = spdk_bs_get_cluster_size(lvol->lvol_store->blobstore);
	uint64_t number_of_clusters = lvol->sz / cluster_size;
	char uuid[UUID_STRING_LEN];
@@ -241,8 +241,8 @@ _spdk_lvol_create_open_cb(void *cb_arg, struct spdk_blob *blob, int lvolerrno)
	return;

invalid:
	assert(req->u.lvol_handle.cb_fn != NULL);
	req->u.lvol_handle.cb_fn(req->u.lvol_handle.cb_arg, NULL, lvolerrno);
	assert(req->cb_fn != NULL);
	req->cb_fn(req->cb_arg, NULL, lvolerrno);
	free(req);
	return;

@@ -251,18 +251,18 @@ invalid:
static void
_spdk_lvol_create_cb(void *cb_arg, spdk_blob_id blobid, int lvolerrno)
{
	struct spdk_lvol_store_req *req = cb_arg;
	struct spdk_lvol_with_handle_req *req = cb_arg;
	struct spdk_blob_store *bs;

	if (lvolerrno < 0) {
		free(req->u.lvol_handle.lvol);
		assert(req->u.lvol_handle.cb_fn != NULL);
		req->u.lvol_handle.cb_fn(req->u.lvol_handle.cb_arg, NULL, lvolerrno);
		free(req->lvol);
		assert(req->cb_fn != NULL);
		req->cb_fn(req->cb_arg, NULL, lvolerrno);
		free(req);
		return;
	}

	bs = req->u.lvol_handle.lvol->lvol_store->blobstore;
	bs = req->lvol->lvol_store->blobstore;

	spdk_bs_md_open_blob(bs, blobid, _spdk_lvol_create_open_cb, req);
}
@@ -271,7 +271,7 @@ int
spdk_lvol_create(struct spdk_lvol_store *lvs, uint64_t sz,
		 spdk_lvol_op_with_handle_complete cb_fn, void *cb_arg)
{
	struct spdk_lvol_store_req *req;
	struct spdk_lvol_with_handle_req *req;
	struct spdk_lvol *lvol;
	uint64_t free_clusters;

@@ -291,8 +291,8 @@ spdk_lvol_create(struct spdk_lvol_store *lvs, uint64_t sz,
		SPDK_ERRLOG("Cannot alloc memory for lvol request pointer\n");
		return -ENOMEM;
	}
	req->u.lvol_handle.cb_fn = cb_fn;
	req->u.lvol_handle.cb_arg = cb_arg;
	req->cb_fn = cb_fn;
	req->cb_arg = cb_arg;

	lvol = calloc(1, sizeof(*lvol));
	if (!lvol) {
@@ -304,7 +304,7 @@ spdk_lvol_create(struct spdk_lvol_store *lvs, uint64_t sz,
	lvol->lvol_store = lvs;
	lvol->sz = sz * spdk_bs_get_cluster_size(lvs->blobstore);
	lvol->close_only = false;
	req->u.lvol_handle.lvol = lvol;
	req->lvol = lvol;

	spdk_bs_md_create_blob(lvs->blobstore, _spdk_lvol_create_cb, req);

@@ -314,9 +314,9 @@ spdk_lvol_create(struct spdk_lvol_store *lvs, uint64_t sz,
static void
_spdk_lvol_resize_cb(void *cb_arg, int lvolerrno)
{
	struct spdk_lvol_store_req *req = cb_arg;
	struct spdk_lvol_req *req = cb_arg;

	req->u.lvol_basic.cb_fn(req->u.lvol_basic.cb_arg,  lvolerrno);
	req->cb_fn(req->cb_arg,  lvolerrno);
	free(req);
}

@@ -327,7 +327,7 @@ spdk_lvol_resize(struct spdk_lvol *lvol, uint64_t sz,
	int rc;
	struct spdk_blob *blob = lvol->blob;
	struct spdk_lvol_store *lvs = lvol->lvol_store;
	struct spdk_lvol_store_req *req;
	struct spdk_lvol_req *req;
	uint64_t cluster_size = spdk_bs_get_cluster_size(lvs->blobstore);
	uint64_t free_clusters = spdk_bs_free_cluster_count(lvs->blobstore);
	uint64_t used_clusters = lvol->sz / cluster_size;
@@ -346,8 +346,8 @@ spdk_lvol_resize(struct spdk_lvol *lvol, uint64_t sz,
		SPDK_ERRLOG("Cannot alloc memory for lvol request pointer\n");
		return -ENOMEM;
	}
	req->u.lvol_basic.cb_fn = cb_fn;
	req->u.lvol_basic.cb_arg = cb_arg;
	req->cb_fn = cb_fn;
	req->cb_arg = cb_arg;

	rc = spdk_bs_md_resize_blob(blob, sz);
	if (rc < 0) {
@@ -363,7 +363,7 @@ spdk_lvol_resize(struct spdk_lvol *lvol, uint64_t sz,
	return rc;

invalid:
	req->u.lvol_basic.cb_fn(req->u.lvol_basic.cb_arg, rc);
	req->cb_fn(req->cb_arg, rc);
	free(req);
	return rc;
}