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