From 9ea88fcb72cb0603e546e6994ba49bb4919a2c70 Mon Sep 17 00:00:00 2001 From: Mike Gerdts Date: Tue, 14 Mar 2023 09:45:34 -0500 Subject: [PATCH] blob: refactor parent_id and allocate_all checks The blob's parent_id and allocate_all examined and/or modified in a two places bs_inflate_blob_open_cpl(). This transforms the two if statements scattered around the function into a switch statement to make it easier to understand how these two values are related. Signed-off-by: Mike Gerdts Change-Id: I2cff2d07a0089b52678035b2ece60db6a5f67a8e Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/17178 Reviewed-by: Jim Harris Community-CI: Mellanox Build Bot Reviewed-by: Ben Walker Tested-by: SPDK CI Jenkins --- lib/blob/blobstore.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/lib/blob/blobstore.c b/lib/blob/blobstore.c index 55ecb9cea..c9ec769f0 100644 --- a/lib/blob/blobstore.c +++ b/lib/blob/blobstore.c @@ -6815,20 +6815,16 @@ bs_inflate_blob_open_cpl(void *cb_arg, struct spdk_blob *_blob, int bserrno) _blob->locked_operation_in_progress = true; - if (!ctx->allocate_all && _blob->parent_id == SPDK_BLOBID_INVALID) { - /* This blob have no parent, so we cannot decouple it. */ - SPDK_ERRLOG("Cannot decouple parent of blob with no parent.\n"); - bs_clone_snapshot_origblob_cleanup(ctx, -EINVAL); - return; - } - - if (spdk_blob_is_thin_provisioned(_blob) == false) { - /* This is not thin provisioned blob. No need to inflate. */ - bs_clone_snapshot_origblob_cleanup(ctx, 0); - return; - } - - if (_blob->parent_id == SPDK_BLOBID_EXTERNAL_SNAPSHOT) { + switch (_blob->parent_id) { + case SPDK_BLOBID_INVALID: + if (!ctx->allocate_all) { + /* This blob has no parent, so we cannot decouple it. */ + SPDK_ERRLOG("Cannot decouple parent of blob with no parent.\n"); + bs_clone_snapshot_origblob_cleanup(ctx, -EINVAL); + return; + } + break; + case SPDK_BLOBID_EXTERNAL_SNAPSHOT: /* * It would be better to rely on back_bs_dev->is_zeroes(), to determine which * clusters require allocation. Until there is a blobstore consumer that @@ -6836,6 +6832,15 @@ bs_inflate_blob_open_cpl(void *cb_arg, struct spdk_blob *_blob, int bserrno) * worth the effort. */ ctx->allocate_all = true; + break; + default: + break; + } + + if (spdk_blob_is_thin_provisioned(_blob) == false) { + /* This is not thin provisioned blob. No need to inflate. */ + bs_clone_snapshot_origblob_cleanup(ctx, 0); + return; } /* Do two passes - one to verify that we can obtain enough clusters