]> git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/io/CopyupRequest.h
add subtree-ish sources for 12.0.3
[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 "librbd/AsyncOperation.h"
8 #include "include/int_types.h"
9 #include "include/rados/librados.hpp"
10 #include "include/buffer.h"
11 #include "librbd/io/Types.h"
12
13 #include <string>
14 #include <vector>
15 #include <atomic>
16
17 namespace librbd {
18
19 struct ImageCtx;
20
21 namespace io {
22
23 struct AioCompletion;
24 template <typename I> class ObjectRequest;
25
26 class CopyupRequest {
27 public:
28 CopyupRequest(ImageCtx *ictx, const std::string &oid, uint64_t objectno,
29 Extents &&image_extents);
30 ~CopyupRequest();
31
32 void append_request(ObjectRequest<ImageCtx> *req);
33
34 void send();
35
36 void complete(int r);
37
38 private:
39 /**
40 * Copyup requests go through the following state machine to read from the
41 * parent image, update the object map, and copyup the object:
42 *
43 *
44 * @verbatim
45 *
46 * <start>
47 * |
48 * v
49 * . . .STATE_READ_FROM_PARENT. . .
50 * . . | .
51 * . . v .
52 * . . STATE_OBJECT_MAP_HEAD v (copy on read /
53 * . . | . no HEAD rev. update)
54 * v v v .
55 * . . STATE_OBJECT_MAP. . . . .
56 * . . |
57 * . . v
58 * . . . . > STATE_COPYUP
59 * . |
60 * . v
61 * . . . . > <finish>
62 *
63 * @endverbatim
64 *
65 * The _OBJECT_MAP state is skipped if the object map isn't enabled or if
66 * an object map update isn't required. The _COPYUP state is skipped if
67 * no data was read from the parent *and* there are no additional ops.
68 */
69 enum State {
70 STATE_READ_FROM_PARENT,
71 STATE_OBJECT_MAP_HEAD, // only update the HEAD revision
72 STATE_OBJECT_MAP, // update HEAD+snaps (if any)
73 STATE_COPYUP
74 };
75
76 ImageCtx *m_ictx;
77 std::string m_oid;
78 uint64_t m_object_no;
79 Extents m_image_extents;
80 State m_state;
81 ceph::bufferlist m_copyup_data;
82 std::vector<ObjectRequest<ImageCtx> *> m_pending_requests;
83 std::atomic<unsigned> m_pending_copyups { 0 };
84
85 AsyncOperation m_async_op;
86
87 std::vector<uint64_t> m_snap_ids;
88 librados::IoCtx m_data_ctx; // for empty SnapContext
89
90 void complete_requests(int r);
91
92 bool should_complete(int r);
93
94 void remove_from_list();
95
96 bool send_object_map_head();
97 bool send_object_map();
98 bool send_copyup();
99 bool is_copyup_required();
100 };
101
102 } // namespace io
103 } // namespace librbd
104
105 #endif // CEPH_LIBRBD_IO_COPYUP_REQUEST_H