From 8e612918c204b15daacf6cab05600f4329e66191 Mon Sep 17 00:00:00 2001 From: Mike Gerdts Date: Tue, 14 Mar 2023 14:35:49 -0500 Subject: [PATCH] lvol: allocate lvs before loading it This refactors the code paths that call lvs_load() to allocate the spdk_lvol_store structure before calling lvs_load(). Previously this allocation was done in lvs_load_cb(). This is being done because a later patch requires a pointer to the structure to be passed to lvs_load via the spdk_bs_opts structure. Signed-off-by: Mike Gerdts Change-Id: I2e942d1f7525fa5a16cd34b1b4b3a0a821e13006 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/17220 Tested-by: SPDK CI Jenkins Reviewed-by: Ben Walker Community-CI: Mellanox Build Bot Reviewed-by: Jim Harris --- lib/lvol/lvol.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/lib/lvol/lvol.c b/lib/lvol/lvol.c index 9cf71b15c..2adbaa35e 100644 --- a/lib/lvol/lvol.c +++ b/lib/lvol/lvol.c @@ -371,26 +371,18 @@ static void lvs_load_cb(void *cb_arg, struct spdk_blob_store *bs, int lvolerrno) { struct spdk_lvs_with_handle_req *req = (struct spdk_lvs_with_handle_req *)cb_arg; - struct spdk_lvol_store *lvs; + struct spdk_lvol_store *lvs = req->lvol_store; if (lvolerrno != 0) { req->cb_fn(req->cb_arg, NULL, lvolerrno); + lvs_free(lvs); free(req); return; } - lvs = lvs_alloc(); - if (lvs == NULL) { - SPDK_ERRLOG("Cannot alloc memory for lvol store\n"); - spdk_bs_unload(bs, bs_unload_with_error_cb, req); - return; - } - lvs->blobstore = bs; lvs->bs_dev = req->bs_dev; - req->lvol_store = lvs; - spdk_bs_get_super(bs, lvs_open_super, req); } @@ -422,6 +414,13 @@ spdk_lvs_load(struct spdk_bs_dev *bs_dev, spdk_lvs_op_with_handle_complete cb_fn return; } + req->lvol_store = lvs_alloc(); + if (req->lvol_store == NULL) { + SPDK_ERRLOG("Cannot alloc memory for lvol store\n"); + free(req); + cb_fn(cb_arg, NULL, -ENOMEM); + return; + } req->cb_fn = cb_fn; req->cb_arg = cb_arg; req->bs_dev = bs_dev; @@ -1528,6 +1527,13 @@ spdk_lvs_grow(struct spdk_bs_dev *bs_dev, spdk_lvs_op_with_handle_complete cb_fn return; } + req->lvol_store = lvs_alloc(); + if (req->lvol_store == NULL) { + SPDK_ERRLOG("Cannot alloc memory for lvol store\n"); + free(req); + cb_fn(cb_arg, NULL, -ENOMEM); + return; + } req->cb_fn = cb_fn; req->cb_arg = cb_arg; req->bs_dev = bs_dev;