Skip to content

Commit 21fe526

Browse files
ronen-frMatan-B
authored andcommitted
osd: use an hex-only format for snap_id when creating snapmapper entries
i.e. - without the optional text representation of NOSNAP & SNAPDIR Signed-off-by: Ronen Friedman <[email protected]> (cherry picked from commit 547b67f) Signed-off-by: Matan Breizman <[email protected]>
1 parent 4e3146c commit 21fe526

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/osd/SnapMapper.cc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,14 @@ int OSDriver::get_next_or_current(
208208
string SnapMapper::get_prefix(int64_t pool, snapid_t snap)
209209
{
210210
static_assert(sizeof(pool) == 8, "assumed by the formatting code");
211+
212+
// note: the snap_id is to be formatted as a 64-bit hex number,
213+
// and not according to the text representation of snapid_t
214+
ceph_assert(snap != CEPH_NOSNAP && snap != CEPH_SNAPDIR);
211215
return fmt::sprintf("%s%lld_%.16X_",
212216
MAPPING_PREFIX,
213217
pool,
214-
snap);
218+
static_cast<uint64_t>(snap));
215219
}
216220

217221
string SnapMapper::to_raw_key(
@@ -729,10 +733,11 @@ int SnapMapper::get_snaps(
729733

730734
string SnapMapper::make_purged_snap_key(int64_t pool, snapid_t last)
731735
{
736+
ceph_assert(last != CEPH_NOSNAP && last != CEPH_SNAPDIR);
732737
return fmt::sprintf("%s_%lld_%016llx",
733738
PURGED_SNAP_PREFIX,
734739
pool,
735-
last);
740+
static_cast<uint64_t>(last));
736741
}
737742

738743
void SnapMapper::make_purged_snap_key_value(
@@ -950,9 +955,10 @@ void SnapMapper::Scrubber::run()
950955

951956
string SnapMapper::get_legacy_prefix(snapid_t snap)
952957
{
958+
ceph_assert(snap != CEPH_NOSNAP && snap != CEPH_SNAPDIR);
953959
return fmt::sprintf("%s%.16X_",
954960
LEGACY_MAPPING_PREFIX,
955-
snap);
961+
static_cast<uint64_t>(snap));
956962
}
957963

958964
string SnapMapper::to_legacy_raw_key(

0 commit comments

Comments
 (0)