Commit 1390df9e authored by Jim Harris's avatar Jim Harris Committed by Konrad Sztyber
Browse files

test/unit/blob: do not make assumptions about first data cluster



A bunch of blobstore unit tests make assumptions that the first
data cluster is cluster index 1 (meaning cluster index 0 contains
all of the metadata).

But to support variable metadata page sizes, this assumption is no
longer valid. For example, with 16KB metadata page sizes, the
metadata will take up more than 1 cluster.

So improve the unit tests to remove assumptions in this area.

Signed-off-by: default avatarJim Harris <jim.harris@samsung.com>
Change-Id: If5112b8bcb7124cadc292dd1fde466cbf3d91cd4
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/25314


Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Reviewed-by: default avatarBen Walker <ben@nvidia.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Community-CI: Community CI Samsung <spdk.community.ci.samsung@gmail.com>
Community-CI: Mellanox Build Bot
parent 1b0a702c
Loading
Loading
Loading
Loading
+31 −23
Original line number Diff line number Diff line
@@ -1576,6 +1576,7 @@ blob_rw_verify_iov(void)
	struct iovec iov_read[3];
	struct iovec iov_write[3];
	void *buf;
	uint32_t first_data_cluster = FIRST_DATA_CLUSTER(bs);

	channel = spdk_bs_alloc_io_channel(bs);
	CU_ASSERT(channel != NULL);
@@ -1592,9 +1593,9 @@ blob_rw_verify_iov(void)
	 *  that cross cluster boundaries.  Start by asserting that the allocated
	 *  clusters are where we expect before modifying the second cluster.
	 */
	CU_ASSERT(blob->active.clusters[0] == 1 * 256);
	CU_ASSERT(blob->active.clusters[1] == 2 * 256);
	blob->active.clusters[1] = 3 * 256;
	CU_ASSERT(blob->active.clusters[0] == first_data_cluster * 256);
	CU_ASSERT(blob->active.clusters[1] == (first_data_cluster + 1) * 256);
	blob->active.clusters[1] = (first_data_cluster + 2) * 256;

	memset(payload_write, 0xE5, sizeof(payload_write));
	iov_write[0].iov_base = payload_write;
@@ -1626,7 +1627,8 @@ blob_rw_verify_iov(void)
	buf = calloc(1, 256 * BLOCKLEN);
	SPDK_CU_ASSERT_FATAL(buf != NULL);
	/* Check that cluster 2 on "disk" was not modified. */
	CU_ASSERT(memcmp(buf, &g_dev_buffer[512 * BLOCKLEN], 256 * BLOCKLEN) == 0);
	CU_ASSERT(memcmp(buf, &g_dev_buffer[(first_data_cluster + 1) * 256 * BLOCKLEN],
			 256 * BLOCKLEN) == 0);
	free(buf);

	spdk_blob_close(blob, blob_op_complete, NULL);
@@ -2085,6 +2087,7 @@ blob_unmap(void)
	struct spdk_io_channel *channel;
	struct spdk_blob_opts opts;
	uint8_t payload[BLOCKLEN];
	uint32_t first_data_cluster = FIRST_DATA_CLUSTER(bs);
	int i;

	channel = spdk_bs_alloc_io_channel(bs);
@@ -2105,10 +2108,9 @@ blob_unmap(void)

	/*
	 * Set first byte of every cluster to 0xFF.
	 * First cluster on device is reserved so let's start from cluster number 1
	 */
	for (i = 1; i < 11; i++) {
		g_dev_buffer[i * SPDK_BLOB_OPTS_CLUSTER_SZ] = 0xFF;
	for (i = 0; i < 10; i++) {
		g_dev_buffer[(first_data_cluster + i) * SPDK_BLOB_OPTS_CLUSTER_SZ] = 0xFF;
	}

	/* Confirm writes */
@@ -2140,17 +2142,17 @@ blob_unmap(void)
	CU_ASSERT(spdk_blob_get_num_allocated_clusters(blob) == 0);

	/* Confirm that only 'allocated' clusters were unmapped */
	for (i = 1; i < 11; i++) {
	for (i = 0; i < 10; i++) {
		switch (i) {
		case 1:
		case 2:
		case 3:
		case 4:
		case 7:
		case 9:
			CU_ASSERT(g_dev_buffer[i * SPDK_BLOB_OPTS_CLUSTER_SZ] == 0xFF);
		case 6:
		case 8:
			CU_ASSERT(g_dev_buffer[(first_data_cluster + i) * SPDK_BLOB_OPTS_CLUSTER_SZ] == 0xFF);
			break;
		default:
			CU_ASSERT(g_dev_buffer[i * SPDK_BLOB_OPTS_CLUSTER_SZ] == 0);
			CU_ASSERT(g_dev_buffer[(first_data_cluster + i) * SPDK_BLOB_OPTS_CLUSTER_SZ] == 0);
			break;
		}
	}
@@ -6602,6 +6604,7 @@ blob_delete_snapshot_power_failure(void)
	int rc;
	bool deleted = false;
	int delete_snapshot_bserrno = -1;
	uint32_t first_data_cluster;

	thresholds.general_threshold = 1;
	while (!deleted) {
@@ -6613,6 +6616,8 @@ blob_delete_snapshot_power_failure(void)
		SPDK_CU_ASSERT_FATAL(g_bs != NULL);
		bs = g_bs;

		first_data_cluster = FIRST_DATA_CLUSTER(bs);

		/* Create blob */
		ut_spdk_blob_opts_init(&opts);
		opts.num_clusters = 10;
@@ -6629,8 +6634,8 @@ blob_delete_snapshot_power_failure(void)
		CU_ASSERT(g_bserrno == 0);
		CU_ASSERT(g_blobid != SPDK_BLOBID_INVALID);
		snapshotid = g_blobid;
		SPDK_CU_ASSERT_FATAL(spdk_bit_pool_is_allocated(bs->used_clusters, 1));
		SPDK_CU_ASSERT_FATAL(!spdk_bit_pool_is_allocated(bs->used_clusters, 11));
		SPDK_CU_ASSERT_FATAL(spdk_bit_pool_is_allocated(bs->used_clusters, first_data_cluster));
		SPDK_CU_ASSERT_FATAL(!spdk_bit_pool_is_allocated(bs->used_clusters, first_data_cluster + 10));

		dev_set_power_failure_thresholds(thresholds);

@@ -6643,8 +6648,8 @@ blob_delete_snapshot_power_failure(void)
		dev_reset_power_failure_event();
		ut_bs_dirty_load(&bs, NULL);

		SPDK_CU_ASSERT_FATAL(spdk_bit_pool_is_allocated(bs->used_clusters, 1));
		SPDK_CU_ASSERT_FATAL(!spdk_bit_pool_is_allocated(bs->used_clusters, 11));
		SPDK_CU_ASSERT_FATAL(spdk_bit_pool_is_allocated(bs->used_clusters, first_data_cluster));
		SPDK_CU_ASSERT_FATAL(!spdk_bit_pool_is_allocated(bs->used_clusters, first_data_cluster + 10));

		spdk_bs_open_blob(bs, blobid, blob_op_with_handle_complete, NULL);
		poll_threads();
@@ -6713,6 +6718,7 @@ blob_create_snapshot_power_failure(void)
	int rc;
	bool created = false;
	int create_snapshot_bserrno = -1;
	uint32_t first_data_cluster;

	thresholds.general_threshold = 1;
	while (!created) {
@@ -6724,6 +6730,8 @@ blob_create_snapshot_power_failure(void)
		SPDK_CU_ASSERT_FATAL(g_bs != NULL);
		bs = g_bs;

		first_data_cluster = FIRST_DATA_CLUSTER(bs);

		/* Create blob */
		ut_spdk_blob_opts_init(&opts);
		opts.num_clusters = 10;
@@ -6733,8 +6741,8 @@ blob_create_snapshot_power_failure(void)
		CU_ASSERT(g_bserrno == 0);
		CU_ASSERT(g_blobid != SPDK_BLOBID_INVALID);
		blobid = g_blobid;
		SPDK_CU_ASSERT_FATAL(spdk_bit_pool_is_allocated(bs->used_clusters, 1));
		SPDK_CU_ASSERT_FATAL(!spdk_bit_pool_is_allocated(bs->used_clusters, 11));
		SPDK_CU_ASSERT_FATAL(spdk_bit_pool_is_allocated(bs->used_clusters, first_data_cluster));
		SPDK_CU_ASSERT_FATAL(!spdk_bit_pool_is_allocated(bs->used_clusters, first_data_cluster + 10));

		dev_set_power_failure_thresholds(thresholds);

@@ -6743,16 +6751,16 @@ blob_create_snapshot_power_failure(void)
		poll_threads();
		create_snapshot_bserrno = g_bserrno;
		snapshotid = g_blobid;
		SPDK_CU_ASSERT_FATAL(spdk_bit_pool_is_allocated(bs->used_clusters, 1));
		SPDK_CU_ASSERT_FATAL(!spdk_bit_pool_is_allocated(bs->used_clusters, 11));
		SPDK_CU_ASSERT_FATAL(spdk_bit_pool_is_allocated(bs->used_clusters, first_data_cluster));
		SPDK_CU_ASSERT_FATAL(!spdk_bit_pool_is_allocated(bs->used_clusters, first_data_cluster + 10));

		/* Do not shut down cleanly. Assumption is that after create snapshot
		 * reports success, both blobs should be power-fail safe. */
		dev_reset_power_failure_event();
		ut_bs_dirty_load(&bs, NULL);

		SPDK_CU_ASSERT_FATAL(spdk_bit_pool_is_allocated(bs->used_clusters, 1));
		SPDK_CU_ASSERT_FATAL(!spdk_bit_pool_is_allocated(bs->used_clusters, 11));
		SPDK_CU_ASSERT_FATAL(spdk_bit_pool_is_allocated(bs->used_clusters, first_data_cluster));
		SPDK_CU_ASSERT_FATAL(!spdk_bit_pool_is_allocated(bs->used_clusters, first_data_cluster + 10));

		spdk_bs_open_blob(bs, blobid, blob_op_with_handle_complete, NULL);
		poll_threads();
+3 −0
Original line number Diff line number Diff line
@@ -12,6 +12,9 @@
#define DEV_BUFFER_BLOCKLEN (4096)
#define DEV_BUFFER_BLOCKCNT (DEV_BUFFER_SIZE / DEV_BUFFER_BLOCKLEN)
#define DEV_MAX_PHYS_BLOCKLEN (16384)
#define FIRST_DATA_CLUSTER(bs) \
	((DEV_BUFFER_SIZE / spdk_bs_get_cluster_size(bs)) - spdk_bs_total_data_cluster_count(bs))

uint8_t *g_dev_buffer;
uint64_t g_dev_write_bytes;
uint64_t g_dev_read_bytes;