]> git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/io/CopyupRequest.h
import 14.2.4 nautilus point release
[ceph.git] / ceph / src / librbd / io / CopyupRequest.h
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
7 #include "include/int_types.h"
8 #include "include/rados/librados.hpp"
9 #include "include/buffer.h"
10 #include "common/Mutex.h"
11 #include "common/zipkin_trace.h"
12 #include "librbd/io/AsyncOperation.h"
13 #include "librbd/io/Types.h"
14
15 #include <string>
16 #include <vector>
17
18 namespace ZTracer { struct Trace; }
19
20 namespace librbd {
21
22 struct ImageCtx;
23
24 namespace io {
25
26 template <typename I> class AbstractObjectWriteRequest;
27
28 template <typename ImageCtxT = librbd::ImageCtx>
29 class CopyupRequest {
30 public:
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,
39 Extents &&image_extents, const ZTracer::Trace &parent_trace);
40 ~CopyupRequest();
41
42 void append_request(AbstractObjectWriteRequest<ImageCtxT> *req);
43
44 void send();
45
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 * |
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 * |
69 * v
70 * <finish>
71 *
72 * @endverbatim
73 *
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
76 * no data was read from the parent *and* there are no additional ops.
77 */
78
79 typedef std::vector<AbstractObjectWriteRequest<ImageCtxT> *> WriteRequests;
80
81 ImageCtxT *m_image_ctx;
82 std::string m_oid;
83 uint64_t m_object_no;
84 Extents m_image_extents;
85 ZTracer::Trace m_trace;
86
87 bool m_flatten = false;
88 bool m_copyup_required = true;
89 bool m_copyup_is_zero = true;
90
91 ceph::bufferlist m_copyup_data;
92
93 AsyncOperation m_async_op;
94
95 std::vector<uint64_t> m_snap_ids;
96 bool m_first_snap_is_clean = false;
97
98 Mutex m_lock;
99 WriteRequests m_pending_requests;
100 unsigned m_pending_copyups = 0;
101
102 WriteRequests m_restart_requests;
103 bool m_append_request_permitted = true;
104
105 void read_from_parent();
106 void handle_read_from_parent(int r);
107
108 void deep_copy();
109 void handle_deep_copy(int r);
110
111 void update_object_maps();
112 void handle_update_object_maps(int r);
113
114 void copyup();
115 void handle_copyup(int r);
116
117 void finish(int r);
118 void complete_requests(bool override_restart_retval, int r);
119
120 void disable_append_requests();
121 void remove_from_list();
122
123 bool is_copyup_required();
124 bool is_update_object_map_required(int r);
125 bool is_deep_copy() const;
126
127 void compute_deep_copy_snap_ids();
128 };
129
130 } // namespace io
131 } // namespace librbd
132
133 extern template class librbd::io::CopyupRequest<librbd::ImageCtx>;
134
135 #endif // CEPH_LIBRBD_IO_COPYUP_REQUEST_H