server: Better newstyle .open failure handling
[nbdkit/ericb.git] / tests / test-layers-filter.c
blobcccfb6541ec72df2c2bece0bf804396128b696e1
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 void *
78 test_layers_filter_open (nbdkit_next_open *next, void *nxdata, int readonly)
80 static int handle;
82 DEBUG_FUNCTION;
84 if (next (nxdata, readonly) == -1)
85 return NULL;
87 return &handle;
90 static void
91 test_layers_filter_close (void *handle)
93 DEBUG_FUNCTION;
96 static int
97 test_layers_filter_prepare (struct nbdkit_next_ops *next_ops, void *nxdata,
98 void *handle, int readonly)
100 DEBUG_FUNCTION;
101 return 0;
104 static int
105 test_layers_filter_finalize (struct nbdkit_next_ops *next_ops, void *nxdata,
106 void *handle)
108 DEBUG_FUNCTION;
109 return 0;
112 static int64_t
113 test_layers_filter_get_size (struct nbdkit_next_ops *next_ops, void *nxdata,
114 void *handle)
116 DEBUG_FUNCTION;
117 return next_ops->get_size (nxdata);
120 static int
121 test_layers_filter_can_write (struct nbdkit_next_ops *next_ops, void *nxdata,
122 void *handle)
124 DEBUG_FUNCTION;
125 return next_ops->can_write (nxdata);
128 static int
129 test_layers_filter_can_flush (struct nbdkit_next_ops *next_ops, void *nxdata,
130 void *handle)
132 DEBUG_FUNCTION;
133 return next_ops->can_flush (nxdata);
136 static int
137 test_layers_filter_is_rotational (struct nbdkit_next_ops *next_ops,
138 void *nxdata,
139 void *handle)
141 DEBUG_FUNCTION;
142 return next_ops->is_rotational (nxdata);
145 static int
146 test_layers_filter_can_trim (struct nbdkit_next_ops *next_ops, void *nxdata,
147 void *handle)
149 DEBUG_FUNCTION;
150 return next_ops->can_trim (nxdata);
153 static int
154 test_layers_filter_can_zero (struct nbdkit_next_ops *next_ops, void *nxdata,
155 void *handle)
157 DEBUG_FUNCTION;
158 return next_ops->can_zero (nxdata);
161 static int
162 test_layers_filter_can_fua (struct nbdkit_next_ops *next_ops, void *nxdata,
163 void *handle)
165 DEBUG_FUNCTION;
166 return next_ops->can_fua (nxdata);
169 static int
170 test_layers_filter_can_multi_conn (struct nbdkit_next_ops *next_ops,
171 void *nxdata,
172 void *handle)
174 DEBUG_FUNCTION;
175 return next_ops->can_multi_conn (nxdata);
178 static int
179 test_layers_filter_can_extents (struct nbdkit_next_ops *next_ops,
180 void *nxdata,
181 void *handle)
183 DEBUG_FUNCTION;
184 return next_ops->can_extents (nxdata);
187 static int
188 test_layers_filter_can_cache (struct nbdkit_next_ops *next_ops,
189 void *nxdata,
190 void *handle)
192 DEBUG_FUNCTION;
193 return next_ops->can_cache (nxdata);
196 static int
197 test_layers_filter_pread (struct nbdkit_next_ops *next_ops, void *nxdata,
198 void *handle, void *buf,
199 uint32_t count, uint64_t offset,
200 uint32_t flags, int *err)
202 DEBUG_FUNCTION;
203 return next_ops->pread (nxdata, buf, count, offset, flags, err);
206 static int
207 test_layers_filter_pwrite (struct nbdkit_next_ops *next_ops, void *nxdata,
208 void *handle,
209 const void *buf, uint32_t count, uint64_t offset,
210 uint32_t flags, int *err)
212 DEBUG_FUNCTION;
213 return next_ops->pwrite (nxdata, buf, count, offset, flags, err);
216 static int
217 test_layers_filter_flush (struct nbdkit_next_ops *next_ops, void *nxdata,
218 void *handle,
219 uint32_t flags, int *err)
221 DEBUG_FUNCTION;
222 return next_ops->flush (nxdata, flags, err);
225 static int
226 test_layers_filter_trim (struct nbdkit_next_ops *next_ops, void *nxdata,
227 void *handle, uint32_t count, uint64_t offset,
228 uint32_t flags, int *err)
230 DEBUG_FUNCTION;
231 return next_ops->trim (nxdata, count, offset, flags, err);
234 static int
235 test_layers_filter_zero (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->zero (nxdata, count, offset, flags, err);
243 static int
244 test_layers_filter_extents (struct nbdkit_next_ops *next_ops, void *nxdata,
245 void *handle, uint32_t count, uint64_t offset,
246 uint32_t flags, struct nbdkit_extents *extents,
247 int *err)
249 DEBUG_FUNCTION;
250 return next_ops->extents (nxdata, count, offset, flags, extents, err);
253 static int
254 test_layers_filter_cache (struct nbdkit_next_ops *next_ops, void *nxdata,
255 void *handle, uint32_t count, uint64_t offset,
256 uint32_t flags, int *err)
258 DEBUG_FUNCTION;
259 return next_ops->cache (nxdata, count, offset, flags, err);
262 static struct nbdkit_filter filter = {
263 .name = "testlayers" layer,
264 .load = test_layers_filter_load,
265 .unload = test_layers_filter_unload,
266 .config = test_layers_filter_config,
267 .config_complete = test_layers_filter_config_complete,
268 .config_help = test_layers_filter_config_help,
269 .open = test_layers_filter_open,
270 .close = test_layers_filter_close,
271 .prepare = test_layers_filter_prepare,
272 .finalize = test_layers_filter_finalize,
273 .get_size = test_layers_filter_get_size,
274 .can_write = test_layers_filter_can_write,
275 .can_flush = test_layers_filter_can_flush,
276 .is_rotational = test_layers_filter_is_rotational,
277 .can_trim = test_layers_filter_can_trim,
278 .can_zero = test_layers_filter_can_zero,
279 .can_fua = test_layers_filter_can_fua,
280 .can_multi_conn = test_layers_filter_can_multi_conn,
281 .can_extents = test_layers_filter_can_extents,
282 .can_cache = test_layers_filter_can_cache,
283 .pread = test_layers_filter_pread,
284 .pwrite = test_layers_filter_pwrite,
285 .flush = test_layers_filter_flush,
286 .trim = test_layers_filter_trim,
287 .zero = test_layers_filter_zero,
288 .extents = test_layers_filter_extents,
289 .cache = test_layers_filter_cache,
292 NBDKIT_REGISTER_FILTER(filter)