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"
19 namespace ZTracer
{ struct Trace
; }
28 template <typename I
> class AbstractObjectWriteRequest
;
30 template <typename ImageCtxT
= librbd::ImageCtx
>
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
),
40 CopyupRequest(ImageCtxT
*ictx
, const std::string
&oid
, uint64_t objectno
,
41 Extents
&&image_extents
, const ZTracer::Trace
&parent_trace
);
44 void append_request(AbstractObjectWriteRequest
<ImageCtxT
> *req
);
52 * Copyup requests go through the following state machine to read from the
53 * parent image, update the object map, and copyup the object:
61 * . . .STATE_READ_FROM_PARENT. . .
64 * . . STATE_OBJECT_MAP_HEAD v (copy on read /
65 * . . | . no HEAD rev. update)
67 * . . STATE_OBJECT_MAP. . . . .
70 * . . . . > STATE_COPYUP
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.
82 STATE_READ_FROM_PARENT
,
83 STATE_OBJECT_MAP_HEAD
, // only update the HEAD revision
84 STATE_OBJECT_MAP
, // update HEAD+snaps (if any)
91 Extents m_image_extents
;
92 ZTracer::Trace m_trace
;
95 ceph::bufferlist m_copyup_data
;
96 std::vector
<AbstractObjectWriteRequest
<ImageCtxT
> *> m_pending_requests
;
97 std::atomic
<unsigned> m_pending_copyups
{ 0 };
99 AsyncOperation m_async_op
;
101 std::vector
<uint64_t> m_snap_ids
;
102 librados::IoCtx m_data_ctx
; // for empty SnapContext
106 void complete_requests(int r
);
108 bool should_complete(int r
);
110 void remove_from_list();
112 bool send_object_map_head();
113 bool send_object_map();
115 bool is_copyup_required();
119 } // namespace librbd
121 extern template class librbd::io::CopyupRequest
<librbd::ImageCtx
>;
123 #endif // CEPH_LIBRBD_IO_COPYUP_REQUEST_H