From a5fff40be34150700dca6d81b8d649745f5f5d59 Mon Sep 17 00:00:00 2001 From: Venky Shankar Date: Mon, 24 Oct 2016 18:46:42 +0530 Subject: [PATCH] librbd: assert failure when using data pool This fixes a silly assert that's hit during image creation (cli/api) when the data pool specified is same as the pool specified by -p/--pool option (or the default). Signed-off-by: Venky Shankar --- src/librbd/image/CreateRequest.cc | 1 + src/test/librbd/test_librbd.cc | 37 +++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/src/librbd/image/CreateRequest.cc b/src/librbd/image/CreateRequest.cc index fd9e21427b1ed..e0448561b4873 100644 --- a/src/librbd/image/CreateRequest.cc +++ b/src/librbd/image/CreateRequest.cc @@ -190,6 +190,7 @@ CreateRequest::CreateRequest(IoCtx &ioctx, const std::string &image_name, if (!m_data_pool.empty() && m_data_pool != ioctx.get_pool_name()) { m_features |= RBD_FEATURE_DATA_POOL; } else { + m_data_pool.clear(); m_features &= ~RBD_FEATURE_DATA_POOL; } diff --git a/src/test/librbd/test_librbd.cc b/src/test/librbd/test_librbd.cc index 35a1815b98ea4..65598c3e4f2bb 100644 --- a/src/test/librbd/test_librbd.cc +++ b/src/test/librbd/test_librbd.cc @@ -254,6 +254,43 @@ TEST_F(TestLibRBD, CreateAndStat) rados_ioctx_destroy(ioctx); } +TEST_F(TestLibRBD, CreateWithSameDataPool) +{ + REQUIRE_FORMAT_V2(); + + rados_ioctx_t ioctx; + ASSERT_EQ(0, rados_ioctx_create(_cluster, m_pool_name.c_str(), &ioctx)); + + rbd_image_t image; + std::string name = get_temp_image_name(); + uint64_t size = 2 << 20; + + bool old_format; + uint64_t features; + ASSERT_EQ(0, get_features(&old_format, &features)); + ASSERT_FALSE(old_format); + + rbd_image_options_t image_options; + rbd_image_options_create(&image_options); + BOOST_SCOPE_EXIT( (&image_options) ) { + rbd_image_options_destroy(image_options); + } BOOST_SCOPE_EXIT_END; + + ASSERT_EQ(0, rbd_image_options_set_uint64(image_options, + RBD_IMAGE_OPTION_FEATURES, + features)); + ASSERT_EQ(0, rbd_image_options_set_string(image_options, + RBD_IMAGE_OPTION_DATA_POOL, + m_pool_name.c_str())); + + ASSERT_EQ(0, rbd_create4(ioctx, name.c_str(), size, image_options)); + ASSERT_EQ(0, rbd_open(ioctx, name.c_str(), &image, NULL)); + + ASSERT_EQ(0, rbd_close(image)); + + rados_ioctx_destroy(ioctx); +} + TEST_F(TestLibRBD, CreateAndStatPP) { librados::IoCtx ioctx; -- 2.39.5