From 8b21bab265572ad2f195fde6d812a70ff7cee3b6 Mon Sep 17 00:00:00 2001 From: Tomasz Zawadzki Date: Fri, 22 Nov 2019 04:11:30 -0500 Subject: [PATCH] ut/blob: test cluster selection using _spdk_bs_allocate_cluster() Previously blob_insert_cluster_msg UT specified the cluster which will be used to store LBA. So for blob the cluster [1], was always stored as cluster 0xF in blobstore. This patch changes _spdk_bs_claim_cluster() with preselected cluster in blobstore to _spdk_bs_allocate_cluster() that will choose first free one in the map. It will help in further patches that add more logic on extent table and extent pages in _spdk_bs_allocate_cluster(). Otherwise this patch 'hard coded' values might get more complex than needed. Signed-off-by: Tomasz Zawadzki Change-Id: I238329b2191e7ebd3f73c1fe85d7e1da0249979e Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/475493 Reviewed-by: Ben Walker Reviewed-by: Jim Harris Tested-by: SPDK CI Jenkins --- test/unit/lib/blob/blob.c/blob_ut.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/test/unit/lib/blob/blob.c/blob_ut.c b/test/unit/lib/blob/blob.c/blob_ut.c index df2c4a132..e23bf1ffe 100644 --- a/test/unit/lib/blob/blob.c/blob_ut.c +++ b/test/unit/lib/blob/blob.c/blob_ut.c @@ -4487,6 +4487,8 @@ blob_insert_cluster_msg(void) struct spdk_blob_opts opts; spdk_blob_id blobid; uint64_t free_clusters; + uint64_t new_cluster = 0; + uint32_t cluster_num = 3; dev = init_dev(); @@ -4517,13 +4519,18 @@ blob_insert_cluster_msg(void) CU_ASSERT(blob->active.num_clusters == 4); CU_ASSERT(spdk_blob_get_num_clusters(blob) == 4); - CU_ASSERT(blob->active.clusters[1] == 0); + CU_ASSERT(blob->active.clusters[cluster_num] == 0); - _spdk_bs_claim_cluster(bs, 0xF); - _spdk_blob_insert_cluster_on_md_thread(blob, 1, 0xF, blob_op_complete, NULL); + /* Specify cluster_num to allocate and new_cluster will be returned to insert on md_thread. + * This is to simulate behaviour when cluster is allocated after blob creation. + * Such as _spdk_bs_allocate_and_copy_cluster(). */ + _spdk_bs_allocate_cluster(blob, cluster_num, &new_cluster, false); + CU_ASSERT(blob->active.clusters[cluster_num] == 0); + + _spdk_blob_insert_cluster_on_md_thread(blob, cluster_num, new_cluster, blob_op_complete, NULL); poll_threads(); - CU_ASSERT(blob->active.clusters[1] != 0); + CU_ASSERT(blob->active.clusters[cluster_num] != 0); spdk_blob_close(blob, blob_op_complete, NULL); poll_threads(); @@ -4552,7 +4559,7 @@ blob_insert_cluster_msg(void) SPDK_CU_ASSERT_FATAL(g_blob != NULL); blob = g_blob; - CU_ASSERT(blob->active.clusters[1] != 0); + CU_ASSERT(blob->active.clusters[cluster_num] != 0); spdk_blob_close(blob, blob_op_complete, NULL); poll_threads();