Merge pull request #22675 from nuyhah/fix_block_name_prefix

librbd: block_name_prefix is not created randomly

Reviewed-by: Jason Dillaman <dillaman@redhat.com>
This commit is contained in:
Jason Dillaman 2018-09-11 20:48:23 -04:00 committed by GitHub
commit 722724e829
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,6 +11,7 @@
#include "common/dout.h"
#include "librbd/ImageCtx.h"
#include "librbd/Features.h"
#include <random>
#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<uint32_t> distribution{0, 0xFFFFFFFF};
uint32_t extra = distribution(generator);
ostringstream bid_ss;
bid_ss << std::hex << bid << std::hex << extra;