Skip to content

Commit

Permalink
feat(blobstore/allocated): retrieve blob allocated cluster bitmap
Browse files Browse the repository at this point in the history
Signed-off-by: Tiago Castro <[email protected]>
  • Loading branch information
tiagolobocastro committed Dec 12, 2023
1 parent 2147fce commit dbb89dd
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
11 changes: 11 additions & 0 deletions include/spdk/blob.h
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,17 @@ 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.
*
* \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
Expand Down
22 changes: 22 additions & 0 deletions lib/blob/blobstore.c
Original file line number Diff line number Diff line change
Expand Up @@ -5985,6 +5985,28 @@ 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;

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);
return NULL;
}

for (i = 0; i < blob->active.num_clusters; i++) {
if (blob->active.clusters[i]) {
spdk_bit_array_set(allocated_bitmap, i);
}
}

return allocated_bitmap;
}

/* START spdk_bs_create_blob */

static void
Expand Down

0 comments on commit dbb89dd

Please sign in to comment.