1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #ifndef CEPH_LIBRBD_IO_COPYUP_REQUEST_H
5 #define CEPH_LIBRBD_IO_COPYUP_REQUEST_H
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"
18 namespace ZTracer
{ struct Trace
; }
26 template <typename I
> class AbstractObjectWriteRequest
;
28 template <typename ImageCtxT
= librbd::ImageCtx
>
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
),
38 CopyupRequest(ImageCtxT
*ictx
, const std::string
&oid
, uint64_t objectno
,
39 Extents
&&image_extents
, const ZTracer::Trace
&parent_trace
);
42 void append_request(AbstractObjectWriteRequest
<ImageCtxT
> *req
);
48 * Copyup requests go through the following state machine to read from the
49 * parent image, update the object map, and copyup the object:
56 * /---------/ \---------\
59 * READ_FROM_PARENT DEEP_COPY
61 * \---------\ /---------/
63 * v (skip if not needed)
66 * v (skip if not needed)
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.
79 typedef std::vector
<AbstractObjectWriteRequest
<ImageCtxT
> *> WriteRequests
;
81 ImageCtxT
*m_image_ctx
;
84 Extents m_image_extents
;
85 ZTracer::Trace m_trace
;
87 bool m_flatten
= false;
88 bool m_copyup_required
= true;
89 bool m_copyup_is_zero
= true;
91 ceph::bufferlist m_copyup_data
;
93 AsyncOperation m_async_op
;
95 std::vector
<uint64_t> m_snap_ids
;
96 bool m_first_snap_is_clean
= false;
99 WriteRequests m_pending_requests
;
100 unsigned m_pending_copyups
= 0;
102 WriteRequests m_restart_requests
;
103 bool m_append_request_permitted
= true;
105 void read_from_parent();
106 void handle_read_from_parent(int r
);
109 void handle_deep_copy(int r
);
111 void update_object_maps();
112 void handle_update_object_maps(int r
);
115 void handle_copyup(int r
);
118 void complete_requests(bool override_restart_retval
, int r
);
120 void disable_append_requests();
121 void remove_from_list();
123 bool is_copyup_required();
124 bool is_update_object_map_required(int r
);
125 bool is_deep_copy() const;
127 void compute_deep_copy_snap_ids();
131 } // namespace librbd
133 extern template class librbd::io::CopyupRequest
<librbd::ImageCtx
>;
135 #endif // CEPH_LIBRBD_IO_COPYUP_REQUEST_H