]>
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 | ||
f67539c2 | 4 | #include "include/neorados/RADOS.hpp" |
7c673cae | 5 | #include "test/librbd/mock/MockImageCtx.h" |
9f95a23c | 6 | #include "test/librbd/mock/MockSafeTimer.h" |
1e59de90 | 7 | #include "test/librbd/mock/crypto/MockEncryptionFormat.h" |
f67539c2 | 8 | #include "librbd/io/AsyncOperation.h" |
9f95a23c TL |
9 | |
10 | static MockSafeTimer *s_timer; | |
11 | static ceph::mutex *s_timer_lock; | |
7c673cae FG |
12 | |
13 | namespace librbd { | |
14 | ||
15 | MockImageCtx* MockImageCtx::s_instance = nullptr; | |
16 | ||
1e59de90 TL |
17 | MockImageCtx::MockImageCtx(librbd::ImageCtx &image_ctx) |
18 | : image_ctx(&image_ctx), | |
19 | cct(image_ctx.cct), | |
20 | perfcounter(image_ctx.perfcounter), | |
21 | snap_namespace(image_ctx.snap_namespace), | |
22 | snap_name(image_ctx.snap_name), | |
23 | snap_id(image_ctx.snap_id), | |
24 | snap_exists(image_ctx.snap_exists), | |
25 | snapc(image_ctx.snapc), | |
26 | snaps(image_ctx.snaps), | |
27 | snap_info(image_ctx.snap_info), | |
28 | snap_ids(image_ctx.snap_ids), | |
29 | old_format(image_ctx.old_format), | |
30 | read_only(image_ctx.read_only), | |
31 | read_only_flags(image_ctx.read_only_flags), | |
32 | read_only_mask(image_ctx.read_only_mask), | |
33 | clone_copy_on_read(image_ctx.clone_copy_on_read), | |
34 | lockers(image_ctx.lockers), | |
35 | exclusive_locked(image_ctx.exclusive_locked), | |
36 | lock_tag(image_ctx.lock_tag), | |
37 | asio_engine(image_ctx.asio_engine), | |
38 | rados_api(image_ctx.rados_api), | |
39 | owner_lock(image_ctx.owner_lock), | |
40 | image_lock(image_ctx.image_lock), | |
41 | timestamp_lock(image_ctx.timestamp_lock), | |
42 | async_ops_lock(image_ctx.async_ops_lock), | |
43 | copyup_list_lock(image_ctx.copyup_list_lock), | |
44 | order(image_ctx.order), | |
45 | size(image_ctx.size), | |
46 | features(image_ctx.features), | |
47 | flags(image_ctx.flags), | |
48 | op_features(image_ctx.op_features), | |
49 | operations_disabled(image_ctx.operations_disabled), | |
50 | stripe_unit(image_ctx.stripe_unit), | |
51 | stripe_count(image_ctx.stripe_count), | |
52 | object_prefix(image_ctx.object_prefix), | |
53 | header_oid(image_ctx.header_oid), | |
54 | id(image_ctx.id), | |
55 | name(image_ctx.name), | |
56 | parent_md(image_ctx.parent_md), | |
57 | format_string(image_ctx.format_string), | |
58 | group_spec(image_ctx.group_spec), | |
59 | layout(image_ctx.layout), | |
60 | io_image_dispatcher(new io::MockImageDispatcher()), | |
61 | io_object_dispatcher(new io::MockObjectDispatcher()), | |
62 | op_work_queue(new MockContextWQ()), | |
63 | plugin_registry(new MockPluginRegistry()), | |
64 | readahead_max_bytes(image_ctx.readahead_max_bytes), | |
65 | event_socket(image_ctx.event_socket), | |
66 | parent(NULL), operations(new MockOperations()), | |
67 | state(new MockImageState()), | |
68 | image_watcher(NULL), object_map(NULL), | |
69 | exclusive_lock(NULL), journal(NULL), | |
70 | trace_endpoint(image_ctx.trace_endpoint), | |
71 | sparse_read_threshold_bytes(image_ctx.sparse_read_threshold_bytes), | |
72 | discard_granularity_bytes(image_ctx.discard_granularity_bytes), | |
73 | mirroring_replay_delay(image_ctx.mirroring_replay_delay), | |
74 | non_blocking_aio(image_ctx.non_blocking_aio), | |
75 | blkin_trace_all(image_ctx.blkin_trace_all), | |
76 | enable_alloc_hint(image_ctx.enable_alloc_hint), | |
77 | alloc_hint_flags(image_ctx.alloc_hint_flags), | |
78 | read_flags(image_ctx.read_flags), | |
79 | ignore_migrating(image_ctx.ignore_migrating), | |
80 | enable_sparse_copyup(image_ctx.enable_sparse_copyup), | |
81 | mtime_update_interval(image_ctx.mtime_update_interval), | |
82 | atime_update_interval(image_ctx.atime_update_interval), | |
83 | cache(image_ctx.cache), | |
84 | config(image_ctx.config) | |
85 | { | |
86 | md_ctx.dup(image_ctx.md_ctx); | |
87 | data_ctx.dup(image_ctx.data_ctx); | |
88 | ||
89 | if (image_ctx.image_watcher != NULL) { | |
90 | image_watcher = new MockImageWatcher(); | |
91 | } | |
92 | } | |
93 | ||
94 | MockImageCtx::~MockImageCtx() { | |
95 | wait_for_async_requests(); | |
96 | wait_for_async_ops(); | |
97 | image_ctx->md_ctx.aio_flush(); | |
98 | image_ctx->data_ctx.aio_flush(); | |
99 | image_ctx->op_work_queue->drain(); | |
100 | delete state; | |
101 | delete operations; | |
102 | delete image_watcher; | |
103 | delete op_work_queue; | |
104 | delete plugin_registry; | |
105 | delete io_image_dispatcher; | |
106 | delete io_object_dispatcher; | |
107 | } | |
108 | ||
9f95a23c TL |
109 | void MockImageCtx::set_timer_instance(MockSafeTimer *timer, |
110 | ceph::mutex *timer_lock) { | |
111 | s_timer = timer; | |
112 | s_timer_lock = timer_lock; | |
113 | } | |
114 | ||
115 | void MockImageCtx::get_timer_instance(CephContext *cct, MockSafeTimer **timer, | |
116 | ceph::mutex **timer_lock) { | |
117 | *timer = s_timer; | |
118 | *timer_lock = s_timer_lock; | |
119 | } | |
120 | ||
f67539c2 TL |
121 | void MockImageCtx::wait_for_async_ops() { |
122 | io::AsyncOperation async_op; | |
123 | async_op.start_op(*image_ctx); | |
124 | ||
125 | C_SaferCond ctx; | |
126 | async_op.flush(&ctx); | |
127 | ctx.wait(); | |
128 | ||
129 | async_op.finish_op(); | |
130 | } | |
131 | ||
132 | IOContext MockImageCtx::get_data_io_context() { | |
133 | auto ctx = std::make_shared<neorados::IOContext>( | |
134 | data_ctx.get_id(), data_ctx.get_namespace()); | |
135 | if (snap_id != CEPH_NOSNAP) { | |
136 | ctx->read_snap(snap_id); | |
137 | } | |
138 | if (!snapc.snaps.empty()) { | |
139 | ctx->write_snap_context( | |
140 | {{snapc.seq, {snapc.snaps.begin(), snapc.snaps.end()}}}); | |
141 | } | |
142 | return ctx; | |
143 | } | |
144 | ||
145 | IOContext MockImageCtx::duplicate_data_io_context() { | |
146 | return std::make_shared<neorados::IOContext>(*get_data_io_context()); | |
147 | } | |
148 | ||
7c673cae | 149 | } // namespace librbd |