Skip to content

Commit 5952230

Browse files
authored
Merge pull request ceph#55397 from jagombar/fixInvalidSnapId2
librbd: return ENOENT from Snapshot::get_timestamp for nonexistent snap_id Reviewed-by: Ilya Dryomov <[email protected]>
2 parents c8337c6 + 2a2d3d4 commit 5952230

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/librbd/api/Snapshot.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,9 @@ int Snapshot<I>::remove(I *ictx, const char *snap_name, uint32_t flags,
378378
template <typename I>
379379
int Snapshot<I>::get_timestamp(I *ictx, uint64_t snap_id, struct timespec *timestamp) {
380380
auto snap_it = ictx->snap_info.find(snap_id);
381-
ceph_assert(snap_it != ictx->snap_info.end());
381+
if (snap_it == ictx->snap_info.end()) {
382+
return -ENOENT;
383+
}
382384
utime_t time = snap_it->second.timestamp;
383385
time.to_timespec(timestamp);
384386
return 0;

src/test/librbd/test_librbd.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1902,6 +1902,8 @@ TEST_F(TestLibRBD, TestGetSnapShotTimeStamp)
19021902
ASSERT_EQ(0, create_image(ioctx, name.c_str(), size, &order));
19031903
ASSERT_EQ(0, rbd_open(ioctx, name.c_str(), &image, NULL));
19041904

1905+
ASSERT_EQ(-ENOENT, rbd_snap_get_timestamp(image, 0, NULL));
1906+
19051907
ASSERT_EQ(0, rbd_snap_create(image, "snap1"));
19061908
num_snaps = rbd_snap_list(image, snaps, &max_size);
19071909
ASSERT_EQ(1, num_snaps);

0 commit comments

Comments
 (0)