]>
Commit | Line | Data |
---|---|---|
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 CEPH_LIBRBD_IO_COPYUP_REQUEST_H | |
5 | #define CEPH_LIBRBD_IO_COPYUP_REQUEST_H | |
6 | ||
7c673cae FG |
7 | #include "include/int_types.h" |
8 | #include "include/rados/librados.hpp" | |
9 | #include "include/buffer.h" | |
b32b8144 | 10 | #include "common/Mutex.h" |
31f18b77 FG |
11 | #include "common/zipkin_trace.h" |
12 | #include "librbd/io/AsyncOperation.h" | |
7c673cae FG |
13 | #include "librbd/io/Types.h" |
14 | ||
15 | #include <string> | |
16 | #include <vector> | |
7c673cae | 17 | |
31f18b77 FG |
18 | namespace ZTracer { struct Trace; } |
19 | ||
7c673cae FG |
20 | namespace librbd { |
21 | ||
22 | struct ImageCtx; | |
23 | ||
24 | namespace io { | |
25 | ||
b32b8144 | 26 | template <typename I> class AbstractObjectWriteRequest; |
7c673cae | 27 | |
b32b8144 | 28 | template <typename ImageCtxT = librbd::ImageCtx> |
7c673cae FG |
29 | class CopyupRequest { |
30 | public: | |
b32b8144 FG |
31 | static CopyupRequest* create(ImageCtxT *ictx, const std::string &oid, |
32 | uint64_t objectno, Extents &&image_extents, | |
33 | const ZTracer::Trace &parent_trace) { | |
34 | return new CopyupRequest(ictx, oid, objectno, std::move(image_extents), | |
35 | parent_trace); | |
36 | } | |
37 | ||
38 | CopyupRequest(ImageCtxT *ictx, const std::string &oid, uint64_t objectno, | |
31f18b77 | 39 | Extents &&image_extents, const ZTracer::Trace &parent_trace); |
7c673cae FG |
40 | ~CopyupRequest(); |
41 | ||
b32b8144 | 42 | void append_request(AbstractObjectWriteRequest<ImageCtxT> *req); |
7c673cae FG |
43 | |
44 | void send(); | |
45 | ||
7c673cae FG |
46 | private: |
47 | /** | |
48 | * Copyup requests go through the following state machine to read from the | |
49 | * parent image, update the object map, and copyup the object: | |
50 | * | |
51 | * | |
52 | * @verbatim | |
53 | * | |
54 | * <start> | |
55 | * | | |
81eedcae TL |
56 | * /---------/ \---------\ |
57 | * | | | |
58 | * v v | |
59 | * READ_FROM_PARENT DEEP_COPY | |
60 | * | | | |
61 | * \---------\ /---------/ | |
62 | * | | |
63 | * v (skip if not needed) | |
64 | * UPDATE_OBJECT_MAPS | |
65 | * | | |
66 | * v (skip if not needed) | |
67 | * COPYUP | |
68 | * | | |
7c673cae | 69 | * v |
81eedcae | 70 | * <finish> |
7c673cae FG |
71 | * |
72 | * @endverbatim | |
73 | * | |
81eedcae TL |
74 | * The OBJECT_MAP state is skipped if the object map isn't enabled or if |
75 | * an object map update isn't required. The COPYUP state is skipped if | |
7c673cae FG |
76 | * no data was read from the parent *and* there are no additional ops. |
77 | */ | |
81eedcae TL |
78 | |
79 | typedef std::vector<AbstractObjectWriteRequest<ImageCtxT> *> WriteRequests; | |
80 | ||
81 | ImageCtxT *m_image_ctx; | |
7c673cae FG |
82 | std::string m_oid; |
83 | uint64_t m_object_no; | |
84 | Extents m_image_extents; | |
31f18b77 FG |
85 | ZTracer::Trace m_trace; |
86 | ||
81eedcae TL |
87 | bool m_deep_copy = false; |
88 | bool m_flatten = false; | |
89 | bool m_copyup_required = true; | |
90 | ||
7c673cae | 91 | ceph::bufferlist m_copyup_data; |
7c673cae FG |
92 | |
93 | AsyncOperation m_async_op; | |
94 | ||
95 | std::vector<uint64_t> m_snap_ids; | |
7c673cae | 96 | |
b32b8144 | 97 | Mutex m_lock; |
81eedcae TL |
98 | WriteRequests m_pending_requests; |
99 | unsigned m_pending_copyups = 0; | |
100 | ||
101 | WriteRequests m_restart_requests; | |
102 | bool m_append_request_permitted = true; | |
103 | ||
104 | void read_from_parent(); | |
105 | void handle_read_from_parent(int r); | |
b32b8144 | 106 | |
81eedcae TL |
107 | void deep_copy(); |
108 | void handle_deep_copy(int r); | |
7c673cae | 109 | |
81eedcae TL |
110 | void update_object_maps(); |
111 | void handle_update_object_maps(int r); | |
7c673cae | 112 | |
81eedcae TL |
113 | void copyup(); |
114 | void handle_copyup(int r); | |
115 | ||
116 | void finish(int r); | |
117 | void complete_requests(bool override_restart_retval, int r); | |
118 | ||
119 | void disable_append_requests(); | |
7c673cae FG |
120 | void remove_from_list(); |
121 | ||
7c673cae | 122 | bool is_copyup_required(); |
11fdf7f2 TL |
123 | bool is_update_object_map_required(int r); |
124 | bool is_deep_copy() const; | |
81eedcae TL |
125 | |
126 | void compute_deep_copy_snap_ids(); | |
7c673cae FG |
127 | }; |
128 | ||
129 | } // namespace io | |
130 | } // namespace librbd | |
131 | ||
b32b8144 FG |
132 | extern template class librbd::io::CopyupRequest<librbd::ImageCtx>; |
133 | ||
7c673cae | 134 | #endif // CEPH_LIBRBD_IO_COPYUP_REQUEST_H |