Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

squid: librbd: make group and group snapshot IDs more random #57092

Merged
merged 1 commit into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/librbd/Utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ librados::AioCompletion *create_rados_callback(Context *on_finish) {
return create_rados_callback<Context, &Context::complete>(on_finish);
}

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

Expand Down
24 changes: 6 additions & 18 deletions src/librbd/api/Group.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,6 @@ snap_t get_group_snap_id(I* ictx,
return CEPH_NOSNAP;
}

string generate_uuid(librados::IoCtx& io_ctx)
{
Rados rados(io_ctx);
uint64_t bid = rados.get_instance_id();

uint32_t extra = rand() % 0xFFFFFFFF;
std::ostringstream bid_ss;
bid_ss << std::hex << bid << std::hex << extra;
return bid_ss.str();
}

int group_snap_list(librados::IoCtx& group_ioctx, const char *group_name,
std::vector<cls::rbd::GroupSnapshot> *cls_snaps)
{
Expand Down Expand Up @@ -523,21 +512,20 @@ int Group<I>::create(librados::IoCtx& io_ctx, const char *group_name)
{
CephContext *cct = (CephContext *)io_ctx.cct();

string id = generate_uuid(io_ctx);

ldout(cct, 2) << "adding group to directory..." << dendl;

std::string group_id = util::generate_image_id(io_ctx);
int r = cls_client::group_dir_add(&io_ctx, RBD_GROUP_DIRECTORY, group_name,
id);
group_id);
if (r < 0) {
lderr(cct) << "error adding group to directory: "
<< cpp_strerror(r)
<< dendl;
return r;
}
string header_oid = util::group_header_name(id);

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

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

string group_header_oid = util::group_header_name(group_id);

group_snap.id = generate_uuid(group_ioctx);
group_snap.id = util::generate_image_id(group_ioctx);
group_snap.name = string(snap_name);
group_snap.state = cls::rbd::GROUP_SNAPSHOT_STATE_INCOMPLETE;
group_snap.snaps = image_snaps;
Expand Down