]> git.proxmox.com Git - ceph.git/blame - ceph/src/librbd/io/CopyupRequest.h
update sources to v12.2.3
[ceph.git] / ceph / src / librbd / io / CopyupRequest.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 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>
17#include <atomic>
18
31f18b77
FG
19namespace ZTracer { struct Trace; }
20
7c673cae
FG
21namespace librbd {
22
23struct ImageCtx;
24
25namespace io {
26
27struct AioCompletion;
b32b8144 28template <typename I> class AbstractObjectWriteRequest;
7c673cae 29
b32b8144 30template <typename ImageCtxT = librbd::ImageCtx>
7c673cae
FG
31class CopyupRequest {
32public:
b32b8144
FG
33 static CopyupRequest* create(ImageCtxT *ictx, const std::string &oid,
34 uint64_t objectno, Extents &&image_extents,
35 const ZTracer::Trace &parent_trace) {
36 return new CopyupRequest(ictx, oid, objectno, std::move(image_extents),
37 parent_trace);
38 }
39
40 CopyupRequest(ImageCtxT *ictx, const std::string &oid, uint64_t objectno,
31f18b77 41 Extents &&image_extents, const ZTracer::Trace &parent_trace);
7c673cae
FG
42 ~CopyupRequest();
43
b32b8144 44 void append_request(AbstractObjectWriteRequest<ImageCtxT> *req);
7c673cae
FG
45
46 void send();
47
48 void complete(int r);
49
50private:
51 /**
52 * Copyup requests go through the following state machine to read from the
53 * parent image, update the object map, and copyup the object:
54 *
55 *
56 * @verbatim
57 *
58 * <start>
59 * |
60 * v
61 * . . .STATE_READ_FROM_PARENT. . .
62 * . . | .
63 * . . v .
64 * . . STATE_OBJECT_MAP_HEAD v (copy on read /
65 * . . | . no HEAD rev. update)
66 * v v v .
67 * . . STATE_OBJECT_MAP. . . . .
68 * . . |
69 * . . v
70 * . . . . > STATE_COPYUP
71 * . |
72 * . v
73 * . . . . > <finish>
74 *
75 * @endverbatim
76 *
77 * The _OBJECT_MAP state is skipped if the object map isn't enabled or if
78 * an object map update isn't required. The _COPYUP state is skipped if
79 * no data was read from the parent *and* there are no additional ops.
80 */
81 enum State {
82 STATE_READ_FROM_PARENT,
83 STATE_OBJECT_MAP_HEAD, // only update the HEAD revision
84 STATE_OBJECT_MAP, // update HEAD+snaps (if any)
85 STATE_COPYUP
86 };
87
88 ImageCtx *m_ictx;
89 std::string m_oid;
90 uint64_t m_object_no;
91 Extents m_image_extents;
31f18b77
FG
92 ZTracer::Trace m_trace;
93
7c673cae
FG
94 State m_state;
95 ceph::bufferlist m_copyup_data;
b32b8144 96 std::vector<AbstractObjectWriteRequest<ImageCtxT> *> m_pending_requests;
7c673cae
FG
97 std::atomic<unsigned> m_pending_copyups { 0 };
98
99 AsyncOperation m_async_op;
100
101 std::vector<uint64_t> m_snap_ids;
102 librados::IoCtx m_data_ctx; // for empty SnapContext
103
b32b8144
FG
104 Mutex m_lock;
105
7c673cae
FG
106 void complete_requests(int r);
107
108 bool should_complete(int r);
109
110 void remove_from_list();
111
112 bool send_object_map_head();
113 bool send_object_map();
114 bool send_copyup();
115 bool is_copyup_required();
116};
117
118} // namespace io
119} // namespace librbd
120
b32b8144
FG
121extern template class librbd::io::CopyupRequest<librbd::ImageCtx>;
122
7c673cae 123#endif // CEPH_LIBRBD_IO_COPYUP_REQUEST_H