blob: make _spdk_bs_allocate_cluster thread safe
Signed-off-by: Maciej Szwed <maciej.szwed@intel.com> Change-Id: I3c7d2096f549a88b4a9884c0026d15d3bcd8dc67 Reviewed-on: https://review.gerrithub.io/396387 Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com> Tested-by: SPDK Automated Test System <sys_sgsw@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
parent
f991492c8d
commit
9103821d3e
@ -91,15 +91,18 @@ static int
|
|||||||
_spdk_bs_allocate_cluster(struct spdk_blob_data *blob, uint32_t cluster_num,
|
_spdk_bs_allocate_cluster(struct spdk_blob_data *blob, uint32_t cluster_num,
|
||||||
uint64_t *lowest_free_cluster, bool update_map)
|
uint64_t *lowest_free_cluster, bool update_map)
|
||||||
{
|
{
|
||||||
|
pthread_mutex_lock(&blob->bs->used_clusters_mutex);
|
||||||
*lowest_free_cluster = spdk_bit_array_find_first_clear(blob->bs->used_clusters,
|
*lowest_free_cluster = spdk_bit_array_find_first_clear(blob->bs->used_clusters,
|
||||||
*lowest_free_cluster);
|
*lowest_free_cluster);
|
||||||
if (*lowest_free_cluster >= blob->bs->total_clusters) {
|
if (*lowest_free_cluster >= blob->bs->total_clusters) {
|
||||||
/* No more free clusters. Cannot satisfy the request */
|
/* No more free clusters. Cannot satisfy the request */
|
||||||
|
pthread_mutex_unlock(&blob->bs->used_clusters_mutex);
|
||||||
return -ENOSPC;
|
return -ENOSPC;
|
||||||
}
|
}
|
||||||
|
|
||||||
SPDK_DEBUGLOG(SPDK_LOG_BLOB, "Claiming cluster %lu for blob %lu\n", *lowest_free_cluster, blob->id);
|
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);
|
_spdk_bs_claim_cluster(blob->bs, *lowest_free_cluster);
|
||||||
|
pthread_mutex_unlock(&blob->bs->used_clusters_mutex);
|
||||||
|
|
||||||
if (update_map) {
|
if (update_map) {
|
||||||
_spdk_blob_insert_cluster(blob, cluster_num, *lowest_free_cluster);
|
_spdk_blob_insert_cluster(blob, cluster_num, *lowest_free_cluster);
|
||||||
@ -117,8 +120,10 @@ _spdk_bs_release_cluster(struct spdk_blob_store *bs, uint32_t cluster_num)
|
|||||||
|
|
||||||
SPDK_DEBUGLOG(SPDK_LOG_BLOB, "Releasing cluster %u\n", cluster_num);
|
SPDK_DEBUGLOG(SPDK_LOG_BLOB, "Releasing cluster %u\n", cluster_num);
|
||||||
|
|
||||||
|
pthread_mutex_lock(&bs->used_clusters_mutex);
|
||||||
spdk_bit_array_clear(bs->used_clusters, cluster_num);
|
spdk_bit_array_clear(bs->used_clusters, cluster_num);
|
||||||
bs->num_free_clusters++;
|
bs->num_free_clusters++;
|
||||||
|
pthread_mutex_unlock(&bs->used_clusters_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -1864,6 +1869,8 @@ _spdk_bs_dev_destroy(void *io_device)
|
|||||||
_spdk_blob_free(blob);
|
_spdk_blob_free(blob);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pthread_mutex_destroy(&bs->used_clusters_mutex);
|
||||||
|
|
||||||
spdk_bit_array_free(&bs->used_blobids);
|
spdk_bit_array_free(&bs->used_blobids);
|
||||||
spdk_bit_array_free(&bs->used_md_pages);
|
spdk_bit_array_free(&bs->used_md_pages);
|
||||||
spdk_bit_array_free(&bs->used_clusters);
|
spdk_bit_array_free(&bs->used_clusters);
|
||||||
@ -1957,11 +1964,14 @@ _spdk_bs_alloc(struct spdk_bs_dev *dev, struct spdk_bs_opts *opts)
|
|||||||
bs->used_md_pages = spdk_bit_array_create(1);
|
bs->used_md_pages = spdk_bit_array_create(1);
|
||||||
bs->used_blobids = spdk_bit_array_create(0);
|
bs->used_blobids = spdk_bit_array_create(0);
|
||||||
|
|
||||||
|
pthread_mutex_init(&bs->used_clusters_mutex, NULL);
|
||||||
|
|
||||||
spdk_io_device_register(bs, _spdk_bs_channel_create, _spdk_bs_channel_destroy,
|
spdk_io_device_register(bs, _spdk_bs_channel_create, _spdk_bs_channel_destroy,
|
||||||
sizeof(struct spdk_bs_channel));
|
sizeof(struct spdk_bs_channel));
|
||||||
rc = spdk_bs_register_md_thread(bs);
|
rc = spdk_bs_register_md_thread(bs);
|
||||||
if (rc == -1) {
|
if (rc == -1) {
|
||||||
spdk_io_device_unregister(bs, NULL);
|
spdk_io_device_unregister(bs, NULL);
|
||||||
|
pthread_mutex_destroy(&bs->used_clusters_mutex);
|
||||||
spdk_bit_array_free(&bs->used_blobids);
|
spdk_bit_array_free(&bs->used_blobids);
|
||||||
spdk_bit_array_free(&bs->used_md_pages);
|
spdk_bit_array_free(&bs->used_md_pages);
|
||||||
spdk_bit_array_free(&bs->used_clusters);
|
spdk_bit_array_free(&bs->used_clusters);
|
||||||
|
@ -161,6 +161,8 @@ struct spdk_blob_store {
|
|||||||
struct spdk_bit_array *used_clusters;
|
struct spdk_bit_array *used_clusters;
|
||||||
struct spdk_bit_array *used_blobids;
|
struct spdk_bit_array *used_blobids;
|
||||||
|
|
||||||
|
pthread_mutex_t used_clusters_mutex;
|
||||||
|
|
||||||
uint32_t cluster_sz;
|
uint32_t cluster_sz;
|
||||||
uint64_t total_clusters;
|
uint64_t total_clusters;
|
||||||
uint64_t total_data_clusters;
|
uint64_t total_data_clusters;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user