tests: vsock: Use VMADDR_CID_LOCAL for loopback testing.
[nbdkit/ericb.git] / tests / test-layers-filter.c
blob0c81252003494a54163427dc5f95d537fbaeea6d
1 /* nbdkit
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
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>
39 #include <nbdkit-filter.h>
41 #define THREAD_MODEL NBDKIT_THREAD_MODEL_PARALLEL
43 #define str(s) #s
44 #define DEBUG_FUNCTION nbdkit_debug ("%s: %s", layer, __func__)
46 static void
47 test_layers_filter_load (void)
49 DEBUG_FUNCTION;
52 static void
53 test_layers_filter_unload (void)
55 DEBUG_FUNCTION;
58 static int
59 test_layers_filter_config (nbdkit_next_config *next, void *nxdata,
60 const char *key, const char *value)
62 DEBUG_FUNCTION;
63 return next (nxdata, key, value);
66 static int
67 test_layers_filter_config_complete (nbdkit_next_config_complete *next,
68 void *nxdata)
70 DEBUG_FUNCTION;
71 return next (nxdata);
74 #define test_layers_filter_config_help \
75 "test_layers_" layer "_config_help"
77 static int
78 test_layers_filter_preconnect (nbdkit_next_preconnect *next,
79 void *nxdata, int readonly)
81 DEBUG_FUNCTION;
82 return next (nxdata, readonly);
85 static void *
86 test_layers_filter_open (nbdkit_next_open *next, void *nxdata, int readonly)
88 static int handle;
90 if (next (nxdata, readonly) == -1)
91 return NULL;
93 /* Debug after recursing, to show opposite order from .close */
94 DEBUG_FUNCTION;
96 return &handle;
99 static void
100 test_layers_filter_close (void *handle)
102 DEBUG_FUNCTION;
105 static int
106 test_layers_filter_prepare (struct nbdkit_next_ops *next_ops, void *nxdata,
107 void *handle, int readonly)
109 DEBUG_FUNCTION;
110 return 0;
113 static int
114 test_layers_filter_finalize (struct nbdkit_next_ops *next_ops, void *nxdata,
115 void *handle)
117 DEBUG_FUNCTION;
118 return 0;
121 static int64_t
122 test_layers_filter_get_size (struct nbdkit_next_ops *next_ops, void *nxdata,
123 void *handle)
125 DEBUG_FUNCTION;
126 return next_ops->get_size (nxdata);
129 static int
130 test_layers_filter_can_write (struct nbdkit_next_ops *next_ops, void *nxdata,
131 void *handle)
133 DEBUG_FUNCTION;
134 return next_ops->can_write (nxdata);
137 static int
138 test_layers_filter_can_flush (struct nbdkit_next_ops *next_ops, void *nxdata,
139 void *handle)
141 DEBUG_FUNCTION;
142 return next_ops->can_flush (nxdata);
145 static int
146 test_layers_filter_is_rotational (struct nbdkit_next_ops *next_ops,
147 void *nxdata,
148 void *handle)
150 DEBUG_FUNCTION;
151 return next_ops->is_rotational (nxdata);
154 static int
155 test_layers_filter_can_trim (struct nbdkit_next_ops *next_ops, void *nxdata,
156 void *handle)
158 DEBUG_FUNCTION;
159 return next_ops->can_trim (nxdata);
162 static int
163 test_layers_filter_can_zero (struct nbdkit_next_ops *next_ops, void *nxdata,
164 void *handle)
166 DEBUG_FUNCTION;
167 return next_ops->can_zero (nxdata);
170 static int
171 test_layers_filter_can_fua (struct nbdkit_next_ops *next_ops, void *nxdata,
172 void *handle)
174 DEBUG_FUNCTION;
175 return next_ops->can_fua (nxdata);
178 static int
179 test_layers_filter_can_multi_conn (struct nbdkit_next_ops *next_ops,
180 void *nxdata,
181 void *handle)
183 DEBUG_FUNCTION;
184 return next_ops->can_multi_conn (nxdata);
187 static int
188 test_layers_filter_can_extents (struct nbdkit_next_ops *next_ops,
189 void *nxdata,
190 void *handle)
192 DEBUG_FUNCTION;
193 return next_ops->can_extents (nxdata);
196 static int
197 test_layers_filter_can_cache (struct nbdkit_next_ops *next_ops,
198 void *nxdata,
199 void *handle)
201 DEBUG_FUNCTION;
202 return next_ops->can_cache (nxdata);
205 static int
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)
211 DEBUG_FUNCTION;
212 return next_ops->pread (nxdata, buf, count, offset, flags, err);
215 static int
216 test_layers_filter_pwrite (struct nbdkit_next_ops *next_ops, void *nxdata,
217 void *handle,
218 const void *buf, uint32_t count, uint64_t offset,
219 uint32_t flags, int *err)
221 DEBUG_FUNCTION;
222 return next_ops->pwrite (nxdata, buf, count, offset, flags, err);
225 static int
226 test_layers_filter_flush (struct nbdkit_next_ops *next_ops, void *nxdata,
227 void *handle,
228 uint32_t flags, int *err)
230 DEBUG_FUNCTION;
231 return next_ops->flush (nxdata, flags, err);
234 static int
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)
239 DEBUG_FUNCTION;
240 return next_ops->trim (nxdata, count, offset, flags, err);
243 static int
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)
248 DEBUG_FUNCTION;
249 return next_ops->zero (nxdata, count, offset, flags, err);
252 static int
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,
256 int *err)
258 DEBUG_FUNCTION;
259 return next_ops->extents (nxdata, count, offset, flags, extents, err);
262 static int
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)
267 DEBUG_FUNCTION;
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)