Project

General

Profile

Bug #24634

librbd: block_name_prefix is not created randomly

Added by hyun ha about 1 year ago. Updated 11 months ago.

Status:
Resolved
Priority:
Normal
Assignee:
-
Target version:
-
Start date:
06/22/2018
Due date:
% Done:

0%

Source:
Community (user)
Tags:
Backport:
Regression:
No
Severity:
3 - minor
Reviewed:
Affected Versions:
ceph-qa-suite:
Pull request ID:

Description

Hi, I found that block_name_prefix is not crated rondomly.

test env:
ceph --version
ceph version 12.2.5 (cad919881333ac92274171586c827e01f554a70a) luminous (stable)

reproduce step:
  1. create rbd images
    $ for i in `seq 1 5`;do rbd create rbd$i -p volumes --image-format 2 --image-feature layering --size 1G;done
  1. show block_name_prefix
    $ for i in `seq 1 5`;do rbd info volumes/rbd$i|grep block_name_prefix;done
    block_name_prefix: rbd_data.2378974b0dc51
    block_name_prefix: rbd_data.2378b643c9869
    block_name_prefix: rbd_data.2378c74b0dc51
    block_name_prefix: rbd_data.2378d74b0dc51
    block_name_prefix: rbd_data.2378e74b0dc51

I've checked the source code ceph/src/librbd/Utils.cc.

std::string generate_image_id(librados::IoCtx &ioctx) {
librados::Rados rados(ioctx);

uint64_t bid = rados.get_instance_id();
uint32_t extra = rand() % 0xFFFFFFFF; -----> here
ostringstream bid_ss;
bid_ss << std::hex << bid << std::hex << extra;
std::string id = bid_ss.str();
// ensure the image id won't overflow the fixed block name size
if (id.length() > RBD_MAX_IMAGE_ID_LENGTH) {
id = id.substr(id.length() - RBD_MAX_IMAGE_ID_LENGTH);
}
return id;
}

I think if we want to make the value of extra random, we need "srand(time(NULL));" in the source code.
Thanks.

History

#2 Updated by Greg Farnum about 1 year ago

  • Project changed from Ceph to rbd
  • Category deleted (librbd)

#3 Updated by Jason Dillaman 11 months ago

  • Status changed from New to Resolved

Also available in: Atom PDF