From aec7a76e36ab932b7ff3aafd215687af1d228ad3 Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Fri, 26 Jan 2018 13:23:59 -0700 Subject: [PATCH] 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 Change-Id: I26fcca235ea0d7a187b9fe559851290b6db13649 Reviewed-on: https://review.gerrithub.io/396711 Reviewed-by: Ben Walker Reviewed-by: Daniel Verkamp Tested-by: SPDK Automated Test System --- lib/blob/blobstore.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/blob/blobstore.c b/lib/blob/blobstore.c index 38a2685a3..06d6636df 100644 --- a/lib/blob/blobstore.c +++ b/lib/blob/blobstore.c @@ -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; }