Commit 9ea88fcb authored by Mike Gerdts's avatar Mike Gerdts Committed by Jim Harris
Browse files

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: default avatarMike Gerdts <mgerdts@nvidia.com>
Change-Id: I2cff2d07a0089b52678035b2ece60db6a5f67a8e
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/17178


Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Community-CI: Mellanox Build Bot
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
parent ecee2273
Loading
Loading
Loading
Loading
+19 −14
Original line number Diff line number Diff line
@@ -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. */
	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;
		}

	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) {
		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