1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #ifndef RBD_MIRROR_IMAGE_SYNC_SNAPSHOT_COPY_REQUEST_H
5 #define RBD_MIRROR_IMAGE_SYNC_SNAPSHOT_COPY_REQUEST_H
7 #include "include/int_types.h"
8 #include "include/rados/librados.hpp"
9 #include "common/snap_types.h"
10 #include "librbd/ImageCtx.h"
11 #include "librbd/Types.h"
12 #include "librbd/journal/TypeTraits.h"
13 #include "tools/rbd_mirror/BaseRequest.h"
21 namespace journal
{ class Journaler
; }
22 namespace librbd
{ namespace journal
{ struct MirrorPeerClientMeta
; } }
26 namespace image_sync
{
28 template <typename ImageCtxT
= librbd::ImageCtx
>
29 class SnapshotCopyRequest
: public BaseRequest
{
31 typedef librbd::journal::TypeTraits
<ImageCtxT
> TypeTraits
;
32 typedef typename
TypeTraits::Journaler Journaler
;
34 typedef std::vector
<librados::snap_t
> SnapIds
;
35 typedef std::map
<librados::snap_t
, SnapIds
> SnapMap
;
37 static SnapshotCopyRequest
* create(ImageCtxT
*local_image_ctx
,
38 ImageCtxT
*remote_image_ctx
,
39 SnapMap
*snap_map
, Journaler
*journaler
,
40 librbd::journal::MirrorPeerClientMeta
*client_meta
,
41 ContextWQ
*work_queue
,
43 return new SnapshotCopyRequest(local_image_ctx
, remote_image_ctx
,
44 snap_map
, journaler
, client_meta
, work_queue
,
48 SnapshotCopyRequest(ImageCtxT
*local_image_ctx
, ImageCtxT
*remote_image_ctx
,
49 SnapMap
*snap_map
, Journaler
*journaler
,
50 librbd::journal::MirrorPeerClientMeta
*client_meta
,
51 ContextWQ
*work_queue
, Context
*on_finish
);
54 void cancel() override
;
64 * v v | (repeat as needed)
65 * UNPROTECT_SNAP ----/
69 * v v | (repeat as needed)
70 * REMOVE_SNAP -------/
74 * v v | (repeat as needed)
75 * CREATE_SNAP -------/
79 * v v | (repeat as needed)
80 * PROTECT_SNAP ------/
91 typedef std::set
<librados::snap_t
> SnapIdSet
;
92 typedef std::map
<librados::snap_t
, librados::snap_t
> SnapSeqs
;
94 ImageCtxT
*m_local_image_ctx
;
95 ImageCtxT
*m_remote_image_ctx
;
97 Journaler
*m_journaler
;
98 librbd::journal::MirrorPeerClientMeta
*m_client_meta
;
99 ContextWQ
*m_work_queue
;
101 SnapIdSet m_local_snap_ids
;
102 SnapIdSet m_remote_snap_ids
;
103 SnapSeqs m_snap_seqs
;
104 librados::snap_t m_prev_snap_id
= CEPH_NOSNAP
;
106 std::string m_snap_name
;
107 cls::rbd::SnapshotNamespace m_snap_namespace
;
109 librbd::ParentSpec m_local_parent_spec
;
112 bool m_canceled
= false;
114 void send_snap_unprotect();
115 void handle_snap_unprotect(int r
);
117 void send_snap_remove();
118 void handle_snap_remove(int r
);
120 void send_snap_create();
121 void handle_snap_create(int r
);
123 void send_snap_protect();
124 void handle_snap_protect(int r
);
126 void send_update_client();
127 void handle_update_client(int r
);
129 bool handle_cancellation();
133 void compute_snap_map();
135 int validate_parent(ImageCtxT
*image_ctx
, librbd::ParentSpec
*spec
);
139 } // namespace image_sync
140 } // namespace mirror
143 extern template class rbd::mirror::image_sync::SnapshotCopyRequest
<librbd::ImageCtx
>;
145 #endif // RBD_MIRROR_IMAGE_SYNC_SNAPSHOT_COPY_REQUEST_H