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