stm32f205: Add the stm32f205 SoC
[qemu/qmp-unstable.git] / block / null.c
blobec2bd27a4b9d1dd60fe62ebc0cce80e6552aa9c1
1 /*
2 * Null block driver
4 * Authors:
5 * Fam Zheng <famz@redhat.com>
7 * Copyright (C) 2014 Red Hat, Inc.
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.
13 #include "block/block_int.h"
15 typedef struct {
16 int64_t length;
17 } BDRVNullState;
19 static QemuOptsList runtime_opts = {
20 .name = "null",
21 .head = QTAILQ_HEAD_INITIALIZER(runtime_opts.head),
22 .desc = {
24 .name = "filename",
25 .type = QEMU_OPT_STRING,
26 .help = "",
29 .name = BLOCK_OPT_SIZE,
30 .type = QEMU_OPT_SIZE,
31 .help = "size of the null block",
33 { /* end of list */ }
37 static int null_file_open(BlockDriverState *bs, QDict *options, int flags,
38 Error **errp)
40 QemuOpts *opts;
41 BDRVNullState *s = bs->opaque;
43 opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);
44 qemu_opts_absorb_qdict(opts, options, &error_abort);
45 s->length =
46 qemu_opt_get_size(opts, BLOCK_OPT_SIZE, 1 << 30);
47 qemu_opts_del(opts);
48 return 0;
51 static void null_close(BlockDriverState *bs)
55 static int64_t null_getlength(BlockDriverState *bs)
57 BDRVNullState *s = bs->opaque;
58 return s->length;
61 static coroutine_fn int null_co_readv(BlockDriverState *bs,
62 int64_t sector_num, int nb_sectors,
63 QEMUIOVector *qiov)
65 return 0;
68 static coroutine_fn int null_co_writev(BlockDriverState *bs,
69 int64_t sector_num, int nb_sectors,
70 QEMUIOVector *qiov)
72 return 0;
75 static coroutine_fn int null_co_flush(BlockDriverState *bs)
77 return 0;
80 typedef struct {
81 BlockAIOCB common;
82 QEMUBH *bh;
83 } NullAIOCB;
85 static const AIOCBInfo null_aiocb_info = {
86 .aiocb_size = sizeof(NullAIOCB),
89 static void null_bh_cb(void *opaque)
91 NullAIOCB *acb = opaque;
92 acb->common.cb(acb->common.opaque, 0);
93 qemu_bh_delete(acb->bh);
94 qemu_aio_unref(acb);
97 static inline BlockAIOCB *null_aio_common(BlockDriverState *bs,
98 BlockCompletionFunc *cb,
99 void *opaque)
101 NullAIOCB *acb;
103 acb = qemu_aio_get(&null_aiocb_info, bs, cb, opaque);
104 acb->bh = aio_bh_new(bdrv_get_aio_context(bs), null_bh_cb, acb);
105 qemu_bh_schedule(acb->bh);
106 return &acb->common;
109 static BlockAIOCB *null_aio_readv(BlockDriverState *bs,
110 int64_t sector_num, QEMUIOVector *qiov,
111 int nb_sectors,
112 BlockCompletionFunc *cb,
113 void *opaque)
115 return null_aio_common(bs, cb, opaque);
118 static BlockAIOCB *null_aio_writev(BlockDriverState *bs,
119 int64_t sector_num, QEMUIOVector *qiov,
120 int nb_sectors,
121 BlockCompletionFunc *cb,
122 void *opaque)
124 return null_aio_common(bs, cb, opaque);
127 static BlockAIOCB *null_aio_flush(BlockDriverState *bs,
128 BlockCompletionFunc *cb,
129 void *opaque)
131 return null_aio_common(bs, cb, opaque);
134 static BlockDriver bdrv_null_co = {
135 .format_name = "null-co",
136 .protocol_name = "null-co",
137 .instance_size = sizeof(BDRVNullState),
139 .bdrv_file_open = null_file_open,
140 .bdrv_close = null_close,
141 .bdrv_getlength = null_getlength,
143 .bdrv_co_readv = null_co_readv,
144 .bdrv_co_writev = null_co_writev,
145 .bdrv_co_flush_to_disk = null_co_flush,
148 static BlockDriver bdrv_null_aio = {
149 .format_name = "null-aio",
150 .protocol_name = "null-aio",
151 .instance_size = sizeof(BDRVNullState),
153 .bdrv_file_open = null_file_open,
154 .bdrv_close = null_close,
155 .bdrv_getlength = null_getlength,
157 .bdrv_aio_readv = null_aio_readv,
158 .bdrv_aio_writev = null_aio_writev,
159 .bdrv_aio_flush = null_aio_flush,
162 static void bdrv_null_init(void)
164 bdrv_register(&bdrv_null_co);
165 bdrv_register(&bdrv_null_aio);
168 block_init(bdrv_null_init);