From c9268075aba0b3974997c7ba8a14fd6e8ba307f1 Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Thu, 19 Aug 2021 03:02:06 -0700 Subject: [PATCH] bdevperf: use uint64_t to save per-job length When specifying -C for multithread mode, we calculate a 'blocks_per_job' to tell each core what subset of the bdev it should target with I/O. But this blocks_per_job, and the config->length member that it gets copied to, were ints. For devices with num blocks > INT32_MAX, this can cause overflow if the num blocks is also < UINT32_MAX (because then we end up storing a negative value in the bdevperf's length field). For sequential workloads, it may take a long time until it happens, but for random workloads it fails almost immediately. Fixes issue #2108. Signed-off-by: Jim Harris Change-Id: I6c2b787ab5d3c6bfe12efd183ce86d4d95f9b6c6 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/9231 Reviewed-by: Ben Walker Reviewed-by: Paul Luse Reviewed-by: Shuhei Matsumoto Reviewed-by: Aleksey Marchuk Reviewed-by: Ziye Yang Reviewed-by: Dong Yi Community-CI: Broadcom CI Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins --- test/bdev/bdevperf/bdevperf.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/test/bdev/bdevperf/bdevperf.c b/test/bdev/bdevperf/bdevperf.c index c07d7b684..96d357bef 100644 --- a/test/bdev/bdevperf/bdevperf.c +++ b/test/bdev/bdevperf/bdevperf.c @@ -175,7 +175,7 @@ struct job_config { int iodepth; int rwmixread; int64_t offset; - int length; + uint64_t length; enum job_config_rw rw; TAILQ_ENTRY(job_config) link; }; @@ -1486,7 +1486,7 @@ bdevperf_construct_config_jobs(void) } static int -make_cli_job_config(const char *filename, int64_t offset, int range) +make_cli_job_config(const char *filename, int64_t offset, uint64_t range) { struct job_config *config = calloc(1, sizeof(*config)); @@ -1519,7 +1519,7 @@ bdevperf_construct_multithread_jobs(void) struct spdk_bdev *bdev; uint32_t i; uint32_t num_cores; - uint32_t blocks_per_job; + uint64_t blocks_per_job; int64_t offset; num_cores = 0; @@ -1698,6 +1698,7 @@ read_job_config(void) const char *rw; bool is_global; int n = 0; + int val; if (g_bdevperf_conf_file == NULL) { return 0; @@ -1813,10 +1814,11 @@ read_job_config(void) goto error; } - config->length = parse_uint_option(s, "length", global_config.length); - if (config->length == BDEVPERF_CONFIG_ERROR) { + val = parse_uint_option(s, "length", global_config.length); + if (val == BDEVPERF_CONFIG_ERROR) { goto error; } + config->length = val; rw = spdk_conf_section_get_val(s, "rw"); config->rw = parse_rw(rw, global_config.rw);