2 * Copyright (C) 2018-2021 Red Hat Inc.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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
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__)
48 test_layers_plugin_load (void)
54 test_layers_plugin_unload (void)
60 test_layers_plugin_config (const char *key
, const char *value
)
67 test_layers_plugin_config_complete (void)
73 #define test_layers_plugin_config_help "test_layers_plugin_config_help"
76 test_layers_plugin_thread_model (void)
79 return NBDKIT_THREAD_MODEL_PARALLEL
;
83 test_layers_plugin_get_ready (void)
90 test_layers_plugin_after_fork (void)
97 test_layers_plugin_cleanup (void)
103 test_layers_plugin_preconnect (int readonly
)
110 test_layers_plugin_list_exports (int readonly
, int default_only
,
111 struct nbdkit_exports
*exports
)
114 return nbdkit_add_export (exports
, "", NULL
);
118 test_layers_plugin_default_export (int readonly
, int is_tls
)
125 test_layers_plugin_open (int readonly
)
134 test_layers_plugin_close (void *handle
)
140 test_layers_plugin_get_size (void *handle
)
147 test_layers_plugin_can_write (void *handle
)
154 test_layers_plugin_can_flush (void *handle
)
161 test_layers_plugin_is_rotational (void *handle
)
168 test_layers_plugin_can_trim (void *handle
)
175 test_layers_plugin_can_zero (void *handle
)
182 test_layers_plugin_can_fast_zero (void *handle
)
189 test_layers_plugin_can_fua (void *handle
)
192 return NBDKIT_FUA_NATIVE
;
196 test_layers_plugin_can_multi_conn (void *handle
)
203 test_layers_plugin_can_cache (void *handle
)
206 return NBDKIT_CACHE_NATIVE
;
210 test_layers_plugin_can_extents (void *handle
)
217 test_layers_plugin_pread (void *handle
,
218 void *buf
, uint32_t count
, uint64_t offset
,
222 memset (buf
, 0, count
);
227 test_layers_plugin_pwrite (void *handle
,
228 const void *buf
, uint32_t count
, uint64_t offset
,
236 test_layers_plugin_flush (void *handle
, uint32_t flags
)
243 test_layers_plugin_trim (void *handle
,
244 uint32_t count
, uint64_t offset
, uint32_t flags
)
251 test_layers_plugin_zero (void *handle
,
252 uint32_t count
, uint64_t offset
, uint32_t flags
)
259 test_layers_plugin_extents (void *handle
,
260 uint32_t count
, uint64_t offset
, uint32_t flags
,
261 struct nbdkit_extents
*extents
)
264 return nbdkit_add_extent (extents
, offset
, count
, 0);
268 test_layers_plugin_cache (void *handle
,
269 uint32_t count
, uint64_t offset
, uint32_t flags
)
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
)