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: Jim Harris <james.r.harris@intel.com>
Change-Id: I26fcca235ea0d7a187b9fe559851290b6db13649

Reviewed-on: https://review.gerrithub.io/396711
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
This commit is contained in:
Jim Harris 2018-01-26 13:23:59 -07:00
parent dfb102b79a
commit aec7a76e36

View File

@ -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;
}