From fda5e1e31d7aa96d87e8efdd2e41b11d52d6f6b1 Mon Sep 17 00:00:00 2001 From: Tiago Castro Date: Tue, 12 Dec 2023 19:40:21 +0000 Subject: [PATCH] blobstore: export allocated cluster bitmap for a blob Signed-off-by: Tiago Castro --- include/spdk/blob.h | 12 ++++++++++++ lib/blob/blobstore.c | 25 +++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/include/spdk/blob.h b/include/spdk/blob.h index ef321131c31..e1b50b9b9f5 100644 --- a/include/spdk/blob.h +++ b/include/spdk/blob.h @@ -1180,6 +1180,18 @@ bool spdk_blob_is_degraded(const struct spdk_blob *blob); */ void spdk_blob_reset_used_clusters_cache(struct spdk_blob *blob); +/** + * Get the allocated cluster bitmap of the given blob. + * This functions takes the blob->bs->used_lock spinlock. + * + * \param blob The blob to retrieve allocated bitmap from. + * + * \return NULL if no memory available, otherwise returns a bitmap where each bit corresponds + * to a cluster. A set bit indicates the cluster is owned by the blob. + * Must be freed using spdk_bit_array_free. + */ +struct spdk_bit_array *spdk_blob_get_cluster_bitmap(struct spdk_blob *blob); + #ifdef __cplusplus } #endif diff --git a/lib/blob/blobstore.c b/lib/blob/blobstore.c index 46145de7bbc..df82026b82e 100644 --- a/lib/blob/blobstore.c +++ b/lib/blob/blobstore.c @@ -5985,6 +5985,31 @@ spdk_blob_reset_used_clusters_cache(struct spdk_blob *blob) spdk_spin_unlock(&blob->bs->used_lock); } } + +struct spdk_bit_array * +spdk_blob_get_cluster_bitmap(struct spdk_blob *blob) +{ + struct spdk_bit_array *allocated_bitmap; + uint64_t i; + + spdk_spin_lock(&blob->bs->used_lock); + allocated_bitmap = spdk_bit_array_create(blob->active.num_clusters); + if (allocated_bitmap == NULL) { + SPDK_ERRLOG("Failed to allocate bit array memory for blob #%ld", blob->id); + spdk_spin_unlock(&blob->bs->used_lock); + return NULL; + } + + for (i = 0; i < blob->active.num_clusters; i++) { + if (blob->active.clusters[i]) { + spdk_bit_array_set(allocated_bitmap, i); + } + } + + spdk_spin_unlock(&blob->bs->used_lock); + return allocated_bitmap; +} + /* START spdk_bs_create_blob */ static void