From 0f4bfd55e71c57ee9d1d9cf6593f656f8ef7606a Mon Sep 17 00:00:00 2001 From: Mike Gerdts Date: Mon, 6 Feb 2023 16:55:50 -0600 Subject: [PATCH] test/blob: test with and without copy offload Perform all tests on devices that do and do not support spdk_bs_dev::copy. Signed-off-by: Mike Gerdts Change-Id: Ic4c13ade9f45709b34a57f9fb7456d6c6a790a85 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/16691 Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Shuhei Matsumoto --- test/unit/lib/blob/blob.c/blob_ut.c | 25 ++++++++++++++++++++++--- test/unit/lib/blob/bs_dev_common.c | 26 ++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/test/unit/lib/blob/blob.c/blob_ut.c b/test/unit/lib/blob/blob.c/blob_ut.c index 721635dad..7f10bf549 100644 --- a/test/unit/lib/blob/blob.c/blob_ut.c +++ b/test/unit/lib/blob/blob.c/blob_ut.c @@ -4580,8 +4580,10 @@ blob_snapshot_rw(void) uint8_t payload_write[10 * 4096]; uint64_t write_bytes_start; uint64_t read_bytes_start; + uint64_t copy_bytes_start; uint64_t write_bytes; uint64_t read_bytes; + uint64_t copy_bytes; free_clusters = spdk_bs_free_cluster_count(bs); cluster_size = spdk_bs_get_cluster_size(bs); @@ -4631,6 +4633,7 @@ blob_snapshot_rw(void) write_bytes_start = g_dev_write_bytes; read_bytes_start = g_dev_read_bytes; + copy_bytes_start = g_dev_copy_bytes; memset(payload_write, 0xAA, sizeof(payload_write)); spdk_blob_io_write(blob, channel, payload_write, 4, 10, blob_op_complete, NULL); @@ -4643,13 +4646,19 @@ blob_snapshot_rw(void) */ write_bytes = g_dev_write_bytes - write_bytes_start; read_bytes = g_dev_read_bytes - read_bytes_start; + copy_bytes = g_dev_copy_bytes - copy_bytes_start; + if (g_dev_copy_enabled) { + CU_ASSERT(copy_bytes == cluster_size); + } else { + CU_ASSERT(copy_bytes == 0); + } if (g_use_extent_table) { /* Add one more page for EXTENT_PAGE write */ - CU_ASSERT(write_bytes == page_size * 12 + cluster_size); + CU_ASSERT(write_bytes + copy_bytes == page_size * 12 + cluster_size); } else { - CU_ASSERT(write_bytes == page_size * 11 + cluster_size); + CU_ASSERT(write_bytes + copy_bytes == page_size * 11 + cluster_size); } - CU_ASSERT(read_bytes == cluster_size); + CU_ASSERT(read_bytes + copy_bytes == cluster_size); spdk_blob_io_read(blob, channel, payload_read, 4, 10, blob_op_complete, NULL); poll_threads(); @@ -7580,6 +7589,16 @@ main(int argc, char **argv) g_dev_buffer = calloc(1, DEV_BUFFER_SIZE); + g_dev_copy_enabled = false; + CU_basic_set_mode(CU_BRM_VERBOSE); + g_use_extent_table = false; + CU_basic_run_tests(); + num_failures = CU_get_number_of_failures(); + g_use_extent_table = true; + CU_basic_run_tests(); + num_failures += CU_get_number_of_failures(); + + g_dev_copy_enabled = true; CU_basic_set_mode(CU_BRM_VERBOSE); g_use_extent_table = false; CU_basic_run_tests(); diff --git a/test/unit/lib/blob/bs_dev_common.c b/test/unit/lib/blob/bs_dev_common.c index e8cff2efe..f241827b6 100644 --- a/test/unit/lib/blob/bs_dev_common.c +++ b/test/unit/lib/blob/bs_dev_common.c @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: BSD-3-Clause * Copyright (C) 2017 Intel Corporation. * All rights reserved. + * Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. */ #include "thread/thread_internal.h" @@ -13,8 +14,10 @@ uint8_t *g_dev_buffer; uint64_t g_dev_write_bytes; uint64_t g_dev_read_bytes; +uint64_t g_dev_copy_bytes; bool g_dev_writev_ext_called; bool g_dev_readv_ext_called; +bool g_dev_copy_enabled; struct spdk_blob_ext_io_opts g_blob_ext_io_opts; struct spdk_power_failure_counters { @@ -372,6 +375,27 @@ dev_write_zeroes(struct spdk_bs_dev *dev, struct spdk_io_channel *channel, spdk_thread_send_msg(spdk_get_thread(), dev_complete, cb_args); } +static bool +dev_translate_lba(struct spdk_bs_dev *dev, uint64_t lba, uint64_t *base_lba) +{ + *base_lba = lba; + return true; +} + +static void +dev_copy(struct spdk_bs_dev *dev, struct spdk_io_channel *channel, uint64_t dst_lba, + uint64_t src_lba, uint64_t lba_count, struct spdk_bs_dev_cb_args *cb_args) +{ + void *dst = &g_dev_buffer[dst_lba * dev->blocklen]; + const void *src = &g_dev_buffer[src_lba * dev->blocklen]; + uint64_t size = lba_count * dev->blocklen; + + memcpy(dst, src, size); + g_dev_copy_bytes += size; + + cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, 0); +} + static struct spdk_bs_dev * init_dev(void) { @@ -391,6 +415,8 @@ init_dev(void) dev->flush = dev_flush; dev->unmap = dev_unmap; dev->write_zeroes = dev_write_zeroes; + dev->translate_lba = dev_translate_lba; + dev->copy = g_dev_copy_enabled ? dev_copy : NULL; dev->blockcnt = DEV_BUFFER_BLOCKCNT; dev->blocklen = DEV_BUFFER_BLOCKLEN;