]> git.proxmox.com Git - ceph.git/blame - ceph/src/tools/rbd_mirror/image_sync/ObjectCopyRequest.h
update sources to 12.2.10
[ceph.git] / ceph / src / tools / rbd_mirror / image_sync / ObjectCopyRequest.h
CommitLineData
7c673cae
FG
1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2// vim: ts=8 sw=2 smarttab
3
4#ifndef RBD_MIRROR_IMAGE_SYNC_OBJECT_COPY_REQUEST_H
5#define RBD_MIRROR_IMAGE_SYNC_OBJECT_COPY_REQUEST_H
6
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 <list>
12#include <map>
13#include <string>
14#include <vector>
15
16class Context;
31f18b77 17class RWLock;
7c673cae
FG
18
19namespace rbd {
20namespace mirror {
21namespace image_sync {
22
23template <typename ImageCtxT = librbd::ImageCtx>
24class ObjectCopyRequest {
25public:
26 typedef std::vector<librados::snap_t> SnapIds;
27 typedef std::map<librados::snap_t, SnapIds> SnapMap;
28
29 static ObjectCopyRequest* create(ImageCtxT *local_image_ctx,
30 ImageCtxT *remote_image_ctx,
31 const SnapMap *snap_map,
32 uint64_t object_number, Context *on_finish) {
33 return new ObjectCopyRequest(local_image_ctx, remote_image_ctx, snap_map,
34 object_number, on_finish);
35 }
36
37 ObjectCopyRequest(ImageCtxT *local_image_ctx, ImageCtxT *remote_image_ctx,
38 const SnapMap *snap_map, uint64_t object_number,
39 Context *on_finish);
40
41 void send();
42
43 // testing support
44 inline librados::IoCtx &get_local_io_ctx() {
45 return m_local_io_ctx;
46 }
47 inline librados::IoCtx &get_remote_io_ctx() {
48 return m_remote_io_ctx;
49 }
50
51private:
52 /**
53 * @verbatim
54 *
55 * <start>
56 * |
57 * v
58 * LIST_SNAPS < * * *
59 * | * (-ENOENT and snap set stale)
60 * | * * * * * *
61 * | *
62 * v *
63 * READ_OBJECT <--------\
64 * | | (repeat for each snapshot)
65 * v |
66 * WRITE_OBJECT --------/
67 * |
68 * | /-----------\
69 * | | | (repeat for each snapshot)
70 * v v |
71 * UPDATE_OBJECT_MAP ---/ (skip if object
72 * | map disabled)
73 * |
74 * v
75 * <finish>
76 *
77 * @endverbatim
78 */
79
80 enum SyncOpType {
81 SYNC_OP_TYPE_WRITE,
82 SYNC_OP_TYPE_TRUNC,
83 SYNC_OP_TYPE_REMOVE
84 };
85
86 typedef std::map<uint64_t, uint64_t> ExtentMap;
87
88 struct SyncOp {
89 SyncOp(SyncOpType type, uint64_t offset, uint64_t length)
90 : type(type), offset(offset), length(length) {
91 }
92
93 SyncOpType type;
94 uint64_t offset;
95 uint64_t length;
96
97 ExtentMap extent_map;
98 bufferlist out_bl;
99 };
100
101 typedef std::list<SyncOp> SyncOps;
102 typedef std::pair<librados::snap_t, librados::snap_t> WriteReadSnapIds;
103 typedef std::map<WriteReadSnapIds, SyncOps> SnapSyncOps;
104 typedef std::map<librados::snap_t, uint8_t> SnapObjectStates;
105 typedef std::map<librados::snap_t, uint64_t> SnapObjectSizes;
106
107 ImageCtxT *m_local_image_ctx;
108 ImageCtxT *m_remote_image_ctx;
109 const SnapMap *m_snap_map;
110 uint64_t m_object_number;
111 Context *m_on_finish;
112
113 decltype(m_local_image_ctx->data_ctx) m_local_io_ctx;
114 decltype(m_remote_image_ctx->data_ctx) m_remote_io_ctx;
115 std::string m_local_oid;
116 std::string m_remote_oid;
117
118 librados::snap_set_t m_snap_set;
119 int m_snap_ret;
120
121 bool m_retry_missing_read = false;
122 librados::snap_set_t m_retry_snap_set;
94b18763 123 std::map<librados::snap_t, bool> m_read_whole_object;
7c673cae
FG
124
125 SnapSyncOps m_snap_sync_ops;
126 SnapObjectStates m_snap_object_states;
127 SnapObjectSizes m_snap_object_sizes;
128
129 void send_list_snaps();
130 void handle_list_snaps(int r);
131
132 void send_read_object();
133 void handle_read_object(int r);
134
135 void send_write_object();
136 void handle_write_object(int r);
137
138 void send_update_object_map();
139 void handle_update_object_map(int r);
140
91327a77 141 Context *start_local_op(RWLock &owner_lock, int *r);
31f18b77 142
7c673cae
FG
143 void compute_diffs();
144 void finish(int r);
145
146};
147
148} // namespace image_sync
149} // namespace mirror
150} // namespace rbd
151
152extern template class rbd::mirror::image_sync::ObjectCopyRequest<librbd::ImageCtx>;
153
154#endif // RBD_MIRROR_IMAGE_SYNC_OBJECT_COPY_REQUEST_H