From: Anatoly Scheglov Date: Tue, 9 Apr 2024 22:13:34 +0000 (+0300) Subject: librbd: make librbd::Image moveable X-Git-Tag: v20.0.0~2161^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=36818ed2f75015da5726a354d3684c685606c07c;p=ceph.git librbd: make librbd::Image moveable Adds move constructor and move assignment operator to the librbd::Image. Also marks copy ctor/assign op as deleted, and makes them public for better compiler diagnostics. Signed-off-by: Anatoly Scheglov --- diff --git a/src/include/rbd/librbd.hpp b/src/include/rbd/librbd.hpp index 5d307cdedf50f..6d97d1087adf6 100644 --- a/src/include/rbd/librbd.hpp +++ b/src/include/rbd/librbd.hpp @@ -532,6 +532,14 @@ public: Image(); ~Image(); + // non-copyable + Image(const Image& rhs) = delete; + Image& operator=(const Image& rhs) = delete; + + // moveable + Image(Image&& rhs) noexcept; + Image& operator=(Image&& rhs) noexcept; + int close(); int aio_close(RBD::AioCompletion *c); @@ -854,9 +862,6 @@ public: private: friend class RBD; - Image(const Image& rhs); - const Image& operator=(const Image& rhs); - image_ctx_t ctx; }; diff --git a/src/librbd/librbd.cc b/src/librbd/librbd.cc index 132a0084a9f66..8749a04d2d5ed 100644 --- a/src/librbd/librbd.cc +++ b/src/librbd/librbd.cc @@ -51,6 +51,7 @@ #include "librbd/io/ReadResult.h" #include #include +#include #include #ifdef WITH_LTTNG @@ -1609,6 +1610,17 @@ namespace librbd { close(); } + Image::Image(Image&& rhs) noexcept : ctx{std::exchange(rhs.ctx, nullptr)} + { + } + + Image& Image::operator=(Image&& rhs) noexcept + { + Image tmp(std::move(rhs)); + std::swap(ctx, tmp.ctx); + return *this; + } + int Image::close() { int r = 0;