Skip to content

Commit d5c8530

Browse files
authored
Merge pull request ceph#56987 from idryomov/wip-65573
librbd: make group and group snapshot IDs more random Reviewed-by: N Balachandran <[email protected]> Reviewed-by: Mykola Golub <[email protected]>
2 parents addad6c + 76ed07d commit d5c8530

File tree

2 files changed

+7
-18
lines changed

2 files changed

+7
-18
lines changed

src/librbd/Utils.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ librados::AioCompletion *create_rados_callback(Context *on_finish) {
5959
return create_rados_callback<Context, &Context::complete>(on_finish);
6060
}
6161

62+
// also used for group and group snapshot ids
6263
std::string generate_image_id(librados::IoCtx &ioctx) {
6364
librados::Rados rados(ioctx);
6465

src/librbd/api/Group.cc

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,6 @@ snap_t get_group_snap_id(I* ictx,
5353
return CEPH_NOSNAP;
5454
}
5555

56-
string generate_uuid(librados::IoCtx& io_ctx)
57-
{
58-
Rados rados(io_ctx);
59-
uint64_t bid = rados.get_instance_id();
60-
61-
uint32_t extra = rand() % 0xFFFFFFFF;
62-
std::ostringstream bid_ss;
63-
bid_ss << std::hex << bid << std::hex << extra;
64-
return bid_ss.str();
65-
}
66-
6756
int group_snap_list(librados::IoCtx& group_ioctx, const char *group_name,
6857
std::vector<cls::rbd::GroupSnapshot> *cls_snaps)
6958
{
@@ -523,21 +512,20 @@ int Group<I>::create(librados::IoCtx& io_ctx, const char *group_name)
523512
{
524513
CephContext *cct = (CephContext *)io_ctx.cct();
525514

526-
string id = generate_uuid(io_ctx);
527-
528515
ldout(cct, 2) << "adding group to directory..." << dendl;
529516

517+
std::string group_id = util::generate_image_id(io_ctx);
530518
int r = cls_client::group_dir_add(&io_ctx, RBD_GROUP_DIRECTORY, group_name,
531-
id);
519+
group_id);
532520
if (r < 0) {
533521
lderr(cct) << "error adding group to directory: "
534522
<< cpp_strerror(r)
535523
<< dendl;
536524
return r;
537525
}
538-
string header_oid = util::group_header_name(id);
539526

540-
r = io_ctx.create(header_oid, true);
527+
std::string group_header_oid = util::group_header_name(group_id);
528+
r = io_ctx.create(group_header_oid, true);
541529
if (r < 0) {
542530
lderr(cct) << "error creating group header: " << cpp_strerror(r) << dendl;
543531
goto err_remove_from_dir;
@@ -547,7 +535,7 @@ int Group<I>::create(librados::IoCtx& io_ctx, const char *group_name)
547535

548536
err_remove_from_dir:
549537
int remove_r = cls_client::group_dir_remove(&io_ctx, RBD_GROUP_DIRECTORY,
550-
group_name, id);
538+
group_name, group_id);
551539
if (remove_r < 0) {
552540
lderr(cct) << "error cleaning up group from rbd_directory "
553541
<< "object after creation failed: " << cpp_strerror(remove_r)
@@ -929,7 +917,7 @@ int Group<I>::snap_create(librados::IoCtx& group_ioctx,
929917

930918
string group_header_oid = util::group_header_name(group_id);
931919

932-
group_snap.id = generate_uuid(group_ioctx);
920+
group_snap.id = util::generate_image_id(group_ioctx);
933921
group_snap.name = string(snap_name);
934922
group_snap.state = cls::rbd::GROUP_SNAPSHOT_STATE_INCOMPLETE;
935923
group_snap.snaps = image_snaps;

0 commit comments

Comments
 (0)