Revert "ci: skip "lib/test-fork-safe-execvpe.sh" on Alpine Linux"
[libnbd.git] / copy / null-ops.c
blobc08d2aa6ff16879dac98582c804db9b934891427
1 /* NBD client library in userspace.
2 * Copyright Red Hat
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 #include <config.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <stdbool.h>
24 #include <errno.h>
26 #include "nbdcopy.h"
28 /* This sinks writes and aborts on any read-like operations. It
29 * should be faster than using /dev/null because it "supports" fast
30 * zeroing.
33 static struct rw_ops null_ops;
35 struct rw_null {
36 struct rw rw;
39 struct rw *
40 null_create (const char *name)
42 struct rw_null *rw = calloc (1, sizeof *rw);
43 if (rw == NULL) { perror ("calloc"); exit (EXIT_FAILURE); }
45 rw->rw.ops = &null_ops;
46 rw->rw.name = name;
47 rw->rw.size = INT64_MAX;
48 rw->rw.preferred = 4096;
49 return &rw->rw;
52 static void
53 null_close (struct rw *rw)
55 free (rw);
58 static void
59 null_flush (struct rw *rw)
61 /* nothing */
64 static bool
65 null_is_read_only (struct rw *rw)
67 return false;
70 static bool
71 null_can_extents (struct rw *rw)
73 return false;
76 static bool
77 null_can_multi_conn (struct rw *rw)
79 return true;
82 static void
83 null_start_multi_conn (struct rw *rw)
85 /* nothing */
88 static size_t
89 null_synch_read (struct rw *rw,
90 void *data, size_t len, uint64_t offset)
92 abort ();
95 static void
96 null_synch_write (struct rw *rw,
97 const void *data, size_t len, uint64_t offset)
99 /* nothing */
102 static bool
103 null_synch_zero (struct rw *rw, uint64_t offset, uint64_t count, bool allocate)
105 return true;
108 static void
109 null_asynch_read (struct rw *rw,
110 struct command *command,
111 nbd_completion_callback cb)
113 abort ();
116 static void
117 null_asynch_write (struct rw *rw,
118 struct command *command,
119 nbd_completion_callback cb)
121 int dummy = 0;
123 cb.callback (cb.user_data, &dummy);
126 static bool
127 null_asynch_zero (struct rw *rw, struct command *command,
128 nbd_completion_callback cb, bool allocate)
130 int dummy = 0;
132 cb.callback (cb.user_data, &dummy);
133 return true;
136 static unsigned
137 null_in_flight (struct rw *rw, size_t index)
139 return 0;
142 static void
143 null_get_extents (struct rw *rw, size_t index,
144 uint64_t offset, uint64_t count,
145 extent_list *ret)
147 abort ();
150 static struct rw_ops null_ops = {
151 .ops_name = "null_ops",
152 .close = null_close,
153 .is_read_only = null_is_read_only,
154 .can_extents = null_can_extents,
155 .can_multi_conn = null_can_multi_conn,
156 .start_multi_conn = null_start_multi_conn,
157 .flush = null_flush,
158 .synch_read = null_synch_read,
159 .synch_write = null_synch_write,
160 .synch_zero = null_synch_zero,
161 .asynch_read = null_asynch_read,
162 .asynch_write = null_asynch_write,
163 .asynch_zero = null_asynch_zero,
164 .in_flight = null_in_flight,
165 .get_polling_fd = get_polling_fd_not_supported,
166 .asynch_notify_read = asynch_notify_read_write_not_supported,
167 .asynch_notify_write = asynch_notify_read_write_not_supported,
168 .get_extents = null_get_extents,