From 67c7e85809d370ffa73e8bf8aaaab336db036043 Mon Sep 17 00:00:00 2001 From: Mike Gerdts Date: Thu, 15 Dec 2022 23:35:35 -0600 Subject: [PATCH] blobstore: use common return path in bs_create_blob() A future commit will add to the complexity when returning with a non-zero value. Rather than further complicating the several error return locations, all affected error returns are handled after the error label. Signed-off-by: Mike Gerdts Change-Id: I56e8e338b0560f849399c085d0bb07efb7df26fb Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/15983 Tested-by: SPDK CI Jenkins Reviewed-by: Aleksey Marchuk Reviewed-by: Jim Harris Reviewed-by: Shuhei Matsumoto Community-CI: Mellanox Build Bot --- lib/blob/blobstore.c | 40 ++++++++++++++++------------------------ 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/lib/blob/blobstore.c b/lib/blob/blobstore.c index 7c9c513ea..9b91add42 100644 --- a/lib/blob/blobstore.c +++ b/lib/blob/blobstore.c @@ -5762,10 +5762,8 @@ bs_create_blob(struct spdk_blob_store *bs, blob = blob_alloc(bs, id); if (!blob) { - spdk_bit_array_clear(bs->used_blobids, page_idx); - bs_release_md_page(bs, page_idx); - cb_fn(cb_arg, 0, -ENOMEM); - return; + rc = -ENOMEM; + goto error; } spdk_blob_opts_init(&opts_local, sizeof(opts_local)); @@ -5785,20 +5783,12 @@ bs_create_blob(struct spdk_blob_store *bs, rc = blob_set_xattrs(blob, &opts_local.xattrs, false); if (rc < 0) { - blob_free(blob); - spdk_bit_array_clear(bs->used_blobids, page_idx); - bs_release_md_page(bs, page_idx); - cb_fn(cb_arg, 0, rc); - return; + goto error; } rc = blob_set_xattrs(blob, internal_xattrs, true); if (rc < 0) { - blob_free(blob); - spdk_bit_array_clear(bs->used_blobids, page_idx); - bs_release_md_page(bs, page_idx); - cb_fn(cb_arg, 0, rc); - return; + goto error; } if (opts_local.thin_provision) { @@ -5809,11 +5799,7 @@ bs_create_blob(struct spdk_blob_store *bs, rc = blob_resize(blob, opts_local.num_clusters); if (rc < 0) { - blob_free(blob); - spdk_bit_array_clear(bs->used_blobids, page_idx); - bs_release_md_page(bs, page_idx); - cb_fn(cb_arg, 0, rc); - return; + goto error; } cpl.type = SPDK_BS_CPL_TYPE_BLOBID; cpl.u.blobid.cb_fn = cb_fn; @@ -5822,14 +5808,20 @@ bs_create_blob(struct spdk_blob_store *bs, seq = bs_sequence_start(bs->md_channel, &cpl); if (!seq) { - blob_free(blob); - spdk_bit_array_clear(bs->used_blobids, page_idx); - bs_release_md_page(bs, page_idx); - cb_fn(cb_arg, 0, -ENOMEM); - return; + rc = -ENOMEM; + goto error; } blob_persist(seq, blob, bs_create_blob_cpl, blob); + return; + +error: + if (blob != NULL) { + blob_free(blob); + } + spdk_bit_array_clear(bs->used_blobids, page_idx); + bs_release_md_page(bs, page_idx); + cb_fn(cb_arg, 0, rc); } void