]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd: "rbd bench" always writes the same byte 59423/head
authorIlya Dryomov <idryomov@gmail.com>
Fri, 23 Aug 2024 21:00:24 +0000 (23:00 +0200)
committerIlya Dryomov <idryomov@gmail.com>
Fri, 23 Aug 2024 21:00:24 +0000 (23:00 +0200)
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 <idryomov@gmail.com>
src/tools/rbd/action/Bench.cc

index 061a76d3332902a9a8310877311c06e3d0e306b7..53f2b6410aed091a0708a84582954e01ca480988 100644 (file)
@@ -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<double> last = std::chrono::duration<double>::zero();
   uint64_t ios = 0;