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
39 #include <nbdkit-filter.h>
41 #define THREAD_MODEL NBDKIT_THREAD_MODEL_PARALLEL
44 #define DEBUG_FUNCTION nbdkit_debug ("%s: %s", layer, __func__)
47 test_layers_filter_load (void)
53 test_layers_filter_unload (void)
59 test_layers_filter_config (nbdkit_next_config
*next
, void *nxdata
,
60 const char *key
, const char *value
)
63 return next (nxdata
, key
, value
);
67 test_layers_filter_config_complete (nbdkit_next_config_complete
*next
,
74 #define test_layers_filter_config_help \
75 "test_layers_" layer "_config_help"
78 test_layers_filter_open (nbdkit_next_open
*next
, void *nxdata
, int readonly
)
82 if (next (nxdata
, readonly
) == -1)
85 /* Debug after recursing, to show opposite order from .close */
92 test_layers_filter_close (void *handle
)
98 test_layers_filter_prepare (struct nbdkit_next_ops
*next_ops
, void *nxdata
,
99 void *handle
, int readonly
)
106 test_layers_filter_finalize (struct nbdkit_next_ops
*next_ops
, void *nxdata
,
114 test_layers_filter_get_size (struct nbdkit_next_ops
*next_ops
, void *nxdata
,
118 return next_ops
->get_size (nxdata
);
122 test_layers_filter_can_write (struct nbdkit_next_ops
*next_ops
, void *nxdata
,
126 return next_ops
->can_write (nxdata
);
130 test_layers_filter_can_flush (struct nbdkit_next_ops
*next_ops
, void *nxdata
,
134 return next_ops
->can_flush (nxdata
);
138 test_layers_filter_is_rotational (struct nbdkit_next_ops
*next_ops
,
143 return next_ops
->is_rotational (nxdata
);
147 test_layers_filter_can_trim (struct nbdkit_next_ops
*next_ops
, void *nxdata
,
151 return next_ops
->can_trim (nxdata
);
155 test_layers_filter_can_zero (struct nbdkit_next_ops
*next_ops
, void *nxdata
,
159 return next_ops
->can_zero (nxdata
);
163 test_layers_filter_can_fua (struct nbdkit_next_ops
*next_ops
, void *nxdata
,
167 return next_ops
->can_fua (nxdata
);
171 test_layers_filter_can_multi_conn (struct nbdkit_next_ops
*next_ops
,
176 return next_ops
->can_multi_conn (nxdata
);
180 test_layers_filter_can_extents (struct nbdkit_next_ops
*next_ops
,
185 return next_ops
->can_extents (nxdata
);
189 test_layers_filter_can_cache (struct nbdkit_next_ops
*next_ops
,
194 return next_ops
->can_cache (nxdata
);
198 test_layers_filter_pread (struct nbdkit_next_ops
*next_ops
, void *nxdata
,
199 void *handle
, void *buf
,
200 uint32_t count
, uint64_t offset
,
201 uint32_t flags
, int *err
)
204 return next_ops
->pread (nxdata
, buf
, count
, offset
, flags
, err
);
208 test_layers_filter_pwrite (struct nbdkit_next_ops
*next_ops
, void *nxdata
,
210 const void *buf
, uint32_t count
, uint64_t offset
,
211 uint32_t flags
, int *err
)
214 return next_ops
->pwrite (nxdata
, buf
, count
, offset
, flags
, err
);
218 test_layers_filter_flush (struct nbdkit_next_ops
*next_ops
, void *nxdata
,
220 uint32_t flags
, int *err
)
223 return next_ops
->flush (nxdata
, flags
, err
);
227 test_layers_filter_trim (struct nbdkit_next_ops
*next_ops
, void *nxdata
,
228 void *handle
, uint32_t count
, uint64_t offset
,
229 uint32_t flags
, int *err
)
232 return next_ops
->trim (nxdata
, count
, offset
, flags
, err
);
236 test_layers_filter_zero (struct nbdkit_next_ops
*next_ops
, void *nxdata
,
237 void *handle
, uint32_t count
, uint64_t offset
,
238 uint32_t flags
, int *err
)
241 return next_ops
->zero (nxdata
, count
, offset
, flags
, err
);
245 test_layers_filter_extents (struct nbdkit_next_ops
*next_ops
, void *nxdata
,
246 void *handle
, uint32_t count
, uint64_t offset
,
247 uint32_t flags
, struct nbdkit_extents
*extents
,
251 return next_ops
->extents (nxdata
, count
, offset
, flags
, extents
, err
);
255 test_layers_filter_cache (struct nbdkit_next_ops
*next_ops
, void *nxdata
,
256 void *handle
, uint32_t count
, uint64_t offset
,
257 uint32_t flags
, int *err
)
260 return next_ops
->cache (nxdata
, count
, offset
, flags
, err
);
263 static struct nbdkit_filter filter
= {
264 .name
= "testlayers" layer
,
265 .load
= test_layers_filter_load
,
266 .unload
= test_layers_filter_unload
,
267 .config
= test_layers_filter_config
,
268 .config_complete
= test_layers_filter_config_complete
,
269 .config_help
= test_layers_filter_config_help
,
270 .open
= test_layers_filter_open
,
271 .close
= test_layers_filter_close
,
272 .prepare
= test_layers_filter_prepare
,
273 .finalize
= test_layers_filter_finalize
,
274 .get_size
= test_layers_filter_get_size
,
275 .can_write
= test_layers_filter_can_write
,
276 .can_flush
= test_layers_filter_can_flush
,
277 .is_rotational
= test_layers_filter_is_rotational
,
278 .can_trim
= test_layers_filter_can_trim
,
279 .can_zero
= test_layers_filter_can_zero
,
280 .can_fua
= test_layers_filter_can_fua
,
281 .can_multi_conn
= test_layers_filter_can_multi_conn
,
282 .can_extents
= test_layers_filter_can_extents
,
283 .can_cache
= test_layers_filter_can_cache
,
284 .pread
= test_layers_filter_pread
,
285 .pwrite
= test_layers_filter_pwrite
,
286 .flush
= test_layers_filter_flush
,
287 .trim
= test_layers_filter_trim
,
288 .zero
= test_layers_filter_zero
,
289 .extents
= test_layers_filter_extents
,
290 .cache
= test_layers_filter_cache
,
293 NBDKIT_REGISTER_FILTER(filter
)