Fam Zheng | e819ab2 | 2014-09-11 14:09:56 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Null block driver |
| 3 | * |
| 4 | * Authors: |
| 5 | * Fam Zheng <famz@redhat.com> |
| 6 | * |
| 7 | * Copyright (C) 2014 Red Hat, Inc. |
| 8 | * |
| 9 | * This work is licensed under the terms of the GNU GPL, version 2 or later. |
| 10 | * See the COPYING file in the top-level directory. |
| 11 | */ |
| 12 | |
Peter Maydell | 80c71a2 | 2016-01-18 18:01:42 +0000 | [diff] [blame] | 13 | #include "qemu/osdep.h" |
Markus Armbruster | da34e65 | 2016-03-14 09:01:28 +0100 | [diff] [blame] | 14 | #include "qapi/error.h" |
Max Reitz | 67882b1 | 2016-06-10 20:57:48 +0200 | [diff] [blame] | 15 | #include "qapi/qmp/qdict.h" |
| 16 | #include "qapi/qmp/qstring.h" |
Markus Armbruster | 0b8fa32 | 2019-05-23 16:35:07 +0200 | [diff] [blame] | 17 | #include "qemu/module.h" |
Markus Armbruster | 922a01a | 2018-02-01 12:18:46 +0100 | [diff] [blame] | 18 | #include "qemu/option.h" |
Fam Zheng | e819ab2 | 2014-09-11 14:09:56 +0800 | [diff] [blame] | 19 | #include "block/block_int.h" |
Pavel Dovgalyuk | e4ec5ad | 2019-09-17 14:58:19 +0300 | [diff] [blame] | 20 | #include "sysemu/replay.h" |
Fam Zheng | e819ab2 | 2014-09-11 14:09:56 +0800 | [diff] [blame] | 21 | |
Fam Zheng | e5e51dd | 2015-04-01 09:45:38 +0800 | [diff] [blame] | 22 | #define NULL_OPT_LATENCY "latency-ns" |
Max Reitz | cd219eb | 2016-03-24 23:33:58 +0100 | [diff] [blame] | 23 | #define NULL_OPT_ZEROES "read-zeroes" |
Fam Zheng | e5e51dd | 2015-04-01 09:45:38 +0800 | [diff] [blame] | 24 | |
Fam Zheng | e819ab2 | 2014-09-11 14:09:56 +0800 | [diff] [blame] | 25 | typedef struct { |
| 26 | int64_t length; |
Fam Zheng | e5e51dd | 2015-04-01 09:45:38 +0800 | [diff] [blame] | 27 | int64_t latency_ns; |
Max Reitz | cd219eb | 2016-03-24 23:33:58 +0100 | [diff] [blame] | 28 | bool read_zeroes; |
Fam Zheng | e819ab2 | 2014-09-11 14:09:56 +0800 | [diff] [blame] | 29 | } BDRVNullState; |
| 30 | |
| 31 | static QemuOptsList runtime_opts = { |
| 32 | .name = "null", |
| 33 | .head = QTAILQ_HEAD_INITIALIZER(runtime_opts.head), |
| 34 | .desc = { |
| 35 | { |
Fam Zheng | e819ab2 | 2014-09-11 14:09:56 +0800 | [diff] [blame] | 36 | .name = BLOCK_OPT_SIZE, |
| 37 | .type = QEMU_OPT_SIZE, |
| 38 | .help = "size of the null block", |
| 39 | }, |
Fam Zheng | e5e51dd | 2015-04-01 09:45:38 +0800 | [diff] [blame] | 40 | { |
| 41 | .name = NULL_OPT_LATENCY, |
| 42 | .type = QEMU_OPT_NUMBER, |
| 43 | .help = "nanoseconds (approximated) to wait " |
| 44 | "before completing request", |
| 45 | }, |
Max Reitz | cd219eb | 2016-03-24 23:33:58 +0100 | [diff] [blame] | 46 | { |
| 47 | .name = NULL_OPT_ZEROES, |
| 48 | .type = QEMU_OPT_BOOL, |
| 49 | .help = "return zeroes when read", |
| 50 | }, |
Fam Zheng | e819ab2 | 2014-09-11 14:09:56 +0800 | [diff] [blame] | 51 | { /* end of list */ } |
| 52 | }, |
| 53 | }; |
| 54 | |
Kevin Wolf | 809eb70 | 2017-08-04 12:44:22 +0200 | [diff] [blame] | 55 | static void null_co_parse_filename(const char *filename, QDict *options, |
| 56 | Error **errp) |
| 57 | { |
| 58 | /* This functions only exists so that a null-co:// filename is accepted |
| 59 | * with the null-co driver. */ |
| 60 | if (strcmp(filename, "null-co://")) { |
| 61 | error_setg(errp, "The only allowed filename for this driver is " |
| 62 | "'null-co://'"); |
| 63 | return; |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | static void null_aio_parse_filename(const char *filename, QDict *options, |
| 68 | Error **errp) |
| 69 | { |
| 70 | /* This functions only exists so that a null-aio:// filename is accepted |
| 71 | * with the null-aio driver. */ |
| 72 | if (strcmp(filename, "null-aio://")) { |
| 73 | error_setg(errp, "The only allowed filename for this driver is " |
| 74 | "'null-aio://'"); |
| 75 | return; |
| 76 | } |
| 77 | } |
| 78 | |
Fam Zheng | e819ab2 | 2014-09-11 14:09:56 +0800 | [diff] [blame] | 79 | static int null_file_open(BlockDriverState *bs, QDict *options, int flags, |
| 80 | Error **errp) |
| 81 | { |
| 82 | QemuOpts *opts; |
| 83 | BDRVNullState *s = bs->opaque; |
Fam Zheng | e5e51dd | 2015-04-01 09:45:38 +0800 | [diff] [blame] | 84 | int ret = 0; |
Fam Zheng | e819ab2 | 2014-09-11 14:09:56 +0800 | [diff] [blame] | 85 | |
| 86 | opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort); |
| 87 | qemu_opts_absorb_qdict(opts, options, &error_abort); |
| 88 | s->length = |
| 89 | qemu_opt_get_size(opts, BLOCK_OPT_SIZE, 1 << 30); |
Fam Zheng | e5e51dd | 2015-04-01 09:45:38 +0800 | [diff] [blame] | 90 | s->latency_ns = |
| 91 | qemu_opt_get_number(opts, NULL_OPT_LATENCY, 0); |
| 92 | if (s->latency_ns < 0) { |
| 93 | error_setg(errp, "latency-ns is invalid"); |
| 94 | ret = -EINVAL; |
| 95 | } |
Max Reitz | cd219eb | 2016-03-24 23:33:58 +0100 | [diff] [blame] | 96 | s->read_zeroes = qemu_opt_get_bool(opts, NULL_OPT_ZEROES, false); |
Fam Zheng | e819ab2 | 2014-09-11 14:09:56 +0800 | [diff] [blame] | 97 | qemu_opts_del(opts); |
Eric Blake | b3241e9 | 2018-04-24 14:25:03 -0500 | [diff] [blame] | 98 | bs->supported_write_flags = BDRV_REQ_FUA; |
Fam Zheng | e5e51dd | 2015-04-01 09:45:38 +0800 | [diff] [blame] | 99 | return ret; |
Fam Zheng | e819ab2 | 2014-09-11 14:09:56 +0800 | [diff] [blame] | 100 | } |
| 101 | |
Fam Zheng | e819ab2 | 2014-09-11 14:09:56 +0800 | [diff] [blame] | 102 | static int64_t null_getlength(BlockDriverState *bs) |
| 103 | { |
| 104 | BDRVNullState *s = bs->opaque; |
| 105 | return s->length; |
| 106 | } |
| 107 | |
Fam Zheng | e5e51dd | 2015-04-01 09:45:38 +0800 | [diff] [blame] | 108 | static coroutine_fn int null_co_common(BlockDriverState *bs) |
| 109 | { |
| 110 | BDRVNullState *s = bs->opaque; |
| 111 | |
| 112 | if (s->latency_ns) { |
Stefan Hajnoczi | 78f1d3d | 2017-11-09 10:26:52 +0000 | [diff] [blame] | 113 | qemu_co_sleep_ns(QEMU_CLOCK_REALTIME, s->latency_ns); |
Fam Zheng | e5e51dd | 2015-04-01 09:45:38 +0800 | [diff] [blame] | 114 | } |
| 115 | return 0; |
| 116 | } |
| 117 | |
Eric Blake | b3241e9 | 2018-04-24 14:25:03 -0500 | [diff] [blame] | 118 | static coroutine_fn int null_co_preadv(BlockDriverState *bs, |
Vladimir Sementsov-Ogievskiy | f7ef38d | 2021-09-03 13:27:59 +0300 | [diff] [blame] | 119 | int64_t offset, int64_t bytes, |
| 120 | QEMUIOVector *qiov, |
| 121 | BdrvRequestFlags flags) |
Fam Zheng | e819ab2 | 2014-09-11 14:09:56 +0800 | [diff] [blame] | 122 | { |
Max Reitz | cd219eb | 2016-03-24 23:33:58 +0100 | [diff] [blame] | 123 | BDRVNullState *s = bs->opaque; |
| 124 | |
| 125 | if (s->read_zeroes) { |
Eric Blake | b3241e9 | 2018-04-24 14:25:03 -0500 | [diff] [blame] | 126 | qemu_iovec_memset(qiov, 0, 0, bytes); |
Max Reitz | cd219eb | 2016-03-24 23:33:58 +0100 | [diff] [blame] | 127 | } |
| 128 | |
Fam Zheng | e5e51dd | 2015-04-01 09:45:38 +0800 | [diff] [blame] | 129 | return null_co_common(bs); |
Fam Zheng | e819ab2 | 2014-09-11 14:09:56 +0800 | [diff] [blame] | 130 | } |
| 131 | |
Eric Blake | b3241e9 | 2018-04-24 14:25:03 -0500 | [diff] [blame] | 132 | static coroutine_fn int null_co_pwritev(BlockDriverState *bs, |
Vladimir Sementsov-Ogievskiy | e75abed | 2021-09-03 13:28:00 +0300 | [diff] [blame] | 133 | int64_t offset, int64_t bytes, |
| 134 | QEMUIOVector *qiov, |
| 135 | BdrvRequestFlags flags) |
Fam Zheng | e819ab2 | 2014-09-11 14:09:56 +0800 | [diff] [blame] | 136 | { |
Fam Zheng | e5e51dd | 2015-04-01 09:45:38 +0800 | [diff] [blame] | 137 | return null_co_common(bs); |
Fam Zheng | e819ab2 | 2014-09-11 14:09:56 +0800 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | static coroutine_fn int null_co_flush(BlockDriverState *bs) |
| 141 | { |
Fam Zheng | e5e51dd | 2015-04-01 09:45:38 +0800 | [diff] [blame] | 142 | return null_co_common(bs); |
Fam Zheng | e819ab2 | 2014-09-11 14:09:56 +0800 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | typedef struct { |
Markus Armbruster | 7c84b1b | 2014-10-07 13:59:14 +0200 | [diff] [blame] | 146 | BlockAIOCB common; |
Fam Zheng | e5e51dd | 2015-04-01 09:45:38 +0800 | [diff] [blame] | 147 | QEMUTimer timer; |
Fam Zheng | e819ab2 | 2014-09-11 14:09:56 +0800 | [diff] [blame] | 148 | } NullAIOCB; |
| 149 | |
| 150 | static const AIOCBInfo null_aiocb_info = { |
| 151 | .aiocb_size = sizeof(NullAIOCB), |
| 152 | }; |
| 153 | |
| 154 | static void null_bh_cb(void *opaque) |
| 155 | { |
| 156 | NullAIOCB *acb = opaque; |
| 157 | acb->common.cb(acb->common.opaque, 0); |
Fam Zheng | e819ab2 | 2014-09-11 14:09:56 +0800 | [diff] [blame] | 158 | qemu_aio_unref(acb); |
| 159 | } |
| 160 | |
Fam Zheng | e5e51dd | 2015-04-01 09:45:38 +0800 | [diff] [blame] | 161 | static void null_timer_cb(void *opaque) |
| 162 | { |
| 163 | NullAIOCB *acb = opaque; |
| 164 | acb->common.cb(acb->common.opaque, 0); |
| 165 | timer_deinit(&acb->timer); |
| 166 | qemu_aio_unref(acb); |
| 167 | } |
| 168 | |
Markus Armbruster | 7c84b1b | 2014-10-07 13:59:14 +0200 | [diff] [blame] | 169 | static inline BlockAIOCB *null_aio_common(BlockDriverState *bs, |
Markus Armbruster | 097310b | 2014-10-07 13:59:15 +0200 | [diff] [blame] | 170 | BlockCompletionFunc *cb, |
Markus Armbruster | 7c84b1b | 2014-10-07 13:59:14 +0200 | [diff] [blame] | 171 | void *opaque) |
Fam Zheng | e819ab2 | 2014-09-11 14:09:56 +0800 | [diff] [blame] | 172 | { |
| 173 | NullAIOCB *acb; |
Fam Zheng | e5e51dd | 2015-04-01 09:45:38 +0800 | [diff] [blame] | 174 | BDRVNullState *s = bs->opaque; |
Fam Zheng | e819ab2 | 2014-09-11 14:09:56 +0800 | [diff] [blame] | 175 | |
| 176 | acb = qemu_aio_get(&null_aiocb_info, bs, cb, opaque); |
Fam Zheng | e5e51dd | 2015-04-01 09:45:38 +0800 | [diff] [blame] | 177 | /* Only emulate latency after vcpu is running. */ |
| 178 | if (s->latency_ns) { |
| 179 | aio_timer_init(bdrv_get_aio_context(bs), &acb->timer, |
| 180 | QEMU_CLOCK_REALTIME, SCALE_NS, |
| 181 | null_timer_cb, acb); |
| 182 | timer_mod_ns(&acb->timer, |
| 183 | qemu_clock_get_ns(QEMU_CLOCK_REALTIME) + s->latency_ns); |
| 184 | } else { |
Pavel Dovgalyuk | e4ec5ad | 2019-09-17 14:58:19 +0300 | [diff] [blame] | 185 | replay_bh_schedule_oneshot_event(bdrv_get_aio_context(bs), |
| 186 | null_bh_cb, acb); |
Fam Zheng | e5e51dd | 2015-04-01 09:45:38 +0800 | [diff] [blame] | 187 | } |
Fam Zheng | e819ab2 | 2014-09-11 14:09:56 +0800 | [diff] [blame] | 188 | return &acb->common; |
| 189 | } |
| 190 | |
Eric Blake | b3241e9 | 2018-04-24 14:25:03 -0500 | [diff] [blame] | 191 | static BlockAIOCB *null_aio_preadv(BlockDriverState *bs, |
Vladimir Sementsov-Ogievskiy | f7ef38d | 2021-09-03 13:27:59 +0300 | [diff] [blame] | 192 | int64_t offset, int64_t bytes, |
| 193 | QEMUIOVector *qiov, BdrvRequestFlags flags, |
Eric Blake | b3241e9 | 2018-04-24 14:25:03 -0500 | [diff] [blame] | 194 | BlockCompletionFunc *cb, |
| 195 | void *opaque) |
Fam Zheng | e819ab2 | 2014-09-11 14:09:56 +0800 | [diff] [blame] | 196 | { |
Max Reitz | cd219eb | 2016-03-24 23:33:58 +0100 | [diff] [blame] | 197 | BDRVNullState *s = bs->opaque; |
| 198 | |
| 199 | if (s->read_zeroes) { |
Eric Blake | b3241e9 | 2018-04-24 14:25:03 -0500 | [diff] [blame] | 200 | qemu_iovec_memset(qiov, 0, 0, bytes); |
Max Reitz | cd219eb | 2016-03-24 23:33:58 +0100 | [diff] [blame] | 201 | } |
| 202 | |
Fam Zheng | e819ab2 | 2014-09-11 14:09:56 +0800 | [diff] [blame] | 203 | return null_aio_common(bs, cb, opaque); |
| 204 | } |
| 205 | |
Eric Blake | b3241e9 | 2018-04-24 14:25:03 -0500 | [diff] [blame] | 206 | static BlockAIOCB *null_aio_pwritev(BlockDriverState *bs, |
Vladimir Sementsov-Ogievskiy | e75abed | 2021-09-03 13:28:00 +0300 | [diff] [blame] | 207 | int64_t offset, int64_t bytes, |
| 208 | QEMUIOVector *qiov, BdrvRequestFlags flags, |
Eric Blake | b3241e9 | 2018-04-24 14:25:03 -0500 | [diff] [blame] | 209 | BlockCompletionFunc *cb, |
| 210 | void *opaque) |
Fam Zheng | e819ab2 | 2014-09-11 14:09:56 +0800 | [diff] [blame] | 211 | { |
| 212 | return null_aio_common(bs, cb, opaque); |
| 213 | } |
| 214 | |
Markus Armbruster | 7c84b1b | 2014-10-07 13:59:14 +0200 | [diff] [blame] | 215 | static BlockAIOCB *null_aio_flush(BlockDriverState *bs, |
Markus Armbruster | 097310b | 2014-10-07 13:59:15 +0200 | [diff] [blame] | 216 | BlockCompletionFunc *cb, |
Markus Armbruster | 7c84b1b | 2014-10-07 13:59:14 +0200 | [diff] [blame] | 217 | void *opaque) |
Fam Zheng | e819ab2 | 2014-09-11 14:09:56 +0800 | [diff] [blame] | 218 | { |
| 219 | return null_aio_common(bs, cb, opaque); |
| 220 | } |
| 221 | |
Fam Zheng | 1c2b49a | 2015-04-01 09:45:39 +0800 | [diff] [blame] | 222 | static int null_reopen_prepare(BDRVReopenState *reopen_state, |
| 223 | BlockReopenQueue *queue, Error **errp) |
| 224 | { |
| 225 | return 0; |
| 226 | } |
| 227 | |
Eric Blake | 05c33f1 | 2018-02-13 14:26:49 -0600 | [diff] [blame] | 228 | static int coroutine_fn null_co_block_status(BlockDriverState *bs, |
| 229 | bool want_zero, int64_t offset, |
| 230 | int64_t bytes, int64_t *pnum, |
| 231 | int64_t *map, |
| 232 | BlockDriverState **file) |
Max Reitz | a906392 | 2016-03-24 23:33:59 +0100 | [diff] [blame] | 233 | { |
| 234 | BDRVNullState *s = bs->opaque; |
Eric Blake | 05c33f1 | 2018-02-13 14:26:49 -0600 | [diff] [blame] | 235 | int ret = BDRV_BLOCK_OFFSET_VALID; |
Max Reitz | a906392 | 2016-03-24 23:33:59 +0100 | [diff] [blame] | 236 | |
Eric Blake | 05c33f1 | 2018-02-13 14:26:49 -0600 | [diff] [blame] | 237 | *pnum = bytes; |
| 238 | *map = offset; |
Max Reitz | a906392 | 2016-03-24 23:33:59 +0100 | [diff] [blame] | 239 | *file = bs; |
| 240 | |
| 241 | if (s->read_zeroes) { |
Eric Blake | 05c33f1 | 2018-02-13 14:26:49 -0600 | [diff] [blame] | 242 | ret |= BDRV_BLOCK_ZERO; |
Max Reitz | a906392 | 2016-03-24 23:33:59 +0100 | [diff] [blame] | 243 | } |
Eric Blake | 05c33f1 | 2018-02-13 14:26:49 -0600 | [diff] [blame] | 244 | return ret; |
Max Reitz | a906392 | 2016-03-24 23:33:59 +0100 | [diff] [blame] | 245 | } |
| 246 | |
Max Reitz | 998b3a1 | 2019-02-01 20:29:28 +0100 | [diff] [blame] | 247 | static void null_refresh_filename(BlockDriverState *bs) |
Max Reitz | 67882b1 | 2016-06-10 20:57:48 +0200 | [diff] [blame] | 248 | { |
Max Reitz | 998b3a1 | 2019-02-01 20:29:28 +0100 | [diff] [blame] | 249 | const QDictEntry *e; |
Max Reitz | 67882b1 | 2016-06-10 20:57:48 +0200 | [diff] [blame] | 250 | |
Max Reitz | 998b3a1 | 2019-02-01 20:29:28 +0100 | [diff] [blame] | 251 | for (e = qdict_first(bs->full_open_options); e; |
| 252 | e = qdict_next(bs->full_open_options, e)) |
| 253 | { |
| 254 | /* These options can be ignored */ |
| 255 | if (strcmp(qdict_entry_key(e), "filename") && |
Max Reitz | 1e47cb7 | 2019-02-01 20:29:33 +0100 | [diff] [blame] | 256 | strcmp(qdict_entry_key(e), "driver") && |
| 257 | strcmp(qdict_entry_key(e), NULL_OPT_LATENCY)) |
Max Reitz | 998b3a1 | 2019-02-01 20:29:28 +0100 | [diff] [blame] | 258 | { |
| 259 | return; |
| 260 | } |
Max Reitz | 67882b1 | 2016-06-10 20:57:48 +0200 | [diff] [blame] | 261 | } |
| 262 | |
Max Reitz | 998b3a1 | 2019-02-01 20:29:28 +0100 | [diff] [blame] | 263 | snprintf(bs->exact_filename, sizeof(bs->exact_filename), "%s://", |
| 264 | bs->drv->format_name); |
Max Reitz | 67882b1 | 2016-06-10 20:57:48 +0200 | [diff] [blame] | 265 | } |
| 266 | |
Max Reitz | 07cd7b6 | 2020-06-22 13:58:45 +0200 | [diff] [blame] | 267 | static int64_t null_allocated_file_size(BlockDriverState *bs) |
| 268 | { |
| 269 | return 0; |
| 270 | } |
| 271 | |
Max Reitz | 2654267 | 2019-02-01 20:29:25 +0100 | [diff] [blame] | 272 | static const char *const null_strong_runtime_opts[] = { |
| 273 | BLOCK_OPT_SIZE, |
| 274 | NULL_OPT_ZEROES, |
| 275 | |
| 276 | NULL |
| 277 | }; |
| 278 | |
Fam Zheng | e819ab2 | 2014-09-11 14:09:56 +0800 | [diff] [blame] | 279 | static BlockDriver bdrv_null_co = { |
| 280 | .format_name = "null-co", |
| 281 | .protocol_name = "null-co", |
| 282 | .instance_size = sizeof(BDRVNullState), |
| 283 | |
| 284 | .bdrv_file_open = null_file_open, |
Kevin Wolf | 809eb70 | 2017-08-04 12:44:22 +0200 | [diff] [blame] | 285 | .bdrv_parse_filename = null_co_parse_filename, |
Fam Zheng | e819ab2 | 2014-09-11 14:09:56 +0800 | [diff] [blame] | 286 | .bdrv_getlength = null_getlength, |
Max Reitz | 07cd7b6 | 2020-06-22 13:58:45 +0200 | [diff] [blame] | 287 | .bdrv_get_allocated_file_size = null_allocated_file_size, |
Fam Zheng | e819ab2 | 2014-09-11 14:09:56 +0800 | [diff] [blame] | 288 | |
Eric Blake | b3241e9 | 2018-04-24 14:25:03 -0500 | [diff] [blame] | 289 | .bdrv_co_preadv = null_co_preadv, |
| 290 | .bdrv_co_pwritev = null_co_pwritev, |
Fam Zheng | e819ab2 | 2014-09-11 14:09:56 +0800 | [diff] [blame] | 291 | .bdrv_co_flush_to_disk = null_co_flush, |
Fam Zheng | 1c2b49a | 2015-04-01 09:45:39 +0800 | [diff] [blame] | 292 | .bdrv_reopen_prepare = null_reopen_prepare, |
Max Reitz | a906392 | 2016-03-24 23:33:59 +0100 | [diff] [blame] | 293 | |
Eric Blake | 05c33f1 | 2018-02-13 14:26:49 -0600 | [diff] [blame] | 294 | .bdrv_co_block_status = null_co_block_status, |
Max Reitz | 67882b1 | 2016-06-10 20:57:48 +0200 | [diff] [blame] | 295 | |
| 296 | .bdrv_refresh_filename = null_refresh_filename, |
Max Reitz | 2654267 | 2019-02-01 20:29:25 +0100 | [diff] [blame] | 297 | .strong_runtime_opts = null_strong_runtime_opts, |
Fam Zheng | e819ab2 | 2014-09-11 14:09:56 +0800 | [diff] [blame] | 298 | }; |
| 299 | |
| 300 | static BlockDriver bdrv_null_aio = { |
| 301 | .format_name = "null-aio", |
| 302 | .protocol_name = "null-aio", |
| 303 | .instance_size = sizeof(BDRVNullState), |
| 304 | |
| 305 | .bdrv_file_open = null_file_open, |
Kevin Wolf | 809eb70 | 2017-08-04 12:44:22 +0200 | [diff] [blame] | 306 | .bdrv_parse_filename = null_aio_parse_filename, |
Fam Zheng | e819ab2 | 2014-09-11 14:09:56 +0800 | [diff] [blame] | 307 | .bdrv_getlength = null_getlength, |
Max Reitz | 07cd7b6 | 2020-06-22 13:58:45 +0200 | [diff] [blame] | 308 | .bdrv_get_allocated_file_size = null_allocated_file_size, |
Fam Zheng | e819ab2 | 2014-09-11 14:09:56 +0800 | [diff] [blame] | 309 | |
Eric Blake | b3241e9 | 2018-04-24 14:25:03 -0500 | [diff] [blame] | 310 | .bdrv_aio_preadv = null_aio_preadv, |
| 311 | .bdrv_aio_pwritev = null_aio_pwritev, |
Fam Zheng | e819ab2 | 2014-09-11 14:09:56 +0800 | [diff] [blame] | 312 | .bdrv_aio_flush = null_aio_flush, |
Fam Zheng | 1c2b49a | 2015-04-01 09:45:39 +0800 | [diff] [blame] | 313 | .bdrv_reopen_prepare = null_reopen_prepare, |
Max Reitz | a906392 | 2016-03-24 23:33:59 +0100 | [diff] [blame] | 314 | |
Eric Blake | 05c33f1 | 2018-02-13 14:26:49 -0600 | [diff] [blame] | 315 | .bdrv_co_block_status = null_co_block_status, |
Max Reitz | 67882b1 | 2016-06-10 20:57:48 +0200 | [diff] [blame] | 316 | |
| 317 | .bdrv_refresh_filename = null_refresh_filename, |
Max Reitz | 2654267 | 2019-02-01 20:29:25 +0100 | [diff] [blame] | 318 | .strong_runtime_opts = null_strong_runtime_opts, |
Fam Zheng | e819ab2 | 2014-09-11 14:09:56 +0800 | [diff] [blame] | 319 | }; |
| 320 | |
| 321 | static void bdrv_null_init(void) |
| 322 | { |
| 323 | bdrv_register(&bdrv_null_co); |
| 324 | bdrv_register(&bdrv_null_aio); |
| 325 | } |
| 326 | |
| 327 | block_init(bdrv_null_init); |