block: minor refactoring in preparation to the block layer API split
v3 cover block: minor refactoring in preparation to the block layer API split
These patches are taken from my old patches and feedback of my series "block layer: split block APIs in global state and I/O".
The reason for a separate series is that the original one is already too long, and these patches are just refactoring the code, mainly deleting or moving functions in blockdev.h and block_int.h.
---
v3:
* Apply Kevin comments, remove getter method added in v2 and do not touch drive_add().
v2:
* Apply Philippe comments, instead of renaming a make if_name public, create a getter method (discard old patch 2).
Emanuele Giuseppe Esposito (3):
block_int: make bdrv_backing_overridden static include/sysemu/blockdev.h: remove drive_mark_claimed_by_board and
inline drive_def
include/sysemu/blockdev.h: remove drive_get_max_devs
block.c | 4 +++- block/monitor/block-hmp-cmds.c | 2 +- blockdev.c | 24 +----------------------- include/block/block_int.h | 3 --- include/sysemu/blockdev.h | 3 --- softmmu/vl.c | 4 +++- 6 files changed, 8 insertions(+), 32 deletions(-)
Signature · 1 line
2.31.1
PATCH v3 1/3 block_int: make bdrv_backing_overridden static
bdrv_backing_overridden is only used in block.c, so there is no need to leave it in block_int.h
--- block.c | 4 +++- include/block/block_int.h | 3 --- 2 files changed, 3 insertions(+), 4 deletions(-)
block.c +3 -1
@@ -103,6 +103,8 @@ static int bdrv_reopen_prepare(BDRVReopenState *reopen_state,static void bdrv_reopen_commit (BDRVReopenState *reopen_state);static void bdrv_reopen_abort (BDRVReopenState *reopen_state); +static bool bdrv_backing_overridden (BlockDriverState *bs); +/* If non-zero, use only whitelisted block drivers */ static int use_bdrv_whitelist;
@@ -7475,7 +7477,7 @@ static bool append_strong_runtime_options(QDict *d, BlockDriverState *bs)/* Note: This function may return false positives; it may return true * even if opening the backing file specified by bs's image header * would result in exactly bs->backing. */ -bool bdrv_backing_overridden (BlockDriverState *bs) +static bool bdrv_backing_overridden (BlockDriverState *bs) {if (bs->backing) { return strcmp(bs->auto_backing_file,
include/block/block_int.h +0 -3
@@ -1122,9 +1122,6 @@ BlockDriver *bdrv_probe_all(const uint8_t *buf, int buf_size,void bdrv_parse_filename_strip_prefix (const char *filename,const char *prefix,QDict *options); -bool bdrv_backing_overridden (BlockDriverState *bs); - -/** * bdrv_add_aio_context_notifier: *
Signature · 1 line
2.31.1
PATCH v3 2/3 include/sysemu/blockdev.h: remove drive_mark_claimed_by_board and inline drive_def
In reply to Emanuele Giuseppe Espositodrive_def is only a particular use case ofqemu_opts_parse_noisily, so it can be inlined.
Also remove drive_mark_claimed_by_board, as it is only defined but not implemented (nor used) anywhere.
--- block/monitor/block-hmp-cmds.c | 2 +- blockdev.c | 7 +------ include/sysemu/blockdev.h | 2 -- softmmu/vl.c | 4 +++- 4 files changed, 5 insertions(+), 10 deletions(-)
block/monitor/block-hmp-cmds.c +1 -1
@@ -101,7 +101,7 @@ void hmp_drive_add(Monitor *mon, const QDict *qdict)return ; } - opts =drive_def (optstr); + opts =qemu_opts_parse_noisily (qemu_find_opts ("drive" ), optstr, false);if (!opts)return ;
blockdev.c +1 -6
@@ -197,17 +197,12 @@ static int drive_index_to_unit_id(BlockInterfaceType type, int index)return max_devs ? index % max_devs : index; } -QemuOpts *drive_def (const char *optstr) -{ -return qemu_opts_parse_noisily (qemu_find_opts ("drive" ), optstr, false); -} -QemuOpts *drive_add (BlockInterfaceType type,int index,const char *file,const char *optstr) {QemuOpts *opts; - opts =drive_def (optstr); + opts =qemu_opts_parse_noisily (qemu_find_opts ("drive" ), optstr, false);if (!opts) {return NULL ; }
include/sysemu/blockdev.h +0 -2
@@ -45,14 +45,12 @@ BlockBackend *blk_by_legacy_dinfo(DriveInfo *dinfo);void override_max_devs (BlockInterfaceType type,int max_devs);DriveInfo *drive_get (BlockInterfaceType type,int bus,int unit); -void drive_mark_claimed_by_board (void );void drive_check_orphaned (void );DriveInfo *drive_get_by_index (BlockInterfaceType type,int index);int drive_get_max_bus (BlockInterfaceType type);int drive_get_max_devs (BlockInterfaceType type);DriveInfo *drive_get_next (BlockInterfaceType type); -QemuOpts *drive_def (const char *optstr);QemuOpts *drive_add (BlockInterfaceType type,int index,const char *file,const char *optstr); DriveInfo *drive_new(QemuOpts *arg, BlockInterfaceType block_default_type,
softmmu/vl.c +3 -1
@@ -2884,7 +2884,9 @@ void qemu_init(int argc, char **argv, char **envp)break ; }case QEMU_OPTION_drive: -if (drive_def (optarg) ==NULL ) { + opts =qemu_opts_parse_noisily (qemu_find_opts ("drive" ), + optarg, false); +if (opts ==NULL ) {exit (1 ); }break ;
Signature · 1 line
2.31.1
PATCH v3 3/3 include/sysemu/blockdev.h: remove drive_get_max_devs
In reply to Emanuele Giuseppe EspositoRemove drive_get_max_devs, as it is not used by anyone.
Last use was removed in commit 8f2d75e81d5
("hw: Drop superfluous special checks for orphaned -drive").
--- blockdev.c | 17 ----------------- include/sysemu/blockdev.h | 1 - 2 files changed, 18 deletions(-)
blockdev.c +0 -17
@@ -168,23 +168,6 @@ void blockdev_auto_del(BlockBackend *blk) } } -/** -* Returns the current mapping of how many units per bus -* a particular interface can support. -* -* A positive integer indicates n units per bus. -* 0 implies the mapping has not been established. -* -1 indicates an invalid BlockInterfaceType was given. -*/ -int drive_get_max_devs (BlockInterfaceType type) -{ -if (type >=IF_IDE && type <IF_COUNT ) { -return if_max_devs[type]; - } - -return -1 ; -} -static int drive_index_to_bus_id (BlockInterfaceType type,int index) {int max_devs = if_max_devs[type];
include/sysemu/blockdev.h +0 -1
@@ -48,7 +48,6 @@ DriveInfo *drive_get(BlockInterfaceType type, int bus, int unit);void drive_check_orphaned (void );DriveInfo *drive_get_by_index (BlockInterfaceType type,int index);int drive_get_max_bus (BlockInterfaceType type); -int drive_get_max_devs (BlockInterfaceType type);DriveInfo *drive_get_next (BlockInterfaceType type); QemuOpts *drive_add(BlockInterfaceType type, int index, const char *file,
Signature · 1 line
2.31.1
Kevin Wolf
AppliedAm 15.12.2021 um 13:11 hat Emanuele Giuseppe Esposito geschrieben:
Quoted 8 lines
These patches are taken from my old patches and feedback of my series "block layer: split block APIs in global state and I/O".
The reason for a separate series is that the original one is already too long, and these patches are just refactoring the code, mainly deleting or moving functions in
blockdev.handblock_int.h.Signed-off-by Emanuele Giuseppe Esposito <[email protected]>
Thanks, applied to the block branch.
Kevin