nbd: Forbid port= when using uri=
[nbdkit/ericb.git] / tests / test-layers-filter.c
blobd590cf95fa81b6695741d8d3f1863451a436d5ab
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 if (next (nxdata, readonly) == -1)
83 return NULL;
85 /* Debug after recursing, to show opposite order from .close */
86 DEBUG_FUNCTION;
88 return &handle;
91 static void
92 test_layers_filter_close (void *handle)
94 DEBUG_FUNCTION;
97 static int
98 test_layers_filter_prepare (struct nbdkit_next_ops *next_ops, void *nxdata,
99 void *handle, int readonly)
101 DEBUG_FUNCTION;
102 return 0;
105 static int
106 test_layers_filter_finalize (struct nbdkit_next_ops *next_ops, void *nxdata,
107 void *handle)
109 DEBUG_FUNCTION;
110 return 0;
113 static int64_t
114 test_layers_filter_get_size (struct nbdkit_next_ops *next_ops, void *nxdata,
115 void *handle)
117 DEBUG_FUNCTION;
118 return next_ops->get_size (nxdata);
121 static int
122 test_layers_filter_can_write (struct nbdkit_next_ops *next_ops, void *nxdata,
123 void *handle)
125 DEBUG_FUNCTION;
126 return next_ops->can_write (nxdata);
129 static int
130 test_layers_filter_can_flush (struct nbdkit_next_ops *next_ops, void *nxdata,
131 void *handle)
133 DEBUG_FUNCTION;
134 return next_ops->can_flush (nxdata);
137 static int
138 test_layers_filter_is_rotational (struct nbdkit_next_ops *next_ops,
139 void *nxdata,
140 void *handle)
142 DEBUG_FUNCTION;
143 return next_ops->is_rotational (nxdata);
146 static int
147 test_layers_filter_can_trim (struct nbdkit_next_ops *next_ops, void *nxdata,
148 void *handle)
150 DEBUG_FUNCTION;
151 return next_ops->can_trim (nxdata);
154 static int
155 test_layers_filter_can_zero (struct nbdkit_next_ops *next_ops, void *nxdata,
156 void *handle)
158 DEBUG_FUNCTION;
159 return next_ops->can_zero (nxdata);
162 static int
163 test_layers_filter_can_fua (struct nbdkit_next_ops *next_ops, void *nxdata,
164 void *handle)
166 DEBUG_FUNCTION;
167 return next_ops->can_fua (nxdata);
170 static int
171 test_layers_filter_can_multi_conn (struct nbdkit_next_ops *next_ops,
172 void *nxdata,
173 void *handle)
175 DEBUG_FUNCTION;
176 return next_ops->can_multi_conn (nxdata);
179 static int
180 test_layers_filter_can_extents (struct nbdkit_next_ops *next_ops,
181 void *nxdata,
182 void *handle)
184 DEBUG_FUNCTION;
185 return next_ops->can_extents (nxdata);
188 static int
189 test_layers_filter_can_cache (struct nbdkit_next_ops *next_ops,
190 void *nxdata,
191 void *handle)
193 DEBUG_FUNCTION;
194 return next_ops->can_cache (nxdata);
197 static int
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)
203 DEBUG_FUNCTION;
204 return next_ops->pread (nxdata, buf, count, offset, flags, err);
207 static int
208 test_layers_filter_pwrite (struct nbdkit_next_ops *next_ops, void *nxdata,
209 void *handle,
210 const void *buf, uint32_t count, uint64_t offset,
211 uint32_t flags, int *err)
213 DEBUG_FUNCTION;
214 return next_ops->pwrite (nxdata, buf, count, offset, flags, err);
217 static int
218 test_layers_filter_flush (struct nbdkit_next_ops *next_ops, void *nxdata,
219 void *handle,
220 uint32_t flags, int *err)
222 DEBUG_FUNCTION;
223 return next_ops->flush (nxdata, flags, err);
226 static int
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)
231 DEBUG_FUNCTION;
232 return next_ops->trim (nxdata, count, offset, flags, err);
235 static int
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)
240 DEBUG_FUNCTION;
241 return next_ops->zero (nxdata, count, offset, flags, err);
244 static int
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,
248 int *err)
250 DEBUG_FUNCTION;
251 return next_ops->extents (nxdata, count, offset, flags, extents, err);
254 static int
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)
259 DEBUG_FUNCTION;
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)