Commit aec7a76e authored by Jim Harris's avatar Jim Harris
Browse files

blob: add _spdk_blob_insert_cluster()



This will be used in the upcoming thin provisioning
patches.  A thread the wishes to insert a newly
allocated cluster into the blob will send a message
to the metadata thread to perform to call this
function, and if it succeeds, sync the blob's
metadata.

Signed-off-by: default avatarJim Harris <james.r.harris@intel.com>
Change-Id: I26fcca235ea0d7a187b9fe559851290b6db13649

Reviewed-on: https://review.gerrithub.io/396711


Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarDaniel Verkamp <daniel.verkamp@intel.com>
Tested-by: default avatarSPDK Automated Test System <sys_sgsw@intel.com>
parent dfb102b7
Loading
Loading
Loading
Loading
+16 −1
Original line number Diff line number Diff line
@@ -70,6 +70,21 @@ _spdk_bs_claim_cluster(struct spdk_blob_store *bs, uint32_t cluster_num)
	bs->num_free_clusters--;
}

static int
_spdk_blob_insert_cluster(struct spdk_blob_data *blob, uint32_t cluster_num, uint64_t cluster)
{
	uint64_t *cluster_lba = &blob->active.clusters[cluster_num];

	assert(spdk_get_thread() == blob->bs->md_thread);

	if (*cluster_lba != 0) {
		return -EEXIST;
	}

	*cluster_lba = _spdk_bs_cluster_to_lba(blob->bs, cluster);
	return 0;
}

static int
_spdk_bs_allocate_cluster(struct spdk_blob_data *blob, uint32_t cluster_num,
			  uint64_t *lowest_free_cluster)
@@ -83,7 +98,7 @@ _spdk_bs_allocate_cluster(struct spdk_blob_data *blob, uint32_t cluster_num,

	SPDK_DEBUGLOG(SPDK_LOG_BLOB, "Claiming cluster %lu for blob %lu\n", *lowest_free_cluster, blob->id);
	_spdk_bs_claim_cluster(blob->bs, *lowest_free_cluster);
	blob->active.clusters[cluster_num] = _spdk_bs_cluster_to_lba(blob->bs, *lowest_free_cluster);
	_spdk_blob_insert_cluster(blob, cluster_num, *lowest_free_cluster);

	return 0;
}