]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: make librbd::Image moveable 56801/head
authorAnatoly Scheglov <finch@mts.ru>
Tue, 9 Apr 2024 22:13:34 +0000 (01:13 +0300)
committerAnatoly Scheglov <finch@mts.ru>
Thu, 11 Apr 2024 22:52:21 +0000 (01:52 +0300)
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 <finch@mts.ru>
src/include/rbd/librbd.hpp
src/librbd/librbd.cc

index 5d307cdedf50f3d06724e4d30e25f8f63dd29091..6d97d1087adf6fc4cd5063323f0f60111508c92f 100644 (file)
@@ -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;
 };
 
index 132a0084a9f66e8af6759080593f855e8fa24e44..8749a04d2d5edfbd930ea5505795ee5e6c462d04 100644 (file)
@@ -51,6 +51,7 @@
 #include "librbd/io/ReadResult.h"
 #include <algorithm>
 #include <string>
+#include <utility>
 #include <vector>
 
 #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;