diff --git a/lib/blob/blobstore.c b/lib/blob/blobstore.c index 9c063fc1b..1bd2843fa 100644 --- a/lib/blob/blobstore.c +++ b/lib/blob/blobstore.c @@ -165,6 +165,10 @@ bs_allocate_cluster(struct spdk_blob *blob, uint32_t cluster_num, if (blob->use_extent_table) { extent_page = bs_cluster_to_extent_page(blob, cluster_num); if (*extent_page == 0) { + /* Extent page shall never occupy md_page so start the search from 1 */ + if (*lowest_free_md_page == 0) { + *lowest_free_md_page = 1; + } /* No extent_page is allocated for the cluster */ *lowest_free_md_page = spdk_bit_array_find_first_clear(blob->bs->used_md_pages, *lowest_free_md_page); diff --git a/test/unit/lib/blob/blob.c/blob_ut.c b/test/unit/lib/blob/blob.c/blob_ut.c index dfcf2a3c2..95c1a5453 100644 --- a/test/unit/lib/blob/blob.c/blob_ut.c +++ b/test/unit/lib/blob/blob.c/blob_ut.c @@ -3769,7 +3769,7 @@ blob_thin_prov_rw(void) { static const uint8_t zero[10 * 4096] = { 0 }; struct spdk_blob_store *bs = g_bs; - struct spdk_blob *blob; + struct spdk_blob *blob, *blob_id0; struct spdk_io_channel *channel, *channel_thread1; struct spdk_blob_opts opts; uint64_t free_clusters; @@ -3788,7 +3788,11 @@ blob_thin_prov_rw(void) ut_spdk_blob_opts_init(&opts); opts.thin_provision = true; + /* Create and delete blob at md page 0, so that next md page allocation + * for extent will use that. */ + blob_id0 = ut_blob_create_and_open(bs, &opts); blob = ut_blob_create_and_open(bs, &opts); + ut_blob_close_and_delete(bs, blob_id0); CU_ASSERT(free_clusters == spdk_bs_free_cluster_count(bs)); CU_ASSERT(blob->active.num_clusters == 0);