blob: don't try to claim cluster 0 in recovery code

Thin provisioned blobs mark unallocated clusters with
cluster ID 0.  During recovery from a dirty shutdown,
we must not try to claim cluster 0 - we should ignore
them instead.

Fixes issue #291.

This is a cherry-pick of commit e8ddb060f8 from master.

Change-Id: I83083bba3a2468d68874b485f1fc1e302e46fbd4
Signed-off-by: Jim Harris <james.r.harris@intel.com>
Reviewed-on: https://review.gerrithub.io/410065
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-on: https://review.gerrithub.io/410699
This commit is contained in:
Jim Harris 2018-05-04 01:41:21 -07:00 committed by Daniel Verkamp
parent f1b747f50f
commit 5f59d919a4
2 changed files with 16 additions and 7 deletions

View File

@ -2648,16 +2648,24 @@ _spdk_bs_load_replay_md_parse_page(const struct spdk_blob_md_page *page, struct
struct spdk_blob_md_descriptor_extent *desc_extent;
unsigned int i, j;
unsigned int cluster_count = 0;
uint32_t cluster_idx;
desc_extent = (struct spdk_blob_md_descriptor_extent *)desc;
for (i = 0; i < desc_extent->length / sizeof(desc_extent->extents[0]); i++) {
for (j = 0; j < desc_extent->extents[i].length; j++) {
spdk_bit_array_set(bs->used_clusters, desc_extent->extents[i].cluster_idx + j);
if (bs->num_free_clusters == 0) {
return -1;
cluster_idx = desc_extent->extents[i].cluster_idx;
/*
* cluster_idx = 0 means an unallocated cluster - don't mark that
* in the used cluster map.
*/
if (cluster_idx != 0) {
spdk_bit_array_set(bs->used_clusters, cluster_idx + j);
if (bs->num_free_clusters == 0) {
return -1;
}
bs->num_free_clusters--;
}
bs->num_free_clusters--;
cluster_count++;
}
}

View File

@ -524,9 +524,10 @@ blob_thin_provision(void)
spdk_blob_close(blob, blob_op_complete, NULL);
CU_ASSERT(g_bserrno == 0);
spdk_bs_unload(g_bs, bs_op_complete, NULL);
CU_ASSERT(g_bserrno == 0);
g_bs = NULL;
/* Do not shut down cleanly. This makes sure that when we load again
* and try to recover a valid used_cluster map, that blobstore will
* ignore clusters with index 0 since these are unallocated clusters.
*/
/* Load an existing blob store and check if invalid_flags is set */
dev = init_dev();