From: Jason Dillaman Date: Mon, 8 Oct 2018 14:09:39 +0000 (-0400) Subject: librbd: move remove API method to api namespace X-Git-Tag: v14.0.1~82^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=24d05023ca49cb18fc7ebe8f4685332385ed1cfa;p=ceph.git librbd: move remove API method to api namespace Signed-off-by: Jason Dillaman --- diff --git a/src/librbd/api/Image.cc b/src/librbd/api/Image.cc index bf5ad695db96..2d6fb757e6b1 100644 --- a/src/librbd/api/Image.cc +++ b/src/librbd/api/Image.cc @@ -12,6 +12,7 @@ #include "librbd/ImageState.h" #include "librbd/Utils.h" #include "librbd/image/CloneRequest.h" +#include "librbd/image/RemoveRequest.h" #include "librbd/internal.h" #include "librbd/Utils.h" #include "librbd/api/Config.h" @@ -370,6 +371,27 @@ int Image::snap_set(I *ictx, uint64_t snap_id) { return 0; } +template +int Image::remove(IoCtx& io_ctx, const std::string &image_name, + const std::string &image_id, ProgressContext& prog_ctx, + bool force, bool from_trash_remove) +{ + CephContext *cct((CephContext *)io_ctx.cct()); + ldout(cct, 20) << (image_id.empty() ? image_name : image_id) << dendl; + + ThreadPool *thread_pool; + ContextWQ *op_work_queue; + ImageCtx::get_thread_pool_instance(cct, &thread_pool, &op_work_queue); + + C_SaferCond cond; + auto req = librbd::image::RemoveRequest<>::create( + io_ctx, image_name, image_id, force, from_trash_remove, prog_ctx, + op_work_queue, &cond); + req->send(); + + return cond.wait(); +} + } // namespace api } // namespace librbd diff --git a/src/librbd/api/Image.h b/src/librbd/api/Image.h index 88c15f80c77b..a46104d5226a 100644 --- a/src/librbd/api/Image.h +++ b/src/librbd/api/Image.h @@ -47,6 +47,10 @@ struct Image { const char *snap_name); static int snap_set(ImageCtxT *ictx, uint64_t snap_id); + static int remove(librados::IoCtx& io_ctx, const std::string &image_name, + const std::string &image_id, ProgressContext& prog_ctx, + bool force=false, bool from_trash_remove=false); + }; } // namespace api diff --git a/src/librbd/api/Trash.cc b/src/librbd/api/Trash.cc index 560c5f2a2410..b6f4cafdcf34 100644 --- a/src/librbd/api/Trash.cc +++ b/src/librbd/api/Trash.cc @@ -13,6 +13,7 @@ #include "librbd/Operations.h" #include "librbd/TrashWatcher.h" #include "librbd/Utils.h" +#include "librbd/api/Image.h" #include "librbd/trash/MoveRequest.h" #define dout_subsys ceph_subsys_rbd @@ -209,7 +210,7 @@ int Trash::remove(IoCtx &io_ctx, const std::string &image_id, bool force, return r; } - r = librbd::remove(io_ctx, "", image_id, prog_ctx, false, true); + r = Image::remove(io_ctx, "", image_id, prog_ctx, false, true); if (r < 0) { lderr(cct) << "error removing image " << image_id << ", which is pending deletion" << dendl; diff --git a/src/librbd/internal.cc b/src/librbd/internal.cc index 903a8ce110da..12d8da2f905a 100644 --- a/src/librbd/internal.cc +++ b/src/librbd/internal.cc @@ -38,7 +38,6 @@ #include "librbd/exclusive_lock/StandardPolicy.h" #include "librbd/image/CloneRequest.h" #include "librbd/image/CreateRequest.h" -#include "librbd/image/RemoveRequest.h" #include "librbd/io/AioCompletion.h" #include "librbd/io/ImageRequest.h" #include "librbd/io/ImageRequestWQ.h" @@ -1371,27 +1370,6 @@ bool compare_by_name(const child_info_t& c1, const child_info_t& c2) return 0; } - int remove(IoCtx& io_ctx, const std::string &image_name, - const std::string &image_id, ProgressContext& prog_ctx, - bool force, bool from_trash_remove) - { - CephContext *cct((CephContext *)io_ctx.cct()); - ldout(cct, 20) << "remove " << &io_ctx << " " - << (image_id.empty() ? image_name : image_id) << dendl; - - ThreadPool *thread_pool; - ContextWQ *op_work_queue; - ImageCtx::get_thread_pool_instance(cct, &thread_pool, &op_work_queue); - - C_SaferCond cond; - auto req = librbd::image::RemoveRequest<>::create( - io_ctx, image_name, image_id, force, from_trash_remove, prog_ctx, - op_work_queue, &cond); - req->send(); - - return cond.wait(); - } - int snap_list(ImageCtx *ictx, vector& snaps) { ldout(ictx->cct, 20) << "snap_list " << ictx << dendl; diff --git a/src/librbd/internal.h b/src/librbd/internal.h index 27e7be8f2e2c..abb618d99715 100644 --- a/src/librbd/internal.h +++ b/src/librbd/internal.h @@ -101,10 +101,6 @@ namespace librbd { int lock_break(ImageCtx *ictx, rbd_lock_mode_t lock_mode, const std::string &lock_owner); - int remove(librados::IoCtx& io_ctx, const std::string &image_name, - const std::string &image_id, ProgressContext& prog_ctx, - bool force=false, bool from_trash_remove=false); - int snap_list(ImageCtx *ictx, std::vector& snaps); int snap_exists(ImageCtx *ictx, const cls::rbd::SnapshotNamespace& snap_namespace, const char *snap_name, bool *exists); diff --git a/src/librbd/librbd.cc b/src/librbd/librbd.cc index 5546cefb1054..6e409babc295 100644 --- a/src/librbd/librbd.cc +++ b/src/librbd/librbd.cc @@ -558,7 +558,7 @@ namespace librbd { TracepointProvider::initialize(get_cct(io_ctx)); tracepoint(librbd, remove_enter, io_ctx.get_pool_name().c_str(), io_ctx.get_id(), name); librbd::NoOpProgressContext prog_ctx; - int r = librbd::remove(io_ctx, name, "", prog_ctx); + int r = librbd::api::Image<>::remove(io_ctx, name, "", prog_ctx); tracepoint(librbd, remove_exit, r); return r; } @@ -568,7 +568,7 @@ namespace librbd { { TracepointProvider::initialize(get_cct(io_ctx)); tracepoint(librbd, remove_enter, io_ctx.get_pool_name().c_str(), io_ctx.get_id(), name); - int r = librbd::remove(io_ctx, name, "", pctx); + int r = librbd::api::Image<>::remove(io_ctx, name, "", pctx); tracepoint(librbd, remove_exit, r); return r; } @@ -2805,7 +2805,7 @@ extern "C" int rbd_remove(rados_ioctx_t p, const char *name) TracepointProvider::initialize(get_cct(io_ctx)); tracepoint(librbd, remove_enter, io_ctx.get_pool_name().c_str(), io_ctx.get_id(), name); librbd::NoOpProgressContext prog_ctx; - int r = librbd::remove(io_ctx, name, "", prog_ctx); + int r = librbd::api::Image<>::remove(io_ctx, name, "", prog_ctx); tracepoint(librbd, remove_exit, r); return r; } @@ -2818,7 +2818,7 @@ extern "C" int rbd_remove_with_progress(rados_ioctx_t p, const char *name, TracepointProvider::initialize(get_cct(io_ctx)); tracepoint(librbd, remove_enter, io_ctx.get_pool_name().c_str(), io_ctx.get_id(), name); librbd::CProgressContext prog_ctx(cb, cbdata); - int r = librbd::remove(io_ctx, name, "", prog_ctx); + int r = librbd::api::Image<>::remove(io_ctx, name, "", prog_ctx); tracepoint(librbd, remove_exit, r); return r; } diff --git a/src/test/librbd/image/test_mock_RefreshRequest.cc b/src/test/librbd/image/test_mock_RefreshRequest.cc index ff1cb4921c24..e7a731d6a332 100644 --- a/src/test/librbd/image/test_mock_RefreshRequest.cc +++ b/src/test/librbd/image/test_mock_RefreshRequest.cc @@ -682,7 +682,7 @@ TEST_F(TestMockImageRefreshRequest, SuccessChild) { } librbd::NoOpProgressContext no_op; - ASSERT_EQ(0, librbd::remove(m_ioctx, clone_name, "", no_op)); + ASSERT_EQ(0, librbd::api::Image<>::remove(m_ioctx, clone_name, "", no_op)); ASSERT_EQ(0, ictx->operations->snap_unprotect(cls::rbd::UserSnapshotNamespace(), "snap")); }; @@ -736,7 +736,7 @@ TEST_F(TestMockImageRefreshRequest, SuccessChildDontOpenParent) { } librbd::NoOpProgressContext no_op; - ASSERT_EQ(0, librbd::remove(m_ioctx, clone_name, "", no_op)); + ASSERT_EQ(0, librbd::api::Image<>::remove(m_ioctx, clone_name, "", no_op)); ASSERT_EQ(0, ictx->operations->snap_unprotect(cls::rbd::UserSnapshotNamespace(), "snap")); }; diff --git a/src/test/librbd/test_internal.cc b/src/test/librbd/test_internal.cc index 326c87435a70..c9af08272454 100644 --- a/src/test/librbd/test_internal.cc +++ b/src/test/librbd/test_internal.cc @@ -326,7 +326,7 @@ TEST_F(TestInternal, FlattenFailsToLockImage) { parent->unlock_image(); } librbd::NoOpProgressContext no_op; - ASSERT_EQ(0, librbd::remove(m_ioctx, clone_name, "", no_op)); + ASSERT_EQ(0, librbd::api::Image<>::remove(m_ioctx, clone_name, "", no_op)); } BOOST_SCOPE_EXIT_END; ASSERT_EQ(0, open_image(clone_name, &ictx2)); @@ -890,7 +890,8 @@ TEST_F(TestInternal, WriteFullCopyup) { } librbd::NoOpProgressContext remove_no_op; - ASSERT_EQ(0, librbd::remove(m_ioctx, clone_name, "", remove_no_op)); + ASSERT_EQ(0, librbd::api::Image<>::remove(m_ioctx, clone_name, "", + remove_no_op)); } BOOST_SCOPE_EXIT_END; ASSERT_EQ(0, open_image(clone_name, &ictx2)); @@ -934,7 +935,8 @@ TEST_F(TestInternal, RemoveById) { close_image(ictx); librbd::NoOpProgressContext remove_no_op; - ASSERT_EQ(0, librbd::remove(m_ioctx, "", image_id, remove_no_op)); + ASSERT_EQ(0, librbd::api::Image<>::remove(m_ioctx, "", image_id, + remove_no_op)); } static int iterate_cb(uint64_t off, size_t len, int exists, void *arg) diff --git a/src/test/rbd_mirror/test_ImageDeleter.cc b/src/test/rbd_mirror/test_ImageDeleter.cc index 2b3fd44cd999..d86a8822e711 100644 --- a/src/test/rbd_mirror/test_ImageDeleter.cc +++ b/src/test/rbd_mirror/test_ImageDeleter.cc @@ -112,7 +112,8 @@ public: promote_image(); } NoOpProgressContext ctx; - int r = remove(m_local_io_ctx, m_image_name, "", ctx, force); + int r = librbd::api::Image<>::remove(m_local_io_ctx, m_image_name, "", ctx, + force); EXPECT_EQ(1, r == 0 || r == -ENOENT); }