2 * Copyright (C) 2018-2019 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_open (int readonly
)
85 test_layers_plugin_close (void *handle
)
91 test_layers_plugin_get_size (void *handle
)
98 test_layers_plugin_can_write (void *handle
)
105 test_layers_plugin_can_flush (void *handle
)
112 test_layers_plugin_is_rotational (void *handle
)
119 test_layers_plugin_can_trim (void *handle
)
126 test_layers_plugin_can_zero (void *handle
)
133 test_layers_plugin_can_fua (void *handle
)
136 return NBDKIT_FUA_NATIVE
;
140 test_layers_plugin_can_multi_conn (void *handle
)
147 test_layers_plugin_can_cache (void *handle
)
150 return NBDKIT_CACHE_NATIVE
;
154 test_layers_plugin_can_extents (void *handle
)
161 test_layers_plugin_pread (void *handle
,
162 void *buf
, uint32_t count
, uint64_t offset
,
166 memset (buf
, 0, count
);
171 test_layers_plugin_pwrite (void *handle
,
172 const void *buf
, uint32_t count
, uint64_t offset
,
180 test_layers_plugin_flush (void *handle
, uint32_t flags
)
187 test_layers_plugin_trim (void *handle
,
188 uint32_t count
, uint64_t offset
, uint32_t flags
)
195 test_layers_plugin_zero (void *handle
,
196 uint32_t count
, uint64_t offset
, uint32_t flags
)
203 test_layers_plugin_extents (void *handle
,
204 uint32_t count
, uint64_t offset
, uint32_t flags
,
205 struct nbdkit_extents
*extents
)
208 return nbdkit_add_extent (extents
, offset
, count
, 0);
212 test_layers_plugin_cache (void *handle
,
213 uint32_t count
, uint64_t offset
, uint32_t flags
)
219 static struct nbdkit_plugin plugin
= {
220 .name
= "testlayersplugin",
221 .version
= PACKAGE_VERSION
,
222 .load
= test_layers_plugin_load
,
223 .unload
= test_layers_plugin_unload
,
224 .config
= test_layers_plugin_config
,
225 .config_complete
= test_layers_plugin_config_complete
,
226 .config_help
= test_layers_plugin_config_help
,
227 .open
= test_layers_plugin_open
,
228 .close
= test_layers_plugin_close
,
229 .get_size
= test_layers_plugin_get_size
,
230 .can_write
= test_layers_plugin_can_write
,
231 .can_flush
= test_layers_plugin_can_flush
,
232 .is_rotational
= test_layers_plugin_is_rotational
,
233 .can_trim
= test_layers_plugin_can_trim
,
234 .can_zero
= test_layers_plugin_can_zero
,
235 .can_fua
= test_layers_plugin_can_fua
,
236 .can_multi_conn
= test_layers_plugin_can_multi_conn
,
237 .can_extents
= test_layers_plugin_can_extents
,
238 .can_cache
= test_layers_plugin_can_cache
,
239 .pread
= test_layers_plugin_pread
,
240 .pwrite
= test_layers_plugin_pwrite
,
241 .flush
= test_layers_plugin_flush
,
242 .trim
= test_layers_plugin_trim
,
243 .zero
= test_layers_plugin_zero
,
244 .extents
= test_layers_plugin_extents
,
245 .cache
= test_layers_plugin_cache
,
246 /* In this plugin, errno is preserved properly along error return
247 * paths from failed system calls.
249 .errno_is_preserved
= 1,
252 NBDKIT_REGISTER_PLUGIN(plugin
)