]> git.proxmox.com Git - ceph.git/blame - ceph/src/test/librbd/mock/MockImageCtx.h
bump version to 12.2.1-pve3
[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 107 mirroring_replay_delay(image_ctx.mirroring_replay_delay),
181888fb
FG
108 non_blocking_aio(image_ctx.non_blocking_aio),
109 blkin_trace_all(image_ctx.blkin_trace_all)
7c673cae
FG
110 {
111 md_ctx.dup(image_ctx.md_ctx);
112 data_ctx.dup(image_ctx.data_ctx);
113
114 if (image_ctx.image_watcher != NULL) {
115 image_watcher = new MockImageWatcher();
116 }
117 }
118
119 ~MockImageCtx() {
120 wait_for_async_requests();
121 image_ctx->md_ctx.aio_flush();
122 image_ctx->data_ctx.aio_flush();
123 image_ctx->op_work_queue->drain();
124 delete state;
125 delete operations;
126 delete image_watcher;
127 delete op_work_queue;
128 delete io_work_queue;
129 }
130
131 void wait_for_async_requests() {
132 async_ops_lock.Lock();
133 if (async_requests.empty()) {
134 async_ops_lock.Unlock();
135 return;
136 }
137
138 C_SaferCond ctx;
139 async_requests_waiters.push_back(&ctx);
140 async_ops_lock.Unlock();
141
142 ctx.wait();
143 }
144
145 MOCK_METHOD0(init_layout, void());
146
147 MOCK_CONST_METHOD1(get_object_name, std::string(uint64_t));
148 MOCK_CONST_METHOD0(get_current_size, uint64_t());
149 MOCK_CONST_METHOD1(get_image_size, uint64_t(librados::snap_t));
150 MOCK_CONST_METHOD1(get_object_count, uint64_t(librados::snap_t));
151 MOCK_CONST_METHOD2(get_snap_id,
152 librados::snap_t(cls::rbd::SnapshotNamespace snap_namespace,
153 std::string in_snap_name));
154 MOCK_CONST_METHOD1(get_snap_info, const SnapInfo*(librados::snap_t));
155 MOCK_CONST_METHOD2(get_snap_namespace, int(librados::snap_t,
156 cls::rbd::SnapshotNamespace *out_snap_namespace));
157 MOCK_CONST_METHOD2(get_parent_spec, int(librados::snap_t in_snap_id,
158 ParentSpec *pspec));
159
160 MOCK_CONST_METHOD2(is_snap_protected, int(librados::snap_t in_snap_id,
161 bool *is_protected));
162 MOCK_CONST_METHOD2(is_snap_unprotected, int(librados::snap_t in_snap_id,
163 bool *is_unprotected));
164
165 MOCK_METHOD8(add_snap, void(cls::rbd::SnapshotNamespace in_snap_namespace,
166 std::string in_snap_name,
167 librados::snap_t id,
168 uint64_t in_size, const ParentInfo &parent,
169 uint8_t protection_status, uint64_t flags, utime_t timestamp));
170 MOCK_METHOD3(rm_snap, void(cls::rbd::SnapshotNamespace in_snap_namespace,
171 std::string in_snap_name,
172 librados::snap_t id));
173
174 MOCK_METHOD0(user_flushed, void());
175 MOCK_METHOD1(flush, void(Context *));
176 MOCK_METHOD1(flush_async_operations, void(Context *));
177 MOCK_METHOD1(flush_copyup, void(Context *));
178
179 MOCK_METHOD1(flush_cache, void(Context *));
180 MOCK_METHOD2(invalidate_cache, void(bool, Context *));
181 MOCK_METHOD1(shut_down_cache, void(Context *));
182 MOCK_METHOD0(is_cache_empty, bool());
183
184 MOCK_CONST_METHOD1(test_features, bool(uint64_t test_features));
185 MOCK_CONST_METHOD2(test_features, bool(uint64_t test_features,
186 const RWLock &in_snap_lock));
187
188 MOCK_METHOD1(cancel_async_requests, void(Context*));
189
190 MOCK_METHOD0(create_exclusive_lock, MockExclusiveLock*());
191 MOCK_METHOD1(create_object_map, MockObjectMap*(uint64_t));
192 MOCK_METHOD0(create_journal, MockJournal*());
193
194 MOCK_METHOD0(notify_update, void());
195 MOCK_METHOD1(notify_update, void(Context *));
196
224ce89b
WB
197 MOCK_CONST_METHOD0(get_exclusive_lock_policy, exclusive_lock::Policy*());
198
7c673cae
FG
199 MOCK_CONST_METHOD0(get_journal_policy, journal::Policy*());
200 MOCK_CONST_METHOD1(set_journal_policy, void(journal::Policy*));
201
31f18b77
FG
202 MOCK_METHOD8(aio_read_from_cache, void(object_t, uint64_t, bufferlist *,
203 size_t, uint64_t, Context *, int, ZTracer::Trace *));
204 MOCK_METHOD8(write_to_cache, void(object_t, const bufferlist&, size_t,
205 uint64_t, Context *, int, uint64_t, ZTracer::Trace *));
7c673cae
FG
206
207 ImageCtx *image_ctx;
208 CephContext *cct;
209 PerfCounters *perfcounter;
210
211 cls::rbd::SnapshotNamespace snap_namespace;
212 std::string snap_name;
213 uint64_t snap_id;
214 bool snap_exists;
215
216 ::SnapContext snapc;
217 std::vector<librados::snap_t> snaps;
218 std::map<librados::snap_t, SnapInfo> snap_info;
219 std::map<std::pair<cls::rbd::SnapshotNamespace, std::string>, librados::snap_t> snap_ids;
220
221 ObjectCacher *object_cacher;
222 ObjectCacher::ObjectSet *object_set;
223
224 bool old_format;
225 bool read_only;
226
227 bool clone_copy_on_read;
228
229 std::map<rados::cls::lock::locker_id_t,
230 rados::cls::lock::locker_info_t> lockers;
231 bool exclusive_locked;
232 std::string lock_tag;
233
234 librados::IoCtx md_ctx;
235 librados::IoCtx data_ctx;
236
237 RWLock &owner_lock;
238 RWLock &md_lock;
239 Mutex &cache_lock;
240 RWLock &snap_lock;
241 RWLock &parent_lock;
242 RWLock &object_map_lock;
243 Mutex &async_ops_lock;
244
245 uint8_t order;
246 uint64_t size;
247 uint64_t features;
248 uint64_t flags;
249 uint64_t stripe_unit;
250 uint64_t stripe_count;
251 std::string object_prefix;
252 std::string header_oid;
253 std::string id;
254 std::string name;
255 ParentInfo parent_md;
256 char *format_string;
257 cls::rbd::GroupSpec group_spec;
258
259 file_layout_t layout;
260
261 xlist<operation::ResizeRequest<MockImageCtx>*> resize_reqs;
262 xlist<AsyncRequest<MockImageCtx>*> async_requests;
263 std::list<Context*> async_requests_waiters;
264
265 io::MockImageRequestWQ *io_work_queue;
266 MockContextWQ *op_work_queue;
267
268 cache::MockImageCache *image_cache = nullptr;
269
270 MockReadahead readahead;
271 uint64_t readahead_max_bytes;
272
224ce89b
WB
273 EventSocket &event_socket;
274
7c673cae
FG
275 MockImageCtx *parent;
276 MockOperations *operations;
277 MockImageState *state;
278
279 MockImageWatcher *image_watcher;
280 MockObjectMap *object_map;
281 MockExclusiveLock *exclusive_lock;
282 MockJournal *journal;
283
31f18b77
FG
284 ZTracer::Endpoint trace_endpoint;
285
7c673cae
FG
286 int concurrent_management_ops;
287 bool blacklist_on_break_lock;
288 uint32_t blacklist_expire_seconds;
289 uint8_t journal_order;
290 uint8_t journal_splay_width;
291 double journal_commit_age;
292 int journal_object_flush_interval;
293 uint64_t journal_object_flush_bytes;
294 double journal_object_flush_age;
295 std::string journal_pool;
296 uint32_t journal_max_payload_bytes;
297 int journal_max_concurrent_object_sets;
298 bool mirroring_resync_after_disconnect;
299 int mirroring_replay_delay;
224ce89b 300 bool non_blocking_aio;
181888fb 301 bool blkin_trace_all;
7c673cae
FG
302};
303
304} // namespace librbd
305
306#endif // CEPH_TEST_LIBRBD_MOCK_IMAGE_CTX_H