Dynamic module loading for block drivers
Subsystems (2)
v4 cover Dynamic module loading for block drivers
Here's v4 of the modularization series. Things that have changed since v3 include:
- Fix indentation of the generated header file module_block.h
- Drivers and probe functions are now all located in the block/ directory, rather than being split between block/ and block/probe/. In addition the header files for each probe/driver pair are in the block/ directory, not the include/block/driver/ directory (which no longer exists).
- Since the probe files are in block/ now, they follow the naming pattern of format-probe.c
- Renamed crypto probe file to be crypto-probe.c, luks is no longer in the filename
- Fixed formatting of parallels_probe() function header
- Enforced consistent naming convention for the probe functions. They now follow the pattern bdrv_format_probe().
Colin Lord (30):
blockdev: prepare iSCSI block driver for dynamic loading
blockdev: Move bochs probe into separate file
blockdev: Move cloop probe to its own file
blockdev: Move luks probe to its own file
blockdev: Move dmg probe to its own file
blockdev: Move parallels probe to its own file
blockdev: Move qcow probe to its own file
blockdev: Move qcow2 probe to its own file
blockdev: Move qed probe to its own file
blockdev: Move raw probe to its own file
blockdev: Move vdi probe to its own file
blockdev: Move vhdx probe to its own file
blockdev: Move vmdk probe to its own file
blockdev: Move vpc probe to its own file
blockdev: Separate bochs probe from its driver
blockdev: Separate cloop probe from its driver
blockdev: Separate luks probe from its driver
blockdev: Separate dmg probe from its driver
blockdev: Separate parallels probe from its driver
blockdev: Separate qcow probe from its driver
blockdev: Separate qcow2 probe from its driver
blockdev: Separate qed probe from its driver
blockdev: Separate raw probe from its driver
blockdev: Separate vdi probe from its driver
blockdev: Separate vhdx probe from its driver
blockdev: Separate vmdk probe from its driver
blockdev: Separate vpc probe from its driver
blockdev: Remove the .bdrv_probe field from BlockDrivers
blockdev: Separate out bdrv_probe_device functions
blockdev: Remove bdrv_probe_device field from BlockDriver
Marc Mari (2):
blockdev: Add dynamic generation of module_block.h
blockdev: Add dynamic module loading for block drivers
Makefile | 7 ++ block.c | 181 ++++++++++++++++++++++++++++++++-------- block/Makefile.objs | 4 + block/bochs-probe.c | 28 +++++++ block/bochs.c | 56 +------------ block/bochs.h | 40 +++++++++ block/cloop-probe.c | 22 +++++ block/cloop.c | 17 +--- block/crypto-probe.c | 26 ++++++ block/crypto.c | 22 +---- block/dmg-probe.c | 22 +++++ block/dmg.c | 17 +--- block/host_cdrom-probe.c | 47 +++++++++++ block/host_device-probe.c | 42 ++++++++++ block/iscsi.c | 36 -------- block/parallels-probe.c | 26 ++++++ block/parallels.c | 44 +--------- block/parallels.h | 26 ++++++ block/qcow-probe.c | 22 +++++ block/qcow.c | 32 +------ block/qcow.h | 21 +++++ block/qcow2-probe.c | 22 +++++ block/qcow2.c | 14 +--- block/qed-probe.c | 24 ++++++ block/qed.c | 16 +--- block/raw-posix.c | 55 +----------- block/raw-probe.c | 14 ++++ block/raw-win32.c | 11 +-- block/raw_bsd.c | 10 +-- block/vdi-probe.c | 29 +++++++ block/vdi.c | 70 +--------------- block/vdi.h | 49 +++++++++++ block/vhdx-probe.c | 27 ++++++ block/vhdx.c | 21 +---- block/vmdk-probe.c | 67 +++++++++++++++ block/vmdk.c | 61 +------------- block/vmdk.h | 7 ++ block/vpc-probe.c | 16 ++++ block/vpc.c | 9 +- include/block/block_int.h | 3 - include/block/probe.h | 33 ++++++++ include/qemu/module.h | 3 + scripts/modules/module_block.py | 108 ++++++++++++++++++++++++ util/module.c | 38 +++------ vl.c | 38 +++++++++ 45 files changed, 948 insertions(+), 535 deletions(-) create mode 100644 block/bochs-probe.c create mode 100644 block/bochs.h create mode 100644 block/cloop-probe.c create mode 100644 block/crypto-probe.c create mode 100644 block/dmg-probe.c create mode 100644 block/host_cdrom-probe.c create mode 100644 block/host_device-probe.c create mode 100644 block/parallels-probe.c create mode 100644 block/parallels.h create mode 100644 block/qcow-probe.c create mode 100644 block/qcow.h create mode 100644 block/qcow2-probe.c create mode 100644 block/qed-probe.c create mode 100644 block/raw-probe.c create mode 100644 block/vdi-probe.c create mode 100644 block/vdi.h create mode 100644 block/vhdx-probe.c create mode 100644 block/vmdk-probe.c create mode 100644 block/vmdk.h create mode 100644 block/vpc-probe.c create mode 100644 include/block/probe.h create mode 100644 scripts/modules/module_block.py
Signature · 1 line
2.5.5
PATCH v4 1/32 blockdev: prepare iSCSI block driver for dynamic loading
This commit moves the initialization of the QemuOptsList qemu_iscsi_opts struct out of block/iscsi.c in order to allow the iscsi module to be dynamically loaded.
--- block/iscsi.c | 36 ------------------------------------ vl.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 36 deletions(-)
block/iscsi.c +0 -36
@@ -1882,45 +1882,9 @@ static BlockDriver bdrv_iscsi = { .bdrv_attach_aio_context = iscsi_attach_aio_context, }; -static QemuOptsList qemu_iscsi_opts = { - .name ="iscsi" , - .head =QTAILQ_HEAD_INITIALIZER (qemu_iscsi_opts.head), - .desc = { - { - .name ="user" , - .type =QEMU_OPT_STRING , - .help ="username for CHAP authentication to target" , - },{ - .name ="password" , - .type =QEMU_OPT_STRING , - .help ="password for CHAP authentication to target" , - },{ - .name ="password-secret" , - .type =QEMU_OPT_STRING , - .help ="ID of the secret providing password for CHAP " -"authentication to target" , - },{ - .name ="header-digest" , - .type =QEMU_OPT_STRING , - .help ="HeaderDigest setting. " -"{CRC32C|CRC32C-NONE|NONE-CRC32C|NONE}" , - },{ - .name ="initiator-name" , - .type =QEMU_OPT_STRING , - .help ="Initiator iqn name to use when connecting" , - },{ - .name ="timeout" , - .type =QEMU_OPT_NUMBER , - .help ="Request timeout in seconds (default 0 = no timeout)" , - }, - {/* end of list */ } - }, -}; -static void iscsi_block_init (void ) {bdrv_register (&bdrv_iscsi); -qemu_add_opts (&qemu_iscsi_opts); }block_init (iscsi_block_init);
vl.c +38 -0
@@ -506,6 +506,41 @@ static QemuOptsList qemu_fw_cfg_opts = { }, }; +static QemuOptsList qemu_iscsi_opts = { + .name ="iscsi" , + .head =QTAILQ_HEAD_INITIALIZER (qemu_iscsi_opts.head), + .desc = { + { + .name ="user" , + .type =QEMU_OPT_STRING , + .help ="username for CHAP authentication to target" , + },{ + .name ="password" , + .type =QEMU_OPT_STRING , + .help ="password for CHAP authentication to target" , + },{ + .name ="password-secret" , + .type =QEMU_OPT_STRING , + .help ="ID of the secret providing password for CHAP " +"authentication to target" , + },{ + .name ="header-digest" , + .type =QEMU_OPT_STRING , + .help ="HeaderDigest setting. " +"{CRC32C|CRC32C-NONE|NONE-CRC32C|NONE}" , + },{ + .name ="initiator-name" , + .type =QEMU_OPT_STRING , + .help ="Initiator iqn name to use when connecting" , + },{ + .name ="timeout" , + .type =QEMU_OPT_NUMBER , + .help ="Request timeout in seconds (default 0 = no timeout)" , + }, + {/* end of list */ } + }, +}; +/** * Get machine options *
@@ -3000,6 +3035,9 @@ int main(int argc, char **argv, char **envp)qemu_add_opts (&qemu_icount_opts);qemu_add_opts (&qemu_semihosting_config_opts);qemu_add_opts (&qemu_fw_cfg_opts); +#ifdef CONFIG_LIBISCSI +qemu_add_opts (&qemu_iscsi_opts); +#endif module_call_init (MODULE_INIT_OPTS );runstate_init ();
Signature · 1 line
2.5.5
PATCH v4 2/32 blockdev: Add dynamic generation of module_block.h
In reply to Colin LordFrom: Marc Mari <[email protected]>
To simplify the addition of new block modules, add a script that generates module_block.h automatically from the modules' source code.
This script assumes that the QEMU coding style rules are followed.
--- Makefile | 7 +++ scripts/modules/module_block.py | 122 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 129 insertions(+) create mode 100644 scripts/modules/module_block.py
Makefile +7 -0
@@ -76,6 +76,8 @@ GENERATED_HEADERS += trace/generated-ust-provider.h GENERATED_SOURCES += trace/generated-ust.c endif +GENERATED_HEADERS += module_block.h + # Don't try to regenerate Makefile or configure # We don't generate any of them Makefile: ;
@@ -352,6 +354,11 @@ ivshmem-client$(EXESUF): $(ivshmem-client-obj-y) libqemuutil.a libqemustub.a ivshmem-server$(EXESUF): $(ivshmem-server-obj-y) libqemuutil.a libqemustub.a $(call LINK, $^) +module_block.h: $(SRC_PATH)/scripts/modules/module_block.py config-host.mak + $(call quiet-command,$(PYTHON) $< $@ \ + $(addprefix $(SRC_PATH)/,$(patsubst %.mo,%.c,$(block-obj-m))), \ + " GEN $@") + clean: # avoid old build problems by removing potentially incorrect old files rm -f config.mak op-i386.h opc-i386.h gen-op-i386.h op-arm.h opc-arm.h gen-op-arm.h
scripts/modules/module_block.py new file +122 -0
122 lines not on this page · raw message
Signature · 1 line
2.5.5
PATCH v4 3/32 blockdev: Add dynamic module loading for block drivers
In reply to Colin LordFrom: Marc Mari <[email protected]>
Extend the current module interface to allow for block drivers to be loaded dynamically on request.
The only block drivers that can be converted into modules are the drivers that don't perform any init operation except for registering themselves.
All the necessary module information is located in a new structure found in module_block.h
--- block.c | 110 ++++++++++++++++++++++++++++++++++++++++++-------- include/qemu/module.h | 3 ++ util/module.c | 38 +++++------------ 3 files changed, 108 insertions(+), 43 deletions(-)
block.c +94 -16
@@ -26,6 +26,7 @@#include "block/block_int.h" #include "block/blockjob.h" #include "qemu/error-report.h" +#include "module_block.h" #include "qemu/module.h" #include "qapi/qmp/qerror.h" #include "qapi/qmp/qbool.h"
@@ -239,17 +240,40 @@ BlockDriverState *bdrv_new(void)return bs; } -BlockDriver *bdrv_find_format (const char *format_name) +static BlockDriver *bdrv_do_find_format (const char *format_name) {BlockDriver *drv1; + QLIST_FOREACH(drv1, &bdrv_drivers, list) {if (!strcmp (drv1->format_name, format_name)) {return drv1; } } +return NULL ; } +BlockDriver *bdrv_find_format (const char *format_name) +{ +BlockDriver *drv1; +size_t i; + + drv1 =bdrv_do_find_format (format_name); +if (drv1) { +return drv1; + } + +/* The driver isn't registered, maybe we need to load a module */ +for (i =0 ; i <ARRAY_SIZE (block_driver_modules); ++i) { +if (!strcmp (block_driver_modules[i].format_name, format_name)) { +block_module_load_one (block_driver_modules[i].library_name); +break ; + } + } + +return bdrv_do_find_format (format_name); +} +static int bdrv_is_whitelisted (BlockDriver *drv,bool read_only) {static const char *whitelist_rw[] = {
@@ -443,8 +467,15 @@ int get_tmp_filename(char *filename, int size)static BlockDriver *find_hdev_driver (const char *filename) {int score_max =0 , score; +size_t i;BlockDriver *drv =NULL , *d; +for (i =0 ; i <ARRAY_SIZE (block_driver_modules); ++i) { +if (block_driver_modules[i].has_probe_device) { +block_module_load_one (block_driver_modules[i].library_name); + } + } + QLIST_FOREACH(d, &bdrv_drivers, list) {if (d->bdrv_probe_device) { score = d->bdrv_probe_device (filename);
@@ -458,6 +489,19 @@ static BlockDriver *find_hdev_driver(const char *filename)return drv; } +static BlockDriver *bdrv_do_find_protocol (const char *protocol) +{ +BlockDriver *drv1; + + QLIST_FOREACH(drv1, &bdrv_drivers, list) { +if (drv1->protocol_name && !strcmp (drv1->protocol_name, protocol)) { +return drv1; + } + } + +return NULL ; +} +BlockDriver *bdrv_find_protocol (const char *filename,bool allow_protocol_prefix,Error **errp)
@@ -466,6 +510,7 @@ BlockDriver *bdrv_find_protocol(const char *filename,char protocol[128 ];int len;const char *p; +size_t i;/* TODO Drivers without bdrv_file_open must be specified explicitly */
@@ -492,15 +537,25 @@ BlockDriver *bdrv_find_protocol(const char *filename, len =sizeof (protocol) -1 ;memcpy (protocol, filename, len); protocol[len] ='\0' ; - QLIST_FOREACH(drv1, &bdrv_drivers, list) { -if (drv1->protocol_name && - !strcmp (drv1->protocol_name, protocol)) { -return drv1; + + drv1 =bdrv_do_find_protocol (protocol); +if (drv1) { +return drv1; + } + +for (i =0 ; i <ARRAY_SIZE (block_driver_modules); ++i) { +if (block_driver_modules[i].protocol_name && + !strcmp (block_driver_modules[i].protocol_name, protocol)) { +block_module_load_one (block_driver_modules[i].library_name); +break ; } } -error_setg (errp,"Unknown protocol '%s'" , protocol); -return NULL ; + drv1 =bdrv_do_find_protocol (protocol); +if (!drv1) { +error_setg (errp,"Unknown protocol '%s'" , protocol); + } +return drv1; }/*
@@ -521,8 +576,15 @@ BlockDriver *bdrv_probe_all(const uint8_t *buf, int buf_size, const char *filename) {int score_max =0 , score; +size_t i;BlockDriver *drv =NULL , *d; +for (i =0 ; i <ARRAY_SIZE (block_driver_modules); ++i) { +if (block_driver_modules[i].has_probe) { +block_module_load_one (block_driver_modules[i].library_name); + } + } + QLIST_FOREACH(d, &bdrv_drivers, list) {if (d->bdrv_probe) { score = d->bdrv_probe (buf, buf_size, filename);
@@ -2628,26 +2690,42 @@ static int qsort_strcmp(const void *a, const void *b)return strcmp (a, b); } +static const char **add_format (const char **formats,int *count, +const char *format_name) +{ +int i; + +for (i =0 ; i < *count; i++) { +if (!strcmp (formats[i], format_name)) { +return formats; + } + } + + formats = g_renew(const char *, formats, *count + 1); + formats[*count] = format_name; + *count +=1 ; +return formats; +} +void bdrv_iterate_format (void (*it)(void *opaque,const char *name),void *opaque) {BlockDriver *drv;int count =0 ;int i; +size_t n;const char **formats =NULL ; QLIST_FOREACH(drv, &bdrv_drivers, list) {if (drv->format_name) { -bool found = false; -int i = count; -while (formats && i && !found) { - found = !strcmp (formats[--i], drv->format_name); - } + formats =add_format (formats, &count, drv->format_name); + } + } -if (!found) { - formats = g_renew(const char *, formats, count + 1); - formats[count++] = drv->format_name; - } +for (n =0 ; n <ARRAY_SIZE (block_driver_modules); n++) { +if (block_driver_modules[n].format_name) { + formats =add_format (formats, &count, + block_driver_modules[n].format_name); } }
include/qemu/module.h +3 -0
@@ -52,9 +52,12 @@ typedef enum {#define qapi_init (function) module_init(function, MODULE_INIT_QAPI)#define type_init (function) module_init(function, MODULE_INIT_QOM) +#define block_module_load_one (lib) module_load_one("block-", lib) +void register_module_init (void (*fn)(void ),module_init_type type);void register_dso_module_init (void (*fn)(void ),module_init_type type);void module_call_init (module_init_type type); +void module_load_one (const char *prefix,const char *lib_name);#endif
util/module.c +11 -27
@@ -87,14 +87,11 @@ void register_dso_module_init(void (*fn)(void), module_init_type type)QTAILQ_INSERT_TAIL (&dso_init_list, e, node); } -static void module_load (module_init_type type); -void module_call_init (module_init_type type) {ModuleTypeList *l;ModuleEntry *e; -module_load (type); l =find_type (type); QTAILQ_FOREACH(e, l, node) {
@@ -145,6 +142,7 @@ static int module_load_file(const char *fname) ret = -EINVAL ; }else { QTAILQ_FOREACH(e, &dso_init_list, node) { + e->init ();register_module_init (e->init, e->type); } ret =0 ;
@@ -159,14 +157,10 @@ out: }#endif -static void module_load (module_init_type type) +void module_load_one (const char *prefix,const char *lib_name) {#ifdef CONFIG_MODULES char *fname =NULL ; -const char **mp; -static const char *block_modules[] = { -CONFIG_BLOCK_MODULES - };char *exec_dir;char *dirs[3 ];int i =0 ;
@@ -177,15 +171,6 @@ static void module_load(module_init_type type)return ; } -switch (type) { -case MODULE_INIT_BLOCK : - mp = block_modules; -break ; -default : -/* no other types have dynamic modules for now*/ -return ; - } - exec_dir =qemu_get_exec_dir (); dirs[i++] =g_strdup_printf ("%s" ,CONFIG_QEMU_MODDIR ); dirs[i++] =g_strdup_printf ("%s/.." , exec_dir ? :"" );
@@ -194,16 +179,15 @@ static void module_load(module_init_type type)g_free (exec_dir); exec_dir =NULL ; -for ( ; *mp; mp++) { -for (i =0 ; i <ARRAY_SIZE (dirs); i++) { - fname =g_strdup_printf ("%s/%s%s" , dirs[i], *mp,HOST_DSOSUF ); - ret =module_load_file (fname); -g_free (fname); - fname =NULL ; -/* Try loading until loaded a module file */ -if (!ret) { -break ; - } +for (i =0 ; i <ARRAY_SIZE (dirs); i++) { + fname =g_strdup_printf ("%s/%s%s%s" , + dirs[i], prefix, lib_name,HOST_DSOSUF ); + ret =module_load_file (fname); +g_free (fname); + fname =NULL ; +/* Try loading until loaded a module file */ +if (!ret) { +break ; } }
Signature · 1 line
2.5.5
PATCH v4 4/32 blockdev: Move bochs probe into separate file
In reply to Colin LordThis puts the bochs probe function into its own separate file as part of the process of modularizing block drivers. Having the probe functions separate from the rest of the driver allows us to probe without having to potentially unnecessarily load the driver.
--- block/Makefile.objs | 1 + block/bochs-probe.c | 21 ++++++++++++++++++++ block/bochs.c | 55 ++------------------------------------------------- block/bochs.h | 40 +++++++++++++++++++++++++++++++++++++ include/block/probe.h | 6 ++++++ 5 files changed, 70 insertions(+), 53 deletions(-) create mode 100644 block/bochs-probe.c create mode 100644 block/bochs.h create mode 100644 include/block/probe.h
block/Makefile.objs +1 -0
@@ -24,6 +24,7 @@ block-obj-y += accounting.o dirty-bitmap.o block-obj-y += write-threshold.o block-obj-y += crypto.o +block-obj-y += bochs-probe.o common-obj-y += stream.o common-obj-y += backup.o
block/bochs-probe.c new file +21 -0
@@ -0,0 +1,21 @@ +#include "qemu/osdep.h" +#include "block/block_int.h" +#include "block/probe.h" +#include "bochs.h" + +int bochs_probe (const uint8_t *buf,int buf_size,const char *filename) +{ +const struct bochs_header *bochs = (const void *)buf; + +if (buf_size <HEADER_SIZE ) +return 0 ; + +if (!strcmp (bochs->magic,HEADER_MAGIC ) && + !strcmp (bochs->type,REDOLOG_TYPE ) && + !strcmp (bochs->subtype,GROWING_TYPE ) && + ((le32_to_cpu (bochs->version) ==HEADER_VERSION ) || + (le32_to_cpu (bochs->version) ==HEADER_V1 ))) +return 100 ; + +return 0 ; +}
block/bochs.c +2 -53
70 lines not on this page · raw message
block/bochs.h new file +40 -0
@@ -0,0 +1,40 @@ +#ifndef BLOCK_BOCHS_H +#define BLOCK_BOCHS_H + +#define HEADER_MAGIC "Bochs Virtual HD Image" +#define HEADER_VERSION 0x00020000 +#define HEADER_V1 0x00010000 +#define HEADER_SIZE 512 + +#define REDOLOG_TYPE "Redolog" +#define GROWING_TYPE "Growing" + +// not allocated: 0xffffffff + +// always little-endian +struct bochs_header { +char magic[32 ];/* "Bochs Virtual HD Image" */ +char type[16 ];/* "Redolog" */ +char subtype[16 ];/* "Undoable" / "Volatile" / "Growing" */ +uint32_t version; +uint32_t header;/* size of header */ + +uint32_t catalog;/* num of entries */ +uint32_t bitmap;/* bitmap size */ +uint32_t extent;/* extent size */ + +union { +struct { +uint32_t reserved;/* for ??? */ +uint64_t disk;/* disk size */ +char padding[HEADER_SIZE -64 -20 -12 ]; + } QEMU_PACKED redolog; +struct { +uint64_t disk;/* disk size */ +char padding[HEADER_SIZE -64 -20 -8 ]; + } QEMU_PACKED redolog_v1; +char padding[HEADER_SIZE -64 -20 ]; + } extra; +}QEMU_PACKED ; + +#endif
include/block/probe.h new file +6 -0
@@ -0,0 +1,6 @@ +#ifndef PROBE_H +#define PROBE_H + +int bochs_probe (const uint8_t *buf,int buf_size,const char *filename); + +#endif
Signature · 1 line
2.5.5
PATCH v4 5/32 blockdev: Move cloop probe to its own file
In reply to Colin LordIsolates cloop probing function as part of the modularization process.
--- block/Makefile.objs | 2 +- block/cloop-probe.c | 17 +++++++++++++++++ block/cloop.c | 16 +--------------- include/block/probe.h | 1 + 4 files changed, 20 insertions(+), 16 deletions(-) create mode 100644 block/cloop-probe.c
block/Makefile.objs +1 -1
@@ -24,7 +24,7 @@ block-obj-y += accounting.o dirty-bitmap.o block-obj-y += write-threshold.o block-obj-y += crypto.o -block-obj-y += bochs-probe.o +block-obj-y += bochs-probe.o cloop-probe.o common-obj-y += stream.o common-obj-y += backup.o
block/cloop-probe.c new file +17 -0
@@ -0,0 +1,17 @@ +#include "qemu/osdep.h" +#include "block/probe.h" + +int cloop_probe (const uint8_t *buf,int buf_size,const char *filename) +{ +const char *magic_version_2_0 ="#!/bin/sh\n" +"#V2.0 Format\n" +"modprobe cloop file=$0 && mount -r -t iso9660 /dev/cloop $1\n" ; +int length =strlen (magic_version_2_0); +if (length > buf_size) { + length = buf_size; + } +if (!memcmp (magic_version_2_0, buf, length)) { +return 2 ; + } +return 0 ; +}
block/cloop.c +1 -15
@@ -25,6 +25,7 @@#include "qapi/error.h" #include "qemu-common.h" #include "block/block_int.h" +#include "block/probe.h" #include "qemu/module.h" #include "qemu/bswap.h" #include <zlib.h>
@@ -44,21 +45,6 @@ typedef struct BDRVCloopState {z_stream zstream; } BDRVCloopState; -static int cloop_probe (const uint8_t *buf,int buf_size,const char *filename) -{ -const char *magic_version_2_0 ="#!/bin/sh\n" -"#V2.0 Format\n" -"modprobe cloop file=$0 && mount -r -t iso9660 /dev/cloop $1\n" ; -int length =strlen (magic_version_2_0); -if (length > buf_size) { - length = buf_size; - } -if (!memcmp (magic_version_2_0, buf, length)) { -return 2 ; - } -return 0 ; -} -static int cloop_open (BlockDriverState *bs,QDict *options,int flags,Error **errp) {
include/block/probe.h +1 -0
@@ -2,5 +2,6 @@#define PROBE_H int bochs_probe (const uint8_t *buf,int buf_size,const char *filename); +int cloop_probe (const uint8_t *buf,int buf_size,const char *filename);#endif
Signature · 1 line
2.5.5
PATCH v4 6/32 blockdev: Move luks probe to its own file
In reply to Colin LordIsolates the luks probe function as part of the modularization process.
--- block/Makefile.objs | 2 +- block/crypto-probe.c | 23 +++++++++++++++++++++++ block/crypto.c | 21 +-------------------- include/block/probe.h | 2 ++ 4 files changed, 27 insertions(+), 21 deletions(-) create mode 100644 block/crypto-probe.c
block/Makefile.objs +1 -1
@@ -24,7 +24,7 @@ block-obj-y += accounting.o dirty-bitmap.o block-obj-y += write-threshold.o block-obj-y += crypto.o -block-obj-y += bochs-probe.o cloop-probe.o +block-obj-y += bochs-probe.o cloop-probe.o crypto-probe.o common-obj-y += stream.o common-obj-y += backup.o
block/crypto-probe.c new file +23 -0
@@ -0,0 +1,23 @@ +#include "qemu/osdep.h" +#include "qapi-types.h" +#include "block/probe.h" +#include "crypto/block.h" + +static int block_crypto_probe_generic (QCryptoBlockFormat format, +const uint8_t *buf, +int buf_size, +const char *filename) +{ +if (qcrypto_block_has_format (format, buf, buf_size)) { +return 100 ; + }else { +return 0 ; + } +} + +int block_crypto_probe_luks (const uint8_t *buf, +int buf_size, +const char *filename) { +return block_crypto_probe_generic (Q_CRYPTO_BLOCK_FORMAT_LUKS , + buf, buf_size, filename); +}
block/crypto.c +1 -20
@@ -21,6 +21,7 @@#include "qemu/osdep.h" #include "block/block_int.h" +#include "block/probe.h" #include "sysemu/block-backend.h" #include "crypto/block.h" #include "qapi/opts-visitor.h"
@@ -41,19 +42,6 @@ struct BlockCrypto { }; -static int block_crypto_probe_generic (QCryptoBlockFormat format, -const uint8_t *buf, -int buf_size, -const char *filename) -{ -if (qcrypto_block_has_format (format, buf, buf_size)) { -return 100 ; - }else { -return 0 ; - } -} - - static ssize_t block_crypto_read_func(QCryptoBlock *block, size_t offset, uint8_t *buf,
@@ -538,13 +526,6 @@ static int64_t block_crypto_getlength(BlockDriverState *bs) } -static int block_crypto_probe_luks (const uint8_t *buf, -int buf_size, -const char *filename) { -return block_crypto_probe_generic (Q_CRYPTO_BLOCK_FORMAT_LUKS , - buf, buf_size, filename); -} - static int block_crypto_open_luks(BlockDriverState *bs, QDict *options, int flags,
include/block/probe.h +2 -0
@@ -3,5 +3,7 @@int bochs_probe (const uint8_t *buf,int buf_size,const char *filename);int cloop_probe (const uint8_t *buf,int buf_size,const char *filename); +int block_crypto_probe_luks (const uint8_t *buf,int buf_size, +const char *filename);#endif
Signature · 1 line
2.5.5
PATCH v4 7/32 blockdev: Move dmg probe to its own file
In reply to Colin LordIsolate dmg probe as part of the modularization process.
--- block/Makefile.objs | 2 +- block/dmg-probe.c | 17 +++++++++++++++++ block/dmg.c | 16 +--------------- include/block/probe.h | 1 + 4 files changed, 20 insertions(+), 16 deletions(-) create mode 100644 block/dmg-probe.c
block/Makefile.objs +1 -1
@@ -24,7 +24,7 @@ block-obj-y += accounting.o dirty-bitmap.o block-obj-y += write-threshold.o block-obj-y += crypto.o -block-obj-y += bochs-probe.o cloop-probe.o crypto-probe.o +block-obj-y += bochs-probe.o cloop-probe.o crypto-probe.o dmg-probe.o common-obj-y += stream.o common-obj-y += backup.o
block/dmg-probe.c new file +17 -0
@@ -0,0 +1,17 @@ +#include "qemu/osdep.h" +#include "block/probe.h" + +int dmg_probe (const uint8_t *buf,int buf_size,const char *filename) +{ +int len; + +if (!filename) { +return 0 ; + } + + len =strlen (filename); +if (len >4 && !strcmp (filename + len -4 ,".dmg" )) { +return 2 ; + } +return 0 ; +}
block/dmg.c +1 -15
@@ -25,6 +25,7 @@#include "qapi/error.h" #include "qemu-common.h" #include "block/block_int.h" +#include "block/probe.h" #include "qemu/bswap.h" #include "qemu/error-report.h" #include "qemu/module.h"
@@ -66,21 +67,6 @@ typedef struct BDRVDMGState {#endif } BDRVDMGState; -static int dmg_probe (const uint8_t *buf,int buf_size,const char *filename) -{ -int len; - -if (!filename) { -return 0 ; - } - - len =strlen (filename); -if (len >4 && !strcmp (filename + len -4 ,".dmg" )) { -return 2 ; - } -return 0 ; -} -static int read_uint64 (BlockDriverState *bs,int64_t offset,uint64_t *result) {uint64_t buffer;
include/block/probe.h +1 -0
@@ -5,5 +5,6 @@ int bochs_probe(const uint8_t *buf, int buf_size, const char *filename);int cloop_probe (const uint8_t *buf,int buf_size,const char *filename);int block_crypto_probe_luks (const uint8_t *buf,int buf_size,const char *filename); +int dmg_probe (const uint8_t *buf,int buf_size,const char *filename);#endif
Signature · 1 line
2.5.5
PATCH v4 8/32 blockdev: Move parallels probe to its own file
In reply to Colin LordIsolate parallels probe as part of the modularization process.
--- block/Makefile.objs | 1 + block/parallels-probe.c | 21 +++++++++++++++++++++ block/parallels.c | 43 ++----------------------------------------- block/parallels.h | 26 ++++++++++++++++++++++++++ include/block/probe.h | 1 + 5 files changed, 51 insertions(+), 41 deletions(-) create mode 100644 block/parallels-probe.c create mode 100644 block/parallels.h
block/Makefile.objs +1 -0
@@ -25,6 +25,7 @@ block-obj-y += write-threshold.o block-obj-y += crypto.o block-obj-y += bochs-probe.o cloop-probe.o crypto-probe.o dmg-probe.o +block-obj-y += parallels-probe.o common-obj-y += stream.o common-obj-y += backup.o
block/parallels-probe.c new file +21 -0
@@ -0,0 +1,21 @@ +#include "qemu/osdep.h" +#include "block/block_int.h" +#include "block/probe.h" +#include "parallels.h" + +int parallels_probe (const uint8_t *buf,int buf_size,const char *filename) +{ +const ParallelsHeader *ph = (const void *)buf; + +if (buf_size <sizeof (ParallelsHeader)) { +return 0 ; + } + +if ((!memcmp (ph->magic,HEADER_MAGIC ,16 ) || + !memcmp (ph->magic,HEADER_MAGIC2 ,16 )) && + (le32_to_cpu (ph->version) ==HEADER_VERSION )) { +return 100 ; + } + +return 0 ; +}
block/parallels.c +2 -41
61 lines not on this page · raw message
block/parallels.h new file +26 -0
@@ -0,0 +1,26 @@ +#ifndef PARALLELS_H +#define PARALLELS_H + +#define HEADER_MAGIC "WithoutFreeSpace" +#define HEADER_MAGIC2 "WithouFreSpacExt" +#define HEADER_VERSION 2 +#define HEADER_INUSE_MAGIC (0x746F6E59) + +#define DEFAULT_CLUSTER_SIZE 1048576/* 1 MiB */ + + +// always little-endian +typedef struct ParallelsHeader { +char magic[16 ];// "WithoutFreeSpace" +uint32_t version; +uint32_t heads; +uint32_t cylinders; +uint32_t tracks; +uint32_t bat_entries; +uint64_t nb_sectors; +uint32_t inuse; +uint32_t data_off; +char padding[12 ]; +} QEMU_PACKED ParallelsHeader; + +#endif
include/block/probe.h +1 -0
@@ -6,5 +6,6 @@ int cloop_probe(const uint8_t *buf, int buf_size, const char *filename);int block_crypto_probe_luks (const uint8_t *buf,int buf_size,const char *filename);int dmg_probe (const uint8_t *buf,int buf_size,const char *filename); +int parallels_probe (const uint8_t *buf,int buf_size,const char *filename);#endif
Signature · 1 line
2.5.5
PATCH v4 9/32 blockdev: Move qcow probe to its own file
In reply to Colin LordIsolates qcow probe as part of the modularization process.
--- block/Makefile.objs | 2 +- block/qcow-probe.c | 16 ++++++++++++++++ block/qcow.c | 31 ++----------------------------- block/qcow.h | 21 +++++++++++++++++++++ include/block/probe.h | 1 + 5 files changed, 41 insertions(+), 30 deletions(-) create mode 100644 block/qcow-probe.c create mode 100644 block/qcow.h
block/Makefile.objs +1 -1
@@ -25,7 +25,7 @@ block-obj-y += write-threshold.o block-obj-y += crypto.o block-obj-y += bochs-probe.o cloop-probe.o crypto-probe.o dmg-probe.o -block-obj-y += parallels-probe.o +block-obj-y += parallels-probe.o qcow-probe.o common-obj-y += stream.o common-obj-y += backup.o
block/qcow-probe.c new file +16 -0
@@ -0,0 +1,16 @@ +#include "qemu/osdep.h" +#include "block/block_int.h" +#include "block/probe.h" +#include "qcow.h" + +int qcow_probe (const uint8_t *buf,int buf_size,const char *filename) +{ +const QCowHeader *cow_header = (const void *)buf; + +if (buf_size >=sizeof (QCowHeader) && +be32_to_cpu (cow_header->magic) ==QCOW_MAGIC && +be32_to_cpu (cow_header->version) ==QCOW_VERSION ) +return 100 ; +else +return 0 ; +}
block/qcow.c +2 -29
@@ -26,6 +26,8 @@#include "qemu-common.h" #include "qemu/error-report.h" #include "block/block_int.h" +#include "block/probe.h" +#include "qcow.h" #include "sysemu/block-backend.h" #include "qemu/module.h" #include "qemu/bswap.h"
@@ -37,28 +39,11 @@/**************************************************************/ /* QEMU COW block driver with compression and encryption support */ -#define QCOW_MAGIC (('Q' << 24) | ('F' << 16) | ('I' << 8) | 0xfb) -#define QCOW_VERSION 1 -#define QCOW_CRYPT_NONE 0#define QCOW_CRYPT_AES 1#define QCOW_OFLAG_COMPRESSED (1LL << 63) -typedef struct QCowHeader { -uint32_t magic; -uint32_t version; -uint64_t backing_file_offset; -uint32_t backing_file_size; -uint32_t mtime; -uint64_t size;/* in bytes */ -uint8_t cluster_bits; -uint8_t l2_bits; -uint16_t padding; -uint32_t crypt_method; -uint64_t l1_table_offset; -} QEMU_PACKED QCowHeader; -#define L2_CACHE_SIZE 16 typedef struct BDRVQcowState {
@@ -85,18 +70,6 @@ typedef struct BDRVQcowState {static int decompress_cluster (BlockDriverState *bs,uint64_t cluster_offset); -static int qcow_probe (const uint8_t *buf,int buf_size,const char *filename) -{ -const QCowHeader *cow_header = (const void *)buf; - -if (buf_size >=sizeof (QCowHeader) && -be32_to_cpu (cow_header->magic) ==QCOW_MAGIC && -be32_to_cpu (cow_header->version) ==QCOW_VERSION ) -return 100 ; -else -return 0 ; -} -static int qcow_open (BlockDriverState *bs,QDict *options,int flags,Error **errp) {
block/qcow.h new file +21 -0
@@ -0,0 +1,21 @@ +#ifndef QCOW_H +#define QCOW_H + +#define QCOW_MAGIC (('Q' << 24) | ('F' << 16) | ('I' << 8) | 0xfb) +#define QCOW_VERSION 1 + +typedef struct QCowHeader { +uint32_t magic; +uint32_t version; +uint64_t backing_file_offset; +uint32_t backing_file_size; +uint32_t mtime; +uint64_t size;/* in bytes */ +uint8_t cluster_bits; +uint8_t l2_bits; +uint16_t padding; +uint32_t crypt_method; +uint64_t l1_table_offset; +} QEMU_PACKED QCowHeader; + +#endif
include/block/probe.h +1 -0
@@ -7,5 +7,6 @@ int block_crypto_probe_luks(const uint8_t *buf, int buf_size, const char *filename);int dmg_probe (const uint8_t *buf,int buf_size,const char *filename);int parallels_probe (const uint8_t *buf,int buf_size,const char *filename); +int qcow_probe (const uint8_t *buf,int buf_size,const char *filename);#endif
Signature · 1 line
2.5.5
PATCH v4 10/32 blockdev: Move qcow2 probe to its own file
In reply to Colin LordIsolates qcow2 probe as part of the modularization process.
--- block/Makefile.objs | 2 +- block/qcow2-probe.c | 16 ++++++++++++++++ block/qcow2.c | 13 +------------ include/block/probe.h | 1 + 4 files changed, 19 insertions(+), 13 deletions(-) create mode 100644 block/qcow2-probe.c
block/Makefile.objs +1 -1
@@ -25,7 +25,7 @@ block-obj-y += write-threshold.o block-obj-y += crypto.o block-obj-y += bochs-probe.o cloop-probe.o crypto-probe.o dmg-probe.o -block-obj-y += parallels-probe.o qcow-probe.o +block-obj-y += parallels-probe.o qcow-probe.o qcow2-probe.o common-obj-y += stream.o common-obj-y += backup.o
block/qcow2-probe.c new file +16 -0
@@ -0,0 +1,16 @@ +#include "qemu/osdep.h" +#include "block/block_int.h" +#include "block/probe.h" +#include "qcow2.h" + +int qcow2_probe (const uint8_t *buf,int buf_size,const char *filename) +{ +const QCowHeader *cow_header = (const void *)buf; + +if (buf_size >=sizeof (QCowHeader) && +be32_to_cpu (cow_header->magic) ==QCOW_MAGIC && +be32_to_cpu (cow_header->version) >=2 ) +return 100 ; +else +return 0 ; +}
block/qcow2.c +1 -12
@@ -27,6 +27,7 @@#include "qemu/module.h" #include <zlib.h> #include "block/qcow2.h" +#include "block/probe.h" #include "qemu/error-report.h" #include "qapi/qmp/qerror.h" #include "qapi/qmp/qbool.h"
@@ -64,18 +65,6 @@ typedef struct {#define QCOW2_EXT_MAGIC_BACKING_FORMAT 0xE2792ACA#define QCOW2_EXT_MAGIC_FEATURE_TABLE 0x6803f857 -static int qcow2_probe (const uint8_t *buf,int buf_size,const char *filename) -{ -const QCowHeader *cow_header = (const void *)buf; - -if (buf_size >=sizeof (QCowHeader) && -be32_to_cpu (cow_header->magic) ==QCOW_MAGIC && -be32_to_cpu (cow_header->version) >=2 ) -return 100 ; -else -return 0 ; -} -/* * read qcow2 extension and fill bs
include/block/probe.h +1 -0
@@ -8,5 +8,6 @@ int block_crypto_probe_luks(const uint8_t *buf, int buf_size,int dmg_probe (const uint8_t *buf,int buf_size,const char *filename);int parallels_probe (const uint8_t *buf,int buf_size,const char *filename);int qcow_probe (const uint8_t *buf,int buf_size,const char *filename); +int qcow2_probe (const uint8_t *buf,int buf_size,const char *filename);#endif
Signature · 1 line
2.5.5
PATCH v4 11/32 blockdev: Move qed probe to its own file
In reply to Colin LordIsolate qed probe as part of the modularization process.
--- block/Makefile.objs | 2 +- block/qed-probe.c | 18 ++++++++++++++++++ block/qed.c | 15 +-------------- include/block/probe.h | 1 + 4 files changed, 21 insertions(+), 15 deletions(-) create mode 100644 block/qed-probe.c
block/Makefile.objs +1 -1
@@ -25,7 +25,7 @@ block-obj-y += write-threshold.o block-obj-y += crypto.o block-obj-y += bochs-probe.o cloop-probe.o crypto-probe.o dmg-probe.o -block-obj-y += parallels-probe.o qcow-probe.o qcow2-probe.o +block-obj-y += parallels-probe.o qcow-probe.o qcow2-probe.o qed-probe.o common-obj-y += stream.o common-obj-y += backup.o
block/qed-probe.c new file +18 -0
@@ -0,0 +1,18 @@ +#include "qemu/osdep.h" +#include "block/block_int.h" +#include "block/probe.h" +#include "qed.h" + +int bdrv_qed_probe (const uint8_t *buf,int buf_size, +const char *filename) +{ +const QEDHeader *header = (const QEDHeader *)buf; + +if (buf_size <sizeof (*header)) { +return 0 ; + } +if (le32_to_cpu (header->magic) !=QED_MAGIC ) { +return 0 ; + } +return 100 ; +}
block/qed.c +1 -14
@@ -16,6 +16,7 @@#include "qapi/error.h" #include "qemu/timer.h" #include "qemu/bswap.h" +#include "block/probe.h" #include "trace.h" #include "qed.h" #include "qapi/qmp/qerror.h"
@@ -26,20 +27,6 @@ static const AIOCBInfo qed_aiocb_info = { .aiocb_size = sizeof(QEDAIOCB), }; -static int bdrv_qed_probe (const uint8_t *buf,int buf_size, -const char *filename) -{ -const QEDHeader *header = (const QEDHeader *)buf; - -if (buf_size <sizeof (*header)) { -return 0 ; - } -if (le32_to_cpu (header->magic) !=QED_MAGIC ) { -return 0 ; - } -return 100 ; -} -/** * Check whether an image format is raw *
include/block/probe.h +1 -0
@@ -9,5 +9,6 @@ int dmg_probe(const uint8_t *buf, int buf_size, const char *filename);int parallels_probe (const uint8_t *buf,int buf_size,const char *filename);int qcow_probe (const uint8_t *buf,int buf_size,const char *filename);int qcow2_probe (const uint8_t *buf,int buf_size,const char *filename); +int bdrv_qed_probe (const uint8_t *buf,int buf_size,const char *filename);#endif
Signature · 1 line
2.5.5
PATCH v4 12/32 blockdev: Move raw probe to its own file
In reply to Colin LordIsolate raw probe as part of the modularization process.
--- block/Makefile.objs | 1 + block/raw-probe.c | 10 ++++++++++ block/raw_bsd.c | 9 +-------- include/block/probe.h | 1 + 4 files changed, 13 insertions(+), 8 deletions(-) create mode 100644 block/raw-probe.c
block/Makefile.objs +1 -0
@@ -26,6 +26,7 @@ block-obj-y += write-threshold.o block-obj-y += crypto.o block-obj-y += bochs-probe.o cloop-probe.o crypto-probe.o dmg-probe.o block-obj-y += parallels-probe.o qcow-probe.o qcow2-probe.o qed-probe.o +block-obj-y += raw-probe.o common-obj-y += stream.o common-obj-y += backup.o
block/raw-probe.c new file +10 -0
@@ -0,0 +1,10 @@ +#include "qemu/osdep.h" +#include "block/probe.h" + +int raw_probe (const uint8_t *buf,int buf_size,const char *filename) +{ +/* smallest possible positive score so that raw is used if and only if no +* other block driver works +*/ +return 1 ; +}
block/raw_bsd.c +1 -8
@@ -28,6 +28,7 @@#include "qemu/osdep.h" #include "block/block_int.h" +#include "block/probe.h" #include "qapi/error.h" #include "qemu/option.h"
@@ -213,14 +214,6 @@ static void raw_close(BlockDriverState *bs) { } -static int raw_probe (const uint8_t *buf,int buf_size,const char *filename) -{ -/* smallest possible positive score so that raw is used if and only if no -* other block driver works -*/ -return 1 ; -} -static int raw_probe_blocksizes (BlockDriverState *bs,BlockSizes *bsz) {return bdrv_probe_blocksizes (bs->file->bs, bsz);
include/block/probe.h +1 -0
@@ -10,5 +10,6 @@ int parallels_probe(const uint8_t *buf, int buf_size, const char *filename);int qcow_probe (const uint8_t *buf,int buf_size,const char *filename);int qcow2_probe (const uint8_t *buf,int buf_size,const char *filename);int bdrv_qed_probe (const uint8_t *buf,int buf_size,const char *filename); +int raw_probe (const uint8_t *buf,int buf_size,const char *filename);#endif
Signature · 1 line
2.5.5
PATCH v4 13/32 blockdev: Move vdi probe to its own file
In reply to Colin LordIsolates vdi probe as part of the modularization process.
--- block/Makefile.objs | 2 +- block/vdi-probe.c | 26 +++++++++++++++++++ block/vdi.c | 69 ++------------------------------------------------- block/vdi.h | 49 ++++++++++++++++++++++++++++++++++++ include/block/probe.h | 1 + 5 files changed, 79 insertions(+), 68 deletions(-) create mode 100644 block/vdi-probe.c create mode 100644 block/vdi.h
block/Makefile.objs +1 -1
@@ -26,7 +26,7 @@ block-obj-y += write-threshold.o block-obj-y += crypto.o block-obj-y += bochs-probe.o cloop-probe.o crypto-probe.o dmg-probe.o block-obj-y += parallels-probe.o qcow-probe.o qcow2-probe.o qed-probe.o -block-obj-y += raw-probe.o +block-obj-y += raw-probe.o vdi-probe.o common-obj-y += stream.o common-obj-y += backup.o
block/vdi-probe.c new file +26 -0
@@ -0,0 +1,26 @@ +#include "qemu/osdep.h" +#include "block/block_int.h" +#include "block/probe.h" +#include "vdi.h" + +int vdi_probe (const uint8_t *buf,int buf_size,const char *filename) +{ +const VdiHeader *header = (const VdiHeader *)buf; +int ret =0 ; + +logout ("\n" ); + +if (buf_size <sizeof (*header)) { +/* Header too small, no VDI. */ + }else if (le32_to_cpu (header->signature) ==VDI_SIGNATURE ) { + ret =100 ; + } + +if (ret ==0 ) { +logout ("no vdi image\n" ); + }else { +logout ("%s" , header->text); + } + +return ret; +}
block/vdi.c +2 -67
99 lines not on this page · raw message
block/vdi.h new file +49 -0
49 lines not on this page · raw message
include/block/probe.h +1 -0
@@ -11,5 +11,6 @@ int qcow_probe(const uint8_t *buf, int buf_size, const char *filename);int qcow2_probe (const uint8_t *buf,int buf_size,const char *filename);int bdrv_qed_probe (const uint8_t *buf,int buf_size,const char *filename);int raw_probe (const uint8_t *buf,int buf_size,const char *filename); +int vdi_probe (const uint8_t *buf,int buf_size,const char *filename);#endif
Signature · 1 line
2.5.5
PATCH v4 14/32 blockdev: Move vhdx probe to its own file
In reply to Colin LordIsolates vhdx probe as part of the modularization process.
--- block/Makefile.objs | 2 +- block/vhdx-probe.c | 21 +++++++++++++++++++++ block/vhdx.c | 20 +------------------- include/block/probe.h | 1 + 4 files changed, 24 insertions(+), 20 deletions(-) create mode 100644 block/vhdx-probe.c
block/Makefile.objs +1 -1
@@ -26,7 +26,7 @@ block-obj-y += write-threshold.o block-obj-y += crypto.o block-obj-y += bochs-probe.o cloop-probe.o crypto-probe.o dmg-probe.o block-obj-y += parallels-probe.o qcow-probe.o qcow2-probe.o qed-probe.o -block-obj-y += raw-probe.o vdi-probe.o +block-obj-y += raw-probe.o vdi-probe.o vhdx-probe.o common-obj-y += stream.o common-obj-y += backup.o
block/vhdx-probe.c new file +21 -0
@@ -0,0 +1,21 @@ +#include "qemu/osdep.h" +#include "block/probe.h" + +/* +* Per the MS VHDX Specification, for every VHDX file: +* - The header section is fixed size - 1 MB +* - The header section is always the first "object" +* - The first 64KB of the header is the File Identifier +* - The first uint64 (8 bytes) is the VHDX Signature ("vhdxfile") +* - The following 512 bytes constitute a UTF-16 string identifiying the +* software that created the file, and is optional and diagnostic only. +* +* Therefore, we probe by looking for the vhdxfile signature "vhdxfile" +*/ +int vhdx_probe (const uint8_t *buf,int buf_size,const char *filename) +{ +if (buf_size >=8 && !memcmp (buf,"vhdxfile" ,8 )) { +return 100 ; + } +return 0 ; +}
block/vhdx.c +1 -19
@@ -19,6 +19,7 @@#include "qapi/error.h" #include "qemu-common.h" #include "block/block_int.h" +#include "block/probe.h" #include "sysemu/block-backend.h" #include "qemu/module.h" #include "qemu/crc32c.h"
@@ -273,25 +274,6 @@ static void vhdx_set_shift_bits(BDRVVHDXState *s) }/* -* Per the MS VHDX Specification, for every VHDX file: -* - The header section is fixed size - 1 MB -* - The header section is always the first "object" -* - The first 64KB of the header is the File Identifier -* - The first uint64 (8 bytes) is the VHDX Signature ("vhdxfile") -* - The following 512 bytes constitute a UTF-16 string identifiying the -* software that created the file, and is optional and diagnostic only. -* -* Therefore, we probe by looking for the vhdxfile signature "vhdxfile" -*/ -static int vhdx_probe (const uint8_t *buf,int buf_size,const char *filename) -{ -if (buf_size >=8 && !memcmp (buf,"vhdxfile" ,8 )) { -return 100 ; - } -return 0 ; -} - -/* * Writes the header to the specified offset. * * This will optionally read in buffer data from disk (otherwise zero-fill),
include/block/probe.h +1 -0
@@ -12,5 +12,6 @@ int qcow2_probe(const uint8_t *buf, int buf_size, const char *filename);int bdrv_qed_probe (const uint8_t *buf,int buf_size,const char *filename);int raw_probe (const uint8_t *buf,int buf_size,const char *filename);int vdi_probe (const uint8_t *buf,int buf_size,const char *filename); +int vhdx_probe (const uint8_t *buf,int buf_size,const char *filename);#endif
Signature · 1 line
2.5.5
PATCH v4 15/32 blockdev: Move vmdk probe to its own file
In reply to Colin LordIsolates vmdk probe as part of the modularization process.
--- block/Makefile.objs | 2 +- block/vmdk-probe.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++ block/vmdk.c | 60 ++------------------------------------------------- block/vmdk.h | 7 ++++++ include/block/probe.h | 1 + 5 files changed, 71 insertions(+), 59 deletions(-) create mode 100644 block/vmdk-probe.c create mode 100644 block/vmdk.h
block/Makefile.objs +1 -1
@@ -26,7 +26,7 @@ block-obj-y += write-threshold.o block-obj-y += crypto.o block-obj-y += bochs-probe.o cloop-probe.o crypto-probe.o dmg-probe.o block-obj-y += parallels-probe.o qcow-probe.o qcow2-probe.o qed-probe.o -block-obj-y += raw-probe.o vdi-probe.o vhdx-probe.o +block-obj-y += raw-probe.o vdi-probe.o vhdx-probe.o vmdk-probe.o common-obj-y += stream.o common-obj-y += backup.o
block/vmdk-probe.c new file +60 -0
60 lines not on this page · raw message
block/vmdk.c +2 -58
78 lines not on this page · raw message
block/vmdk.h new file +7 -0
@@ -0,0 +1,7 @@ +#ifndef VMDK_H +#define VMDK_H + +#define VMDK3_MAGIC (('C' << 24) | ('O' << 16) | ('W' << 8) | 'D') +#define VMDK4_MAGIC (('K' << 24) | ('D' << 16) | ('M' << 8) | 'V') + +#endif
include/block/probe.h +1 -0
@@ -13,5 +13,6 @@ int bdrv_qed_probe(const uint8_t *buf, int buf_size, const char *filename);int raw_probe (const uint8_t *buf,int buf_size,const char *filename);int vdi_probe (const uint8_t *buf,int buf_size,const char *filename);int vhdx_probe (const uint8_t *buf,int buf_size,const char *filename); +int vmdk_probe (const uint8_t *buf,int buf_size,const char *filename);#endif
Signature · 1 line
2.5.5
PATCH v4 16/32 blockdev: Move vpc probe to its own file
In reply to Colin LordIsolates vpc probe as part of the modularization process.
--- block/Makefile.objs | 2 +- block/vpc-probe.c | 9 +++++++++ block/vpc.c | 8 +------- include/block/probe.h | 1 + 4 files changed, 12 insertions(+), 8 deletions(-) create mode 100644 block/vpc-probe.c
block/Makefile.objs +1 -1
@@ -26,7 +26,7 @@ block-obj-y += write-threshold.o block-obj-y += crypto.o block-obj-y += bochs-probe.o cloop-probe.o crypto-probe.o dmg-probe.o block-obj-y += parallels-probe.o qcow-probe.o qcow2-probe.o qed-probe.o -block-obj-y += raw-probe.o vdi-probe.o vhdx-probe.o vmdk-probe.o +block-obj-y += raw-probe.o vdi-probe.o vhdx-probe.o vmdk-probe.o vpc-probe.o common-obj-y += stream.o common-obj-y += backup.o
block/vpc-probe.c new file +9 -0
@@ -0,0 +1,9 @@ +#include "qemu/osdep.h" +#include "block/probe.h" + +int vpc_probe (const uint8_t *buf,int buf_size,const char *filename) +{ +if (buf_size >=8 && !strncmp ((char *)buf,"conectix" ,8 )) +return 100 ; +return 0 ; +}
block/vpc.c +1 -7
@@ -26,6 +26,7 @@#include "qapi/error.h" #include "qemu-common.h" #include "block/block_int.h" +#include "block/probe.h" #include "sysemu/block-backend.h" #include "qemu/module.h" #include "migration/migration.h"
@@ -179,13 +180,6 @@ static uint32_t vpc_checksum(uint8_t* buf, size_t size) } -static int vpc_probe (const uint8_t *buf,int buf_size,const char *filename) -{ -if (buf_size >=8 && !strncmp ((char *)buf,"conectix" ,8 )) -return 100 ; -return 0 ; -} -static void vpc_parse_options (BlockDriverState *bs,QemuOpts *opts,Error **errp) {
include/block/probe.h +1 -0
@@ -14,5 +14,6 @@ int raw_probe(const uint8_t *buf, int buf_size, const char *filename);int vdi_probe (const uint8_t *buf,int buf_size,const char *filename);int vhdx_probe (const uint8_t *buf,int buf_size,const char *filename);int vmdk_probe (const uint8_t *buf,int buf_size,const char *filename); +int vpc_probe (const uint8_t *buf,int buf_size,const char *filename);#endif
Signature · 1 line
2.5.5
PATCH v4 17/32 blockdev: Separate bochs probe from its driver
In reply to Colin LordModifies the bochs probe to return the format name as well as the score as the final step of separating the probe function from the driver. This keeps the probe completely independent of the driver, making future modularization easier to accomplish. Returning the format name as well as the score allows the score to be correlated to the driver without the probe function needing to be part of the driver.
--- block.c | 20 ++++++++++++++++++++ block/bochs-probe.c | 25 ++++++++++++++++--------- block/bochs.c | 1 - include/block/probe.h | 3 ++- 4 files changed, 38 insertions(+), 11 deletions(-)
block.c +20 -0
@@ -25,6 +25,7 @@#include "trace.h" #include "block/block_int.h" #include "block/blockjob.h" +#include "block/probe.h" #include "qemu/error-report.h" #include "module_block.h" #include "qemu/module.h"
@@ -56,6 +57,13 @@#define NOT_DONE 0x7fffffff/* used while emulated sync operation in progress */ +typedef const char *BdrvProbeFunc (const uint8_t *buf,int buf_size, +const char *filename,int *score); + +static BdrvProbeFunc *format_probes[] = { + bdrv_bochs_probe, +}; + static QTAILQ_HEAD(, BlockDriverState) graph_bdrv_states =QTAILQ_HEAD_INITIALIZER (graph_bdrv_states);
@@ -576,6 +584,8 @@ BlockDriver *bdrv_probe_all(const uint8_t *buf, int buf_size, const char *filename) {int score_max =0 , score; +const char *format_max =NULL ; +const char *format;size_t i;BlockDriver *drv =NULL , *d;
@@ -595,6 +605,16 @@ BlockDriver *bdrv_probe_all(const uint8_t *buf, int buf_size, } } +for (i =0 ; i <ARRAY_SIZE (format_probes); i++) { + format = format_probes[i](buf, buf_size, filename, &score); +if (score > score_max) { + score_max = score; + format_max = format; +/* TODO: move call to find_format outside this loop */ + drv =bdrv_find_format (format_max); + } + } +return drv; }
block/bochs-probe.c +16 -9
@@ -3,19 +3,26 @@#include "block/probe.h" #include "bochs.h" -int bochs_probe (const uint8_t *buf,int buf_size,const char *filename) +const char *bdrv_bochs_probe (const uint8_t *buf,int buf_size, +const char *filename,int *score) { +const char *format ="bochs" ;const struct bochs_header *bochs = (const void *)buf; +assert (score); + *score =0 ; -if (buf_size <HEADER_SIZE ) -return 0 ; +if (buf_size <HEADER_SIZE ) { +return format; + }if (!strcmp (bochs->magic,HEADER_MAGIC ) && - !strcmp (bochs->type,REDOLOG_TYPE ) && - !strcmp (bochs->subtype,GROWING_TYPE ) && - ((le32_to_cpu (bochs->version) ==HEADER_VERSION ) || - (le32_to_cpu (bochs->version) ==HEADER_V1 ))) -return 100 ; + !strcmp (bochs->type,REDOLOG_TYPE ) && + !strcmp (bochs->subtype,GROWING_TYPE ) && + ((le32_to_cpu (bochs->version) ==HEADER_VERSION ) || + (le32_to_cpu (bochs->version) ==HEADER_V1 ))) { + *score =100 ; +return format; + } -return 0 ; +return format; }
block/bochs.c +0 -1
@@ -234,7 +234,6 @@ static void bochs_close(BlockDriverState *bs)static BlockDriver bdrv_bochs = { .format_name ="bochs" , .instance_size =sizeof (BDRVBochsState), - .bdrv_probe = bochs_probe, .bdrv_open = bochs_open, .bdrv_refresh_limits = bochs_refresh_limits, .bdrv_co_preadv = bochs_co_preadv,
include/block/probe.h +2 -1
@@ -1,7 +1,6 @@#ifndef PROBE_H #define PROBE_H -int bochs_probe (const uint8_t *buf,int buf_size,const char *filename);int cloop_probe (const uint8_t *buf,int buf_size,const char *filename);int block_crypto_probe_luks (const uint8_t *buf,int buf_size,const char *filename);
@@ -15,5 +14,7 @@ int vdi_probe(const uint8_t *buf, int buf_size, const char *filename);int vhdx_probe (const uint8_t *buf,int buf_size,const char *filename);int vmdk_probe (const uint8_t *buf,int buf_size,const char *filename);int vpc_probe (const uint8_t *buf,int buf_size,const char *filename); +const char *bdrv_bochs_probe (const uint8_t *buf,int buf_size, +const char *filename,int *score);#endif
Signature · 1 line
2.5.5
Re: [Qemu-devel] [PATCH v4 17/32] blockdev: Separate bochs probe from its driver
Quoted 28 lines · Colin Lord
Modifies the bochs probe to return the format name as well as the score as the final step of separating the probe function from the driver. This keeps the probe completely independent of the driver, making future modularization easier to accomplish. Returning the format name as well as the score allows the score to be correlated to the driver without the probe function needing to be part of the driver.
Signed-off-by Colin Lord <[email protected]>--- block.c | 20 ++++++++++++++++++++ block/bochs-probe.c | 25 ++++++++++++++++--------- block/bochs.c | 1 - include/block/probe.h | 3 ++- 4 files changed, 38 insertions(+), 11 deletions(-)block.c +1
-0@@ -25,6 +25,7 @@#include "trace.h" #include "block/block_int.h" #include "block/blockjob.h" +#include "block/probe.h" #include "qemu/error-report.h" #include "module_block.h" #include "qemu/module.h"
block.c line 66
Quoted 10 lines
block.c +7
-0@@ -56,6 +57,13 @@#define NOT_DONE 0x7fffffff/* used while emulated sync operation in progress */ +typedef const char *BdrvProbeFunc (const uint8_t *buf,int buf_size, +const char *filename,int *score); + +static BdrvProbeFunc *format_probes[] = { + bdrv_bochs_probe, +}; +
I really can't convince you of my "struct concept", can I? :-)
Unless maybe I can:
Re: [Qemu-devel] [PATCH v4 17/32] blockdev: Separate bochs probe from its driver
Quoted 42 lines · Max Reitz
Quoted 28 lines · Colin Lord
Modifies the bochs probe to return the format name as well as the score as the final step of separating the probe function from the driver. This keeps the probe completely independent of the driver, making future modularization easier to accomplish. Returning the format name as well as the score allows the score to be correlated to the driver without the probe function needing to be part of the driver.
Signed-off-by Colin Lord <[email protected]>--- block.c | 20 ++++++++++++++++++++ block/bochs-probe.c | 25 ++++++++++++++++--------- block/bochs.c | 1 - include/block/probe.h | 3 ++- 4 files changed, 38 insertions(+), 11 deletions(-)block.c +1
-0@@ -25,6 +25,7 @@#include "trace.h" #include "block/block_int.h" #include "block/blockjob.h" +#include "block/probe.h" #include "qemu/error-report.h" #include "module_block.h" #include "qemu/module.h" block.c line 66
Quoted 10 lines
block.c +7
-0@@ -56,6 +57,13 @@#define NOT_DONE 0x7fffffff/* used while emulated sync operation in progress */ +typedef const char *BdrvProbeFunc (const uint8_t *buf,int buf_size, +const char *filename,int *score); + +static BdrvProbeFunc *format_probes[] = { + bdrv_bochs_probe, +}; +I really can't convince you of my "struct concept", can I? :-)
Quoted 4 lines
Unless maybe I can:
Reviewed-by Max Reitz <[email protected]>
If you really want me to I could go back and change it. I do have to agree that it's a little odd to be returning the same string every time, but it also strikes me as pretty weird if the probing functions themselves can't even be associated with their drivers without the help of another struct. It doesn't seem quite right to me if the functions can't be used independently of the struct containing the mappings. Technically of course they could still be used, but without the mappings they are practically indistinguishable from each other so they're basically useless.
Since both options seem to have their own quirks, I'm not too excited to go back and edit all the patches only to end up with something I see as equally weird. But again, if you (or others) really want me to change it, or show me why having a bunch of indistinguishable probing functions isn't as weird as I think, I could certainly do so.
Colin
PATCH v4 18/32 blockdev: Separate cloop probe from its driver
In reply to Colin LordCompletes the separation of the cloop probe from the cloop driver. The cloop probe now returns the format in addition to the score, allowing correlation of the score and driver without the probe function being part of the driver itself.
--- block.c | 1 + block/cloop-probe.c | 11 ++++++++--- block/cloop.c | 1 - include/block/probe.h | 3 ++- 4 files changed, 11 insertions(+), 5 deletions(-)
block.c +1 -0
@@ -62,6 +62,7 @@ typedef const char *BdrvProbeFunc(const uint8_t *buf, int buf_size,static BdrvProbeFunc *format_probes[] = { bdrv_bochs_probe, + bdrv_cloop_probe, }; static QTAILQ_HEAD(, BlockDriverState) graph_bdrv_states =
block/cloop-probe.c +8 -3
@@ -1,17 +1,22 @@#include "qemu/osdep.h" #include "block/probe.h" -int cloop_probe (const uint8_t *buf,int buf_size,const char *filename) +const char *bdrv_cloop_probe (const uint8_t *buf,int buf_size, +const char *filename,int *score) { +const char *format ="cloop" ;const char *magic_version_2_0 ="#!/bin/sh\n" "#V2.0 Format\n" "modprobe cloop file=$0 && mount -r -t iso9660 /dev/cloop $1\n" ;int length =strlen (magic_version_2_0); +assert (score);if (length > buf_size) { length = buf_size; }if (!memcmp (magic_version_2_0, buf, length)) { -return 2 ; + *score =2 ; +return format; } -return 0 ; + *score =0 ; +return format; }
block/cloop.c +0 -1
@@ -268,7 +268,6 @@ static void cloop_close(BlockDriverState *bs)static BlockDriver bdrv_cloop = { .format_name ="cloop" , .instance_size =sizeof (BDRVCloopState), - .bdrv_probe = cloop_probe, .bdrv_open = cloop_open, .bdrv_refresh_limits = cloop_refresh_limits, .bdrv_co_preadv = cloop_co_preadv,
include/block/probe.h +2 -1
@@ -1,7 +1,6 @@#ifndef PROBE_H #define PROBE_H -int cloop_probe (const uint8_t *buf,int buf_size,const char *filename);int block_crypto_probe_luks (const uint8_t *buf,int buf_size,const char *filename);int dmg_probe (const uint8_t *buf,int buf_size,const char *filename);
@@ -16,5 +15,7 @@ int vmdk_probe(const uint8_t *buf, int buf_size, const char *filename);int vpc_probe (const uint8_t *buf,int buf_size,const char *filename);const char *bdrv_bochs_probe (const uint8_t *buf,int buf_size,const char *filename,int *score); +const char *bdrv_cloop_probe (const uint8_t *buf,int buf_size, +const char *filename,int *score);#endif
Signature · 1 line
2.5.5
PATCH v4 19/32 blockdev: Separate luks probe from its driver
In reply to Colin LordCompletes the separation of the luks probe from the crypto driver. The luks probe now returns the format in addition to the score, allowing correlation of the score and driver without the probe function being part of the driver itself.
--- block.c | 1 + block/crypto-probe.c | 13 ++++++++----- block/crypto.c | 1 - include/block/probe.h | 4 ++-- 4 files changed, 11 insertions(+), 8 deletions(-)
block.c +1 -0
@@ -63,6 +63,7 @@ typedef const char *BdrvProbeFunc(const uint8_t *buf, int buf_size,static BdrvProbeFunc *format_probes[] = { bdrv_bochs_probe, bdrv_cloop_probe, + bdrv_crypto_probe_luks, }; static QTAILQ_HEAD(, BlockDriverState) graph_bdrv_states =
block/crypto-probe.c +8 -5
@@ -15,9 +15,12 @@ static int block_crypto_probe_generic(QCryptoBlockFormat format, } } -int block_crypto_probe_luks (const uint8_t *buf, -int buf_size, -const char *filename) { -return block_crypto_probe_generic (Q_CRYPTO_BLOCK_FORMAT_LUKS , - buf, buf_size, filename); +const char *bdrv_crypto_probe_luks (const uint8_t *buf,int buf_size, +const char *filename,int *score) +{ +const char *format ="luks" ; +assert (score); + *score =block_crypto_probe_generic (Q_CRYPTO_BLOCK_FORMAT_LUKS , + buf, buf_size, filename); +return format; }
block/crypto.c +0 -1
@@ -547,7 +547,6 @@ static int block_crypto_create_luks(const char *filename,BlockDriver bdrv_crypto_luks = { .format_name ="luks" , .instance_size =sizeof (BlockCrypto), - .bdrv_probe = block_crypto_probe_luks, .bdrv_open = block_crypto_open_luks, .bdrv_close = block_crypto_close, .bdrv_create = block_crypto_create_luks,
include/block/probe.h +2 -2
@@ -1,8 +1,6 @@#ifndef PROBE_H #define PROBE_H -int block_crypto_probe_luks (const uint8_t *buf,int buf_size, -const char *filename);int dmg_probe (const uint8_t *buf,int buf_size,const char *filename);int parallels_probe (const uint8_t *buf,int buf_size,const char *filename);int qcow_probe (const uint8_t *buf,int buf_size,const char *filename);
@@ -17,5 +15,7 @@ const char *bdrv_bochs_probe(const uint8_t *buf, int buf_size, const char *filename, int *score);const char *bdrv_cloop_probe (const uint8_t *buf,int buf_size,const char *filename,int *score); +const char *bdrv_crypto_probe_luks (const uint8_t *buf,int buf_size, +const char *filename,int *score);#endif
Signature · 1 line
2.5.5
PATCH v4 20/32 blockdev: Separate dmg probe from its driver
In reply to Colin LordCompletes the separation of the dmg probe from the dmg driver. The dmg probe now returns the format in addition to the score, allowing correlation of the score and driver without the probe function being part of the driver itself.
--- block.c | 1 + block/dmg-probe.c | 13 +++++++++---- block/dmg.c | 1 - include/block/probe.h | 3 ++- 4 files changed, 12 insertions(+), 6 deletions(-)
block.c +1 -0
@@ -64,6 +64,7 @@ static BdrvProbeFunc *format_probes[] = { bdrv_bochs_probe, bdrv_cloop_probe, bdrv_crypto_probe_luks, + bdrv_dmg_probe, }; static QTAILQ_HEAD(, BlockDriverState) graph_bdrv_states =
block/dmg-probe.c +9 -4
@@ -1,17 +1,22 @@#include "qemu/osdep.h" #include "block/probe.h" -int dmg_probe (const uint8_t *buf,int buf_size,const char *filename) +const char *bdrv_dmg_probe (const uint8_t *buf,int buf_size, +const char *filename,int *score) { +const char *format ="dmg" ;int len; +assert (score); + *score =0 ;if (!filename) { -return 0 ; +return format; } len =strlen (filename);if (len >4 && !strcmp (filename + len -4 ,".dmg" )) { -return 2 ; + *score =2 ; +return format; } -return 0 ; +return format; }
block/dmg.c +0 -1
@@ -709,7 +709,6 @@ static void dmg_close(BlockDriverState *bs)static BlockDriver bdrv_dmg = { .format_name ="dmg" , .instance_size =sizeof (BDRVDMGState), - .bdrv_probe = dmg_probe, .bdrv_open = dmg_open, .bdrv_refresh_limits = dmg_refresh_limits, .bdrv_co_preadv = dmg_co_preadv,
include/block/probe.h +2 -1
@@ -1,7 +1,6 @@#ifndef PROBE_H #define PROBE_H -int dmg_probe (const uint8_t *buf,int buf_size,const char *filename);int parallels_probe (const uint8_t *buf,int buf_size,const char *filename);int qcow_probe (const uint8_t *buf,int buf_size,const char *filename);int qcow2_probe (const uint8_t *buf,int buf_size,const char *filename);
@@ -17,5 +16,7 @@ const char *bdrv_cloop_probe(const uint8_t *buf, int buf_size, const char *filename, int *score);const char *bdrv_crypto_probe_luks (const uint8_t *buf,int buf_size,const char *filename,int *score); +const char *bdrv_dmg_probe (const uint8_t *buf,int buf_size, +const char *filename,int *score);#endif
Signature · 1 line
2.5.5
PATCH v4 21/32 blockdev: Separate parallels probe from its driver
In reply to Colin LordCompletes the separation of the parallels probe from the parallels driver. The parallels probe now returns the format in addition to the score, allowing correlation of the score and driver without the probe function being part of the driver itself.
--- block.c | 1 + block/parallels-probe.c | 17 +++++++++++------ block/parallels.c | 1 - include/block/probe.h | 3 ++- 4 files changed, 14 insertions(+), 8 deletions(-)
block.c +1 -0
@@ -65,6 +65,7 @@ static BdrvProbeFunc *format_probes[] = { bdrv_cloop_probe, bdrv_crypto_probe_luks, bdrv_dmg_probe, + bdrv_parallels_probe, }; static QTAILQ_HEAD(, BlockDriverState) graph_bdrv_states =
block/parallels-probe.c +11 -6
@@ -3,19 +3,24 @@#include "block/probe.h" #include "parallels.h" -int parallels_probe (const uint8_t *buf,int buf_size,const char *filename) +const char *bdrv_parallels_probe (const uint8_t *buf,int buf_size, +const char *filename,int *score) { +const char *format ="parallels" ;const ParallelsHeader *ph = (const void *)buf; +assert (score); + *score =0 ;if (buf_size <sizeof (ParallelsHeader)) { -return 0 ; +return format; }if ((!memcmp (ph->magic,HEADER_MAGIC ,16 ) || - !memcmp (ph->magic,HEADER_MAGIC2 ,16 )) && - (le32_to_cpu (ph->version) ==HEADER_VERSION )) { -return 100 ; + !memcmp (ph->magic,HEADER_MAGIC2 ,16 )) && + (le32_to_cpu (ph->version) ==HEADER_VERSION )) { + *score =100 ; +return format; } -return 0 ; +return format; }
block/parallels.c +0 -1
@@ -709,7 +709,6 @@ static QemuOptsList parallels_create_opts = {static BlockDriver bdrv_parallels = { .format_name ="parallels" , .instance_size =sizeof (BDRVParallelsState), - .bdrv_probe = parallels_probe, .bdrv_open = parallels_open, .bdrv_close = parallels_close, .bdrv_co_get_block_status = parallels_co_get_block_status,
include/block/probe.h +2 -1
@@ -1,7 +1,6 @@#ifndef PROBE_H #define PROBE_H -int parallels_probe (const uint8_t *buf,int buf_size,const char *filename);int qcow_probe (const uint8_t *buf,int buf_size,const char *filename);int qcow2_probe (const uint8_t *buf,int buf_size,const char *filename);int bdrv_qed_probe (const uint8_t *buf,int buf_size,const char *filename);
@@ -18,5 +17,7 @@ const char *bdrv_crypto_probe_luks(const uint8_t *buf, int buf_size, const char *filename, int *score);const char *bdrv_dmg_probe (const uint8_t *buf,int buf_size,const char *filename,int *score); +const char *bdrv_parallels_probe (const uint8_t *buf,int buf_size, +const char *filename,int *score);#endif
Signature · 1 line
2.5.5
PATCH v4 22/32 blockdev: Separate qcow probe from its driver
In reply to Colin LordCompletes the separation of the qcow probe from the qcow driver. The qcow probe now returns the format in addition to the score, allowing correlation of the score and driver without the probe function being part of the driver itself.
--- block.c | 1 + block/qcow-probe.c | 16 +++++++++++----- block/qcow.c | 1 - include/block/probe.h | 3 ++- 4 files changed, 14 insertions(+), 7 deletions(-)
block.c +1 -0
@@ -66,6 +66,7 @@ static BdrvProbeFunc *format_probes[] = { bdrv_crypto_probe_luks, bdrv_dmg_probe, bdrv_parallels_probe, + bdrv_qcow_probe, }; static QTAILQ_HEAD(, BlockDriverState) graph_bdrv_states =
block/qcow-probe.c +11 -5
@@ -3,14 +3,20 @@#include "block/probe.h" #include "qcow.h" -int qcow_probe (const uint8_t *buf,int buf_size,const char *filename) +const char *bdrv_qcow_probe (const uint8_t *buf,int buf_size, +const char *filename,int *score) { +const char *format ="qcow" ;const QCowHeader *cow_header = (const void *)buf; +assert (score);if (buf_size >=sizeof (QCowHeader) &&be32_to_cpu (cow_header->magic) ==QCOW_MAGIC && -be32_to_cpu (cow_header->version) ==QCOW_VERSION ) -return 100 ; -else -return 0 ; +be32_to_cpu (cow_header->version) ==QCOW_VERSION ) { + *score =100 ; +return format; + } + + *score =0 ; +return format; }
block/qcow.c +0 -1
@@ -1044,7 +1044,6 @@ static QemuOptsList qcow_create_opts = {static BlockDriver bdrv_qcow = { .format_name ="qcow" , .instance_size =sizeof (BDRVQcowState), - .bdrv_probe = qcow_probe, .bdrv_open = qcow_open, .bdrv_close = qcow_close, .bdrv_reopen_prepare = qcow_reopen_prepare,
include/block/probe.h +2 -1
@@ -1,7 +1,6 @@#ifndef PROBE_H #define PROBE_H -int qcow_probe (const uint8_t *buf,int buf_size,const char *filename);int qcow2_probe (const uint8_t *buf,int buf_size,const char *filename);int bdrv_qed_probe (const uint8_t *buf,int buf_size,const char *filename);int raw_probe (const uint8_t *buf,int buf_size,const char *filename);
@@ -19,5 +18,7 @@ const char *bdrv_dmg_probe(const uint8_t *buf, int buf_size, const char *filename, int *score);const char *bdrv_parallels_probe (const uint8_t *buf,int buf_size,const char *filename,int *score); +const char *bdrv_qcow_probe (const uint8_t *buf,int buf_size, +const char *filename,int *score);#endif
Signature · 1 line
2.5.5
PATCH v4 23/32 blockdev: Separate qcow2 probe from its driver
In reply to Colin LordCompletes the separation of the qcow2 probe from the qcow2 driver. The qcow2 probe now returns the format in addition to the score, allowing correlation of the score and driver without the probe function being part of the driver itself.
--- block.c | 1 + block/qcow2-probe.c | 16 +++++++++++----- block/qcow2.c | 1 - include/block/probe.h | 3 ++- 4 files changed, 14 insertions(+), 7 deletions(-)
block.c +1 -0
@@ -67,6 +67,7 @@ static BdrvProbeFunc *format_probes[] = { bdrv_dmg_probe, bdrv_parallels_probe, bdrv_qcow_probe, + bdrv_qcow2_probe, }; static QTAILQ_HEAD(, BlockDriverState) graph_bdrv_states =
block/qcow2-probe.c +11 -5
@@ -3,14 +3,20 @@#include "block/probe.h" #include "qcow2.h" -int qcow2_probe (const uint8_t *buf,int buf_size,const char *filename) +const char *bdrv_qcow2_probe (const uint8_t *buf,int buf_size, +const char *filename,int *score) { +const char *format ="qcow2" ;const QCowHeader *cow_header = (const void *)buf; +assert (score);if (buf_size >=sizeof (QCowHeader) &&be32_to_cpu (cow_header->magic) ==QCOW_MAGIC && -be32_to_cpu (cow_header->version) >=2 ) -return 100 ; -else -return 0 ; +be32_to_cpu (cow_header->version) >=2 ) { + *score =100 ; +return format; + } + + *score =0 ; +return format; }
block/qcow2.c +0 -1
@@ -3382,7 +3382,6 @@ static QemuOptsList qcow2_create_opts = {BlockDriver bdrv_qcow2 = { .format_name ="qcow2" , .instance_size =sizeof (BDRVQcow2State), - .bdrv_probe = qcow2_probe, .bdrv_open = qcow2_open, .bdrv_close = qcow2_close, .bdrv_reopen_prepare = qcow2_reopen_prepare,
include/block/probe.h +2 -1
@@ -1,7 +1,6 @@#ifndef PROBE_H #define PROBE_H -int qcow2_probe (const uint8_t *buf,int buf_size,const char *filename);int bdrv_qed_probe (const uint8_t *buf,int buf_size,const char *filename);int raw_probe (const uint8_t *buf,int buf_size,const char *filename);int vdi_probe (const uint8_t *buf,int buf_size,const char *filename);
@@ -20,5 +19,7 @@ const char *bdrv_parallels_probe(const uint8_t *buf, int buf_size, const char *filename, int *score);const char *bdrv_qcow_probe (const uint8_t *buf,int buf_size,const char *filename,int *score); +const char *bdrv_qcow2_probe (const uint8_t *buf,int buf_size, +const char *filename,int *score);#endif
Signature · 1 line
2.5.5
PATCH v4 24/32 blockdev: Separate qed probe from its driver
In reply to Colin LordCompletes the separation of the qed probe from the qed driver. The qed probe now returns the format in addition to the score, allowing correlation of the score and driver without the probe function being part of the driver itself.
--- block.c | 1 + block/qed-probe.c | 16 +++++++++++----- block/qed.c | 1 - include/block/probe.h | 3 ++- 4 files changed, 14 insertions(+), 7 deletions(-)
block.c +1 -0
@@ -68,6 +68,7 @@ static BdrvProbeFunc *format_probes[] = { bdrv_parallels_probe, bdrv_qcow_probe, bdrv_qcow2_probe, + bdrv_qed_probe, }; static QTAILQ_HEAD(, BlockDriverState) graph_bdrv_states =
block/qed-probe.c +11 -5
@@ -3,16 +3,22 @@#include "block/probe.h" #include "qed.h" -int bdrv_qed_probe (const uint8_t *buf,int buf_size, -const char *filename) +const char *bdrv_qed_probe (const uint8_t *buf,int buf_size, +const char *filename,int *score) { +const char *format ="qed" ;const QEDHeader *header = (const QEDHeader *)buf; +assert (score); + *score =0 ;if (buf_size <sizeof (*header)) { -return 0 ; +return format; } +if (le32_to_cpu (header->magic) !=QED_MAGIC ) { -return 0 ; +return format; } -return 100 ; + + *score =100 ; +return format; }
block/qed.c +0 -1
@@ -1638,7 +1638,6 @@ static BlockDriver bdrv_qed = { .create_opts = &qed_create_opts, .supports_backing = true, - .bdrv_probe = bdrv_qed_probe, .bdrv_open = bdrv_qed_open, .bdrv_close = bdrv_qed_close, .bdrv_reopen_prepare = bdrv_qed_reopen_prepare,
include/block/probe.h +2 -1
@@ -1,7 +1,6 @@#ifndef PROBE_H #define PROBE_H -int bdrv_qed_probe (const uint8_t *buf,int buf_size,const char *filename);int raw_probe (const uint8_t *buf,int buf_size,const char *filename);int vdi_probe (const uint8_t *buf,int buf_size,const char *filename);int vhdx_probe (const uint8_t *buf,int buf_size,const char *filename);
@@ -21,5 +20,7 @@ const char *bdrv_qcow_probe(const uint8_t *buf, int buf_size, const char *filename, int *score);const char *bdrv_qcow2_probe (const uint8_t *buf,int buf_size,const char *filename,int *score); +const char *bdrv_qed_probe (const uint8_t *buf,int buf_size, +const char *filename,int *score);#endif
Signature · 1 line
2.5.5
PATCH v4 25/32 blockdev: Separate raw probe from its driver
In reply to Colin LordCompletes the separation of the raw probe from the raw driver. The raw probe now returns the format in addition to the score, allowing correlation of the score and driver without the probe function being part of the driver itself.
--- block.c | 1 + block/raw-probe.c | 8 ++++++-- block/raw_bsd.c | 1 - include/block/probe.h | 3 ++- 4 files changed, 9 insertions(+), 4 deletions(-)
block.c +1 -0
@@ -69,6 +69,7 @@ static BdrvProbeFunc *format_probes[] = { bdrv_qcow_probe, bdrv_qcow2_probe, bdrv_qed_probe, + bdrv_raw_probe, }; static QTAILQ_HEAD(, BlockDriverState) graph_bdrv_states =
block/raw-probe.c +6 -2
@@ -1,10 +1,14 @@#include "qemu/osdep.h" #include "block/probe.h" -int raw_probe (const uint8_t *buf,int buf_size,const char *filename) +const char *bdrv_raw_probe (const uint8_t *buf,int buf_size, +const char *filename,int *score) { +const char *format ="raw" ; +assert (score);/* smallest possible positive score so that raw is used if and only if no * other block driver works */ -return 1 ; + *score =1 ; +return format; }
block/raw_bsd.c +0 -1
@@ -226,7 +226,6 @@ static int raw_probe_geometry(BlockDriverState *bs, HDGeometry *geo)BlockDriver bdrv_raw = { .format_name ="raw" , - .bdrv_probe = &raw_probe, .bdrv_reopen_prepare = &raw_reopen_prepare, .bdrv_open = &raw_open, .bdrv_close = &raw_close,
include/block/probe.h +2 -1
@@ -1,7 +1,6 @@#ifndef PROBE_H #define PROBE_H -int raw_probe (const uint8_t *buf,int buf_size,const char *filename);int vdi_probe (const uint8_t *buf,int buf_size,const char *filename);int vhdx_probe (const uint8_t *buf,int buf_size,const char *filename);int vmdk_probe (const uint8_t *buf,int buf_size,const char *filename);
@@ -22,5 +21,7 @@ const char *bdrv_qcow2_probe(const uint8_t *buf, int buf_size, const char *filename, int *score);const char *bdrv_qed_probe (const uint8_t *buf,int buf_size,const char *filename,int *score); +const char *bdrv_raw_probe (const uint8_t *buf,int buf_size, +const char *filename,int *score);#endif
Signature · 1 line
2.5.5
PATCH v4 26/32 blockdev: Separate vdi probe from its driver
In reply to Colin LordCompletes the separation of the vdi probe from the vdi driver. The vdi probe now returns the format in addition to the score, allowing correlation of the score and driver without the probe function being part of the driver itself.
--- block.c | 1 + block/vdi-probe.c | 13 ++++++++----- block/vdi.c | 1 - include/block/probe.h | 3 ++- 4 files changed, 11 insertions(+), 7 deletions(-)
block.c +1 -0
@@ -70,6 +70,7 @@ static BdrvProbeFunc *format_probes[] = { bdrv_qcow2_probe, bdrv_qed_probe, bdrv_raw_probe, + bdrv_vdi_probe, }; static QTAILQ_HEAD(, BlockDriverState) graph_bdrv_states =
block/vdi-probe.c +8 -5
@@ -3,24 +3,27 @@#include "block/probe.h" #include "vdi.h" -int vdi_probe (const uint8_t *buf,int buf_size,const char *filename) +const char *bdrv_vdi_probe (const uint8_t *buf,int buf_size, +const char *filename,int *score) { +const char *format ="vdi" ;const VdiHeader *header = (const VdiHeader *)buf; -int ret =0 ; +assert (score); + *score =0 ;logout ("\n" );if (buf_size <sizeof (*header)) {/* Header too small, no VDI. */ }else if (le32_to_cpu (header->signature) ==VDI_SIGNATURE ) { - ret =100 ; + *score =100 ; } -if (ret ==0 ) { +if (*score ==0 ) {logout ("no vdi image\n" ); }else {logout ("%s" , header->text); } -return ret; +return format; }
block/vdi.c +0 -1
@@ -849,7 +849,6 @@ static QemuOptsList vdi_create_opts = {static BlockDriver bdrv_vdi = { .format_name ="vdi" , .instance_size =sizeof (BDRVVdiState), - .bdrv_probe = vdi_probe, .bdrv_open = vdi_open, .bdrv_close = vdi_close, .bdrv_reopen_prepare = vdi_reopen_prepare,
include/block/probe.h +2 -1
@@ -1,7 +1,6 @@#ifndef PROBE_H #define PROBE_H -int vdi_probe (const uint8_t *buf,int buf_size,const char *filename);int vhdx_probe (const uint8_t *buf,int buf_size,const char *filename);int vmdk_probe (const uint8_t *buf,int buf_size,const char *filename);int vpc_probe (const uint8_t *buf,int buf_size,const char *filename);
@@ -23,5 +22,7 @@ const char *bdrv_qed_probe(const uint8_t *buf, int buf_size, const char *filename, int *score);const char *bdrv_raw_probe (const uint8_t *buf,int buf_size,const char *filename,int *score); +const char *bdrv_vdi_probe (const uint8_t *buf,int buf_size, +const char *filename,int *score);#endif
Signature · 1 line
2.5.5
PATCH v4 27/32 blockdev: Separate vhdx probe from its driver
In reply to Colin LordCompletes the separation of the vhdx probe from the vhdx driver. The vhdx probe now returns the format in addition to the score, allowing correlation of the score and driver without the probe function being part of the driver itself.
--- block.c | 1 + block/vhdx-probe.c | 12 +++++++++--- block/vhdx.c | 1 - include/block/probe.h | 3 ++- 4 files changed, 12 insertions(+), 5 deletions(-)
block.c +1 -0
@@ -71,6 +71,7 @@ static BdrvProbeFunc *format_probes[] = { bdrv_qed_probe, bdrv_raw_probe, bdrv_vdi_probe, + bdrv_vhdx_probe, }; static QTAILQ_HEAD(, BlockDriverState) graph_bdrv_states =
block/vhdx-probe.c +9 -3
@@ -12,10 +12,16 @@* * Therefore, we probe by looking for the vhdxfile signature "vhdxfile" */ -int vhdx_probe (const uint8_t *buf,int buf_size,const char *filename) +const char *bdrv_vhdx_probe (const uint8_t *buf,int buf_size, +const char *filename,int *score) { +const char *format ="vhdx" ; +assert (score); +if (buf_size >=8 && !memcmp (buf,"vhdxfile" ,8 )) { -return 100 ; + *score =100 ; +return format; } -return 0 ; + *score =0 ; +return format; }
block/vhdx.c +0 -1
@@ -1951,7 +1951,6 @@ static QemuOptsList vhdx_create_opts = {static BlockDriver bdrv_vhdx = { .format_name ="vhdx" , .instance_size =sizeof (BDRVVHDXState), - .bdrv_probe = vhdx_probe, .bdrv_open = vhdx_open, .bdrv_close = vhdx_close, .bdrv_reopen_prepare = vhdx_reopen_prepare,
include/block/probe.h +2 -1
@@ -1,7 +1,6 @@#ifndef PROBE_H #define PROBE_H -int vhdx_probe (const uint8_t *buf,int buf_size,const char *filename);int vmdk_probe (const uint8_t *buf,int buf_size,const char *filename);int vpc_probe (const uint8_t *buf,int buf_size,const char *filename); const char *bdrv_bochs_probe(const uint8_t *buf, int buf_size,
@@ -24,5 +23,7 @@ const char *bdrv_raw_probe(const uint8_t *buf, int buf_size, const char *filename, int *score);const char *bdrv_vdi_probe (const uint8_t *buf,int buf_size,const char *filename,int *score); +const char *bdrv_vhdx_probe (const uint8_t *buf,int buf_size, +const char *filename,int *score);#endif
Signature · 1 line
2.5.5
PATCH v4 28/32 blockdev: Separate vmdk probe from its driver
In reply to Colin LordCompletes the separation of the vmdk probe from the vmdk driver. The vmdk probe now returns the format in addition to the score, allowing correlation of the score and driver without the probe function being part of the driver itself.
--- block.c | 1 + block/vmdk-probe.c | 23 +++++++++++++++-------- block/vmdk.c | 1 - include/block/probe.h | 3 ++- 4 files changed, 18 insertions(+), 10 deletions(-)
block.c +1 -0
@@ -72,6 +72,7 @@ static BdrvProbeFunc *format_probes[] = { bdrv_raw_probe, bdrv_vdi_probe, bdrv_vhdx_probe, + bdrv_vmdk_probe, }; static QTAILQ_HEAD(, BlockDriverState) graph_bdrv_states =
block/vmdk-probe.c +15 -8
@@ -3,17 +3,22 @@#include "block/probe.h" #include "vmdk.h" -int vmdk_probe (const uint8_t *buf,int buf_size,const char *filename) +const char *bdrv_vmdk_probe (const uint8_t *buf,int buf_size, +const char *filename,int *score) { +const char *format ="vmdk" ;uint32_t magic; +assert (score); + *score =0 ;if (buf_size <4 ) { -return 0 ; +return format; } magic =be32_to_cpu (*(uint32_t *)buf);if (magic ==VMDK3_MAGIC || magic ==VMDK4_MAGIC ) { -return 100 ; + *score =100 ; +return format; }else {const char *p = (const char *)buf;const char *end = p + buf_size;
@@ -36,7 +41,7 @@ int vmdk_probe(const uint8_t *buf, int buf_size, const char *filename) }/* only accept blank lines before 'version=' line */ if (p == end || *p !='\n' ) { -return 0 ; +return format; } p++;continue ;
@@ -44,17 +49,19 @@ int vmdk_probe(const uint8_t *buf, int buf_size, const char *filename)if (end - p >=strlen ("version=X\n" )) {if (strncmp ("version=1\n" , p,strlen ("version=1\n" )) ==0 ||strncmp ("version=2\n" , p,strlen ("version=2\n" )) ==0 ) { -return 100 ; + *score =100 ; +return format; } }if (end - p >=strlen ("version=X\r\n" )) {if (strncmp ("version=1\r\n" , p,strlen ("version=1\r\n" )) ==0 ||strncmp ("version=2\r\n" , p,strlen ("version=2\r\n" )) ==0 ) { -return 100 ; + *score =100 ; +return format; } } -return 0 ; +return format; } -return 0 ; +return format; } }
block/vmdk.c +0 -1
@@ -2331,7 +2331,6 @@ static QemuOptsList vmdk_create_opts = {static BlockDriver bdrv_vmdk = { .format_name ="vmdk" , .instance_size =sizeof (BDRVVmdkState), - .bdrv_probe = vmdk_probe, .bdrv_open = vmdk_open, .bdrv_check = vmdk_check, .bdrv_reopen_prepare = vmdk_reopen_prepare,
include/block/probe.h +2 -1
@@ -1,7 +1,6 @@#ifndef PROBE_H #define PROBE_H -int vmdk_probe (const uint8_t *buf,int buf_size,const char *filename);int vpc_probe (const uint8_t *buf,int buf_size,const char *filename);const char *bdrv_bochs_probe (const uint8_t *buf,int buf_size,const char *filename,int *score);
@@ -25,5 +24,7 @@ const char *bdrv_vdi_probe(const uint8_t *buf, int buf_size, const char *filename, int *score);const char *bdrv_vhdx_probe (const uint8_t *buf,int buf_size,const char *filename,int *score); +const char *bdrv_vmdk_probe (const uint8_t *buf,int buf_size, +const char *filename,int *score);#endif
Signature · 1 line
2.5.5
PATCH v4 29/32 blockdev: Separate vpc probe from its driver
In reply to Colin LordCompletes the separation of the vpc probe from the vpc driver. The vpc probe now returns the format in addition to the score, allowing correlation of the score and driver without the probe function being part of the driver itself.
--- block.c | 1 + block/vpc-probe.c | 15 +++++++++++---- block/vpc.c | 1 - include/block/probe.h | 3 ++- 4 files changed, 14 insertions(+), 6 deletions(-)
block.c +1 -0
@@ -73,6 +73,7 @@ static BdrvProbeFunc *format_probes[] = { bdrv_vdi_probe, bdrv_vhdx_probe, bdrv_vmdk_probe, + bdrv_vpc_probe }; static QTAILQ_HEAD(, BlockDriverState) graph_bdrv_states =
block/vpc-probe.c +11 -4
@@ -1,9 +1,16 @@#include "qemu/osdep.h" #include "block/probe.h" -int vpc_probe (const uint8_t *buf,int buf_size,const char *filename) +const char *bdrv_vpc_probe (const uint8_t *buf,int buf_size, +const char *filename,int *score) { -if (buf_size >=8 && !strncmp ((char *)buf,"conectix" ,8 )) -return 100 ; -return 0 ; +const char *format ="vpc" ; +assert (score); +if (buf_size >=8 && !strncmp ((char *)buf,"conectix" ,8 )) { + *score =100 ; +return format; + } + + *score =0 ; +return format; }
block/vpc.c +0 -1
@@ -1050,7 +1050,6 @@ static BlockDriver bdrv_vpc = { .format_name = "vpc", .instance_size = sizeof(BDRVVPCState), - .bdrv_probe = vpc_probe, .bdrv_open = vpc_open, .bdrv_close = vpc_close, .bdrv_reopen_prepare = vpc_reopen_prepare,
include/block/probe.h +2 -1
@@ -1,7 +1,6 @@#ifndef PROBE_H #define PROBE_H -int vpc_probe (const uint8_t *buf,int buf_size,const char *filename);const char *bdrv_bochs_probe (const uint8_t *buf,int buf_size,const char *filename,int *score); const char *bdrv_cloop_probe(const uint8_t *buf, int buf_size,
@@ -26,5 +25,7 @@ const char *bdrv_vhdx_probe(const uint8_t *buf, int buf_size, const char *filename, int *score);const char *bdrv_vmdk_probe (const uint8_t *buf,int buf_size,const char *filename,int *score); +const char *bdrv_vpc_probe (const uint8_t *buf,int buf_size, +const char *filename,int *score);#endif
Signature · 1 line
2.5.5
PATCH v4 30/32 blockdev: Remove the .bdrv_probe field from BlockDrivers
In reply to Colin LordThis commit finalizes the separation of the block driver and probe function by removing the .bdrv_probe field from all BlockDrivers. Probing is now accomplished solely by iterating over the array of probe function pointers in the format_probes array.
--- block.c | 21 +-------------------- block/raw-posix.c | 1 - include/block/block_int.h | 1 - scripts/modules/module_block.py | 10 ++-------- 4 files changed, 3 insertions(+), 30 deletions(-)
block.c +1 -20
@@ -599,35 +599,16 @@ BlockDriver *bdrv_probe_all(const uint8_t *buf, int buf_size,const char *format_max =NULL ;const char *format;size_t i; -BlockDriver *drv =NULL , *d; - -for (i =0 ; i <ARRAY_SIZE (block_driver_modules); ++i) { -if (block_driver_modules[i].has_probe) { -block_module_load_one (block_driver_modules[i].library_name); - } - } - - QLIST_FOREACH(d, &bdrv_drivers, list) { -if (d->bdrv_probe) { - score = d->bdrv_probe (buf, buf_size, filename); -if (score > score_max) { - score_max = score; - drv = d; - } - } - }for (i =0 ; i <ARRAY_SIZE (format_probes); i++) { format = format_probes[i](buf, buf_size, filename, &score);if (score > score_max) { score_max = score; format_max = format; -/* TODO: move call to find_format outside this loop */ - drv =bdrv_find_format (format_max); } } -return drv; +return bdrv_find_format (format_max); } static int find_image_format(BdrvChild *file, const char *filename,
block/raw-posix.c +0 -1
@@ -1936,7 +1936,6 @@ BlockDriver bdrv_file = { .protocol_name = "file", .instance_size = sizeof(BDRVRawState), .bdrv_needs_filename = true, - .bdrv_probe = NULL, /* no probe for protocols */ .bdrv_parse_filename = raw_parse_filename, .bdrv_file_open = raw_open, .bdrv_reopen_prepare = raw_reopen_prepare,
include/block/block_int.h +0 -1
@@ -99,7 +99,6 @@ struct BlockDriver {bool (*bdrv_recurse_is_first_non_filter)(BlockDriverState *bs,BlockDriverState *candidate); -int (*bdrv_probe)(const uint8_t *buf,int buf_size,const char *filename);int (*bdrv_probe_device)(const char *filename);/* Any driver implementing this callback is expected to be able to handle
scripts/modules/module_block.py +2 -8
@@ -24,15 +24,13 @@ def get_string_struct(line): return data[2].replace('"', '')[:-1] def add_module(fheader, library, format_name, protocol_name, - probe, probe_device): + probe_device): lines = [] lines.append('.library_name = "' + library + '",') if format_name != "": lines.append('.format_name = "' + format_name + '",') if protocol_name != "": lines.append('.protocol_name = "' + protocol_name + '",') - if probe: - lines.append('.has_probe = true,') if probe_device: lines.append('.has_probe_device = true,')
@@ -52,20 +50,17 @@ def process_file(fheader, filename): format_name = get_string_struct(line) elif line.find(".protocol_name") != -1: protocol_name = get_string_struct(line) - elif line.find(".bdrv_probe") != -1: - probe = True elif line.find(".bdrv_probe_device") != -1: probe_device = True elif line == "};": add_module(fheader, library, format_name, protocol_name, - probe, probe_device) + probe_device) found_start = False elif line.find("static BlockDriver") != -1: found_something = True found_start = True format_name = "" protocol_name = "" - probe = False probe_device = False if not found_something:
@@ -93,7 +88,6 @@ static const struct { const char *format_name; const char *protocol_name; const char *library_name; - bool has_probe; bool has_probe_device; } block_driver_modules[] = {''')
Signature · 1 line
2.5.5
PATCH v4 31/32 blockdev: Separate out bdrv_probe_device functions
In reply to Colin LordThis puts the bdrv_probe_device functions into their own files to facilitate the modularization of the block drivers.
--- block/Makefile.objs | 1 + block/host_cdrom-probe.c | 40 +++++++++++++++++++++++++++++++++++++ block/host_device-probe.c | 30 ++++++++++++++++++++++++++++ block/raw-posix.c | 51 +---------------------------------------------- block/raw-win32.c | 10 +--------- include/block/probe.h | 2 ++ 6 files changed, 75 insertions(+), 59 deletions(-) create mode 100644 block/host_cdrom-probe.c create mode 100644 block/host_device-probe.c
block/Makefile.objs +1 -0
@@ -27,6 +27,7 @@ block-obj-y += crypto.o block-obj-y += bochs-probe.o cloop-probe.o crypto-probe.o dmg-probe.o block-obj-y += parallels-probe.o qcow-probe.o qcow2-probe.o qed-probe.o block-obj-y += raw-probe.o vdi-probe.o vhdx-probe.o vmdk-probe.o vpc-probe.o +block-obj-y += host_device-probe.o host_cdrom-probe.o common-obj-y += stream.o common-obj-y += backup.o
block/host_cdrom-probe.c new file +40 -0
@@ -0,0 +1,40 @@ +#include "qemu/osdep.h" +#include "block/probe.h" + +#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) +int cdrom_probe_device (const char *filename) +{ +if (strstart (filename,"/dev/cd" ,NULL ) || +strstart (filename,"/dev/acd" ,NULL )) +return 100 ; +return 0 ; +} +#elif defined(__linux__) +#include <sys/ioctl.h> +#include <linux/cdrom.h> +int cdrom_probe_device (const char *filename) +{ +int fd, ret; +int prio =0 ; +struct stat st; + + fd =qemu_open (filename,O_RDONLY |O_NONBLOCK ); +if (fd <0 ) { + goto out; + } + ret =fstat (fd, &st); +if (ret ==-1 || !S_ISBLK (st.st_mode)) { + goto outc; + } + +/* Attempt to detect via a CDROM specific ioctl */ + ret =ioctl (fd,CDROM_DRIVE_STATUS ,CDSL_CURRENT ); +if (ret >=0 ) + prio =100 ; + +outc: +qemu_close (fd); +out: +return prio; +} +#endif
block/host_device-probe.c new file +30 -0
@@ -0,0 +1,30 @@ +#include "qemu/osdep.h" +#include "block/probe.h" +#include "qemu/cutils.h" + +#ifdef _WIN32 +int hdev_probe_device (const char *filename) +{ +if (strstart (filename,"/dev/cdrom" ,NULL )) +return 100 ; +if (is_windows_drive (filename)) +return 100 ; +return 0 ; +} +#else +int hdev_probe_device (const char *filename) +{ +struct stat st; + +/* allow a dedicated CD-ROM driver to match with a higher priority */ +if (strstart (filename,"/dev/cdrom" ,NULL )) +return 50 ; + +if (stat (filename, &st) >=0 && + (S_ISCHR (st.st_mode) ||S_ISBLK (st.st_mode))) { +return 100 ; + } + +return 0 ; +} +#endif
block/raw-posix.c +1 -50
75 lines not on this page · raw message
block/raw-win32.c +1 -9
@@ -26,6 +26,7 @@#include "qemu/cutils.h" #include "qemu/timer.h" #include "block/block_int.h" +#include "block/probe.h" #include "qemu/module.h" #include "raw-aio.h" #include "trace.h"
@@ -615,15 +616,6 @@ static int find_device_type(BlockDriverState *bs, const char *filename) } } -static int hdev_probe_device (const char *filename) -{ -if (strstart (filename,"/dev/cdrom" ,NULL )) -return 100 ; -if (is_windows_drive (filename)) -return 100 ; -return 0 ; -} -static void hdev_parse_filename (const char *filename,QDict *options,Error **errp) {
include/block/probe.h +2 -0
@@ -27,5 +27,7 @@ const char *bdrv_vmdk_probe(const uint8_t *buf, int buf_size, const char *filename, int *score);const char *bdrv_vpc_probe (const uint8_t *buf,int buf_size,const char *filename,int *score); +int hdev_probe_device (const char *filename); +int cdrom_probe_device (const char *filename);#endif
Signature · 1 line
2.5.5
PATCH v4 32/32 blockdev: Remove bdrv_probe_device field from BlockDriver
In reply to Colin LordThis commit finalizes the separation of the BlockDriver from its device probing function. Now the accesses to these functions in block.c occur through the protocol_probes array, and each function returns a score and protocol name with which to find the corresponding driver.
--- block.c | 46 ++++++++++++++++++++++++++++++----------- block/host_cdrom-probe.c | 23 ++++++++++++++------- block/host_device-probe.c | 34 ++++++++++++++++++++---------- block/raw-posix.c | 3 --- block/raw-win32.c | 1 - include/block/block_int.h | 2 -- include/block/probe.h | 4 ++-- scripts/modules/module_block.py | 12 ++--------- 8 files changed, 76 insertions(+), 49 deletions(-)
block.c +34 -12
@@ -59,6 +59,7 @@typedef const char *BdrvProbeFunc (const uint8_t *buf,int buf_size,const char *filename,int *score); +typedef const char *BdrvProbeDevFunc (const char *filename,int *score);static BdrvProbeFunc *format_probes[] = { bdrv_bochs_probe,
@@ -76,6 +77,13 @@ static BdrvProbeFunc *format_probes[] = {bdrv_vpc_probe }; +static BdrvProbeDevFunc *protocol_probes[] = { + hdev_probe_device, +#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__linux__) + cdrom_probe_device +#endif +}; + static QTAILQ_HEAD(, BlockDriverState) graph_bdrv_states =QTAILQ_HEAD_INITIALIZER (graph_bdrv_states);
@@ -95,6 +103,8 @@ static BlockDriverState *bdrv_open_inherit(const char *filename,/* If non-zero, use only whitelisted block drivers */ static int use_bdrv_whitelist; +static BlockDriver *bdrv_do_find_protocol (const char *protocol); +#ifdef _WIN32static int is_windows_drive_prefix (const char *filename) {
@@ -487,25 +497,37 @@ int get_tmp_filename(char *filename, int size)static BlockDriver *find_hdev_driver (const char *filename) {int score_max =0 , score; +const char *protocol_max =NULL ; +const char *protocol; +BlockDriver *drv;size_t i; -BlockDriver *drv =NULL , *d; + +for (i =0 ; i <ARRAY_SIZE (protocol_probes); i++) { + protocol = protocol_probes[i](filename, &score); +if (score > score_max) { + protocol_max = protocol; + score_max = score; + } + } + +if (!protocol_max) { +return NULL ; + } + + drv =bdrv_do_find_protocol (protocol_max); +if (drv) { +return drv; + }for (i =0 ; i <ARRAY_SIZE (block_driver_modules); ++i) { -if (block_driver_modules[i].has_probe_device) { +if (block_driver_modules[i].protocol_name && + !strcmp (block_driver_modules[i].protocol_name, protocol_max)) {block_module_load_one (block_driver_modules[i].library_name); +break ; } } - QLIST_FOREACH(d, &bdrv_drivers, list) { -if (d->bdrv_probe_device) { - score = d->bdrv_probe_device (filename); -if (score > score_max) { - score_max = score; - drv = d; - } - } - } - + drv =bdrv_do_find_protocol (protocol);return drv; }
block/host_cdrom-probe.c +15 -8
@@ -1,22 +1,28 @@#include "qemu/osdep.h" #include "block/probe.h" +static const char *protocol ="host_cdrom" ; +#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) -int cdrom_probe_device (const char *filename) +const char *cdrom_probe_device (const char *filename,int *score) { +assert (score);if (strstart (filename,"/dev/cd" ,NULL ) || -strstart (filename,"/dev/acd" ,NULL )) -return 100 ; +strstart (filename,"/dev/acd" ,NULL )) { + *score =100 ; +return protocol; + }return 0 ; }#elif defined(__linux__)#include <sys/ioctl.h> #include <linux/cdrom.h> -int cdrom_probe_device (const char *filename) +const char *cdrom_probe_device (const char *filename,int *score) {int fd, ret; -int prio =0 ;struct stat st; +assert (score); + *score =0 ; fd =qemu_open (filename,O_RDONLY |O_NONBLOCK );if (fd <0 ) {
@@ -29,12 +35,13 @@ int cdrom_probe_device(const char *filename)/* Attempt to detect via a CDROM specific ioctl */ ret =ioctl (fd,CDROM_DRIVE_STATUS ,CDSL_CURRENT ); -if (ret >=0 ) - prio =100 ; +if (ret >=0 ) { + *score =100 ; + } outc:qemu_close (fd); out: - return prio; + return protocol; }#endif
block/host_device-probe.c +23 -11
@@ -2,29 +2,41 @@#include "block/probe.h" #include "qemu/cutils.h" +static const char *protocol ="host_device" ; +#ifdef _WIN32 -int hdev_probe_device (const char *filename) +const char *hdev_probe_device (const char *filename,int *score) { -if (strstart (filename,"/dev/cdrom" ,NULL )) -return 100 ; -if (is_windows_drive (filename)) -return 100 ; -return 0 ; +assert (score); + *score =100 ; +if (strstart (filename,"/dev/cdrom" ,NULL )) { +return protocol; + } +if (is_windows_drive (filename)) { + return protocol + } + *score =0 ; +return protocol; }#else -int hdev_probe_device (const char *filename) +const char *hdev_probe_device (const char *filename,int *score) {struct stat st; +assert (score);/* allow a dedicated CD-ROM driver to match with a higher priority */ -if (strstart (filename,"/dev/cdrom" ,NULL )) -return 50 ; +if (strstart (filename,"/dev/cdrom" ,NULL )) { + *score =50 ; +return protocol; + }if (stat (filename, &st) >=0 && (S_ISCHR (st.st_mode) ||S_ISBLK (st.st_mode))) { -return 100 ; + *score =100 ; +return protocol; } -return 0 ; + *score =0 ; +return protocol; }#endif
block/raw-posix.c +0 -3
@@ -2367,7 +2367,6 @@ static BlockDriver bdrv_host_device = { .protocol_name = "host_device", .instance_size = sizeof(BDRVRawState), .bdrv_needs_filename = true, - .bdrv_probe_device = hdev_probe_device, .bdrv_parse_filename = hdev_parse_filename, .bdrv_file_open = hdev_open, .bdrv_close = raw_close,
@@ -2466,7 +2465,6 @@ static BlockDriver bdrv_host_cdrom = { .protocol_name = "host_cdrom", .instance_size = sizeof(BDRVRawState), .bdrv_needs_filename = true, - .bdrv_probe_device = cdrom_probe_device, .bdrv_parse_filename = cdrom_parse_filename, .bdrv_file_open = cdrom_open, .bdrv_close = raw_close,
@@ -2592,7 +2590,6 @@ static BlockDriver bdrv_host_cdrom = { .protocol_name = "host_cdrom", .instance_size = sizeof(BDRVRawState), .bdrv_needs_filename = true, - .bdrv_probe_device = cdrom_probe_device, .bdrv_parse_filename = cdrom_parse_filename, .bdrv_file_open = cdrom_open, .bdrv_close = raw_close,
block/raw-win32.c +0 -1
@@ -696,7 +696,6 @@ static BlockDriver bdrv_host_device = { .instance_size = sizeof(BDRVRawState), .bdrv_needs_filename = true, .bdrv_parse_filename = hdev_parse_filename, - .bdrv_probe_device = hdev_probe_device, .bdrv_file_open = hdev_open, .bdrv_close = raw_close,
include/block/block_int.h +0 -2
@@ -99,8 +99,6 @@ struct BlockDriver {bool (*bdrv_recurse_is_first_non_filter)(BlockDriverState *bs,BlockDriverState *candidate); -int (*bdrv_probe_device)(const char *filename); -/* Any driver implementing this callback is expected to be able to handle * NULL file names in its .bdrv_open() implementation */ void (*bdrv_parse_filename)(const char *filename,QDict *options,Error **errp);
include/block/probe.h +2 -2
@@ -27,7 +27,7 @@ const char *bdrv_vmdk_probe(const uint8_t *buf, int buf_size, const char *filename, int *score);const char *bdrv_vpc_probe (const uint8_t *buf,int buf_size,const char *filename,int *score); -int hdev_probe_device (const char *filename); -int cdrom_probe_device (const char *filename); +const char *hdev_probe_device (const char *filename,int *score); +const char *cdrom_probe_device (const char *filename,int *score);#endif
scripts/modules/module_block.py +2 -10
@@ -23,16 +23,13 @@ def get_string_struct(line): return data[2].replace('"', '')[:-1] -def add_module(fheader, library, format_name, protocol_name, - probe_device): +def add_module(fheader, library, format_name, protocol_name): lines = [] lines.append('.library_name = "' + library + '",') if format_name != "": lines.append('.format_name = "' + format_name + '",') if protocol_name != "": lines.append('.protocol_name = "' + protocol_name + '",') - if probe_device: - lines.append('.has_probe_device = true,') text = '\n '.join(lines) fheader.write('\n {\n ' + text + '\n },')
@@ -50,18 +47,14 @@ def process_file(fheader, filename): format_name = get_string_struct(line) elif line.find(".protocol_name") != -1: protocol_name = get_string_struct(line) - elif line.find(".bdrv_probe_device") != -1: - probe_device = True elif line == "};": - add_module(fheader, library, format_name, protocol_name, - probe_device) + add_module(fheader, library, format_name, protocol_name) found_start = False elif line.find("static BlockDriver") != -1: found_something = True found_start = True format_name = "" protocol_name = "" - probe_device = False if not found_something: print("No BlockDriver struct found in " + filename + ". \
@@ -88,7 +81,6 @@ static const struct { const char *format_name; const char *protocol_name; const char *library_name; - bool has_probe_device; } block_driver_modules[] = {''') def print_bottom(fheader):
Signature · 1 line
2.5.5
Quoted 16 lines · Colin Lord
Here's v4 of the modularization series. Things that have changed since v3 include:
- Fix indentation of the generated header file
module_block.h
- Drivers and probe functions are now all located in theblock/directory, rather than being split betweenblock/andblock/probe/. In addition the header files for each probe/driver pair are in theblock/directory, not theinclude/block/driver/directory (which no longer exists).
- Since the probe files are inblock/now, they follow the naming pattern offormat-probe.c
- Renamed crypto probe file to becrypto-probe.c, luks is no longer in the filename
- Fixed formatting ofparallels_probe()function header
- Enforced consistent naming convention for the probe functions. They now follow the patternbdrv_format_probe().
It's still not clear to me why probes need to be separate for drivers that (presumably) will never be modularized.
Paolo
Quoted 105 lines
Colin Lord (30):
blockdev: prepare iSCSI block driver for dynamic loading
blockdev: Move bochs probe into separate file
blockdev: Move cloop probe to its own file
blockdev: Move luks probe to its own file
blockdev: Move dmg probe to its own file
blockdev: Move parallels probe to its own file
blockdev: Move qcow probe to its own file
blockdev: Move qcow2 probe to its own file
blockdev: Move qed probe to its own file
blockdev: Move raw probe to its own file
blockdev: Move vdi probe to its own file
blockdev: Move vhdx probe to its own file
blockdev: Move vmdk probe to its own file
blockdev: Move vpc probe to its own file
blockdev: Separate bochs probe from its driver
blockdev: Separate cloop probe from its driver
blockdev: Separate luks probe from its driver
blockdev: Separate dmg probe from its driver
blockdev: Separate parallels probe from its driver
blockdev: Separate qcow probe from its driver
blockdev: Separate qcow2 probe from its driver
blockdev: Separate qed probe from its driver
blockdev: Separate raw probe from its driver
blockdev: Separate vdi probe from its driver
blockdev: Separate vhdx probe from its driver
blockdev: Separate vmdk probe from its driver
blockdev: Separate vpc probe from its driver
blockdev: Remove the .bdrv_probe field from BlockDrivers
blockdev: Separate outbdrv_probe_devicefunctions
blockdev: Removebdrv_probe_devicefield from BlockDriverMarc Mari (2):
blockdev: Add dynamic generation ofmodule_block.h
blockdev: Add dynamic module loading for block driversMakefile | 7 ++ block.c | 181 ++++++++++++++++++++++++++++++++-------- block/Makefile.objs | 4 + block/bochs-probe.c | 28 +++++++ block/bochs.c | 56 +------------ block/bochs.h | 40 +++++++++ block/cloop-probe.c | 22 +++++ block/cloop.c | 17 +--- block/crypto-probe.c | 26 ++++++ block/crypto.c | 22 +---- block/dmg-probe.c | 22 +++++ block/dmg.c | 17 +--- block/host_cdrom-probe.c | 47 +++++++++++ block/host_device-probe.c | 42 ++++++++++ block/iscsi.c | 36 -------- block/parallels-probe.c | 26 ++++++ block/parallels.c | 44 +--------- block/parallels.h | 26 ++++++ block/qcow-probe.c | 22 +++++ block/qcow.c | 32 +------ block/qcow.h | 21 +++++ block/qcow2-probe.c | 22 +++++ block/qcow2.c | 14 +--- block/qed-probe.c | 24 ++++++ block/qed.c | 16 +--- block/raw-posix.c | 55 +----------- block/raw-probe.c | 14 ++++ block/raw-win32.c | 11 +-- block/raw_bsd.c | 10 +-- block/vdi-probe.c | 29 +++++++ block/vdi.c | 70 +--------------- block/vdi.h | 49 +++++++++++ block/vhdx-probe.c | 27 ++++++ block/vhdx.c | 21 +---- block/vmdk-probe.c | 67 +++++++++++++++ block/vmdk.c | 61 +------------- block/vmdk.h | 7 ++ block/vpc-probe.c | 16 ++++ block/vpc.c | 9 +- include/block/block_int.h | 3 - include/block/probe.h | 33 ++++++++ include/qemu/module.h | 3 + scripts/modules/module_block.py | 108 ++++++++++++++++++++++++ util/module.c | 38 +++------ vl.c | 38 +++++++++ 45 files changed, 948 insertions(+), 535 deletions(-) create mode 100644 block/bochs-probe.c create mode 100644 block/bochs.h create mode 100644 block/cloop-probe.c create mode 100644 block/crypto-probe.c create mode 100644 block/dmg-probe.c create mode 100644 block/host_cdrom-probe.c create mode 100644 block/host_device-probe.c create mode 100644 block/parallels-probe.c create mode 100644 block/parallels.h create mode 100644 block/qcow-probe.c create mode 100644 block/qcow.h create mode 100644 block/qcow2-probe.c create mode 100644 block/qed-probe.c create mode 100644 block/raw-probe.c create mode 100644 block/vdi-probe.c create mode 100644 block/vdi.h create mode 100644 block/vhdx-probe.c create mode 100644 block/vmdk-probe.c create mode 100644 block/vmdk.h create mode 100644 block/vpc-probe.c create mode 100644 include/block/probe.h create mode 100644 scripts/modules/module_block.py
Quoted 20 lines · Paolo Bonzini
Quoted 16 lines · Colin Lord
Here's v4 of the modularization series. Things that have changed since v3 include:
- Fix indentation of the generated header file
module_block.h
- Drivers and probe functions are now all located in theblock/directory, rather than being split betweenblock/andblock/probe/. In addition the header files for each probe/driver pair are in theblock/directory, not theinclude/block/driver/directory (which no longer exists).
- Since the probe files are inblock/now, they follow the naming pattern offormat-probe.c
- Renamed crypto probe file to becrypto-probe.c, luks is no longer in the filename
- Fixed formatting ofparallels_probe()function header
- Enforced consistent naming convention for the probe functions. They now follow the patternbdrv_format_probe().
Quoted 3 lines
It's still not clear to me why probes need to be separate for drivers that (presumably) will never be modularized.
I was hoping someone more experienced with this project would respond to you the last time you asked this, so apologies if it felt like I was ignoring it. I'll tell you what I'm seeing from my perspective though and hopefully that can get some discussion going.
As far as performance benefits go, you are correct that modularizing the drivers that these probes are being separated from will have essentially no effect. At this point it's more of a question of how the project should be organized. I can see why having modules seems like a nice organization of things, but on the other hand it does move code around without accomplishing anything other than a different project structure.
However, the protocol drivers do tend to see noticeable performance benefits. Most of them get modularized in the first three patches of this series. This includes the iscsi, glusterfs, ssh, curl, and rbd drivers. A minimal configuration excluding all of these drivers takes around 3 ms to reach main(), and each of these drivers respectively add times of approximately 0.2, 0.9, 1.2, 2.5, and a massive time of 41.6 ms to the time to main. So some of these aren't even a huge benefit by themselves but they do add up, and also it makes sense to modularize all of the protocol drivers if we're already modularizing one.
As for the format drivers, as I said that's a question of project structure. The dmg driver is in this patch series simply because it was there in Marc's patches and I didn't remove it, and only recently did I realize that it wouldn't actually affect performance. I think the whole deal of probes being separated just fell out from having the dmg driver modularized. There is maybe an argument to be made that if the protocol drivers are getting modularized, the format drivers should as well just for consistency, but at the end of the day it's mostly just personal preferences I think, and I will add to that that although this series only modularizes dmg, if this series goes through I'll be working on modularizing the rest of them as well. Most of them should be trivial to modularize, although there may be a tricky one or two that I'm not aware of yet.
Hopefully this has helped make the situation more clear.
Colin
Quoted 107 lines
Paolo
Quoted 105 lines
Colin Lord (30):
blockdev: prepare iSCSI block driver for dynamic loading
blockdev: Move bochs probe into separate file
blockdev: Move cloop probe to its own file
blockdev: Move luks probe to its own file
blockdev: Move dmg probe to its own file
blockdev: Move parallels probe to its own file
blockdev: Move qcow probe to its own file
blockdev: Move qcow2 probe to its own file
blockdev: Move qed probe to its own file
blockdev: Move raw probe to its own file
blockdev: Move vdi probe to its own file
blockdev: Move vhdx probe to its own file
blockdev: Move vmdk probe to its own file
blockdev: Move vpc probe to its own file
blockdev: Separate bochs probe from its driver
blockdev: Separate cloop probe from its driver
blockdev: Separate luks probe from its driver
blockdev: Separate dmg probe from its driver
blockdev: Separate parallels probe from its driver
blockdev: Separate qcow probe from its driver
blockdev: Separate qcow2 probe from its driver
blockdev: Separate qed probe from its driver
blockdev: Separate raw probe from its driver
blockdev: Separate vdi probe from its driver
blockdev: Separate vhdx probe from its driver
blockdev: Separate vmdk probe from its driver
blockdev: Separate vpc probe from its driver
blockdev: Remove the .bdrv_probe field from BlockDrivers
blockdev: Separate outbdrv_probe_devicefunctions
blockdev: Removebdrv_probe_devicefield from BlockDriverMarc Mari (2):
blockdev: Add dynamic generation ofmodule_block.h
blockdev: Add dynamic module loading for block driversMakefile | 7 ++ block.c | 181 ++++++++++++++++++++++++++++++++-------- block/Makefile.objs | 4 + block/bochs-probe.c | 28 +++++++ block/bochs.c | 56 +------------ block/bochs.h | 40 +++++++++ block/cloop-probe.c | 22 +++++ block/cloop.c | 17 +--- block/crypto-probe.c | 26 ++++++ block/crypto.c | 22 +---- block/dmg-probe.c | 22 +++++ block/dmg.c | 17 +--- block/host_cdrom-probe.c | 47 +++++++++++ block/host_device-probe.c | 42 ++++++++++ block/iscsi.c | 36 -------- block/parallels-probe.c | 26 ++++++ block/parallels.c | 44 +--------- block/parallels.h | 26 ++++++ block/qcow-probe.c | 22 +++++ block/qcow.c | 32 +------ block/qcow.h | 21 +++++ block/qcow2-probe.c | 22 +++++ block/qcow2.c | 14 +--- block/qed-probe.c | 24 ++++++ block/qed.c | 16 +--- block/raw-posix.c | 55 +----------- block/raw-probe.c | 14 ++++ block/raw-win32.c | 11 +-- block/raw_bsd.c | 10 +-- block/vdi-probe.c | 29 +++++++ block/vdi.c | 70 +--------------- block/vdi.h | 49 +++++++++++ block/vhdx-probe.c | 27 ++++++ block/vhdx.c | 21 +---- block/vmdk-probe.c | 67 +++++++++++++++ block/vmdk.c | 61 +------------- block/vmdk.h | 7 ++ block/vpc-probe.c | 16 ++++ block/vpc.c | 9 +- include/block/block_int.h | 3 - include/block/probe.h | 33 ++++++++ include/qemu/module.h | 3 + scripts/modules/module_block.py | 108 ++++++++++++++++++++++++ util/module.c | 38 +++------ vl.c | 38 +++++++++ 45 files changed, 948 insertions(+), 535 deletions(-) create mode 100644 block/bochs-probe.c create mode 100644 block/bochs.h create mode 100644 block/cloop-probe.c create mode 100644 block/crypto-probe.c create mode 100644 block/dmg-probe.c create mode 100644 block/host_cdrom-probe.c create mode 100644 block/host_device-probe.c create mode 100644 block/parallels-probe.c create mode 100644 block/parallels.h create mode 100644 block/qcow-probe.c create mode 100644 block/qcow.h create mode 100644 block/qcow2-probe.c create mode 100644 block/qed-probe.c create mode 100644 block/raw-probe.c create mode 100644 block/vdi-probe.c create mode 100644 block/vdi.h create mode 100644 block/vhdx-probe.c create mode 100644 block/vmdk-probe.c create mode 100644 block/vmdk.h create mode 100644 block/vpc-probe.c create mode 100644 include/block/probe.h create mode 100644 scripts/modules/module_block.py
Quoted 4 lines · Colin Lord
However, the protocol drivers do tend to see noticeable performance benefits. Most of them get modularized in the first three patches of this series. This includes the iscsi, glusterfs, ssh, curl, and rbd drivers.
Indeed, but... protocol drivers don't have probes, do they? There is a distinction between "formats" and "protocols", and only formats need to be probed for.
Quoted 6 lines
A minimal configuration excluding all of these drivers takes around 3 ms to reach
main(), and each of these drivers respectively add times of approximately 0.2, 0.9, 1.2, 2.5, and a massive time of 41.6 ms to the time to main. So some of these aren't even a huge benefit by themselves but they do add up, and also it makes sense to modularize all of the protocol drivers if we're already modularizing one.
All this I entirely agree with.
Paolo
Quoted 11 lines · Paolo Bonzini
Quoted 4 lines · Colin Lord
However, the protocol drivers do tend to see noticeable performance benefits. Most of them get modularized in the first three patches of this series. This includes the iscsi, glusterfs, ssh, curl, and rbd drivers.
Indeed, but... protocol drivers don't have probes, do they? There is a distinction between "formats" and "protocols", and only formats need to be probed for.
IOW, if we only modularized the protocol drivers, then there's no reason to split out the probe code to separate files, so we avoid a whole lot of code churn, and keep all the format drivers largely self contained as today which would be nice.
Regards,
Daniel
Signature · 4 lines
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
Quoted 20 lines · Paolo Bonzini
Quoted 16 lines · Colin Lord
Here's v4 of the modularization series. Things that have changed since v3 include:
- Fix indentation of the generated header file
module_block.h
- Drivers and probe functions are now all located in theblock/directory, rather than being split betweenblock/andblock/probe/. In addition the header files for each probe/driver pair are in theblock/directory, not theinclude/block/driver/directory (which no longer exists).
- Since the probe files are inblock/now, they follow the naming pattern offormat-probe.c
- Renamed crypto probe file to becrypto-probe.c, luks is no longer in the filename
- Fixed formatting ofparallels_probe()function header
- Enforced consistent naming convention for the probe functions. They now follow the patternbdrv_format_probe().
Quoted 2 lines
It's still not clear to me why probes need to be separate for drivers that (presumably) will never be modularized.
For completeness' sake, my stance on the issue can be summarized as "Why not?".
The patches exist, so "Someone would need to do it" is not an argument anymore.
Daniel said the separation of the probing functions introduced by this series would break the block drivers' "self-containedness", but I'm not sure all block drivers are contained in a single file, if that is what he meant by it. qcow2 and vhdx aren't, and I never had any problem with that.
Maybe he was referring to the file placement discussion we had some weeks ago. Obviously we didn't end up with a unanimous consensus, so intuitively I'd say sidestepping this issue would be worth something. But it really isn't. In my very personal opinion, letting dissent over coding style get in the way of a functional issue is not really something we should do.
Also, I think it's actually debatable whether the probing function belongs to a block driver. One could argue that all the probing functions in theory belong to a virtual block driver that we haven't given a name to yet, but that is selected by not specifying any driver. That virtual driver then does nothing but replace itself by the probed one.
As far as I'm aware, we've always planned to give that virtual block driver a name (such as "probe-format") in the future.
From that point of view, one could argue that pulling out the probe functions from the block drivers is actually the right thing to do, independently of modularization, because the probing functions are actually not part of the drivers themselves.
So I can't see a strong argument for not modularizing the format block drivers, but in turn I don't have a strong argument for doing so either.
Therefore: Why not? :-)
Max
Quoted 5 lines · Max Reitz
So I can't see a strong argument for not modularizing the format block drivers, but in turn I don't have a strong argument for doing so either.
Therefore: Why not? :-)
The usual argument is that there is an additional cost in maintainability. This applies particularly in this case where you wouldn't have to care at all about dynamically loading a driver based on the outcome of a probe---only based on the driver name or a colon-separated prefix in the filename.
Thanks,
Paolo
Quoted 7 lines · Paolo Bonzini
Quoted 4 lines · Max Reitz
So I can't see a strong argument for not modularizing the format block drivers, but in turn I don't have a strong argument for doing so either.
Quoted 7 lines
Quoted 1 line
Therefore: Why not? :-)
The usual argument is that there is an additional cost in maintainability. This applies particularly in this case where you wouldn't have to care at all about dynamically loading a driver based on the outcome of a probe---only based on the driver name or a colon-separated prefix in the filename.
That's a good point, especially since it's likely only a few people will use modularized format block drivers, so we may break it without noticing.
Max