From be8373688c1ba11bcb5e9b17d7a482025dcc9c2d Mon Sep 17 00:00:00 2001 From: hyun-ha Date: Sat, 23 Jun 2018 01:10:20 +0900 Subject: [PATCH] librbd: block_name_prefix is not created randomly fixes: http://tracker.ceph.com/issues/24634 Signed-off-by: hyun ha hyun.ha@navercorp.com --- src/librbd/Utils.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/librbd/Utils.cc b/src/librbd/Utils.cc index d4b4c94914f..a858ddf857c 100644 --- a/src/librbd/Utils.cc +++ b/src/librbd/Utils.cc @@ -11,6 +11,7 @@ #include "common/dout.h" #include "librbd/ImageCtx.h" #include "librbd/Features.h" +#include #define dout_subsys ceph_subsys_rbd #undef dout_prefix @@ -51,7 +52,9 @@ std::string generate_image_id(librados::IoCtx &ioctx) { librados::Rados rados(ioctx); uint64_t bid = rados.get_instance_id(); - uint32_t extra = rand() % 0xFFFFFFFF; + std::mt19937 generator{std::random_device{}()}; + std::uniform_int_distribution distribution{0, 0xFFFFFFFF}; + uint32_t extra = distribution(generator); ostringstream bid_ss; bid_ss << std::hex << bid << std::hex << extra;