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_preconnect (nbdkit_next_preconnect
*next
,
79 void *nxdata
, int readonly
)
82 return next (nxdata
, readonly
);
86 test_layers_filter_open (nbdkit_next_open
*next
, void *nxdata
, int readonly
)
90 if (next (nxdata
, readonly
) == -1)
93 /* Debug after recursing, to show opposite order from .close */
100 test_layers_filter_close (void *handle
)
106 test_layers_filter_prepare (struct nbdkit_next_ops
*next_ops
, void *nxdata
,
107 void *handle
, int readonly
)
114 test_layers_filter_finalize (struct nbdkit_next_ops
*next_ops
, void *nxdata
,
122 test_layers_filter_get_size (struct nbdkit_next_ops
*next_ops
, void *nxdata
,
126 return next_ops
->get_size (nxdata
);
130 test_layers_filter_can_write (struct nbdkit_next_ops
*next_ops
, void *nxdata
,
134 return next_ops
->can_write (nxdata
);
138 test_layers_filter_can_flush (struct nbdkit_next_ops
*next_ops
, void *nxdata
,
142 return next_ops
->can_flush (nxdata
);
146 test_layers_filter_is_rotational (struct nbdkit_next_ops
*next_ops
,
151 return next_ops
->is_rotational (nxdata
);
155 test_layers_filter_can_trim (struct nbdkit_next_ops
*next_ops
, void *nxdata
,
159 return next_ops
->can_trim (nxdata
);
163 test_layers_filter_can_zero (struct nbdkit_next_ops
*next_ops
, void *nxdata
,
167 return next_ops
->can_zero (nxdata
);
171 test_layers_filter_can_fua (struct nbdkit_next_ops
*next_ops
, void *nxdata
,
175 return next_ops
->can_fua (nxdata
);
179 test_layers_filter_can_multi_conn (struct nbdkit_next_ops
*next_ops
,
184 return next_ops
->can_multi_conn (nxdata
);
188 test_layers_filter_can_extents (struct nbdkit_next_ops
*next_ops
,
193 return next_ops
->can_extents (nxdata
);
197 test_layers_filter_can_cache (struct nbdkit_next_ops
*next_ops
,
202 return next_ops
->can_cache (nxdata
);
206 test_layers_filter_pread (struct nbdkit_next_ops
*next_ops
, void *nxdata
,
207 void *handle
, void *buf
,
208 uint32_t count
, uint64_t offset
,
209 uint32_t flags
, int *err
)
212 return next_ops
->pread (nxdata
, buf
, count
, offset
, flags
, err
);
216 test_layers_filter_pwrite (struct nbdkit_next_ops
*next_ops
, void *nxdata
,
218 const void *buf
, uint32_t count
, uint64_t offset
,
219 uint32_t flags
, int *err
)
222 return next_ops
->pwrite (nxdata
, buf
, count
, offset
, flags
, err
);
226 test_layers_filter_flush (struct nbdkit_next_ops
*next_ops
, void *nxdata
,
228 uint32_t flags
, int *err
)
231 return next_ops
->flush (nxdata
, flags
, err
);
235 test_layers_filter_trim (struct nbdkit_next_ops
*next_ops
, void *nxdata
,
236 void *handle
, uint32_t count
, uint64_t offset
,
237 uint32_t flags
, int *err
)
240 return next_ops
->trim (nxdata
, count
, offset
, flags
, err
);
244 test_layers_filter_zero (struct nbdkit_next_ops
*next_ops
, void *nxdata
,
245 void *handle
, uint32_t count
, uint64_t offset
,
246 uint32_t flags
, int *err
)
249 return next_ops
->zero (nxdata
, count
, offset
, flags
, err
);
253 test_layers_filter_extents (struct nbdkit_next_ops
*next_ops
, void *nxdata
,
254 void *handle
, uint32_t count
, uint64_t offset
,
255 uint32_t flags
, struct nbdkit_extents
*extents
,
259 return next_ops
->extents (nxdata
, count
, offset
, flags
, extents
, err
);
263 test_layers_filter_cache (struct nbdkit_next_ops
*next_ops
, void *nxdata
,
264 void *handle
, uint32_t count
, uint64_t offset
,
265 uint32_t flags
, int *err
)
268 return next_ops
->cache (nxdata
, count
, offset
, flags
, err
);
271 static struct nbdkit_filter filter
= {
272 .name
= "testlayers" layer
,
273 .load
= test_layers_filter_load
,
274 .unload
= test_layers_filter_unload
,
275 .config
= test_layers_filter_config
,
276 .config_complete
= test_layers_filter_config_complete
,
277 .config_help
= test_layers_filter_config_help
,
278 .preconnect
= test_layers_filter_preconnect
,
279 .open
= test_layers_filter_open
,
280 .close
= test_layers_filter_close
,
281 .prepare
= test_layers_filter_prepare
,
282 .finalize
= test_layers_filter_finalize
,
283 .get_size
= test_layers_filter_get_size
,
284 .can_write
= test_layers_filter_can_write
,
285 .can_flush
= test_layers_filter_can_flush
,
286 .is_rotational
= test_layers_filter_is_rotational
,
287 .can_trim
= test_layers_filter_can_trim
,
288 .can_zero
= test_layers_filter_can_zero
,
289 .can_fua
= test_layers_filter_can_fua
,
290 .can_multi_conn
= test_layers_filter_can_multi_conn
,
291 .can_extents
= test_layers_filter_can_extents
,
292 .can_cache
= test_layers_filter_can_cache
,
293 .pread
= test_layers_filter_pread
,
294 .pwrite
= test_layers_filter_pwrite
,
295 .flush
= test_layers_filter_flush
,
296 .trim
= test_layers_filter_trim
,
297 .zero
= test_layers_filter_zero
,
298 .extents
= test_layers_filter_extents
,
299 .cache
= test_layers_filter_cache
,
302 NBDKIT_REGISTER_FILTER(filter
)