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