block: Introduce "null" drivers
PATCH v5 1/1 block: Introduce "null" drivers
This is an analogue to Linux null_blk. It can be used for testing or benchmarking block device emulation and general block layer functionalities such as coroutines and throttling, where disk IO is not necessary or wanted.
Use null-aio:// for AIO version, and null-co:// for coroutine version.
---
v5: Rename "null://" to "null-aio://". (Stefan)
Add Benoit's rev-by line.
--- block/Makefile.objs | 1 + block/null.c | 176 +++++++++++++++++++++++++++++++++++++++++++++++++++ qapi/block-core.json | 20 +++++- 3 files changed, 195 insertions(+), 2 deletions(-) create mode 100644 block/null.c
block/Makefile.objs +1 -0
@@ -9,6 +9,7 @@ block-obj-y += snapshot.o qapi.o block-obj-$(CONFIG_WIN32) += raw-win32.o win32-aio.o block-obj-$(CONFIG_POSIX) += raw-posix.o block-obj-$(CONFIG_LINUX_AIO) += linux-aio.o +block-obj-y += null.o ifeq ($(CONFIG_POSIX),y) block-obj-y += nbd.o nbd-client.o sheepdog.o
block/null.c new file +176 -0
176 lines not on this page · raw message
qapi/block-core.json +18 -2
@@ -1150,7 +1150,8 @@ 'data': [ 'archipelago', 'file', 'host_device', 'host_cdrom', 'host_floppy', 'http', 'https', 'ftp', 'ftps', 'tftp', 'vvfat', 'blkdebug', 'blkverify', 'bochs', 'cloop', 'cow', 'dmg', 'parallels', 'qcow', - 'qcow2', 'qed', 'raw', 'vdi', 'vhdx', 'vmdk', 'vpc', 'quorum' ] } + 'qcow2', 'qed', 'raw', 'vdi', 'vhdx', 'vmdk', 'vpc', 'quorum', + 'null-aio', 'null-co' ] } ## # @BlockdevOptionsBase
@@ -1203,6 +1204,19 @@ 'data': { 'filename': 'str' } } ## +# @BlockdevOptionsNull +# +# Driver specific block device options for the null backend. +# +# @size: #optional size of the device in bytes. +# +# Since: 2.2 +## +{ 'type': 'BlockdevOptionsNull', + 'base': 'BlockdevOptionsFile', + 'data': { '*size': 'int' } } + +## # @BlockdevOptionsVVFAT # # Driver specific block device options for the vvfat protocol.
@@ -1484,7 +1498,9 @@ 'vhdx': 'BlockdevOptionsGenericFormat', 'vmdk': 'BlockdevOptionsGenericCOWFormat', 'vpc': 'BlockdevOptionsGenericFormat', - 'quorum': 'BlockdevOptionsQuorum' + 'quorum': 'BlockdevOptionsQuorum', + 'null-aio': 'BlockdevOptionsNull', + 'null-co': 'BlockdevOptionsNull' } } ##
Signature · 1 line
2.1.0
qapi/block-core.json line 1217
Quoted 3 lines · Fam Zheng
qapi/block-core.json +3
-0+{ 'type': 'BlockdevOptionsNull', + 'base': 'BlockdevOptionsFile', + 'data': { '*size': 'int' } }
Why inherit from BlockdevOptionsFile?
No other blockdev options type does that. Unless there is a real inheritance relationship, please don't do this.
Stefan
Am 01.09.2014 um 11:22 hat Fam Zheng geschrieben:
Quoted 11 lines
This is an analogue to Linux
null_blk. It can be used for testing or benchmarking block device emulation and general block layer functionalities such as coroutines and throttling, where disk IO is not necessary or wanted.Use null-aio:// for AIO version, and null-co:// for coroutine version.
Signed-off-by Fam Zheng <[email protected]>Reviewed-by Benoît Canet <[email protected]>block/null.c new file +1
-0+static BlockDriver bdrv_null_co = {
block/null.c line 152
Quoted 10 lines
block/null.c new file +10
-0+ .format_name = "null-co", + .protocol_name = "null-co", + .instance_size = sizeof(BDRVNullState), + + .bdrv_file_open = null_file_open, + .bdrv_close = null_close, + .bdrv_getlength = null_getlength, + + .bdrv_read = null_co_read, + .bdrv_write = null_co_write,
Any reason not to use the native .bdrv_co_readv/writev interfaces instead of the old, emulated versions that involve a bounce buffer?
Review
Quoted 2 lines
(quoted diff) +2
-0+ .bdrv_co_flush_to_disk = null_co_flush, +};
Kevin
Quoted 11 lines · Kevin Wolf
Am 01.09.2014 um 11:22 hat Fam Zheng geschrieben:
Quoted 9 lines
This is an analogue to Linux
null_blk. It can be used for testing or benchmarking block device emulation and general block layer functionalities such as coroutines and throttling, where disk IO is not necessary or wanted.Use null-aio:// for AIO version, and null-co:// for coroutine version.
Signed-off-by Fam Zheng <[email protected]>Reviewed-by Benoît Canet <[email protected]>
Quoted 14 lines
block/null.c line 152
Quoted 11 lines
block/null.c new file +11
-0+static BlockDriver bdrv_null_co = { + .format_name ="null-co" , + .protocol_name ="null-co" , + .instance_size =sizeof (BDRVNullState), + + .bdrv_file_open = null_file_open, + .bdrv_close = null_close, + .bdrv_getlength = null_getlength, + + .bdrv_read = null_co_read, + .bdrv_write = null_co_write,Any reason not to use the native .bdrv_co_readv/writev interfaces instead of the old, emulated versions that involve a bounce buffer?
No good reason, I'll change it in the next version.
Thanks,
Fam