]>
git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/ObjectMap.h
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_OBJECT_MAP_H
5 #define CEPH_LIBRBD_OBJECT_MAP_H
7 #include "include/int_types.h"
8 #include "include/fs_types.h"
9 #include "include/rbd/object_map_types.h"
10 #include "common/bit_vector.hpp"
11 #include "librbd/Utils.h"
12 #include <boost/optional.hpp>
22 template <typename Op
> class BlockGuard
;
23 struct BlockGuardCell
;
26 template <typename ImageCtxT
= ImageCtx
>
29 static ObjectMap
*create(ImageCtxT
&image_ctx
, uint64_t snap_id
) {
30 return new ObjectMap(image_ctx
, snap_id
);
33 ObjectMap(ImageCtxT
&image_ctx
, uint64_t snap_id
);
36 static int aio_remove(librados::IoCtx
&io_ctx
, const std::string
&image_id
, librados::AioCompletion
*c
);
37 static std::string
object_map_name(const std::string
&image_id
,
40 static bool is_compatible(const file_layout_t
& layout
, uint64_t size
);
42 ceph::BitVector
<2u>::Reference
operator[](uint64_t object_no
);
43 uint8_t operator[](uint64_t object_no
) const;
44 inline uint64_t size() const {
45 return m_object_map
.size();
48 void open(Context
*on_finish
);
49 void close(Context
*on_finish
);
51 bool object_may_exist(uint64_t object_no
) const;
53 void aio_save(Context
*on_finish
);
54 void aio_resize(uint64_t new_size
, uint8_t default_object_state
,
57 template <typename T
, void(T::*MF
)(int) = &T::complete
>
58 bool aio_update(uint64_t snap_id
, uint64_t start_object_no
, uint8_t new_state
,
59 const boost::optional
<uint8_t> ¤t_state
,
61 return aio_update
<T
, MF
>(snap_id
, start_object_no
, start_object_no
+ 1,
62 new_state
, current_state
, callback_object
);
65 template <typename T
, void(T::*MF
)(int) = &T::complete
>
66 bool aio_update(uint64_t snap_id
, uint64_t start_object_no
,
67 uint64_t end_object_no
, uint8_t new_state
,
68 const boost::optional
<uint8_t> ¤t_state
,
70 assert(start_object_no
< end_object_no
);
71 if (snap_id
== CEPH_NOSNAP
) {
73 for (object_no
= start_object_no
; object_no
< end_object_no
;
75 if (update_required(object_no
, new_state
)) {
80 if (object_no
== end_object_no
) {
84 UpdateOperation
update_operation(start_object_no
, end_object_no
,
85 new_state
, current_state
,
86 util::create_context_callback
<T
, MF
>(
88 detained_aio_update(std::move(update_operation
));
90 aio_update(snap_id
, start_object_no
, end_object_no
, new_state
,
92 util::create_context_callback
<T
, MF
>(callback_object
));
97 void rollback(uint64_t snap_id
, Context
*on_finish
);
98 void snapshot_add(uint64_t snap_id
, Context
*on_finish
);
99 void snapshot_remove(uint64_t snap_id
, Context
*on_finish
);
102 struct UpdateOperation
{
103 uint64_t start_object_no
;
104 uint64_t end_object_no
;
106 boost::optional
<uint8_t> current_state
;
109 UpdateOperation(uint64_t start_object_no
, uint64_t end_object_no
,
111 const boost::optional
<uint8_t> ¤t_state
,
113 : start_object_no(start_object_no
), end_object_no(end_object_no
),
114 new_state(new_state
), current_state(current_state
),
115 on_finish(on_finish
) {
119 typedef BlockGuard
<UpdateOperation
> UpdateGuard
;
121 ImageCtxT
&m_image_ctx
;
122 ceph::BitVector
<2> m_object_map
;
125 UpdateGuard
*m_update_guard
= nullptr;
127 void detained_aio_update(UpdateOperation
&&update_operation
);
128 void handle_detained_aio_update(BlockGuardCell
*cell
, int r
,
131 void aio_update(uint64_t snap_id
, uint64_t start_object_no
,
132 uint64_t end_object_no
, uint8_t new_state
,
133 const boost::optional
<uint8_t> ¤t_state
,
135 bool update_required(uint64_t object_no
, uint8_t new_state
);
139 } // namespace librbd
141 extern template class librbd::ObjectMap
<librbd::ImageCtx
>;
143 #endif // CEPH_LIBRBD_OBJECT_MAP_H