]> git.proxmox.com Git - ceph.git/blame - ceph/src/test/librbd/mock/MockImageCtx.h
update sources to v12.1.1
[ceph.git] / ceph / src / test / librbd / mock / MockImageCtx.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_TEST_LIBRBD_MOCK_IMAGE_CTX_H
5#define CEPH_TEST_LIBRBD_MOCK_IMAGE_CTX_H
6
7#include "include/rados/librados.hpp"
8#include "test/librbd/mock/MockContextWQ.h"
9#include "test/librbd/mock/MockExclusiveLock.h"
10#include "test/librbd/mock/MockImageState.h"
11#include "test/librbd/mock/MockImageWatcher.h"
12#include "test/librbd/mock/MockJournal.h"
13#include "test/librbd/mock/MockObjectMap.h"
14#include "test/librbd/mock/MockOperations.h"
15#include "test/librbd/mock/MockReadahead.h"
16#include "test/librbd/mock/io/MockImageRequestWQ.h"
17#include "common/RWLock.h"
18#include "common/WorkQueue.h"
31f18b77 19#include "common/zipkin_trace.h"
7c673cae
FG
20#include "librbd/ImageCtx.h"
21#include "gmock/gmock.h"
22#include <string>
23
24namespace librbd {
25
26namespace cache { class MockImageCache; }
27namespace operation {
28template <typename> class ResizeRequest;
29}
30
31struct MockImageCtx {
32 static MockImageCtx *s_instance;
33 static MockImageCtx *create(const std::string &image_name,
34 const std::string &image_id,
35 const char *snap, librados::IoCtx& p,
36 bool read_only) {
37 assert(s_instance != nullptr);
38 return s_instance;
39 }
40 MOCK_METHOD0(destroy, void());
41
42 MockImageCtx(librbd::ImageCtx &image_ctx)
43 : image_ctx(&image_ctx),
44 cct(image_ctx.cct),
45 perfcounter(image_ctx.perfcounter),
46 snap_namespace(image_ctx.snap_namespace),
47 snap_name(image_ctx.snap_name),
48 snap_id(image_ctx.snap_id),
49 snap_exists(image_ctx.snap_exists),
50 snapc(image_ctx.snapc),
51 snaps(image_ctx.snaps),
52 snap_info(image_ctx.snap_info),
53 snap_ids(image_ctx.snap_ids),
54 object_cacher(image_ctx.object_cacher),
55 object_set(image_ctx.object_set),
56 old_format(image_ctx.old_format),
57 read_only(image_ctx.read_only),
58 clone_copy_on_read(image_ctx.clone_copy_on_read),
59 lockers(image_ctx.lockers),
60 exclusive_locked(image_ctx.exclusive_locked),
61 lock_tag(image_ctx.lock_tag),
62 owner_lock(image_ctx.owner_lock),
63 md_lock(image_ctx.md_lock),
64 cache_lock(image_ctx.cache_lock),
65 snap_lock(image_ctx.snap_lock),
66 parent_lock(image_ctx.parent_lock),
67 object_map_lock(image_ctx.object_map_lock),
68 async_ops_lock(image_ctx.async_ops_lock),
69 order(image_ctx.order),
70 size(image_ctx.size),
71 features(image_ctx.features),
72 flags(image_ctx.flags),
73 stripe_unit(image_ctx.stripe_unit),
74 stripe_count(image_ctx.stripe_count),
75 object_prefix(image_ctx.object_prefix),
76 header_oid(image_ctx.header_oid),
77 id(image_ctx.id),
78 name(image_ctx.name),
79 parent_md(image_ctx.parent_md),
80 format_string(image_ctx.format_string),
81 group_spec(image_ctx.group_spec),
82 layout(image_ctx.layout),
83 io_work_queue(new io::MockImageRequestWQ()),
84 op_work_queue(new MockContextWQ()),
85 readahead_max_bytes(image_ctx.readahead_max_bytes),
224ce89b 86 event_socket(image_ctx.event_socket),
7c673cae
FG
87 parent(NULL), operations(new MockOperations()),
88 state(new MockImageState()),
89 image_watcher(NULL), object_map(NULL),
90 exclusive_lock(NULL), journal(NULL),
31f18b77 91 trace_endpoint(image_ctx.trace_endpoint),
7c673cae
FG
92 concurrent_management_ops(image_ctx.concurrent_management_ops),
93 blacklist_on_break_lock(image_ctx.blacklist_on_break_lock),
94 blacklist_expire_seconds(image_ctx.blacklist_expire_seconds),
95 journal_order(image_ctx.journal_order),
96 journal_splay_width(image_ctx.journal_splay_width),
97 journal_commit_age(image_ctx.journal_commit_age),
98 journal_object_flush_interval(image_ctx.journal_object_flush_interval),
99 journal_object_flush_bytes(image_ctx.journal_object_flush_bytes),
100 journal_object_flush_age(image_ctx.journal_object_flush_age),
101 journal_pool(image_ctx.journal_pool),
102 journal_max_payload_bytes(image_ctx.journal_max_payload_bytes),
103 journal_max_concurrent_object_sets(
104 image_ctx.journal_max_concurrent_object_sets),
105 mirroring_resync_after_disconnect(
106 image_ctx.mirroring_resync_after_disconnect),
224ce89b
WB
107 mirroring_replay_delay(image_ctx.mirroring_replay_delay),
108 non_blocking_aio(image_ctx.non_blocking_aio)
7c673cae
FG
109 {
110 md_ctx.dup(image_ctx.md_ctx);
111 data_ctx.dup(image_ctx.data_ctx);
112
113 if (image_ctx.image_watcher != NULL) {
114 image_watcher = new MockImageWatcher();
115 }
116 }
117
118 ~MockImageCtx() {
119 wait_for_async_requests();
120 image_ctx->md_ctx.aio_flush();
121 image_ctx->data_ctx.aio_flush();
122 image_ctx->op_work_queue->drain();
123 delete state;
124 delete operations;
125 delete image_watcher;
126 delete op_work_queue;
127 delete io_work_queue;
128 }
129
130 void wait_for_async_requests() {
131 async_ops_lock.Lock();
132 if (async_requests.empty()) {
133 async_ops_lock.Unlock();
134 return;
135 }
136
137 C_SaferCond ctx;
138 async_requests_waiters.push_back(&ctx);
139 async_ops_lock.Unlock();
140
141 ctx.wait();
142 }
143
144 MOCK_METHOD0(init_layout, void());
145
146 MOCK_CONST_METHOD1(get_object_name, std::string(uint64_t));
147 MOCK_CONST_METHOD0(get_current_size, uint64_t());
148 MOCK_CONST_METHOD1(get_image_size, uint64_t(librados::snap_t));
149 MOCK_CONST_METHOD1(get_object_count, uint64_t(librados::snap_t));
150 MOCK_CONST_METHOD2(get_snap_id,
151 librados::snap_t(cls::rbd::SnapshotNamespace snap_namespace,
152 std::string in_snap_name));
153 MOCK_CONST_METHOD1(get_snap_info, const SnapInfo*(librados::snap_t));
154 MOCK_CONST_METHOD2(get_snap_namespace, int(librados::snap_t,
155 cls::rbd::SnapshotNamespace *out_snap_namespace));
156 MOCK_CONST_METHOD2(get_parent_spec, int(librados::snap_t in_snap_id,
157 ParentSpec *pspec));
158
159 MOCK_CONST_METHOD2(is_snap_protected, int(librados::snap_t in_snap_id,
160 bool *is_protected));
161 MOCK_CONST_METHOD2(is_snap_unprotected, int(librados::snap_t in_snap_id,
162 bool *is_unprotected));
163
164 MOCK_METHOD8(add_snap, void(cls::rbd::SnapshotNamespace in_snap_namespace,
165 std::string in_snap_name,
166 librados::snap_t id,
167 uint64_t in_size, const ParentInfo &parent,
168 uint8_t protection_status, uint64_t flags, utime_t timestamp));
169 MOCK_METHOD3(rm_snap, void(cls::rbd::SnapshotNamespace in_snap_namespace,
170 std::string in_snap_name,
171 librados::snap_t id));
172
173 MOCK_METHOD0(user_flushed, void());
174 MOCK_METHOD1(flush, void(Context *));
175 MOCK_METHOD1(flush_async_operations, void(Context *));
176 MOCK_METHOD1(flush_copyup, void(Context *));
177
178 MOCK_METHOD1(flush_cache, void(Context *));
179 MOCK_METHOD2(invalidate_cache, void(bool, Context *));
180 MOCK_METHOD1(shut_down_cache, void(Context *));
181 MOCK_METHOD0(is_cache_empty, bool());
182
183 MOCK_CONST_METHOD1(test_features, bool(uint64_t test_features));
184 MOCK_CONST_METHOD2(test_features, bool(uint64_t test_features,
185 const RWLock &in_snap_lock));
186
187 MOCK_METHOD1(cancel_async_requests, void(Context*));
188
189 MOCK_METHOD0(create_exclusive_lock, MockExclusiveLock*());
190 MOCK_METHOD1(create_object_map, MockObjectMap*(uint64_t));
191 MOCK_METHOD0(create_journal, MockJournal*());
192
193 MOCK_METHOD0(notify_update, void());
194 MOCK_METHOD1(notify_update, void(Context *));
195
224ce89b
WB
196 MOCK_CONST_METHOD0(get_exclusive_lock_policy, exclusive_lock::Policy*());
197
7c673cae
FG
198 MOCK_CONST_METHOD0(get_journal_policy, journal::Policy*());
199 MOCK_CONST_METHOD1(set_journal_policy, void(journal::Policy*));
200
31f18b77
FG
201 MOCK_METHOD8(aio_read_from_cache, void(object_t, uint64_t, bufferlist *,
202 size_t, uint64_t, Context *, int, ZTracer::Trace *));
203 MOCK_METHOD8(write_to_cache, void(object_t, const bufferlist&, size_t,
204 uint64_t, Context *, int, uint64_t, ZTracer::Trace *));
7c673cae
FG
205
206 ImageCtx *image_ctx;
207 CephContext *cct;
208 PerfCounters *perfcounter;
209
210 cls::rbd::SnapshotNamespace snap_namespace;
211 std::string snap_name;
212 uint64_t snap_id;
213 bool snap_exists;
214
215 ::SnapContext snapc;
216 std::vector<librados::snap_t> snaps;
217 std::map<librados::snap_t, SnapInfo> snap_info;
218 std::map<std::pair<cls::rbd::SnapshotNamespace, std::string>, librados::snap_t> snap_ids;
219
220 ObjectCacher *object_cacher;
221 ObjectCacher::ObjectSet *object_set;
222
223 bool old_format;
224 bool read_only;
225
226 bool clone_copy_on_read;
227
228 std::map<rados::cls::lock::locker_id_t,
229 rados::cls::lock::locker_info_t> lockers;
230 bool exclusive_locked;
231 std::string lock_tag;
232
233 librados::IoCtx md_ctx;
234 librados::IoCtx data_ctx;
235
236 RWLock &owner_lock;
237 RWLock &md_lock;
238 Mutex &cache_lock;
239 RWLock &snap_lock;
240 RWLock &parent_lock;
241 RWLock &object_map_lock;
242 Mutex &async_ops_lock;
243
244 uint8_t order;
245 uint64_t size;
246 uint64_t features;
247 uint64_t flags;
248 uint64_t stripe_unit;
249 uint64_t stripe_count;
250 std::string object_prefix;
251 std::string header_oid;
252 std::string id;
253 std::string name;
254 ParentInfo parent_md;
255 char *format_string;
256 cls::rbd::GroupSpec group_spec;
257
258 file_layout_t layout;
259
260 xlist<operation::ResizeRequest<MockImageCtx>*> resize_reqs;
261 xlist<AsyncRequest<MockImageCtx>*> async_requests;
262 std::list<Context*> async_requests_waiters;
263
264 io::MockImageRequestWQ *io_work_queue;
265 MockContextWQ *op_work_queue;
266
267 cache::MockImageCache *image_cache = nullptr;
268
269 MockReadahead readahead;
270 uint64_t readahead_max_bytes;
271
224ce89b
WB
272 EventSocket &event_socket;
273
7c673cae
FG
274 MockImageCtx *parent;
275 MockOperations *operations;
276 MockImageState *state;
277
278 MockImageWatcher *image_watcher;
279 MockObjectMap *object_map;
280 MockExclusiveLock *exclusive_lock;
281 MockJournal *journal;
282
31f18b77
FG
283 ZTracer::Endpoint trace_endpoint;
284
7c673cae
FG
285 int concurrent_management_ops;
286 bool blacklist_on_break_lock;
287 uint32_t blacklist_expire_seconds;
288 uint8_t journal_order;
289 uint8_t journal_splay_width;
290 double journal_commit_age;
291 int journal_object_flush_interval;
292 uint64_t journal_object_flush_bytes;
293 double journal_object_flush_age;
294 std::string journal_pool;
295 uint32_t journal_max_payload_bytes;
296 int journal_max_concurrent_object_sets;
297 bool mirroring_resync_after_disconnect;
298 int mirroring_replay_delay;
224ce89b 299 bool non_blocking_aio;
7c673cae
FG
300};
301
302} // namespace librbd
303
304#endif // CEPH_TEST_LIBRBD_MOCK_IMAGE_CTX_H