Skip to content

Commit b986965

Browse files
authored
Merge pull request ceph#56801 from ascheglov/feature/notask/movable-rbd-image
librbd: make librbd::Image moveable Reviewed-by: Ilya Dryomov <[email protected]>
2 parents d455c06 + 36818ed commit b986965

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

src/include/rbd/librbd.hpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,14 @@ class CEPH_RBD_API Image
532532
Image();
533533
~Image();
534534

535+
// non-copyable
536+
Image(const Image& rhs) = delete;
537+
Image& operator=(const Image& rhs) = delete;
538+
539+
// moveable
540+
Image(Image&& rhs) noexcept;
541+
Image& operator=(Image&& rhs) noexcept;
542+
535543
int close();
536544
int aio_close(RBD::AioCompletion *c);
537545

@@ -854,9 +862,6 @@ class CEPH_RBD_API Image
854862
private:
855863
friend class RBD;
856864

857-
Image(const Image& rhs);
858-
const Image& operator=(const Image& rhs);
859-
860865
image_ctx_t ctx;
861866
};
862867

src/librbd/librbd.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#include "librbd/io/ReadResult.h"
5252
#include <algorithm>
5353
#include <string>
54+
#include <utility>
5455
#include <vector>
5556

5657
#ifdef WITH_LTTNG
@@ -1609,6 +1610,17 @@ namespace librbd {
16091610
close();
16101611
}
16111612

1613+
Image::Image(Image&& rhs) noexcept : ctx{std::exchange(rhs.ctx, nullptr)}
1614+
{
1615+
}
1616+
1617+
Image& Image::operator=(Image&& rhs) noexcept
1618+
{
1619+
Image tmp(std::move(rhs));
1620+
std::swap(ctx, tmp.ctx);
1621+
return *this;
1622+
}
1623+
16121624
int Image::close()
16131625
{
16141626
int r = 0;

0 commit comments

Comments
 (0)