From 73821266d9dcf4dd83266b7cd25fa2dbd5cf4adc Mon Sep 17 00:00:00 2001 From: Ilya Dryomov Date: Fri, 23 Aug 2024 23:00:24 +0200 Subject: [PATCH] rbd: "rbd bench" always writes the same byte It's expected that the buffer is filled with the same byte, but the byte should differ from run to run: memset(bp.c_str(), rand() & 0xff, io_size); This was broken in commit c7f71d14a5d3 ("rbd: migrated existing command logic to new namespaces") which inadvertently moved the call to srand(), leaving rand() unseeded for the above memset(). Fixes: https://tracker.ceph.com/issues/67698 Signed-off-by: Ilya Dryomov (cherry picked from commit 907e53aa8524971e3d969ec519953cdd3d83871f) --- src/tools/rbd/action/Bench.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/tools/rbd/action/Bench.cc b/src/tools/rbd/action/Bench.cc index 061a76d333290..53f2b6410aed0 100644 --- a/src/tools/rbd/action/Bench.cc +++ b/src/tools/rbd/action/Bench.cc @@ -233,6 +233,9 @@ int do_bench(librbd::Image& image, io_type_t io_type, return r; } + // seed rand() before constructing rbd_bencher + srand(time(NULL) % (unsigned long) -1); + rbd_bencher b(&image, io_type, io_size); std::cout << "bench " @@ -261,8 +264,6 @@ int do_bench(librbd::Image& image, io_type_t io_type, } std::cout << std::endl; - srand(time(NULL) % (unsigned long) -1); - coarse_mono_time start = coarse_mono_clock::now(); std::chrono::duration last = std::chrono::duration::zero(); uint64_t ios = 0; -- 2.39.5