]> git.proxmox.com Git - ceph.git/blame - ceph/src/test/librbd/mock/MockImageCtx.h
import new upstream nautilus stable release 14.2.8
[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"
11fdf7f2 17#include "test/librbd/mock/io/MockObjectDispatcher.h"
7c673cae
FG
18#include "common/RWLock.h"
19#include "common/WorkQueue.h"
31f18b77 20#include "common/zipkin_trace.h"
7c673cae
FG
21#include "librbd/ImageCtx.h"
22#include "gmock/gmock.h"
23#include <string>
24
25namespace librbd {
26
27namespace cache { class MockImageCache; }
28namespace operation {
29template <typename> class ResizeRequest;
30}
31
32struct MockImageCtx {
33 static MockImageCtx *s_instance;
34 static MockImageCtx *create(const std::string &image_name,
35 const std::string &image_id,
36 const char *snap, librados::IoCtx& p,
37 bool read_only) {
11fdf7f2 38 ceph_assert(s_instance != nullptr);
7c673cae
FG
39 return s_instance;
40 }
41 MOCK_METHOD0(destroy, void());
42
43 MockImageCtx(librbd::ImageCtx &image_ctx)
44 : image_ctx(&image_ctx),
45 cct(image_ctx.cct),
46 perfcounter(image_ctx.perfcounter),
47 snap_namespace(image_ctx.snap_namespace),
48 snap_name(image_ctx.snap_name),
49 snap_id(image_ctx.snap_id),
50 snap_exists(image_ctx.snap_exists),
51 snapc(image_ctx.snapc),
52 snaps(image_ctx.snaps),
53 snap_info(image_ctx.snap_info),
54 snap_ids(image_ctx.snap_ids),
7c673cae
FG
55 old_format(image_ctx.old_format),
56 read_only(image_ctx.read_only),
57 clone_copy_on_read(image_ctx.clone_copy_on_read),
58 lockers(image_ctx.lockers),
59 exclusive_locked(image_ctx.exclusive_locked),
60 lock_tag(image_ctx.lock_tag),
61 owner_lock(image_ctx.owner_lock),
62 md_lock(image_ctx.md_lock),
7c673cae 63 snap_lock(image_ctx.snap_lock),
11fdf7f2 64 timestamp_lock(image_ctx.timestamp_lock),
7c673cae
FG
65 parent_lock(image_ctx.parent_lock),
66 object_map_lock(image_ctx.object_map_lock),
67 async_ops_lock(image_ctx.async_ops_lock),
b32b8144 68 copyup_list_lock(image_ctx.copyup_list_lock),
7c673cae
FG
69 order(image_ctx.order),
70 size(image_ctx.size),
71 features(image_ctx.features),
72 flags(image_ctx.flags),
11fdf7f2
TL
73 op_features(image_ctx.op_features),
74 operations_disabled(image_ctx.operations_disabled),
7c673cae
FG
75 stripe_unit(image_ctx.stripe_unit),
76 stripe_count(image_ctx.stripe_count),
77 object_prefix(image_ctx.object_prefix),
78 header_oid(image_ctx.header_oid),
79 id(image_ctx.id),
80 name(image_ctx.name),
81 parent_md(image_ctx.parent_md),
82 format_string(image_ctx.format_string),
83 group_spec(image_ctx.group_spec),
84 layout(image_ctx.layout),
85 io_work_queue(new io::MockImageRequestWQ()),
11fdf7f2 86 io_object_dispatcher(new io::MockObjectDispatcher()),
7c673cae
FG
87 op_work_queue(new MockContextWQ()),
88 readahead_max_bytes(image_ctx.readahead_max_bytes),
224ce89b 89 event_socket(image_ctx.event_socket),
7c673cae
FG
90 parent(NULL), operations(new MockOperations()),
91 state(new MockImageState()),
92 image_watcher(NULL), object_map(NULL),
93 exclusive_lock(NULL), journal(NULL),
31f18b77 94 trace_endpoint(image_ctx.trace_endpoint),
b32b8144 95 sparse_read_threshold_bytes(image_ctx.sparse_read_threshold_bytes),
11fdf7f2 96 discard_granularity_bytes(image_ctx.discard_granularity_bytes),
224ce89b 97 mirroring_replay_delay(image_ctx.mirroring_replay_delay),
181888fb 98 non_blocking_aio(image_ctx.non_blocking_aio),
b32b8144 99 blkin_trace_all(image_ctx.blkin_trace_all),
11fdf7f2 100 enable_alloc_hint(image_ctx.enable_alloc_hint),
92f5a8d4 101 alloc_hint_flags(image_ctx.alloc_hint_flags),
11fdf7f2
TL
102 ignore_migrating(image_ctx.ignore_migrating),
103 mtime_update_interval(image_ctx.mtime_update_interval),
104 atime_update_interval(image_ctx.atime_update_interval),
105 cache(image_ctx.cache),
106 config(image_ctx.config)
7c673cae
FG
107 {
108 md_ctx.dup(image_ctx.md_ctx);
109 data_ctx.dup(image_ctx.data_ctx);
110
111 if (image_ctx.image_watcher != NULL) {
112 image_watcher = new MockImageWatcher();
113 }
114 }
115
116 ~MockImageCtx() {
117 wait_for_async_requests();
118 image_ctx->md_ctx.aio_flush();
119 image_ctx->data_ctx.aio_flush();
120 image_ctx->op_work_queue->drain();
121 delete state;
122 delete operations;
123 delete image_watcher;
124 delete op_work_queue;
125 delete io_work_queue;
11fdf7f2 126 delete io_object_dispatcher;
7c673cae
FG
127 }
128
129 void wait_for_async_requests() {
130 async_ops_lock.Lock();
131 if (async_requests.empty()) {
132 async_ops_lock.Unlock();
133 return;
134 }
135
136 C_SaferCond ctx;
137 async_requests_waiters.push_back(&ctx);
138 async_ops_lock.Unlock();
139
140 ctx.wait();
141 }
142
eafe8130 143 MOCK_METHOD1(init_layout, void(int64_t));
7c673cae
FG
144
145 MOCK_CONST_METHOD1(get_object_name, std::string(uint64_t));
b32b8144 146 MOCK_CONST_METHOD0(get_object_size, uint64_t());
7c673cae
FG
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));
b32b8144 150 MOCK_CONST_METHOD1(get_read_flags, int(librados::snap_t));
11fdf7f2
TL
151 MOCK_CONST_METHOD2(get_flags, int(librados::snap_t in_snap_id,
152 uint64_t *flags));
7c673cae
FG
153 MOCK_CONST_METHOD2(get_snap_id,
154 librados::snap_t(cls::rbd::SnapshotNamespace snap_namespace,
155 std::string in_snap_name));
156 MOCK_CONST_METHOD1(get_snap_info, const SnapInfo*(librados::snap_t));
11fdf7f2 157 MOCK_CONST_METHOD2(get_snap_name, int(librados::snap_t, std::string *));
7c673cae
FG
158 MOCK_CONST_METHOD2(get_snap_namespace, int(librados::snap_t,
159 cls::rbd::SnapshotNamespace *out_snap_namespace));
160 MOCK_CONST_METHOD2(get_parent_spec, int(librados::snap_t in_snap_id,
11fdf7f2
TL
161 cls::rbd::ParentImageSpec *pspec));
162 MOCK_CONST_METHOD1(get_parent_info, const ParentImageInfo*(librados::snap_t));
3efd9988
FG
163 MOCK_CONST_METHOD2(get_parent_overlap, int(librados::snap_t in_snap_id,
164 uint64_t *overlap));
b32b8144
FG
165 MOCK_CONST_METHOD2(prune_parent_extents, uint64_t(vector<pair<uint64_t,uint64_t> >& ,
166 uint64_t));
7c673cae
FG
167
168 MOCK_CONST_METHOD2(is_snap_protected, int(librados::snap_t in_snap_id,
169 bool *is_protected));
170 MOCK_CONST_METHOD2(is_snap_unprotected, int(librados::snap_t in_snap_id,
171 bool *is_unprotected));
172
11fdf7f2
TL
173 MOCK_CONST_METHOD0(get_create_timestamp, utime_t());
174 MOCK_CONST_METHOD0(get_access_timestamp, utime_t());
175 MOCK_CONST_METHOD0(get_modify_timestamp, utime_t());
176
177 MOCK_METHOD1(set_access_timestamp, void(const utime_t at));
178 MOCK_METHOD1(set_modify_timestamp, void(const utime_t at));
179
7c673cae
FG
180 MOCK_METHOD8(add_snap, void(cls::rbd::SnapshotNamespace in_snap_namespace,
181 std::string in_snap_name,
182 librados::snap_t id,
11fdf7f2 183 uint64_t in_size, const ParentImageInfo &parent,
7c673cae
FG
184 uint8_t protection_status, uint64_t flags, utime_t timestamp));
185 MOCK_METHOD3(rm_snap, void(cls::rbd::SnapshotNamespace in_snap_namespace,
186 std::string in_snap_name,
187 librados::snap_t id));
188
189 MOCK_METHOD0(user_flushed, void());
7c673cae
FG
190 MOCK_METHOD1(flush_copyup, void(Context *));
191
7c673cae
FG
192 MOCK_CONST_METHOD1(test_features, bool(uint64_t test_features));
193 MOCK_CONST_METHOD2(test_features, bool(uint64_t test_features,
194 const RWLock &in_snap_lock));
195
11fdf7f2
TL
196 MOCK_CONST_METHOD1(test_op_features, bool(uint64_t op_features));
197
7c673cae
FG
198 MOCK_METHOD1(cancel_async_requests, void(Context*));
199
200 MOCK_METHOD0(create_exclusive_lock, MockExclusiveLock*());
201 MOCK_METHOD1(create_object_map, MockObjectMap*(uint64_t));
202 MOCK_METHOD0(create_journal, MockJournal*());
203
204 MOCK_METHOD0(notify_update, void());
205 MOCK_METHOD1(notify_update, void(Context *));
206
224ce89b 207 MOCK_CONST_METHOD0(get_exclusive_lock_policy, exclusive_lock::Policy*());
7c673cae 208 MOCK_CONST_METHOD0(get_journal_policy, journal::Policy*());
11fdf7f2 209 MOCK_METHOD1(set_journal_policy, void(journal::Policy*));
7c673cae 210
b32b8144
FG
211 MOCK_METHOD2(apply_metadata, int(const std::map<std::string, bufferlist> &,
212 bool));
7c673cae 213
3efd9988
FG
214 MOCK_CONST_METHOD0(get_stripe_count, uint64_t());
215 MOCK_CONST_METHOD0(get_stripe_period, uint64_t());
216
28e407b8
AA
217 MOCK_CONST_METHOD0(is_writeback_cache_enabled, bool());
218
7c673cae
FG
219 ImageCtx *image_ctx;
220 CephContext *cct;
221 PerfCounters *perfcounter;
222
223 cls::rbd::SnapshotNamespace snap_namespace;
224 std::string snap_name;
225 uint64_t snap_id;
226 bool snap_exists;
227
228 ::SnapContext snapc;
229 std::vector<librados::snap_t> snaps;
230 std::map<librados::snap_t, SnapInfo> snap_info;
231 std::map<std::pair<cls::rbd::SnapshotNamespace, std::string>, librados::snap_t> snap_ids;
232
7c673cae
FG
233 bool old_format;
234 bool read_only;
235
236 bool clone_copy_on_read;
237
238 std::map<rados::cls::lock::locker_id_t,
239 rados::cls::lock::locker_info_t> lockers;
240 bool exclusive_locked;
241 std::string lock_tag;
242
243 librados::IoCtx md_ctx;
244 librados::IoCtx data_ctx;
245
246 RWLock &owner_lock;
247 RWLock &md_lock;
7c673cae 248 RWLock &snap_lock;
11fdf7f2 249 RWLock &timestamp_lock;
7c673cae
FG
250 RWLock &parent_lock;
251 RWLock &object_map_lock;
252 Mutex &async_ops_lock;
b32b8144 253 Mutex &copyup_list_lock;
7c673cae
FG
254
255 uint8_t order;
256 uint64_t size;
257 uint64_t features;
258 uint64_t flags;
11fdf7f2
TL
259 uint64_t op_features;
260 bool operations_disabled;
7c673cae
FG
261 uint64_t stripe_unit;
262 uint64_t stripe_count;
263 std::string object_prefix;
264 std::string header_oid;
265 std::string id;
266 std::string name;
11fdf7f2
TL
267 ParentImageInfo parent_md;
268 MigrationInfo migration_info;
7c673cae
FG
269 char *format_string;
270 cls::rbd::GroupSpec group_spec;
271
272 file_layout_t layout;
273
274 xlist<operation::ResizeRequest<MockImageCtx>*> resize_reqs;
275 xlist<AsyncRequest<MockImageCtx>*> async_requests;
276 std::list<Context*> async_requests_waiters;
277
b32b8144
FG
278 std::map<uint64_t, io::CopyupRequest<MockImageCtx>*> copyup_list;
279
7c673cae 280 io::MockImageRequestWQ *io_work_queue;
11fdf7f2 281 io::MockObjectDispatcher *io_object_dispatcher;
7c673cae
FG
282 MockContextWQ *op_work_queue;
283
284 cache::MockImageCache *image_cache = nullptr;
285
286 MockReadahead readahead;
287 uint64_t readahead_max_bytes;
288
224ce89b
WB
289 EventSocket &event_socket;
290
7c673cae
FG
291 MockImageCtx *parent;
292 MockOperations *operations;
293 MockImageState *state;
294
295 MockImageWatcher *image_watcher;
296 MockObjectMap *object_map;
297 MockExclusiveLock *exclusive_lock;
298 MockJournal *journal;
299
31f18b77
FG
300 ZTracer::Endpoint trace_endpoint;
301
b32b8144 302 uint64_t sparse_read_threshold_bytes;
11fdf7f2 303 uint32_t discard_granularity_bytes;
7c673cae 304 int mirroring_replay_delay;
224ce89b 305 bool non_blocking_aio;
181888fb 306 bool blkin_trace_all;
b32b8144 307 bool enable_alloc_hint;
92f5a8d4 308 uint32_t alloc_hint_flags;
11fdf7f2
TL
309 bool ignore_migrating;
310 uint64_t mtime_update_interval;
311 uint64_t atime_update_interval;
312 bool cache;
313
314 ConfigProxy config;
7c673cae
FG
315};
316
317} // namespace librbd
318
319#endif // CEPH_TEST_LIBRBD_MOCK_IMAGE_CTX_H