Project

General

Profile

Actions

Bug #24634

closed

librbd: block_name_prefix is not created randomly

Added by hyun ha almost 6 years ago. Updated over 5 years ago.

Status:
Resolved
Priority:
Normal
Assignee:
-
Target version:
-
% Done:

0%

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

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.

Actions #2

Updated by Greg Farnum almost 6 years ago

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

Updated by Jason Dillaman over 5 years ago

  • Status changed from New to Resolved
Actions

Also available in: Atom PDF