From: Mykola Golub Date: Fri, 22 Jun 2018 17:50:51 +0000 (+0300) Subject: librbd: fix crash when opening nonexistent snapshot X-Git-Tag: v13.2.1~60^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=a91b6bb3a43d5b6316968d4b89ac9f8b164f269e;p=ceph.git librbd: fix crash when opening nonexistent snapshot Fixes: http://tracker.ceph.com/issues/24637 Signed-off-by: Mykola Golub (cherry picked from commit 70936c3bb5c281eed1c0bb5e26337efdedfa1e06) --- diff --git a/src/librbd/image/OpenRequest.cc b/src/librbd/image/OpenRequest.cc index 26e909f892425..547e59d81c337 100644 --- a/src/librbd/image/OpenRequest.cc +++ b/src/librbd/image/OpenRequest.cc @@ -515,8 +515,9 @@ Context *OpenRequest::send_set_snap(int *result) { m_image_ctx->snap_name); } if (snap_id == CEPH_NOSNAP) { - *result = -ENOENT; - return m_on_finish; + lderr(cct) << "failed to find snapshot " << m_image_ctx->snap_name << dendl; + send_close_image(-ENOENT); + return nullptr; } using klass = OpenRequest; diff --git a/src/test/librbd/test_internal.cc b/src/test/librbd/test_internal.cc index 2952abfeec197..a3f2630c9b1f0 100644 --- a/src/test/librbd/test_internal.cc +++ b/src/test/librbd/test_internal.cc @@ -142,6 +142,14 @@ TEST_F(TestInternal, OpenByID) { close_image(ictx); } +TEST_F(TestInternal, OpenSnapDNE) { + librbd::ImageCtx *ictx; + ASSERT_EQ(0, open_image(m_image_name, &ictx)); + + ictx = new librbd::ImageCtx(m_image_name, "", "unknown_snap", m_ioctx, true); + ASSERT_EQ(-ENOENT, ictx->state->open(true)); +} + TEST_F(TestInternal, IsExclusiveLockOwner) { REQUIRE_FEATURE(RBD_FEATURE_EXCLUSIVE_LOCK);