From: Ilya Dryomov Date: Fri, 23 Aug 2024 21:00:24 +0000 (+0200) Subject: rbd: "rbd bench" always writes the same byte X-Git-Tag: v20.0.0~1197^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=907e53aa8524971e3d969ec519953cdd3d83871f;p=ceph.git 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 --- 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;