Commit f5b949d5 authored by Jim Harris's avatar Jim Harris Committed by Tomasz Zawadzki
Browse files

blob: simplify free cluster counting in inflate path



Signed-off-by: default avatarJim Harris <james.r.harris@intel.com>
Change-Id: I5716290476d4abdf8646a36206f07acb5b2dd4ec
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/3967


Community-CI: Mellanox Build Bot
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
parent 2d87587f
Loading
Loading
Loading
Loading
+9 −9
Original line number Diff line number Diff line
@@ -5922,7 +5922,7 @@ static void
bs_inflate_blob_open_cpl(void *cb_arg, struct spdk_blob *_blob, int bserrno)
{
	struct spdk_clone_snapshot_ctx *ctx = (struct spdk_clone_snapshot_ctx *)cb_arg;
	uint64_t lfc; /* lowest free cluster */
	uint64_t clusters_needed;
	uint64_t i;

	if (bserrno != 0) {
@@ -5957,17 +5957,17 @@ bs_inflate_blob_open_cpl(void *cb_arg, struct spdk_blob *_blob, int bserrno)
	/* Do two passes - one to verify that we can obtain enough clusters
	 * and another to actually claim them.
	 */
	lfc = 0;
	clusters_needed = 0;
	for (i = 0; i < _blob->active.num_clusters; i++) {
		if (bs_cluster_needs_allocation(_blob, i, ctx->allocate_all)) {
			lfc = spdk_bit_array_find_first_clear(_blob->bs->used_clusters, lfc);
			if (lfc == UINT32_MAX) {
				/* No more free clusters. Cannot satisfy the request */
				bs_clone_snapshot_origblob_cleanup(ctx, -ENOSPC);
				return;
			clusters_needed++;
		}
			lfc++;
	}

	if (clusters_needed > _blob->bs->num_free_clusters) {
		/* Not enough free clusters. Cannot satisfy the request. */
		bs_clone_snapshot_origblob_cleanup(ctx, -ENOSPC);
		return;
	}

	ctx->cluster = 0;