1 /* NBD client library in userspace.
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
28 /* This sinks writes and aborts on any read-like operations. It
29 * should be faster than using /dev/null because it "supports" fast
33 static struct rw_ops null_ops
;
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
;
47 rw
->rw
.size
= INT64_MAX
;
48 rw
->rw
.preferred
= 4096;
53 null_close (struct rw
*rw
)
59 null_flush (struct rw
*rw
)
65 null_is_read_only (struct rw
*rw
)
71 null_can_extents (struct rw
*rw
)
77 null_can_multi_conn (struct rw
*rw
)
83 null_start_multi_conn (struct rw
*rw
)
89 null_synch_read (struct rw
*rw
,
90 void *data
, size_t len
, uint64_t offset
)
96 null_synch_write (struct rw
*rw
,
97 const void *data
, size_t len
, uint64_t offset
)
103 null_synch_zero (struct rw
*rw
, uint64_t offset
, uint64_t count
, bool allocate
)
109 null_asynch_read (struct rw
*rw
,
110 struct command
*command
,
111 nbd_completion_callback cb
)
117 null_asynch_write (struct rw
*rw
,
118 struct command
*command
,
119 nbd_completion_callback cb
)
123 cb
.callback (cb
.user_data
, &dummy
);
127 null_asynch_zero (struct rw
*rw
, struct command
*command
,
128 nbd_completion_callback cb
, bool allocate
)
132 cb
.callback (cb
.user_data
, &dummy
);
137 null_in_flight (struct rw
*rw
, size_t index
)
143 null_get_extents (struct rw
*rw
, size_t index
,
144 uint64_t offset
, uint64_t count
,
150 static struct rw_ops null_ops
= {
151 .ops_name
= "null_ops",
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
,
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
,