Update Red Hat Copyright Notices
[nbdkit.git] / tests / test-layers-plugin.c
blob3b241495c8deb94fd12bd1645ad93c8707872ed3
1 /* nbdkit
2 * Copyright Red Hat
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * * Neither the name of Red Hat nor the names of its contributors may be
16 * used to endorse or promote products derived from this software without
17 * specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
22 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
26 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
29 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
33 #include <config.h>
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <stdint.h>
38 #include <string.h>
40 #define NBDKIT_API_VERSION 2
41 #include <nbdkit-plugin.h>
43 #define THREAD_MODEL NBDKIT_THREAD_MODEL_PARALLEL
45 #define DEBUG_FUNCTION nbdkit_debug ("%s", __func__)
47 static void
48 test_layers_plugin_load (void)
50 DEBUG_FUNCTION;
53 static void
54 test_layers_plugin_unload (void)
56 DEBUG_FUNCTION;
59 static int
60 test_layers_plugin_config (const char *key, const char *value)
62 DEBUG_FUNCTION;
63 return 0;
66 static int
67 test_layers_plugin_config_complete (void)
69 DEBUG_FUNCTION;
70 return 0;
73 #define test_layers_plugin_config_help "test_layers_plugin_config_help"
75 static int
76 test_layers_plugin_thread_model (void)
78 DEBUG_FUNCTION;
79 return NBDKIT_THREAD_MODEL_PARALLEL;
82 static int
83 test_layers_plugin_get_ready (void)
85 DEBUG_FUNCTION;
86 return 0;
89 static int
90 test_layers_plugin_after_fork (void)
92 DEBUG_FUNCTION;
93 return 0;
96 static void
97 test_layers_plugin_cleanup (void)
99 DEBUG_FUNCTION;
102 static int
103 test_layers_plugin_preconnect (int readonly)
105 DEBUG_FUNCTION;
106 return 0;
109 static int
110 test_layers_plugin_list_exports (int readonly, int default_only,
111 struct nbdkit_exports *exports)
113 DEBUG_FUNCTION;
114 return nbdkit_add_export (exports, "", NULL);
117 static const char *
118 test_layers_plugin_default_export (int readonly, int is_tls)
120 DEBUG_FUNCTION;
121 return "";
124 static void *
125 test_layers_plugin_open (int readonly)
127 static int handle;
129 DEBUG_FUNCTION;
130 return &handle;
133 static void
134 test_layers_plugin_close (void *handle)
136 DEBUG_FUNCTION;
139 static int64_t
140 test_layers_plugin_get_size (void *handle)
142 DEBUG_FUNCTION;
143 return 1024;
146 static int
147 test_layers_plugin_can_write (void *handle)
149 DEBUG_FUNCTION;
150 return 1;
153 static int
154 test_layers_plugin_can_flush (void *handle)
156 DEBUG_FUNCTION;
157 return 1;
160 static int
161 test_layers_plugin_is_rotational (void *handle)
163 DEBUG_FUNCTION;
164 return 1;
167 static int
168 test_layers_plugin_can_trim (void *handle)
170 DEBUG_FUNCTION;
171 return 1;
174 static int
175 test_layers_plugin_can_zero (void *handle)
177 DEBUG_FUNCTION;
178 return 1;
181 static int
182 test_layers_plugin_can_fast_zero (void *handle)
184 DEBUG_FUNCTION;
185 return 1;
188 static int
189 test_layers_plugin_can_fua (void *handle)
191 DEBUG_FUNCTION;
192 return NBDKIT_FUA_NATIVE;
195 static int
196 test_layers_plugin_can_multi_conn (void *handle)
198 DEBUG_FUNCTION;
199 return 1;
202 static int
203 test_layers_plugin_can_cache (void *handle)
205 DEBUG_FUNCTION;
206 return NBDKIT_CACHE_NATIVE;
209 static int
210 test_layers_plugin_can_extents (void *handle)
212 DEBUG_FUNCTION;
213 return 1;
216 static int
217 test_layers_plugin_pread (void *handle,
218 void *buf, uint32_t count, uint64_t offset,
219 uint32_t flags)
221 DEBUG_FUNCTION;
222 memset (buf, 0, count);
223 return 0;
226 static int
227 test_layers_plugin_pwrite (void *handle,
228 const void *buf, uint32_t count, uint64_t offset,
229 uint32_t flags)
231 DEBUG_FUNCTION;
232 return 0;
235 static int
236 test_layers_plugin_flush (void *handle, uint32_t flags)
238 DEBUG_FUNCTION;
239 return 0;
242 static int
243 test_layers_plugin_trim (void *handle,
244 uint32_t count, uint64_t offset, uint32_t flags)
246 DEBUG_FUNCTION;
247 return 0;
250 static int
251 test_layers_plugin_zero (void *handle,
252 uint32_t count, uint64_t offset, uint32_t flags)
254 DEBUG_FUNCTION;
255 return 0;
258 static int
259 test_layers_plugin_extents (void *handle,
260 uint32_t count, uint64_t offset, uint32_t flags,
261 struct nbdkit_extents *extents)
263 DEBUG_FUNCTION;
264 return nbdkit_add_extent (extents, offset, count, 0);
267 static int
268 test_layers_plugin_cache (void *handle,
269 uint32_t count, uint64_t offset, uint32_t flags)
271 DEBUG_FUNCTION;
272 return 0;
275 static struct nbdkit_plugin plugin = {
276 .name = "testlayersplugin",
277 .version = PACKAGE_VERSION,
278 .load = test_layers_plugin_load,
279 .unload = test_layers_plugin_unload,
280 .config = test_layers_plugin_config,
281 .config_complete = test_layers_plugin_config_complete,
282 .config_help = test_layers_plugin_config_help,
283 .thread_model = test_layers_plugin_thread_model,
284 .get_ready = test_layers_plugin_get_ready,
285 .after_fork = test_layers_plugin_after_fork,
286 .cleanup = test_layers_plugin_cleanup,
287 .preconnect = test_layers_plugin_preconnect,
288 .list_exports = test_layers_plugin_list_exports,
289 .default_export = test_layers_plugin_default_export,
290 .open = test_layers_plugin_open,
291 .close = test_layers_plugin_close,
292 .get_size = test_layers_plugin_get_size,
293 .can_write = test_layers_plugin_can_write,
294 .can_flush = test_layers_plugin_can_flush,
295 .is_rotational = test_layers_plugin_is_rotational,
296 .can_trim = test_layers_plugin_can_trim,
297 .can_zero = test_layers_plugin_can_zero,
298 .can_fast_zero = test_layers_plugin_can_fast_zero,
299 .can_fua = test_layers_plugin_can_fua,
300 .can_multi_conn = test_layers_plugin_can_multi_conn,
301 .can_extents = test_layers_plugin_can_extents,
302 .can_cache = test_layers_plugin_can_cache,
303 .pread = test_layers_plugin_pread,
304 .pwrite = test_layers_plugin_pwrite,
305 .flush = test_layers_plugin_flush,
306 .trim = test_layers_plugin_trim,
307 .zero = test_layers_plugin_zero,
308 .extents = test_layers_plugin_extents,
309 .cache = test_layers_plugin_cache,
310 /* In this plugin, errno is preserved properly along error return
311 * paths from failed system calls.
313 .errno_is_preserved = 1,
316 NBDKIT_REGISTER_PLUGIN (plugin)