Replace some unwise uses of error_report() & friends
Subsystems (4)
PATCH 9/31 ioapic: Fix error handling in realize()
In reply to Markus ArmbrusterCalling error_report() in a function that takes an Error ** argument is suspicious. ioapic_realize() does that, and then exit()s. Currently mostly harmless, as the device cannot be hot-plugged.
--- hw/intc/ioapic.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
hw/intc/ioapic.c +4 -4
@@ -21,7 +21,7 @@*/ #include "qemu/osdep.h" -#include "qemu/error-report.h" +#include "qapi/error.h" #include "monitor/monitor.h" #include "hw/hw.h" #include "hw/i386/pc.h"
@@ -393,9 +393,9 @@ static void ioapic_realize(DeviceState *dev, Error **errp)IOAPICCommonState *s =IOAPIC_COMMON (dev);if (s->version !=0x11 && s->version !=0x20 ) { -error_report ("IOAPIC only supports version 0x11 or 0x20 " -"(default: 0x%x)." ,IOAPIC_VER_DEF ); -exit (1 ); +error_setg (errp,"IOAPIC only supports version 0x11 or 0x20 " +"(default: 0x%x)." ,IOAPIC_VER_DEF ); +return ; } memory_region_init_io(&s->io_memory, OBJECT(s), &ioapic_io_ops, s,
Signature · 1 line
2.17.1
PATCH 11/31 migration: Fix !replay_can_snapshot() error handling
In reply to Markus ArmbrusterCalling error_report() in a function that takes an Error ** argument is suspicious. save_snapshot() and load_snapshot() do that, and then fail without setting an error. Wrong. The HMP commands survive this unscathed, since hmp_handle_error() does nothing when no error has been set. Callers main() (on behalf of -loadvm) and replay_vmstate_init() crash, but I'm not sure the error is possible there.
Screwed up when commit 377b21ccea1 (v2.12.0) added incorrect error handling right next to correct examples. Fix by calling error_setg() instead of error_report().
--- migration/savevm.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
migration/savevm.c +4 -4
@@ -2414,8 +2414,8 @@ int save_snapshot(const char *name, Error **errp)AioContext *aio_context;if (!replay_can_snapshot ()) { -error_report ("Record/replay does not allow making snapshot " -"right now. Try once more later." ); +error_setg (errp,"Record/replay does not allow making snapshot " +"right now. Try once more later." );return ret; }
@@ -2611,8 +2611,8 @@ int load_snapshot(const char *name, Error **errp)MigrationIncomingState *mis =migration_incoming_get_current ();if (!replay_can_snapshot ()) { -error_report ("Record/replay does not allow loading snapshot " -"right now. Try once more later." ); +error_setg (errp,"Record/replay does not allow loading snapshot " +"right now. Try once more later." );return -EINVAL ; }
Signature · 1 line
2.17.1
PATCH 23/31 vl: Clean up error reporting in device_init_func()
In reply to Markus ArmbrusterCalling error_report() in a function that takes an Error ** argument is suspicious. device_init_func() does that, and then fails without setting an error. Its caller main(), via qemu_opts_foreach(), is fine with it, but clean it up anyway.
--- vl.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
vl.c +3 -7
@@ -2222,12 +2222,10 @@ static int device_help_func(void *opaque, QemuOpts *opts, Error **errp)static int device_init_func (void *opaque,QemuOpts *opts,Error **errp) { -Error *err =NULL ;DeviceState *dev; - dev =qdev_device_add (opts, &err); + dev =qdev_device_add (opts, errp);if (!dev) { -error_report_err (err);return -1 ; }object_unref (OBJECT (dev));
@@ -4444,10 +4442,8 @@ int main(int argc, char **argv, char **envp)/* init generic devices */ rom_set_order_override (FW_CFG_ORDER_OVERRIDE_DEVICE ); -if (qemu_opts_foreach (qemu_find_opts ("device" ), - device_init_func,NULL ,NULL )) { -exit (1 ); - } +qemu_opts_foreach (qemu_find_opts ("device" ), + device_init_func,NULL , &error_fatal);cpu_synchronize_all_post_init ();
Signature · 1 line
2.17.1
PATCH 24/31 vl: Clean up error reporting in vnc_init_func()
In reply to Markus ArmbrusterCalling error_report() in a function that takes an Error ** argument is suspicious. vnc_init_func() does that, and then fails without setting an error. Its caller main(), via qemu_opts_foreach(), is fine with it, but clean it up anyway.
--- ui/vnc.c | 5 +++-- vl.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-)
ui/vnc.c +3 -2
@@ -4082,8 +4082,9 @@ int vnc_init_func(void *opaque, QemuOpts *opts, Error **errp)vnc_display_init (id);vnc_display_open (id, &local_err);if (local_err !=NULL ) { -error_reportf_err (local_err,"Failed to start VNC server: " ); -exit (1 ); +error_propagate (errp, local_err); +error_prepend (errp,"Failed to start VNC server: " ); +return -1 ; }return 0 ; }
vl.c +1 -1
@@ -4479,7 +4479,7 @@ int main(int argc, char **argv, char **envp)/* init remote displays */ #ifdef CONFIG_VNC qemu_opts_foreach (qemu_find_opts ("vnc" ), - vnc_init_func,NULL ,NULL ); + vnc_init_func,NULL , &error_fatal);#endif if (using_spice) {
Signature · 1 line
2.17.1
PATCH 26/31 tpm: Clean up error reporting in tpm_init_tpmdev()
In reply to Markus ArmbrusterCalling error_report() in a function that takes an Error ** argument is suspicious. tpm_init_tpmdev() does that, and then fails without setting an error. Its caller main(), via tpm_init() and qemu_opts_foreach(), is fine with it, but clean it up anyway.
--- include/sysemu/tpm.h | 2 +- stubs/tpm.c | 3 +-- tpm.c | 22 +++++++++------------- vl.c | 4 +--- 4 files changed, 12 insertions(+), 19 deletions(-)
include/sysemu/tpm.h +1 -1
@@ -16,7 +16,7 @@#include "qom/object.h" int tpm_config_parse (QemuOptsList *opts_list,const char *optarg); -int tpm_init (void ); +void tpm_init (void );void tpm_cleanup (void ); typedef enum TPMVersion {
stubs/tpm.c +1 -2
@@ -9,9 +9,8 @@#include "qapi/qapi-commands-tpm.h" #include "sysemu/tpm.h" -int tpm_init (void ) +void tpm_init (void ) { -return 0 ; }void tpm_cleanup (void )
tpm.c +9 -13
@@ -89,19 +89,19 @@ static int tpm_init_tpmdev(void *dummy, QemuOpts *opts, Error **errp)int i;if (!QLIST_EMPTY (&tpm_backends)) { -error_report ("Only one TPM is allowed." ); +error_setg (errp,"Only one TPM is allowed." );return 1 ; } id =qemu_opts_id (opts);if (id ==NULL ) { -error_report (QERR_MISSING_PARAMETER ,"id" ); +error_setg (errp,QERR_MISSING_PARAMETER ,"id" );return 1 ; } value =qemu_opt_get (opts,"type" );if (!value) { -error_report (QERR_MISSING_PARAMETER ,"type" ); +error_setg (errp,QERR_MISSING_PARAMETER ,"type" );tpm_display_backend_drivers ();return 1 ; }
@@ -109,8 +109,8 @@ static int tpm_init_tpmdev(void *dummy, QemuOpts *opts, Error **errp) i =qapi_enum_parse (&TpmType_lookup, value,-1 ,NULL ); be = i >=0 ?tpm_be_find_by_type (i) :NULL ;if (be ==NULL ) { -error_report (QERR_INVALID_PARAMETER_VALUE , -"type" ,"a TPM backend type" ); +error_setg (errp,QERR_INVALID_PARAMETER_VALUE ,"type" , +"a TPM backend type" );tpm_display_backend_drivers ();return 1 ; }
@@ -118,7 +118,7 @@ static int tpm_init_tpmdev(void *dummy, QemuOpts *opts, Error **errp)/* validate backend specific opts */ qemu_opts_validate (opts, be->opts, &local_err);if (local_err) { -error_report_err (local_err); +error_propagate (errp, local_err);return 1 ; }
@@ -151,14 +151,10 @@ void tpm_cleanup(void)* Initialize the TPM. Process the tpmdev command line options describing the * TPM backend. */ -int tpm_init (void ) +void tpm_init (void ) { -if (qemu_opts_foreach (qemu_find_opts ("tpmdev" ), - tpm_init_tpmdev,NULL ,NULL )) { -return -1 ; - } - -return 0 ; +qemu_opts_foreach (qemu_find_opts ("tpmdev" ), + tpm_init_tpmdev,NULL , &error_fatal); }/*
vl.c +1 -3
@@ -4312,9 +4312,7 @@ int main(int argc, char **argv, char **envp) user_creatable_add_opts_foreach, object_create_delayed, &error_fatal); -if (tpm_init () <0 ) { -exit (1 ); - } +tpm_init ();/* init the bluetooth world */ if (foreach_device_config (DEV_BT , bt_parse))
Signature · 1 line
2.17.1
cover Replace some unwise uses of error_report() & friends
Calling error_report() or similar in a function that takes an Error ** argument is suspicious. Fux a number of instances that are actually wrong. Clean up a few more that are merely fragile / bad examples.
Markus Armbruster (31):
Use error_fatal to simplify obvious fatal errors (again)
block: Use warn_report() & friends to report warnings cpus hw target: Use warn_report() & friends to report warnings
vfio: Use warn_report() & friends to report warnings
vfio: Clean up error reporting after previous commit
char: Use error_printf() to print help and such
9pfs: Fix CLI parsing crash on error
pc: Fix machine property nvdimm-persistence error handling
ioapic: Fix error handling in realize()
smbios: Clean up error handling in smbios_add()
migration: Fix !replay_can_snapshot() error handling
l2tpv3: Improve -netdev/netdev_add/-net/... error reporting net/socket: Fix invalid socket type error handling
numa: Fix QMP command set-numa-node error handling xen/pt: Fix incomplete conversion to realize()
seccomp: Clean up error reporting in parse_sandbox()
vl: Clean up error reporting in parse_add_fd()
qom: Clean up error reporting in user_creatable_add_opts_foreach()
vl: Clean up error reporting in parse_add_fd()
vl: Clean up error reporting in machine_set_property()
vl: Clean up error reporting in mon_init_func()
vl: Clean up error reporting in parse_fw_cfg()
vl: Clean up error reporting in device_init_func()
vl: Clean up error reporting in vnc_init_func()
numa: Clean up error reporting in parse_numa()
tpm: Clean up error reporting in tpm_init_tpmdev()
spice: Clean up error reporting in add_channel()
fsdev: Clean up error reporting in qemu_fsdev_add()
vl: Assert drive_new() does not fail in default_drive()
blockdev: Convert drive_new() to Error
vl: Simplify call of parse_name()
block/bochs.c | 8 +- block/cloop.c | 8 +- block/dmg.c | 8 +- block/iscsi.c | 2 +- block/rbd.c | 12 +- block/sheepdog.c | 2 +- block/vvfat.c | 8 +- blockdev.c | 27 ++--- chardev/char-pty.c | 2 +- chardev/char.c | 2 +- cpus.c | 8 +- device-hotplug.c | 5 +- fsdev/qemu-fsdev-dummy.c | 2 +- fsdev/qemu-fsdev.c | 12 +- fsdev/qemu-fsdev.h | 2 +- hw/9pfs/9p-handle.c | 6 +- hw/9pfs/xen-9p-backend.c | 7 +- hw/display/cg3.c | 2 +- hw/display/tcx.c | 2 +- hw/i386/pc.c | 5 +- hw/intc/ioapic.c | 8 +- hw/intc/xics_kvm.c | 7 +- hw/misc/ivshmem.c | 4 +- hw/net/virtio-net.c | 8 +- hw/smbios/smbios.c | 90 ++++++++++----- hw/vfio/pci-quirks.c | 4 +- hw/vfio/pci.c | 22 ++-- hw/vfio/platform.c | 6 +- hw/virtio/virtio-pci.c | 4 +- hw/xen/xen_pt.c | 2 +- include/hw/vfio/vfio-common.h | 3 +- include/sysemu/blockdev.h | 3 +- include/sysemu/numa.h | 1 - include/sysemu/tpm.h | 2 +- migration/savevm.c | 8 +- net/l2tpv3.c | 26 ++--- net/socket.c | 4 +- numa.c | 21 ++-- qemu-io.c | 8 +- qemu-nbd.c | 14 +-- qemu-seccomp.c | 18 +-- qom/object_interfaces.c | 4 +- scripts/coccinelle/use-error_fatal.cocci | 20 ++++ stubs/tpm.c | 3 +- target/i386/cpu.c | 17 +-- target/ppc/translate_init.inc.c | 4 +- tpm.c | 22 ++-- ui/spice-core.c | 13 ++- ui/vnc.c | 5 +- vl.c | 140 +++++++++-------------- 50 files changed, 317 insertions(+), 304 deletions(-) create mode 100644 scripts/coccinelle/use-error_fatal.cocci
Signature · 1 line
2.17.1
PATCH 18/31 qom: Clean up error reporting in user_creatable_add_opts_foreach()
Calling error_report() in a function that takes an Error ** argument is suspicious. user_creatable_add_opts_foreach() does that, and then fails without setting an error. Its caller main(), via qemu_opts_foreach(), is fine with it, but clean it up anyway.
--- qemu-io.c | 8 +++----- qemu-nbd.c | 8 +++----- qom/object_interfaces.c | 4 +--- vl.c | 16 ++++++---------- 4 files changed, 13 insertions(+), 23 deletions(-)
qemu-io.c +3 -5
@@ -620,11 +620,9 @@ int main(int argc, char **argv)exit (1 ); } -if (qemu_opts_foreach (&qemu_object_opts, - user_creatable_add_opts_foreach, -NULL ,NULL )) { -exit (1 ); - } +qemu_opts_foreach (&qemu_object_opts, + user_creatable_add_opts_foreach, +NULL , &error_fatal);if (!trace_init_backends ()) {exit (1 );
qemu-nbd.c +3 -5
@@ -766,11 +766,9 @@ int main(int argc, char **argv)exit (EXIT_FAILURE ); } -if (qemu_opts_foreach (&qemu_object_opts, - user_creatable_add_opts_foreach, -NULL ,NULL )) { -exit (EXIT_FAILURE ); - } +qemu_opts_foreach (&qemu_object_opts, + user_creatable_add_opts_foreach, +NULL , &error_fatal);if (!trace_init_backends ()) {exit (1 );
qom/object_interfaces.c +1 -3
@@ -143,7 +143,6 @@ int user_creatable_add_opts_foreach(void *opaque, QemuOpts *opts, Error **errp) {bool (*type_predicate)(const char *) = opaque;Object *obj =NULL ; -Error *err =NULL ;const char *type; type =qemu_opt_get (opts,"qom-type" );
@@ -152,9 +151,8 @@ int user_creatable_add_opts_foreach(void *opaque, QemuOpts *opts, Error **errp)return 0 ; } - obj =user_creatable_add_opts (opts, &err); + obj =user_creatable_add_opts (opts, errp);if (!obj) { -error_report_err (err);return -1 ; }object_unref (obj);
vl.c +6 -10
@@ -4181,11 +4181,9 @@ int main(int argc, char **argv, char **envp)page_size_init ();socket_init (); -if (qemu_opts_foreach (qemu_find_opts ("object" ), - user_creatable_add_opts_foreach, - object_create_initial,NULL )) { -exit (1 ); - } +qemu_opts_foreach (qemu_find_opts ("object" ), + user_creatable_add_opts_foreach, + object_create_initial, &error_fatal);if (qemu_opts_foreach (qemu_find_opts ("chardev" ), chardev_init_func,NULL ,NULL )) {
@@ -4316,11 +4314,9 @@ int main(int argc, char **argv, char **envp)exit (1 ); } -if (qemu_opts_foreach (qemu_find_opts ("object" ), - user_creatable_add_opts_foreach, - object_create_delayed,NULL )) { -exit (1 ); - } +qemu_opts_foreach (qemu_find_opts ("object" ), + user_creatable_add_opts_foreach, + object_create_delayed, &error_fatal);if (tpm_init () <0 ) {exit (1 );
Signature · 1 line
2.17.1
PATCH 21/31 vl: Clean up error reporting in mon_init_func()
In reply to Markus ArmbrusterCalling error_report() in a function that takes an Error ** argument is suspicious. mon_init_func() does that, and then fails without setting an error. Its caller main(), via qemu_opts_foreach(), is fine with it, but clean it up anyway.
--- vl.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
vl.c +6 -8
@@ -2270,8 +2270,8 @@ static int mon_init_func(void *opaque, QemuOpts *opts, Error **errp) }else if (strcmp (mode,"control" ) ==0 ) { flags =MONITOR_USE_CONTROL ; }else { -error_report ("unknown monitor mode \"%s\"" , mode); -exit (1 ); +error_setg (errp,"unknown monitor mode \"%s\"" , mode); +return -1 ; }if (qemu_opt_get_bool (opts,"pretty" ,0 ))
@@ -2285,8 +2285,8 @@ static int mon_init_func(void *opaque, QemuOpts *opts, Error **errp) chardev =qemu_opt_get (opts,"chardev" ); chr =qemu_chr_find (chardev);if (chr ==NULL ) { -error_report ("chardev \"%s\" not found" , chardev); -exit (1 ); +error_setg (errp,"chardev \"%s\" not found" , chardev); +return -1 ; }monitor_init (chr, flags);
@@ -4365,10 +4365,8 @@ int main(int argc, char **argv, char **envp)default_drive (default_floppy, snapshot,IF_FLOPPY ,0 ,FD_OPTS );default_drive (default_sdcard, snapshot,IF_SD ,0 ,SD_OPTS ); -if (qemu_opts_foreach (qemu_find_opts ("mon" ), - mon_init_func,NULL ,NULL )) { -exit (1 ); - } +qemu_opts_foreach (qemu_find_opts ("mon" ), + mon_init_func,NULL , &error_fatal);if (foreach_device_config (DEV_SERIAL , serial_parse) <0 )exit (1 );
Signature · 1 line
2.17.1
PATCH 29/31 vl: Assert drive_new() does not fail in default_drive()
In reply to Markus ArmbrusterIf creating (empty) default drives fails, it's a bug. Therefore, assert() is more appropriate than exit(1).
--- vl.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
vl.c +1 -3
@@ -1156,9 +1156,7 @@ static void default_drive(int enable, int snapshot, BlockInterfaceType type, } dinfo =drive_new (opts, type); -if (!dinfo) { -exit (1 ); - } +assert (dinfo); dinfo->is_default = true; }
Signature · 1 line
2.17.1
PATCH 8/31 pc: Fix machine property nvdimm-persistence error handling
In reply to Markus ArmbrusterCalling error_report() in a function that takes an Error ** argument is suspicious. pc.c's pc_machine_set_nvdimm_persistence() does that, and then exit()s. Wrong. Attempting to set machine property nvdimm-persistence to a bad value instantly kills the VM:
$ qemu-system-x86_64 -nodefaults -S -display none -qmp stdio
{"QMP": {"version": {"qemu": {"micro": 50, "minor": 0, "major": 3}, "package": "v3.0.0-837-gc5e4e49258"}, "capabilities": []}}
{"execute": "qmp_capabilities"}
{"return": {}}
{"execute": "qom-set", "arguments": {"path": "/machine", "property": "nvdimm-persistence", "value": "instadeath"}}
-machine nvdimm-persistence=instadeath: unsupported option
$ echo $?
1Broken when commit 11c39b5cd96 (v3.0.0) replaced error_propagate(); return by error_report(); exit() instead of error_setg(); return. Fix that.
--- hw/i386/pc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
hw/i386/pc.c +3 -2
@@ -2209,8 +2209,9 @@ static void pc_machine_set_nvdimm_persistence(Object *obj, const char *value,else if (strcmp (value,"mem-ctrl" ) ==0 ) nvdimm_state->persistence =2 ;else { -error_report ("-machine nvdimm-persistence=%s: unsupported option" , value); -exit (EXIT_FAILURE ); +error_setg (errp,"-machine nvdimm-persistence=%s: unsupported option" , + value); +return ; }g_free (nvdimm_state->persistence_string);
Signature · 1 line
2.17.1
PATCH 3/31 cpus hw target: Use warn_report() & friends to report warnings
In reply to Markus ArmbrusterCalling error_report() in a function that takes an Error ** argument is suspicious. Convert a few that are actually warnings to warn_report().
While there, split a warning consisting of multiple sentences to conform to conventions spelled out in warn_report()'s contract.
--- cpus.c | 8 ++++---- hw/display/cg3.c | 2 +- hw/display/tcx.c | 2 +- hw/misc/ivshmem.c | 4 ++-- hw/net/virtio-net.c | 8 ++++---- hw/virtio/virtio-pci.c | 4 ++-- target/i386/cpu.c | 17 +++++++++-------- target/ppc/translate_init.inc.c | 4 ++-- 8 files changed, 25 insertions(+), 24 deletions(-)
cpus.c +4 -4
@@ -211,12 +211,12 @@ void qemu_tcg_configure(QemuOpts *opts, Error **errp)error_setg (errp,"No MTTCG when icount is enabled" ); }else {#ifndef TARGET_SUPPORTS_MTTCG -error_report ("Guest not yet converted to MTTCG - " -"you may get unexpected results" ); +warn_report ("Guest not yet converted to MTTCG - " +"you may get unexpected results" );#endif if (!check_tcg_memory_orders_compatible ()) { -error_report ("Guest expects a stronger memory ordering " -"than the host provides" ); +warn_report ("Guest expects a stronger memory ordering " +"than the host provides" );error_printf ("This may cause strange/hard to debug errors\n" ); } mttcg_enabled = true;
hw/display/cg3.c +1 -1
@@ -307,7 +307,7 @@ static void cg3_realizefn(DeviceState *dev, Error **errp) ret =load_image_mr (fcode_filename, &s->rom);g_free (fcode_filename);if (ret <0 || ret >FCODE_MAX_ROM_SIZE ) { -error_report ("cg3: could not load prom '%s'" ,CG3_ROM_FILE ); +warn_report ("cg3: could not load prom '%s'" ,CG3_ROM_FILE ); } }
hw/display/tcx.c +1 -1
@@ -823,7 +823,7 @@ static void tcx_realizefn(DeviceState *dev, Error **errp) ret =load_image_mr (fcode_filename, &s->rom);g_free (fcode_filename);if (ret <0 || ret >FCODE_MAX_ROM_SIZE ) { -error_report ("tcx: could not load prom '%s'" ,TCX_ROM_FILE ); +warn_report ("tcx: could not load prom '%s'" ,TCX_ROM_FILE ); } }
hw/misc/ivshmem.c +2 -2
@@ -1292,8 +1292,8 @@ static void ivshmem_realize(PCIDevice *dev, Error **errp)IVShmemState *s =IVSHMEM_COMMON (dev);if (!qtest_enabled ()) { -error_report ("ivshmem is deprecated, please use ivshmem-plain" -" or ivshmem-doorbell instead" ); +warn_report ("ivshmem is deprecated, please use ivshmem-plain" +" or ivshmem-doorbell instead" ); }if (qemu_chr_fe_backend_connected (&s->server_chr) + !!s->shmobj !=1 ) {
hw/net/virtio-net.c +4 -4
@@ -2020,10 +2020,10 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp)if (n->net_conf.tx &&strcmp (n->net_conf.tx,"timer" ) &&strcmp (n->net_conf.tx,"bh" )) { -error_report ("virtio-net: " -"Unknown option tx=%s, valid options: \"timer\" \"bh\"" , - n->net_conf.tx); -error_report ("Defaulting to \"bh\"" ); +warn_report ("virtio-net: " +"Unknown option tx=%s, valid options: \"timer\" \"bh\"" , + n->net_conf.tx); +error_printf ("Defaulting to \"bh\"" ); } n->net_conf.tx_queue_size = MIN(virtio_net_max_tx_queue_size(n),
hw/virtio/virtio-pci.c +2 -2
@@ -1683,8 +1683,8 @@ static void virtio_pci_device_plugged(DeviceState *d, Error **errp)if (err) {/* Notice when a system that supports MSIx can't initialize it */ if (err != -ENOTSUP ) { -error_report ("unable to init msix vectors to %" PRIu32, - proxy->nvectors); +warn_report ("unable to init msix vectors to %" PRIu32, + proxy->nvectors); } proxy->nvectors =0 ; }
target/i386/cpu.c +9 -8
@@ -5123,14 +5123,15 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)* NOTE: the following code has to follow qemu_init_vcpu(). Otherwise * cs->nr_threads hasn't be populated yet and the checking is incorrect. */ -if (IS_AMD_CPU (env) && - !(env->features[FEAT_8000_0001_ECX ] &CPUID_EXT3_TOPOEXT ) && - cs->nr_threads >1 && !ht_warned) { -error_report ("This family of AMD CPU doesn't support " -"hyperthreading(%d). Please configure -smp " -"options properly or try enabling topoext feature." , - cs->nr_threads); - ht_warned = true; +if (IS_AMD_CPU (env) && + !(env->features[FEAT_8000_0001_ECX ] &CPUID_EXT3_TOPOEXT ) && + cs->nr_threads >1 && !ht_warned) { +warn_report ("This family of AMD CPU doesn't support " +"hyperthreading(%d)" , + cs->nr_threads); +error_printf ("Please configure -smp options properly" +" or try enabling topoext feature.\n" ); + ht_warned = true; }x86_cpu_apic_realize (cpu, &local_err);
target/ppc/translate_init.inc.c +2 -2
@@ -8381,8 +8381,8 @@ static void getset_compat_deprecated(Object *obj, Visitor *v, const char *name,QNull *null =NULL ;if (!qtest_enabled ()) { -error_report ("CPU 'compat' property is deprecated and has no effect; " -"use max-cpu-compat machine property instead" ); +warn_report ("CPU 'compat' property is deprecated and has no effect; " +"use max-cpu-compat machine property instead" ); }visit_type_null (v, name, &null,NULL );qobject_unref (null);
Signature · 1 line
2.17.1
PATCH 1/31 Use error_fatal to simplify obvious fatal errors (again)
In reply to Markus ArmbrusterAdd a slight improvement of the Coccinelle semantic patch from commit 07d04a0219b, and use it to clean up. It leaves dead Error * variables behind, cleaned up manually.
--- hw/intc/xics_kvm.c | 7 +------ qemu-nbd.c | 6 +----- scripts/coccinelle/use-error_fatal.cocci | 20 ++++++++++++++++++++ vl.c | 7 +------ 4 files changed, 23 insertions(+), 17 deletions(-) create mode 100644 scripts/coccinelle/use-error_fatal.cocci
hw/intc/xics_kvm.c +1 -6
@@ -198,17 +198,12 @@ static void ics_get_kvm_state(ICSState *ics) {uint64_t state;int i; -Error *local_err =NULL ;for (i =0 ; i < ics->nr_irqs; i++) {ICSIRQState *irq = &ics->irqs[i];kvm_device_access (kernel_xics_fd,KVM_DEV_XICS_GRP_SOURCES , - i + ics->offset, &state, false, &local_err); -if (local_err) { -error_report_err (local_err); -exit (1 ); - } + i + ics->offset, &state, false, &error_fatal); irq->server = state &KVM_XICS_DESTINATION_MASK ; irq->saved_priority = (state >>KVM_XICS_PRIORITY_SHIFT )
qemu-nbd.c +1 -5
@@ -1002,11 +1002,7 @@ int main(int argc, char **argv) } exp =nbd_export_new (bs, dev_offset, fd_size, nbdflags, nbd_export_closed, - writethrough,NULL , &local_err); -if (!exp) { -error_report_err (local_err); -exit (EXIT_FAILURE ); - } + writethrough,NULL , &error_fatal);nbd_export_set_name (exp, export_name);nbd_export_set_description (exp, export_description);
scripts/coccinelle/use-error_fatal.cocci new file +20 -0
@@ -0,0 +1,20 @@ +@@ +type T; +identifier FUN, RET; +expression list ARGS; +expression ERR, EC, FAIL; +@@ +( +- T RET = FUN(ARGS, &ERR); ++ T RET = FUN(ARGS, &error_fatal); +| +- RET = FUN(ARGS, &ERR); ++ RET = FUN(ARGS, &error_fatal); +| +- FUN(ARGS, &ERR); ++ FUN(ARGS, &error_fatal); +) +- if (FAIL) { +- error_report_err(ERR); +- exit(EC); +- }
vl.c +1 -6
@@ -2002,15 +2002,10 @@ static void select_vgahw(const char *p)static void parse_display_qapi (const char *optarg) { -Error *err =NULL ;DisplayOptions *opts;Visitor *v; - v =qobject_input_visitor_new_str (optarg,"type" , &err); -if (!v) { -error_report_err (err); -exit (1 ); - } + v =qobject_input_visitor_new_str (optarg,"type" , &error_fatal);visit_type_DisplayOptions (v,NULL , &opts, &error_fatal);QAPI_CLONE_MEMBERS (DisplayOptions, &dpy, opts);
Signature · 1 line
2.17.1
PATCH 2/31 block: Use warn_report() & friends to report warnings
In reply to Markus ArmbrusterCalling error_report() in a function that takes an Error ** argument is suspicious. Convert a few that are actually warnings to warn_report().
While there, split warnings consisting of multiple sentences to conform to conventions spelled out in warn_report()'s contract, and improve a rather useless warning in sheepdog.c.
--- block/bochs.c | 8 ++++---- block/cloop.c | 8 ++++---- block/dmg.c | 8 ++++---- block/iscsi.c | 2 +- block/rbd.c | 12 ++++++------ block/sheepdog.c | 2 +- block/vvfat.c | 8 ++++---- 7 files changed, 24 insertions(+), 24 deletions(-)
block/bochs.c +4 -4
@@ -112,10 +112,10 @@ static int bochs_open(BlockDriverState *bs, QDict *options, int flags, }if (!bdrv_is_read_only (bs)) { -error_report ("Opening bochs images without an explicit read-only=on " -"option is deprecated. Future versions will refuse to " -"open the image instead of automatically marking the " -"image read-only." ); +warn_report ("Opening bochs images without an explicit read-only=on " +"option is deprecated" ); +error_printf ("Future versions may refuse to open the image " +"instead of automatically marking it read-only.\n" ); ret =bdrv_set_read_only (bs, true, errp);/* no write support yet */ if (ret <0 ) {return ret;
block/cloop.c +4 -4
@@ -74,10 +74,10 @@ static int cloop_open(BlockDriverState *bs, QDict *options, int flags, }if (!bdrv_is_read_only (bs)) { -error_report ("Opening cloop images without an explicit read-only=on " -"option is deprecated. Future versions will refuse to " -"open the image instead of automatically marking the " -"image read-only." ); +warn_report ("Opening cloop images without an explicit read-only=on " +"option is deprecated" ); +error_printf ("Future versions may refuse to open the image " +"instead of automatically marking it read-only.\n" ); ret =bdrv_set_read_only (bs, true, errp);if (ret <0 ) {return ret;
block/dmg.c +4 -4
@@ -420,10 +420,10 @@ static int dmg_open(BlockDriverState *bs, QDict *options, int flags, }if (!bdrv_is_read_only (bs)) { -error_report ("Opening dmg images without an explicit read-only=on " -"option is deprecated. Future versions will refuse to " -"open the image instead of automatically marking the " -"image read-only." ); +warn_report ("Opening dmg images without an explicit read-only=on " +"option is deprecated" ); +error_printf ("Future versions may refuse to open the image " +"instead of automatically marking it read-only.\n" ); ret =bdrv_set_read_only (bs, true, errp);if (ret <0 ) {return ret;
block/iscsi.c +1 -1
@@ -1844,7 +1844,7 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,iscsi_set_timeout (iscsi, timeout);#else if (timeout) { -error_report ("iSCSI: ignoring timeout value for libiscsi <1.15.0" ); +warn_report ("iSCSI: ignoring timeout value for libiscsi <1.15.0" ); }#endif
block/rbd.c +6 -6
@@ -750,8 +750,8 @@ static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags,/* Take care whenever deciding to actually deprecate; once this ability * is removed, we will not be able to open any images with legacy-styled * backing image strings. */ -error_report ("RBD options encoded in the filename as keyvalue pairs " -"is deprecated" ); +warn_report ("RBD options encoded in the filename as keyvalue pairs " +"is deprecated" ); }/* Remove the processed options from the QDict (the visitor processes
@@ -781,10 +781,10 @@ static int qemu_rbd_open(BlockDriverState *bs, QDict *options, int flags,* leave as-is */ if (s->snap !=NULL ) {if (!bdrv_is_read_only (bs)) { -error_report ("Opening rbd snapshots without an explicit " -"read-only=on option is deprecated. Future versions " -"will refuse to open the image instead of " -"automatically marking the image read-only." ); +warn_report ("Opening rbd snapshots without an explicit " +"read-only=on option is deprecated" ); +error_printf ("Future versions may refuse to open the image " +"instead of automatically marking it read-only.\n" ); r =bdrv_set_read_only (bs, true, &local_err);if (r <0 ) {error_propagate (errp, local_err);
block/sheepdog.c +1 -1
@@ -572,7 +572,7 @@ static int connect_to_sdog(BDRVSheepdogState *s, Error **errp)if (s->addr->type ==SOCKET_ADDRESS_TYPE_INET && fd >=0 ) {int ret =socket_set_nodelay (fd);if (ret <0 ) { -error_report ("%s" ,strerror (errno)); +warn_report ("can't set TCP_NODELAY: %s" ,strerror (errno)); } }
block/vvfat.c +4 -4
@@ -1263,10 +1263,10 @@ static int vvfat_open(BlockDriverState *bs, QDict *options, int flags, goto fail; } }else if (!bdrv_is_read_only (bs)) { -error_report ("Opening non-rw vvfat images without an explicit " -"read-only=on option is deprecated. Future versions " -"will refuse to open the image instead of " -"automatically marking the image read-only." ); +warn_report ("Opening non-rw vvfat images without an explicit " +"read-only=on option is deprecated" ); +error_printf ("Future versions may refuse to open the image " +"instead of automatically marking it read-only.\n" );/* read only is the default for safety */ ret =bdrv_set_read_only (bs, true, &local_err);if (ret <0 ) {
Signature · 1 line
2.17.1
PATCH 4/31 vfio: Use warn_report() & friends to report warnings
In reply to Markus ArmbrusterThe vfio code reports warnings like
error_report(WARN_PREFIX "Could not frobnicate", DEV-NAME);
where WARN_PREFIX is defined so the message comes out as
vfio warning: DEV-NAME: Could not frobnicate
This usage predates the introduction of warn_report() & friends in commit 97f40301f1d. It's time to convert to that interface. Since these functions already prefix the message with "warning: ", replace WARN_PREFIX by VFIO_MSG_PREFIX, so the messages come out like
warning: vfio DEV-NAME: Could not frobnicate
The next commit will replace ERR_PREFIX.
--- hw/vfio/pci.c | 14 +++++++------- hw/vfio/platform.c | 4 ++-- include/hw/vfio/vfio-common.h | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-)
hw/vfio/pci.c +7 -7
@@ -249,7 +249,7 @@ static void vfio_intx_update(PCIDevice *pdev)vfio_intx_enable_kvm (vdev, &err);if (err) { -error_reportf_err (err,WARN_PREFIX , vdev->vbasedev.name); +warn_reportf_err (err,VFIO_MSG_PREFIX , vdev->vbasedev.name); }/* Re-enable the interrupt in cased we missed an EOI */
@@ -314,7 +314,7 @@ static int vfio_intx_enable(VFIOPCIDevice *vdev, Error **errp)vfio_intx_enable_kvm (vdev, &err);if (err) { -error_reportf_err (err,WARN_PREFIX , vdev->vbasedev.name); +warn_reportf_err (err,VFIO_MSG_PREFIX , vdev->vbasedev.name); } vdev->interrupt = VFIO_INT_INTx;
@@ -1555,7 +1555,7 @@ static int vfio_msix_setup(VFIOPCIDevice *vdev, int pos, Error **errp) &err);if (ret <0 ) {if (ret == -ENOTSUP ) { -error_report_err (err); +warn_report_err (err);return 0 ; }
@@ -2588,9 +2588,9 @@ static void vfio_populate_device(VFIOPCIDevice *vdev, Error **errp) }else if (irq_info.count ==1 ) { vdev->pci_aer = true; }else { -error_report (WARN_PREFIX -"Could not enable error recovery for the device" , - vbasedev->name); +warn_report (VFIO_MSG_PREFIX +"Could not enable error recovery for the device" , + vbasedev->name); } }
@@ -2715,7 +2715,7 @@ static void vfio_req_notifier_handler(void *opaque)qdev_unplug (&vdev->pdev.qdev, &err);if (err) { -error_reportf_err (err,WARN_PREFIX , vdev->vbasedev.name); +warn_reportf_err (err,VFIO_MSG_PREFIX , vdev->vbasedev.name); } }
hw/vfio/platform.c +2 -2
@@ -657,8 +657,8 @@ static void vfio_platform_realize(DeviceState *dev, Error **errp)for (i =0 ; i < vbasedev->num_regions; i++) {if (vfio_region_mmap (vdev->regions[i])) { -error_report ("%s mmap unsupported. Performance may be slow" , -memory_region_name (vdev->regions[i]->mem)); +warn_report ("%s mmap unsupported, performance may be slow" , +memory_region_name (vdev->regions[i]->mem)); }sysbus_init_mmio (sbdev, vdev->regions[i]->mem); }
include/hw/vfio/vfio-common.h +1 -1
@@ -31,7 +31,7 @@#endif #define ERR_PREFIX "vfio error: %s: " -#define WARN_PREFIX "vfio warning: %s: " +#define VFIO_MSG_PREFIX "vfio %s: "enum {VFIO_DEVICE_TYPE_PCI =0 ,
Signature · 1 line
2.17.1
PATCH 5/31 vfio: Clean up error reporting after previous commit
In reply to Markus ArmbrusterThe previous commit changed vfio's warning messages from
vfio warning: DEV-NAME: Could not frobnicate
to
warning: vfio DEV-NAME: Could not frobnicate
To match this change, change error messages from
vfio error: DEV-NAME: On fire
to
vfio DEV-NAME: On fire
Note the loss of "error". If we think marking error messages that way is a good idea, we should mark *all* error messages, i.e. make error_report() print it.
--- hw/vfio/pci-quirks.c | 4 ++-- hw/vfio/pci.c | 8 ++++---- hw/vfio/platform.c | 2 +- include/hw/vfio/vfio-common.h | 1 - 4 files changed, 7 insertions(+), 8 deletions(-)
hw/vfio/pci-quirks.c +2 -2
@@ -1670,7 +1670,7 @@ static void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr)* but also no point in us enabling VGA if disabled in hardware. */ if (!(gmch &0x2 ) && !vdev->vga &&vfio_populate_vga (vdev, &err)) { -error_reportf_err (err,ERR_PREFIX , vdev->vbasedev.name); +error_reportf_err (err,VFIO_MSG_PREFIX , vdev->vbasedev.name);error_report ("IGD device %s failed to enable VGA access, " "legacy mode disabled" , vdev->vbasedev.name); goto out;
@@ -1696,7 +1696,7 @@ static void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr) ret =vfio_pci_igd_opregion_init (vdev, opregion, &err);if (ret) {error_append_hint (&err,"IGD legacy mode disabled\n" ); -error_reportf_err (err,ERR_PREFIX , vdev->vbasedev.name); +error_reportf_err (err,VFIO_MSG_PREFIX , vdev->vbasedev.name); goto out; }
hw/vfio/pci.c +4 -4
@@ -742,7 +742,7 @@ static void vfio_msi_disable_common(VFIOPCIDevice *vdev)vfio_intx_enable (vdev, &err);if (err) { -error_reportf_err (err,ERR_PREFIX , vdev->vbasedev.name); +error_reportf_err (err,VFIO_MSG_PREFIX , vdev->vbasedev.name); } }
@@ -2194,7 +2194,7 @@ static void vfio_pci_post_reset(VFIOPCIDevice *vdev)vfio_intx_enable (vdev, &err);if (err) { -error_reportf_err (err,ERR_PREFIX , vdev->vbasedev.name); +error_reportf_err (err,VFIO_MSG_PREFIX , vdev->vbasedev.name); }for (nr =0 ; nr <PCI_NUM_REGIONS -1 ; ++nr) {
@@ -2828,7 +2828,7 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)if (stat (vdev->vbasedev.sysfsdev, &st) <0 ) {error_setg_errno (errp, errno,"no such host device" ); -error_prepend (errp,ERR_PREFIX , vdev->vbasedev.sysfsdev); +error_prepend (errp,VFIO_MSG_PREFIX , vdev->vbasedev.sysfsdev);return ; }
@@ -3079,7 +3079,7 @@ out_teardown:vfio_teardown_msi (vdev);vfio_bars_exit (vdev); error: -error_prepend (errp,ERR_PREFIX , vdev->vbasedev.name); +error_prepend (errp,VFIO_MSG_PREFIX , vdev->vbasedev.name); }static void vfio_instance_finalize (Object *obj)
hw/vfio/platform.c +1 -1
@@ -668,7 +668,7 @@ out: }if (vdev->vbasedev.name) { -error_prepend (errp,ERR_PREFIX , vdev->vbasedev.name); +error_prepend (errp,VFIO_MSG_PREFIX , vdev->vbasedev.name); }else {error_prepend (errp,"vfio error: " ); }
include/hw/vfio/vfio-common.h +0 -1
@@ -30,7 +30,6 @@#include <linux/vfio.h> #endif -#define ERR_PREFIX "vfio error: %s: "#define VFIO_MSG_PREFIX "vfio %s: "enum {
Signature · 1 line
2.17.1
PATCH 6/31 char: Use error_printf() to print help and such
In reply to Markus ArmbrusterCalling error_report() in a function that takes an Error ** argument is suspicious. Convert a few that are actually help and such to error_printf().
Improves output of -chardev help from
qemu-system-x86_64: -chardev help: Available chardev backend types:
serial
...
to
Available chardev backend types:
serial
...
--- chardev/char-pty.c | 2 +- chardev/char.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
chardev/char-pty.c +1 -1
@@ -259,7 +259,7 @@ static void char_pty_open(Chardev *chr,qemu_set_nonblock (master_fd); chr->filename =g_strdup_printf ("pty:%s" , pty_name); -error_report ("char device redirected to %s (label %s)" , +error_printf ("char device redirected to %s (label %s)\n" , pty_name, chr->label); s =PTY_CHARDEV (chr);
chardev/char.c +1 -1
@@ -634,7 +634,7 @@ Chardev *qemu_chr_new_from_opts(QemuOpts *opts, Error **errp)chardev_name_foreach (help_string_append, str); -error_report ("Available chardev backend types: %s" , str->str); +error_printf ("Available chardev backend types: %s\n" , str->str);g_string_free (str, true);return NULL ; }
Signature · 1 line
2.17.1
PATCH 10/31 smbios: Clean up error handling in smbios_add()
In reply to Markus ArmbrusterCalling error_report() in a function that takes an Error ** argument is suspicious. smbios_entry_add() does that, and then exit()s. It also passes &error_fatal to qemu_opts_validate(). Both wrong, but currently harmless, as its only caller passes &error_fatal. Messed up in commit 1007a37e208. Clean it up.
--- hw/smbios/smbios.c | 90 +++++++++++++++++++++++++++++++--------------- 1 file changed, 62 insertions(+), 28 deletions(-)
hw/smbios/smbios.c +62 -28
@@ -950,6 +950,7 @@ static void save_opt_list(size_t *ndest, const char ***dest,void smbios_entry_add (QemuOpts *opts,Error **errp) { +Error *err =NULL ;const char *val;assert (!smbios_immutable);
@@ -960,12 +961,16 @@ void smbios_entry_add(QemuOpts *opts, Error **errp)int size;struct smbios_table *table;/* legacy mode only */ -qemu_opts_validate (opts, qemu_smbios_file_opts, &error_fatal); +qemu_opts_validate (opts, qemu_smbios_file_opts, &err); +if (err) { +error_propagate (errp, err); +return ; + } size =get_image_size (val);if (size ==-1 || size <sizeof (struct smbios_structure_header )) { -error_report ("Cannot read SMBIOS file %s" , val); -exit (1 ); +error_setg (errp,"Cannot read SMBIOS file %s" , val); +return ; }/*
@@ -978,14 +983,15 @@ void smbios_entry_add(QemuOpts *opts, Error **errp) smbios_tables_len);if (load_image (val, (uint8_t *)header) != size) { -error_report ("Failed to load SMBIOS file %s" , val); -exit (1 ); +error_setg (errp,"Failed to load SMBIOS file %s" , val); +return ; }if (test_bit (header->type, have_fields_bitmap)) { -error_report ("can't load type %d struct, fields already specified!" , - header->type); -exit (1 ); +error_setg (errp, +"can't load type %d struct, fields already specified!" , + header->type); +return ; }set_bit (header->type, have_binfile_bitmap);
@@ -1030,19 +1036,23 @@ void smbios_entry_add(QemuOpts *opts, Error **errp)unsigned long type =strtoul (val,NULL ,0 );if (type >SMBIOS_MAX_TYPE ) { -error_report ("out of range!" ); -exit (1 ); +error_setg (errp,"out of range!" ); +return ; }if (test_bit (type, have_binfile_bitmap)) { -error_report ("can't add fields, binary file already loaded!" ); -exit (1 ); +error_setg (errp,"can't add fields, binary file already loaded!" ); +return ; }set_bit (type, have_fields_bitmap);switch (type) {case 0 : -qemu_opts_validate (opts, qemu_smbios_type0_opts, &error_fatal); +qemu_opts_validate (opts, qemu_smbios_type0_opts, &err); +if (err) { +error_propagate (errp, err); +return ; + }save_opt (&type0.vendor, opts,"vendor" );save_opt (&type0.version, opts,"version" );save_opt (&type0.date, opts,"date" );
@@ -1051,14 +1061,18 @@ void smbios_entry_add(QemuOpts *opts, Error **errp) val =qemu_opt_get (opts,"release" );if (val) {if (sscanf (val,"%hhu.%hhu" , &type0.major, &type0.minor) !=2 ) { -error_report ("Invalid release" ); -exit (1 ); +error_setg (errp,"Invalid release" ); +return ; } type0.have_major_minor = true; }return ;case 1 : -qemu_opts_validate (opts, qemu_smbios_type1_opts, &error_fatal); +qemu_opts_validate (opts, qemu_smbios_type1_opts, &err); +if (err) { +error_propagate (errp, err); +return ; + }save_opt (&type1.manufacturer, opts,"manufacturer" );save_opt (&type1.product, opts,"product" );save_opt (&type1.version, opts,"version" );
@@ -1069,14 +1083,18 @@ void smbios_entry_add(QemuOpts *opts, Error **errp) val =qemu_opt_get (opts,"uuid" );if (val) {if (qemu_uuid_parse (val, &qemu_uuid) !=0 ) { -error_report ("Invalid UUID" ); -exit (1 ); +error_setg (errp,"Invalid UUID" ); +return ; } qemu_uuid_set = true; }return ;case 2 : -qemu_opts_validate (opts, qemu_smbios_type2_opts, &error_fatal); +qemu_opts_validate (opts, qemu_smbios_type2_opts, &err); +if (err) { +error_propagate (errp, err); +return ; + }save_opt (&type2.manufacturer, opts,"manufacturer" );save_opt (&type2.product, opts,"product" );save_opt (&type2.version, opts,"version" );
@@ -1085,7 +1103,11 @@ void smbios_entry_add(QemuOpts *opts, Error **errp)save_opt (&type2.location, opts,"location" );return ;case 3 : -qemu_opts_validate (opts, qemu_smbios_type3_opts, &error_fatal); +qemu_opts_validate (opts, qemu_smbios_type3_opts, &err); +if (err) { +error_propagate (errp, err); +return ; + }save_opt (&type3.manufacturer, opts,"manufacturer" );save_opt (&type3.version, opts,"version" );save_opt (&type3.serial, opts,"serial" );
@@ -1093,7 +1115,11 @@ void smbios_entry_add(QemuOpts *opts, Error **errp)save_opt (&type3.sku, opts,"sku" );return ;case 4 : -qemu_opts_validate (opts, qemu_smbios_type4_opts, &error_fatal); +qemu_opts_validate (opts, qemu_smbios_type4_opts, &err); +if (err) { +error_propagate (errp, err); +return ; + }save_opt (&type4.sock_pfx, opts,"sock_pfx" );save_opt (&type4.manufacturer, opts,"manufacturer" );save_opt (&type4.version, opts,"version" );
@@ -1102,11 +1128,19 @@ void smbios_entry_add(QemuOpts *opts, Error **errp)save_opt (&type4.part, opts,"part" );return ;case 11 : -qemu_opts_validate (opts, qemu_smbios_type11_opts, &error_fatal); +qemu_opts_validate (opts, qemu_smbios_type11_opts, &err); +if (err) { +error_propagate (errp, err); +return ; + }save_opt_list (&type11.nvalues, &type11.values, opts,"value" );return ;case 17 : -qemu_opts_validate (opts, qemu_smbios_type17_opts, &error_fatal); +qemu_opts_validate (opts, qemu_smbios_type17_opts, &err); +if (err) { +error_propagate (errp, err); +return ; + }save_opt (&type17.loc_pfx, opts,"loc_pfx" );save_opt (&type17.bank, opts,"bank" );save_opt (&type17.manufacturer, opts,"manufacturer" );
@@ -1116,12 +1150,12 @@ void smbios_entry_add(QemuOpts *opts, Error **errp) type17.speed =qemu_opt_get_number (opts,"speed" ,0 );return ;default : -error_report ("Don't know how to build fields for SMBIOS type %ld" , - type); -exit (1 ); +error_setg (errp, +"Don't know how to build fields for SMBIOS type %ld" , + type); +return ; } } -error_report ("Must specify type= or file=" ); -exit (1 ); +error_setg (errp,"Must specify type= or file=" ); }
Signature · 1 line
2.17.1
PATCH 13/31 net/socket: Fix invalid socket type error handling
In reply to Markus ArmbrusterCalling error_report() in a function that takes an Error ** argument is suspicious. net_socket_fd_init() does that, and then fails without setting an error. Wrong. I didn't analyze how exactly this can break. A caller that reports the error on failure would crash.
Broken when commit c37f0bb1d0d (v2.11.0) converted the function to Error. Fix by calling error_setg() instead of error_report().
--- net/socket.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/socket.c +2 -2
@@ -453,8 +453,8 @@ static NetSocketState *net_socket_fd_init(NetClientState *peer,case SOCK_STREAM :return net_socket_fd_init_stream (peer, model, name, fd, is_connected);default : -error_report ("socket type=%d for fd=%d must be either" -" SOCK_DGRAM or SOCK_STREAM" , so_type, fd); +error_setg (errp,"socket type=%d for fd=%d must be either" +" SOCK_DGRAM or SOCK_STREAM" , so_type, fd);closesocket (fd); }return NULL ;
Signature · 1 line
2.17.1
PATCH 14/31 numa: Fix QMP command set-numa-node error handling
In reply to Markus ArmbrusterCalling error_report() in a function that takes an Error ** argument is suspicious. parse_numa_node() does that, and then exit()s. It also passes &error_fatal to machine_set_cpu_numa_node(). Both wrong. Attempting to configure numa when the machine doesn't support it kills the VM:
$ qemu-system-x86_64 -nodefaults -S -display none -M none -preconfig -qmp stdio
{"QMP": {"version": {"qemu": {"micro": 50, "minor": 0, "major": 3}, "package": "v3.0.0-837-gc5e4e49258"}, "capabilities": []}}
{"execute": "qmp_capabilities"}
{"return": {}}
{"execute": "set-numa-node", "arguments": {"type": "node"}}
NUMA is not supported by this machine-type
$ echo $?
1Messed up when commit 64c2a8f6d3f and 7c88e65d9e9 (v2.10.0) added incorrect error handling right next to correct examples. Latent bug until commit f3be67812c2 (v3.0.0) made it accessible via QMP. Fairly harmless in practice, because it's limited to RUN_STATE_PRECONFIG. The fix is obvious: replace error_report(); exit() by error_setg(); return.
This affects parse_numa_node()'s other caller numa_complete_configuration(): since it ignores errors, the "NUMA is not supported by this machine-type" is now ignored, too. But that error is as unexpected there as any other. Change it to abort on error instead.
fixup! numa: Fix QMP command set-numa-node error handling
--- numa.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
numa.c +9 -4
@@ -60,6 +60,7 @@ NodeInfo numa_info[MAX_NODES];static void parse_numa_node (MachineState *ms,NumaNodeOptions *node,Error **errp) { +Error *err =NULL ;uint16_t nodenr;uint16List *cpus =NULL ;MachineClass *mc =MACHINE_GET_CLASS (ms);
@@ -82,8 +83,8 @@ static void parse_numa_node(MachineState *ms, NumaNodeOptions *node, }if (!mc->cpu_index_to_instance_props || !mc->get_default_cpu_node_id) { -error_report ("NUMA is not supported by this machine-type" ); -exit (1 ); +error_setg (errp,"NUMA is not supported by this machine-type" ); +return ; }for (cpus = node->cpus; cpus; cpus = cpus->next) {CpuInstanceProperties props;
@@ -97,7 +98,11 @@ static void parse_numa_node(MachineState *ms, NumaNodeOptions *node, props = mc->cpu_index_to_instance_props (ms, cpus->value); props.node_id = nodenr; props.has_node_id = true; -machine_set_cpu_numa_node (ms, &props, &error_fatal); +machine_set_cpu_numa_node (ms, &props, &err); +if (err) { +error_propagate (errp, err); +return ; + } }if (node->has_mem && node->has_memdev) {
@@ -367,7 +372,7 @@ void numa_complete_configuration(MachineState *ms)if (ms->ram_slots >0 && nb_numa_nodes ==0 && mc->auto_enable_numa_with_memhp) {NumaNodeOptions node = { }; -parse_numa_node (ms, &node,NULL ); +parse_numa_node (ms, &node, &error_abort); }assert (max_numa_nodeid <=MAX_NODES );
Signature · 1 line
2.17.1
PATCH 15/31 xen/pt: Fix incomplete conversion to realize()
In reply to Markus ArmbrusterThe conversion of "xen-pci-passthrough" to realize() (commit 5a11d0f7549, v2.6.0) neglected to convert the xen_pt_config_init() error path. If xen_pt_config_init() fails, xen_pt_realize() reports the error, then returns success without completing its job. I don't know the exact impact, but it can't be good.
Belatedly convert the error path.
--- hw/xen/xen_pt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/xen/xen_pt.c +1 -1
@@ -830,7 +830,7 @@ static void xen_pt_realize(PCIDevice *d, Error **errp)xen_pt_config_init (s, &err);if (err) {error_append_hint (&err,"PCI Config space initialisation failed" ); -error_report_err (err); +error_propagate (errp, err); rc =-1 ; goto err_out; }
Signature · 1 line
2.17.1
PATCH 16/31 seccomp: Clean up error reporting in parse_sandbox()
In reply to Markus ArmbrusterCalling error_report() in a function that takes an Error ** argument is suspicious. parse_sandbox() does that, and then fails without setting an error. Its caller main(), via qemu_opts_foreach(), is fine with it, but clean it up anyway.
--- qemu-seccomp.c | 18 +++++++++--------- vl.c | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-)
qemu-seccomp.c +9 -9
@@ -12,11 +12,12 @@* Contributions after 2012-01-13 are licensed under the terms of the * GNU GPL, version 2 or (at your option) any later version. */ +#include "qemu/osdep.h" +#include "qapi/error.h" #include "qemu/config-file.h" #include "qemu/option.h" #include "qemu/module.h" -#include "qemu/error-report.h" #include <sys/prctl.h> #include <seccomp.h> #include "sysemu/seccomp.h"
@@ -190,7 +191,7 @@ int parse_sandbox(void *opaque, QemuOpts *opts, Error **errp)* to provide a little bit of consistency for * the command line */ }else { -error_report ("invalid argument for obsolete" ); +error_setg (errp,"invalid argument for obsolete" );return -1 ; } }
@@ -205,14 +206,13 @@ int parse_sandbox(void *opaque, QemuOpts *opts, Error **errp)/* calling prctl directly because we're * not sure if host has CAP_SYS_ADMIN set*/ if (prctl (PR_SET_NO_NEW_PRIVS ,1 )) { -error_report ("failed to set no_new_privs " -"aborting" ); +error_setg (errp,"failed to set no_new_privs " "aborting" );return -1 ; } }else if (g_str_equal (value,"allow" )) {/* default value */ }else { -error_report ("invalid argument for elevateprivileges" ); +error_setg (errp,"invalid argument for elevateprivileges" );return -1 ; } }
@@ -224,7 +224,7 @@ int parse_sandbox(void *opaque, QemuOpts *opts, Error **errp) }else if (g_str_equal (value,"allow" )) {/* default value */ }else { -error_report ("invalid argument for spawn" ); +error_setg (errp,"invalid argument for spawn" );return -1 ; } }
@@ -236,14 +236,14 @@ int parse_sandbox(void *opaque, QemuOpts *opts, Error **errp) }else if (g_str_equal (value,"allow" )) {/* default value */ }else { -error_report ("invalid argument for resourcecontrol" ); +error_setg (errp,"invalid argument for resourcecontrol" );return -1 ; } }if (seccomp_start (seccomp_opts) <0 ) { -error_report ("failed to install seccomp syscall filter " -"in the kernel" ); +error_setg (errp,"failed to install seccomp syscall filter " +"in the kernel" );return -1 ; } }
vl.c +2 -2
@@ -3925,8 +3925,8 @@ int main(int argc, char **argv, char **envp)#ifdef CONFIG_SECCOMP olist =qemu_find_opts_err ("sandbox" ,NULL ); -if (olist &&qemu_opts_foreach (olist, parse_sandbox,NULL ,NULL )) { -exit (1 ); +if (olist) { +qemu_opts_foreach (olist, parse_sandbox,NULL , &error_fatal); }#endif
Signature · 1 line
2.17.1
PATCH 19/31 vl: Clean up error reporting in parse_add_fd()
In reply to Markus ArmbrusterCalling error_report() in a function that takes an Error ** argument is suspicious. chardev_init_func() does that, and then fails without setting an error. Its caller main(), via qemu_opts_foreach(), is fine with it, but clean it up anyway.
--- vl.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
vl.c +3 -5
@@ -2239,7 +2239,7 @@ static int chardev_init_func(void *opaque, QemuOpts *opts, Error **errp)if (!qemu_chr_new_from_opts (opts, &local_err)) {if (local_err) { -error_report_err (local_err); +error_propagate (errp, local_err);return -1 ; }exit (0 );
@@ -4185,10 +4185,8 @@ int main(int argc, char **argv, char **envp) user_creatable_add_opts_foreach, object_create_initial, &error_fatal); -if (qemu_opts_foreach (qemu_find_opts ("chardev" ), - chardev_init_func,NULL ,NULL )) { -exit (1 ); - } +qemu_opts_foreach (qemu_find_opts ("chardev" ), + chardev_init_func,NULL , &error_fatal);#ifdef CONFIG_VIRTFS if (qemu_opts_foreach(qemu_find_opts("fsdev"),
Signature · 1 line
2.17.1
PATCH 20/31 vl: Clean up error reporting in machine_set_property()
In reply to Markus ArmbrusterCalling error_report() in a function that takes an Error ** argument is suspicious. machine_set_property() does that, and then fails without setting an error. Its caller main(), via qemu_opts_foreach(), is fine with it, but clean it up anyway.
--- vl.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
vl.c +3 -6
@@ -2676,7 +2676,7 @@ static int machine_set_property(void *opaque,g_free (qom_name);if (local_err) { -error_report_err (local_err); +error_propagate (errp, local_err);return -1 ; }
@@ -4201,11 +4201,8 @@ int main(int argc, char **argv, char **envp) } machine_opts =qemu_get_machine_opts (); -if (qemu_opt_foreach (machine_opts, machine_set_property, current_machine, -NULL )) { -object_unref (OBJECT (current_machine)); -exit (1 ); - } +qemu_opt_foreach (machine_opts, machine_set_property, current_machine, + &error_fatal);configure_accelerator (current_machine);
Signature · 1 line
2.17.1
PATCH 27/31 spice: Clean up error reporting in add_channel()
In reply to Markus ArmbrusterCalling error_report() in a function that takes an Error ** argument is suspicious. add_channel() does that, and then exit()s. Its caller main(), via qemu_opts_foreach(), is fine with it, but clean it up anyway.
--- ui/spice-core.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
ui/spice-core.c +7 -6
@@ -597,9 +597,9 @@ static int add_channel(void *opaque, const char *name, const char *value,if (strcmp (name,"tls-channel" ) ==0 ) {int *tls_port = opaque;if (!*tls_port) { -error_report ("spice: tried to setup tls-channel" -" without specifying a TLS port" ); -exit (1 ); +error_setg (errp,"spice: tried to setup tls-channel" +" without specifying a TLS port" ); +return -1 ; } security =SPICE_CHANNEL_SECURITY_SSL ; }
@@ -615,8 +615,9 @@ static int add_channel(void *opaque, const char *name, const char *value, rc =spice_server_set_channel_security (spice_server, value, security); }if (rc !=0 ) { -error_report ("spice: failed to set channel security for %s" , value); -exit (1 ); +error_setg (errp,"spice: failed to set channel security for %s" , + value); +return -1 ; }return 0 ; }
@@ -787,7 +788,7 @@ void qemu_spice_init(void)spice_server_set_playback_compression (spice_server,qemu_opt_get_bool (opts,"playback-compression" ,1 )); -qemu_opt_foreach (opts, add_channel, &tls_port,NULL ); +qemu_opt_foreach (opts, add_channel, &tls_port, &error_fatal);spice_server_set_name (spice_server, qemu_name);spice_server_set_uuid (spice_server, (unsigned char *)&qemu_uuid);
Signature · 1 line
2.17.1
PATCH 31/31 vl: Simplify call of parse_name()
In reply to Markus Armbrustermain() checks for parse_name() failure even though it can't actually fail. That's okay. Simplify it to check by passing &error_fatal, like the other users of qemu_opts_foreach().
--- vl.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
vl.c +2 -4
@@ -3926,10 +3926,8 @@ int main(int argc, char **argv, char **envp) }#endif -if (qemu_opts_foreach (qemu_find_opts ("name" ), - parse_name,NULL ,NULL )) { -exit (1 ); - } +qemu_opts_foreach (qemu_find_opts ("name" ), + parse_name,NULL , &error_fatal);#ifndef _WIN32 qemu_opts_foreach(qemu_find_opts("add-fd"),
Signature · 1 line
2.17.1
PATCH 17/31 vl: Clean up error reporting in parse_add_fd()
In reply to Markus ArmbrusterCalling error_report() in a function that takes an Error ** argument is suspicious. parse_add_fd() does that, and then fails without setting an error. Its caller main(), via qemu_opts_foreach(), is fine with it, but clean it up anyway.
Also change call of cleanup_add_fd(), which can't fail, for symmetry.
--- vl.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-)
vl.c +9 -13
@@ -1059,12 +1059,12 @@ static int parse_add_fd(void *opaque, QemuOpts *opts, Error **errp) fd_opaque =qemu_opt_get (opts,"opaque" );if (fd <0 ) { -error_report ("fd option is required and must be non-negative" ); +error_setg (errp,"fd option is required and must be non-negative" );return -1 ; }if (fd <=STDERR_FILENO ) { -error_report ("fd cannot be a standard I/O stream" ); +error_setg (errp,"fd cannot be a standard I/O stream" );return -1 ; }
@@ -1074,12 +1074,12 @@ static int parse_add_fd(void *opaque, QemuOpts *opts, Error **errp)*/ flags =fcntl (fd,F_GETFD );if (flags ==-1 || (flags &FD_CLOEXEC )) { -error_report ("fd is not valid or already in use" ); +error_setg (errp,"fd is not valid or already in use" );return -1 ; }if (fdset_id <0 ) { -error_report ("set option is required and must be non-negative" ); +error_setg (errp,"set option is required and must be non-negative" );return -1 ; }
@@ -1092,7 +1092,7 @@ static int parse_add_fd(void *opaque, QemuOpts *opts, Error **errp) }#endif if (dupfd ==-1 ) { -error_report ("error duplicating fd: %s" ,strerror (errno)); +error_setg (errp,"error duplicating fd: %s" ,strerror (errno));return -1 ; }
@@ -3936,15 +3936,11 @@ int main(int argc, char **argv, char **envp) }#ifndef _WIN32 -if (qemu_opts_foreach (qemu_find_opts ("add-fd" ), - parse_add_fd,NULL ,NULL )) { -exit (1 ); - } +qemu_opts_foreach (qemu_find_opts ("add-fd" ), + parse_add_fd,NULL , &error_fatal); -if (qemu_opts_foreach (qemu_find_opts ("add-fd" ), - cleanup_add_fd,NULL ,NULL )) { -exit (1 ); - } +qemu_opts_foreach (qemu_find_opts ("add-fd" ), + cleanup_add_fd,NULL , &error_fatal);#endif current_machine = MACHINE(object_new(object_class_get_name(
Signature · 1 line
2.17.1
PATCH 22/31 vl: Clean up error reporting in parse_fw_cfg()
In reply to Markus ArmbrusterCalling error_report() in a function that takes an Error ** argument is suspicious. parse_fw_cfg() does that, and then fails without setting an error. Its caller main(), via qemu_opts_foreach(), is fine with it, but clean it up anyway.
--- vl.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)
vl.c +8 -9
@@ -2174,7 +2174,7 @@ static int parse_fw_cfg(void *opaque, QemuOpts *opts, Error **errp)FWCfgState *fw_cfg = (FWCfgState *) opaque;if (fw_cfg ==NULL ) { -error_report ("fw_cfg device not available" ); +error_setg (errp,"fw_cfg device not available" );return -1 ; } name =qemu_opt_get (opts,"name" );
@@ -2183,15 +2183,16 @@ static int parse_fw_cfg(void *opaque, QemuOpts *opts, Error **errp)/* we need name and either a file or the content string */ if (!(nonempty_str (name) && (nonempty_str (file) ||nonempty_str (str)))) { -error_report ("invalid argument(s)" ); +error_setg (errp,"invalid argument(s)" );return -1 ; }if (nonempty_str (file) &&nonempty_str (str)) { -error_report ("file and string are mutually exclusive" ); +error_setg (errp,"file and string are mutually exclusive" );return -1 ; }if (strlen (name) >FW_CFG_MAX_FILE_PATH -1 ) { -error_report ("name too long (max. %d char)" ,FW_CFG_MAX_FILE_PATH -1 ); +error_setg (errp,"name too long (max. %d char)" , +FW_CFG_MAX_FILE_PATH -1 );return -1 ; }if (strncmp (name,"opt/" ,4 ) !=0 ) {
@@ -2203,7 +2204,7 @@ static int parse_fw_cfg(void *opaque, QemuOpts *opts, Error **errp) buf =g_memdup (str, size); }else {if (!g_file_get_contents (file, &buf, &size,NULL )) { -error_report ("can't load %s" , file); +error_setg (errp,"can't load %s" , file);return -1 ; } }
@@ -4429,10 +4430,8 @@ int main(int argc, char **argv, char **envp)hax_sync_vcpus (); } -if (qemu_opts_foreach (qemu_find_opts ("fw_cfg" ), - parse_fw_cfg,fw_cfg_find (),NULL ) !=0 ) { -exit (1 ); - } +qemu_opts_foreach (qemu_find_opts ("fw_cfg" ), + parse_fw_cfg,fw_cfg_find (), &error_fatal);/* init USB devices */ if (machine_usb (current_machine)) {
Signature · 1 line
2.17.1
PATCH 25/31 numa: Clean up error reporting in parse_numa()
In reply to Markus ArmbrusterCalling error_report() in a function that takes an Error ** argument is suspicious. parse_numa() does that, and then fails without setting an error. Its caller main(), via qemu_opts_foreach(), is fine with it, but clean it up anyway.
While there, give parse_numa() internal linkage.
--- include/sysemu/numa.h | 1 - numa.c | 8 +++----- 2 files changed, 3 insertions(+), 6 deletions(-)
include/sysemu/numa.h +0 -1
@@ -22,7 +22,6 @@ struct NumaNodeMem { };extern NodeInfo numa_info[MAX_NODES ]; -int parse_numa (void *opaque,QemuOpts *opts,Error **errp);void parse_numa_opts (MachineState *ms);void numa_complete_configuration (MachineState *ms);void query_numa_node_mem (NumaNodeMem node_mem[]);
numa.c +3 -5
@@ -215,7 +215,7 @@ end:error_propagate (errp, err); } -int parse_numa (void *opaque,QemuOpts *opts,Error **errp) +static int parse_numa (void *opaque,QemuOpts *opts,Error **errp) {NumaOptions *object =NULL ;MachineState *ms =MACHINE (opaque);
@@ -239,7 +239,7 @@ int parse_numa(void *opaque, QemuOpts *opts, Error **errp) end:qapi_free_NumaOptions (object);if (err) { -error_report_err (err); +error_propagate (errp, err);return -1 ; }
@@ -444,9 +444,7 @@ void numa_complete_configuration(MachineState *ms)void parse_numa_opts (MachineState *ms) { -if (qemu_opts_foreach (qemu_find_opts ("numa" ), parse_numa, ms,NULL )) { -exit (1 ); - } +qemu_opts_foreach (qemu_find_opts ("numa" ), parse_numa, ms, &error_fatal); }void qmp_set_numa_node (NumaOptions *cmd,Error **errp)
Signature · 1 line
2.17.1
PATCH 28/31 fsdev: Clean up error reporting in qemu_fsdev_add()
In reply to Markus ArmbrusterCalling error_report() from within a a function that takes an Error ** argument is suspicious. qemu_fsdev_add() does that, and its caller fsdev_init_func() then fails without setting an error. Its caller main(), via qemu_opts_foreach(), is fine with it, but clean it up anyway.
--- fsdev/qemu-fsdev-dummy.c | 2 +- fsdev/qemu-fsdev.c | 12 +++++------- fsdev/qemu-fsdev.h | 2 +- hw/9pfs/xen-9p-backend.c | 7 ++++++- vl.c | 8 +++----- 5 files changed, 16 insertions(+), 15 deletions(-)
fsdev/qemu-fsdev-dummy.c +1 -1
@@ -15,7 +15,7 @@#include "qemu/config-file.h" #include "qemu/module.h" -int qemu_fsdev_add (QemuOpts *opts) +int qemu_fsdev_add (QemuOpts *opts,Error **errp) {return 0 ; }
fsdev/qemu-fsdev.c +5 -7
@@ -30,7 +30,7 @@ static FsDriverTable FsDrivers[] = { { .name = "proxy", .ops = &proxy_ops}, }; -int qemu_fsdev_add (QemuOpts *opts) +int qemu_fsdev_add (QemuOpts *opts,Error **errp) {int i;struct FsDriverListEntry *fsle;
@@ -38,10 +38,9 @@ int qemu_fsdev_add(QemuOpts *opts)const char *fsdriver =qemu_opt_get (opts,"fsdriver" );const char *writeout =qemu_opt_get (opts,"writeout" );bool ro =qemu_opt_get_bool (opts,"readonly" ,0 ); -Error *local_err =NULL ;if (!fsdev_id) { -error_report ("fsdev: No id specified" ); +error_setg (errp,"fsdev: No id specified" );return -1 ; }
@@ -53,11 +52,11 @@ int qemu_fsdev_add(QemuOpts *opts) }if (i ==ARRAY_SIZE (FsDrivers)) { -error_report ("fsdev: fsdriver %s not found" , fsdriver); +error_setg (errp,"fsdev: fsdriver %s not found" , fsdriver);return -1 ; } }else { -error_report ("fsdev: No fsdriver specified" ); +error_setg (errp,"fsdev: No fsdriver specified" );return -1 ; }
@@ -76,8 +75,7 @@ int qemu_fsdev_add(QemuOpts *opts) }if (fsle->fse.ops->parse_opts) { -if (fsle->fse.ops->parse_opts (opts, &fsle->fse, &local_err)) { -error_report_err (local_err); +if (fsle->fse.ops->parse_opts (opts, &fsle->fse, errp)) {g_free (fsle->fse.fsdev_id);g_free (fsle);return -1 ;
fsdev/qemu-fsdev.h +1 -1
@@ -38,7 +38,7 @@ typedef struct FsDriverListEntry {QTAILQ_ENTRY (FsDriverListEntry) next; } FsDriverListEntry; -int qemu_fsdev_add (QemuOpts *opts); +int qemu_fsdev_add (QemuOpts *opts,Error **errp);FsDriverEntry *get_fsdev_fsentry (char *id);extern FileOperations local_ops;extern FileOperations handle_ops;
hw/9pfs/xen-9p-backend.c +6 -1
@@ -14,6 +14,7 @@#include "hw/9pfs/9p.h" #include "hw/xen/xen_backend.h" #include "hw/9pfs/xen-9pfs.h" +#include "qapi/error.h" #include "qemu/config-file.h" #include "qemu/option.h" #include "fsdev/qemu-fsdev.h"
@@ -355,6 +356,7 @@ static int xen_9pfs_free(struct XenDevice *xendev)static int xen_9pfs_connect (struct XenDevice *xendev) { +Error *err =NULL ;int i;Xen9pfsDev *xen_9pdev =container_of (xendev, Xen9pfsDev, xendev);V9fsState *s = &xen_9pdev->state;
@@ -452,7 +454,10 @@ static int xen_9pfs_connect(struct XenDevice *xendev)qemu_opt_set (fsdev,"path" , xen_9pdev->path,NULL );qemu_opt_set (fsdev,"security_model" , xen_9pdev->security_model,NULL );qemu_opts_set_id (fsdev, s->fsconf.fsdev_id); -qemu_fsdev_add (fsdev); +qemu_fsdev_add (fsdev, &err); +if (err) { +error_report_err (err); + }v9fs_device_realize_common (s, &xen_9p_transport,NULL );return 0 ;
vl.c +3 -5
@@ -2249,7 +2249,7 @@ static int chardev_init_func(void *opaque, QemuOpts *opts, Error **errp)#ifdef CONFIG_VIRTFS static int fsdev_init_func (void *opaque,QemuOpts *opts,Error **errp) { -return qemu_fsdev_add (opts); +return qemu_fsdev_add (opts, errp); }#endif
@@ -4188,10 +4188,8 @@ int main(int argc, char **argv, char **envp) chardev_init_func, NULL, &error_fatal);#ifdef CONFIG_VIRTFS -if (qemu_opts_foreach (qemu_find_opts ("fsdev" ), - fsdev_init_func,NULL ,NULL )) { -exit (1 ); - } +qemu_opts_foreach (qemu_find_opts ("fsdev" ), + fsdev_init_func,NULL , &error_fatal);#endif if (qemu_opts_foreach(qemu_find_opts("device"),
Signature · 1 line
2.17.1
PATCH 12/31 l2tpv3: Improve -netdev/netdev_add/-net/... error reporting
In reply to Markus ArmbrusterWhen -netdev l2tpv3 fails, it first reports a specific error, then a generic one, like this:
$ qemu-system-x86_64 -netdev l2tpv3,id=foo,src=,dst=,txsession=1
qemu-system-x86_64: -netdev l2tpv3,id=foo,src=,dst=,txsession=1: l2tpv3_open : could not resolve src, errno = Name or service not known
qemu-system-x86_64: Device 'l2tpv3' could not be initializedWith the command line, the messages go to stderr. In HMP, they go to the monitor. In QMP, the second one becomes the error reply, and the first one goes to stderr.
Convert net_init_tap() to Error. This suppresses the unwanted second message, and makes the specific error the QMP error reply.
--- net/l2tpv3.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)
net/l2tpv3.c +13 -13
@@ -28,6 +28,7 @@#include <netdb.h> #include "net/net.h" #include "clients.h" +#include "qapi/error.h" #include "qemu-common.h" #include "qemu/error-report.h" #include "qemu/option.h"
@@ -528,7 +529,6 @@ int net_init_l2tpv3(const Netdev *netdev,const char *name, NetClientState *peer, Error **errp) { - /* FIXME error_setg(errp, ...) on failure */ const NetdevL2TPv3Options *l2tpv3;NetL2TPV3State *s;NetClientState *nc;
@@ -555,7 +555,7 @@ int net_init_l2tpv3(const Netdev *netdev, }if ((l2tpv3->has_offset) && (l2tpv3->offset >256 )) { -error_report ("l2tpv3_open : offset must be less than 256 bytes" ); +error_setg (errp,"l2tpv3_open : offset must be less than 256 bytes" ); goto outerr; }
@@ -563,6 +563,8 @@ int net_init_l2tpv3(const Netdev *netdev,if (l2tpv3->has_rxcookie && l2tpv3->has_txcookie) { s->cookie = true; }else { +error_setg (errp, +"require both 'rxcookie' and 'txcookie' or neither" ); goto outerr; } }else {
@@ -578,7 +580,8 @@ int net_init_l2tpv3(const Netdev *netdev,if (l2tpv3->has_udp && l2tpv3->udp) { s->udp = true;if (!(l2tpv3->has_srcport && l2tpv3->has_dstport)) { -error_report ("l2tpv3_open : need both src and dst port for udp" ); +error_setg (errp, +"l2tpv3_open : need both src and dst port for udp" ); goto outerr; }else { srcport = l2tpv3->srcport;
@@ -639,20 +642,19 @@ int net_init_l2tpv3(const Netdev *netdev, gairet =getaddrinfo (l2tpv3->src, srcport, &hints, &result);if ((gairet !=0 ) || (result ==NULL )) { -error_report ( -"l2tpv3_open : could not resolve src, errno = %s" , -gai_strerror (gairet) - ); +error_setg (errp,"l2tpv3_open : could not resolve src, errno = %s" , +gai_strerror (gairet)); goto outerr; } fd =socket (result->ai_family, result->ai_socktype, result->ai_protocol);if (fd ==-1 ) { fd = -errno; -error_report ("l2tpv3_open : socket creation failed, errno = %d" , -fd); +error_setg (errp,"l2tpv3_open : socket creation failed, errno = %d" , + -fd); goto outerr; }if (bind (fd, (struct sockaddr *) result->ai_addr, result->ai_addrlen)) { -error_report ("l2tpv3_open : could not bind socket err=%i" , errno); +error_setg (errp,"l2tpv3_open : could not bind socket err=%i" , errno); goto outerr; }if (result) {
@@ -677,10 +679,8 @@ int net_init_l2tpv3(const Netdev *netdev, result =NULL ; gairet =getaddrinfo (l2tpv3->dst, dstport, &hints, &result);if ((gairet !=0 ) || (result ==NULL )) { -error_report ( -"l2tpv3_open : could not resolve dst, error = %s" , -gai_strerror (gairet) - ); +error_setg (errp,"l2tpv3_open : could not resolve dst, error = %s" , +gai_strerror (gairet)); goto outerr; }
Signature · 1 line
2.17.1
PATCH 30/31 blockdev: Convert drive_new() to Error
In reply to Markus ArmbrusterCalling error_report() from within a a function that takes an Error ** argument is suspicious. drive_new() does that, and its caller drive_init_func() then exit()s. Its caller main(), via qemu_opts_foreach(), is fine with it, but clean it up anyway:
* Convert drive_new() to Error
* Update add_init_drive() to report the error received from drive_new().
* Make main() pass &error_fatal through qemu_opts_foreach(), drive_init_func() to drive_new()
* Make default_drive() pass &error_abort through qemu_opts_foreach(), drive_init_func() to drive_new()
--- blockdev.c | 27 ++++++++++++++------------- device-hotplug.c | 5 ++++- include/sysemu/blockdev.h | 3 ++- vl.c | 11 ++++------- 4 files changed, 24 insertions(+), 22 deletions(-)
blockdev.c +14 -13
@@ -759,7 +759,8 @@ QemuOptsList qemu_legacy_drive_opts = { }, }; -DriveInfo *drive_new (QemuOpts *all_opts,BlockInterfaceType block_default_type) +DriveInfo *drive_new (QemuOpts *all_opts,BlockInterfaceType block_default_type, +Error **errp) {const char *value;BlockBackend *blk;
@@ -808,7 +809,7 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type)qemu_opt_rename (all_opts, opt_renames[i].from, opt_renames[i].to, &local_err);if (local_err) { -error_report_err (local_err); +error_propagate (errp, local_err);return NULL ; } }
@@ -819,7 +820,7 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type)bool writethrough;if (bdrv_parse_cache_mode (value, &flags, &writethrough) !=0 ) { -error_report ("invalid cache option" ); +error_setg (errp,"invalid cache option" );return NULL ; }
@@ -847,7 +848,7 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type) &error_abort);qemu_opts_absorb_qdict (legacy_opts, bs_opts, &local_err);if (local_err) { -error_report_err (local_err); +error_propagate (errp, local_err); goto fail; }
@@ -860,7 +861,7 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type) media =MEDIA_CDROM ; read_only = true; }else { -error_report ("'%s' invalid media" , value); +error_setg (errp,"'%s' invalid media" , value); goto fail; } }
@@ -885,7 +886,7 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type) type++) { }if (type ==IF_COUNT ) { -error_report ("unsupported bus type '%s'" , value); +error_setg (errp,"unsupported bus type '%s'" , value); goto fail; } }else {
@@ -902,7 +903,7 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type)if (index !=-1 ) {if (bus_id !=0 || unit_id !=-1 ) { -error_report ("index cannot be used with bus and unit" ); +error_setg (errp,"index cannot be used with bus and unit" ); goto fail; } bus_id =drive_index_to_bus_id (type, index);
@@ -921,13 +922,13 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type) }if (max_devs && unit_id >= max_devs) { -error_report ("unit %d too big (max is %d)" , unit_id, max_devs -1 ); +error_setg (errp,"unit %d too big (max is %d)" , unit_id, max_devs -1 ); goto fail; }if (drive_get (type, bus_id, unit_id) !=NULL ) { -error_report ("drive with bus=%d, unit=%d (index=%d) exists" , - bus_id, unit_id, index); +error_setg (errp,"drive with bus=%d, unit=%d (index=%d) exists" , + bus_id, unit_id, index); goto fail; }
@@ -970,7 +971,7 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type)if (werror !=NULL ) {if (type !=IF_IDE && type !=IF_SCSI && type !=IF_VIRTIO && type !=IF_NONE ) { -error_report ("werror is not supported by this bus type" ); +error_setg (errp,"werror is not supported by this bus type" ); goto fail; }qdict_put_str (bs_opts,"werror" , werror);
@@ -980,7 +981,7 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type)if (rerror !=NULL ) {if (type !=IF_IDE && type !=IF_VIRTIO && type !=IF_SCSI && type !=IF_NONE ) { -error_report ("rerror is not supported by this bus type" ); +error_setg (errp,"rerror is not supported by this bus type" ); goto fail; }qdict_put_str (bs_opts,"rerror" , rerror);
@@ -991,7 +992,7 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type) bs_opts =NULL ;if (!blk) {if (local_err) { -error_report_err (local_err); +error_propagate (errp, local_err); } goto fail; }else {
device-hotplug.c +4 -1
@@ -28,6 +28,7 @@#include "sysemu/block-backend.h" #include "sysemu/blockdev.h" #include "qapi/qmp/qdict.h" +#include "qapi/error.h" #include "qemu/config-file.h" #include "qemu/option.h" #include "sysemu/sysemu.h"
@@ -36,6 +37,7 @@static DriveInfo *add_init_drive (const char *optstr) { +Error *err =NULL ;DriveInfo *dinfo;QemuOpts *opts;MachineClass *mc;
@@ -45,8 +47,9 @@ static DriveInfo *add_init_drive(const char *optstr)return NULL ; mc =MACHINE_GET_CLASS (current_machine); - dinfo =drive_new (opts, mc->block_default_type); + dinfo =drive_new (opts, mc->block_default_type, &err);if (!dinfo) { +error_report_err (err);qemu_opts_del (opts);return NULL ; }
include/sysemu/blockdev.h +2 -1
@@ -54,7 +54,8 @@ DriveInfo *drive_get_next(BlockInterfaceType type);QemuOpts *drive_def (const char *optstr);QemuOpts *drive_add (BlockInterfaceType type,int index,const char *file,const char *optstr); -DriveInfo *drive_new (QemuOpts *arg,BlockInterfaceType block_default_type); +DriveInfo *drive_new (QemuOpts *arg,BlockInterfaceType block_default_type, +Error **errp);/* device-hotplug */
vl.c +4 -7
@@ -1129,7 +1129,7 @@ static int drive_init_func(void *opaque, QemuOpts *opts, Error **errp) {BlockInterfaceType *block_default_type = opaque; -return drive_new (opts, *block_default_type) ==NULL ; +return drive_new (opts, *block_default_type, errp) ==NULL ; }static int drive_enable_snapshot (void *opaque,QemuOpts *opts,Error **errp)
@@ -1155,8 +1155,7 @@ static void default_drive(int enable, int snapshot, BlockInterfaceType type,drive_enable_snapshot (NULL , opts,NULL ); } - dinfo =drive_new (opts, type); -assert (dinfo); + dinfo =drive_new (opts, type, &error_abort); dinfo->is_default = true; }
@@ -4348,10 +4347,8 @@ int main(int argc, char **argv, char **envp)qemu_opts_foreach (qemu_find_opts ("drive" ), drive_enable_snapshot,NULL ,NULL ); } -if (qemu_opts_foreach (qemu_find_opts ("drive" ), drive_init_func, - &machine_class->block_default_type,NULL )) { -exit (1 ); - } +qemu_opts_foreach (qemu_find_opts ("drive" ), drive_init_func, + &machine_class->block_default_type, &error_fatal);default_drive (default_cdrom, snapshot, machine_class->block_default_type,2 ,CDROM_OPTS );
Signature · 1 line
2.17.1
PATCH 7/31 9pfs: Fix CLI parsing crash on error
In reply to Markus ArmbrusterCalling error_report() in a function that takes an Error ** argument is suspicious. 9p-handle.c's handle_parse_opts() does that, and then fails without setting an error. Wrong. Its caller crashes when it tries to report the error:
$ qemu-system-x86_64 -nodefaults -fsdev id=foo,fsdriver=handle
qemu-system-x86_64: -fsdev id=foo,fsdriver=handle: warning: handle backend is deprecated
qemu-system-x86_64: -fsdev id=foo,fsdriver=handle: fsdev: No path specified
Segmentation fault (core dumped)Screwed up when commit 91cda4e8f37 (v2.12.0) converted the function to Error. Fix by calling error_setg() instead of error_report().
--- hw/9pfs/9p-handle.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
hw/9pfs/9p-handle.c +4 -2
@@ -19,6 +19,7 @@#include <grp.h> #include <sys/socket.h> #include <sys/un.h> +#include "qapi/error.h" #include "qemu/xattr.h" #include "qemu/cutils.h" #include "qemu/error-report.h"
@@ -655,12 +656,13 @@ static int handle_parse_opts(QemuOpts *opts, FsDriverEntry *fse, Error **errp)warn_report ("handle backend is deprecated" );if (sec_model) { -error_report ("Invalid argument security_model specified with handle fsdriver" ); +error_setg (errp, +"Invalid argument security_model specified with handle fsdriver" );return -1 ; }if (!path) { -error_report ("fsdev: No path specified" ); +error_setg (errp,"fsdev: No path specified" );return -1 ; } fse->path =g_strdup (path);
Signature · 1 line
2.17.1
Re: [Qemu-devel] [PATCH 14/31] numa: Fix QMP command set-numa-node error handling
In reply to Markus ArmbrusterQuoted 28 lines · Markus Armbruster
Calling
error_report()in a function that takes an Error ** argument is suspicious.parse_numa_node()does that, and then exit()s. It also passes&error_fataltomachine_set_cpu_numa_node(). Both wrong. Attempting to configure numa when the machine doesn't support it kills the VM:$ qemu-system-x86_64 -nodefaults -S -display none -M none -preconfig -qmp stdio {"QMP": {"version": {"qemu": {"micro": 50, "minor": 0, "major": 3}, "package": "v3.0.0-837-gc5e4e49258"}, "capabilities": []}} {"execute": "qmp_capabilities"} {"return": {}} {"execute": "set-numa-node", "arguments": {"type": "node"}} NUMA is not supported by this machine-type $ echo $? 1Messed up when commit
64c2a8f6d3fand7c88e65d9e9(v2.10.0) added incorrect error handling right next to correct examples. Latent bug until commitf3be67812c2(v3.0.0) made it accessible via QMP. Fairly harmless in practice, because it's limited toRUN_STATE_PRECONFIG. The fix is obvious: replaceerror_report();exit()byerror_setg(); return.This affects parse_numa_node()'s other caller
numa_complete_configuration(): since it ignores errors, the "NUMA is not supported by this machine-type" is now ignored, too. But that error is as unexpected there as any other. Change it to abort on error instead.
Quoted 5 lines
Fixes f3be67812c226162f86ce92634bd913714445420Cc Igor Mammedov <[email protected]>Signed-off-by Markus Armbruster <[email protected]>fixup! numa: Fix QMP command set-numa-node error handling
I assume this last line was kept by mistake, and I'm removing it while committing.
Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH 25/31] numa: Clean up error reporting in parse_numa()
In reply to Markus ArmbrusterQuoted 9 lines · Markus Armbruster
Calling
error_report()in a function that takes an Error ** argument is suspicious.parse_numa()does that, and then fails without setting an error. Its callermain(), viaqemu_opts_foreach(), is fine with it, but clean it up anyway.While there, give
parse_numa()internal linkage.Cc Eduardo Habkost <[email protected]>Signed-off-by Markus Armbruster <[email protected]>
Queueing on machine-next. Thanks!
Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH 04/31] vfio: Use warn_report() & friends to report warnings
In reply to Markus ArmbrusterQuoted 17 lines · On Mon, 8 Oct 2018 19:30:58 +0200 Markus Armbruster <[email protected]> wrote:
The vfio code reports warnings like
error_report(WARN_PREFIX "Could not frobnicate", DEV-NAME);where
WARN_PREFIXis defined so the message comes out asvfio warning: DEV-NAME: Could not frobnicate
This usage predates the introduction of
warn_report()& friends in commit97f40301f1d. It's time to convert to that interface. Since these functions already prefix the message with "warning: ", replaceWARN_PREFIXbyVFIO_MSG_PREFIX, so the messages come out likewarning: vfio DEV-NAME: Could not frobnicate
The next commit will replace
ERR_PREFIX.
Quoted 7 lines
Cc Alex Williamson <[email protected]>Signed-off-by Markus Armbruster <[email protected]>--- hw/vfio/pci.c | 14 +++++++------- hw/vfio/platform.c | 4 ++-- include/hw/vfio/vfio-common.h | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-)
Re: [Qemu-devel] [PATCH 05/31] vfio: Clean up error reporting after previous commit
In reply to Markus ArmbrusterQuoted 20 lines · On Mon, 8 Oct 2018 19:30:59 +0200 Markus Armbruster <[email protected]> wrote:
The previous commit changed vfio's warning messages from
vfio warning: DEV-NAME: Could not frobnicate
to
warning: vfio DEV-NAME: Could not frobnicate
To match this change, change error messages from
vfio error: DEV-NAME: On fire
to
vfio DEV-NAME: On fire
Note the loss of "error". If we think marking error messages that way is a good idea, we should mark *all* error messages, i.e. make
error_report()print it.
Quoted 8 lines
Cc Alex Williamson <[email protected]>Signed-off-by Markus Armbruster <[email protected]>--- hw/vfio/pci-quirks.c | 4 ++-- hw/vfio/pci.c | 8 ++++---- hw/vfio/platform.c | 2 +- include/hw/vfio/vfio-common.h | 1 - 4 files changed, 7 insertions(+), 8 deletions(-)
Re: [Qemu-devel] [PATCH 01/31] Use error_fatal to simplify obvious fatal errors (again)
In reply to Markus ArmbrusterQuoted 2 lines · Markus Armbruster
Add a slight improvement of the Coccinelle semantic patch from commit
07d04a0219b,
which shares the same commit title, but does not actually have a semantic patch, but rather defers to the even older 007b065. But I'm not too worried about either the duplicated commit title nor the chain of references to follow - as this is a no-semantic-change patch rather than a bugfix, it's less likely to cause confusion to any downstream backport efforts.
Quoted 2 lines
and use it to clean up. It leaves dead Error * variables behind, cleaned up manually.
Coccinelle can handle that too, if we want to make the .cocci file longer (but off-hand, I don't remember the exact semantic patch formula to express a variable that is initialized but then never used, as a result of applying earlier semantic patches). So the manual cleanup for now still seems tractable.
Quoted 17 lines
Cc David Gibson <[email protected]>Cc Alexander Graf <[email protected]>Cc Eric Blake <[email protected]>Cc Paolo Bonzini <[email protected]>Signed-off-by Markus Armbruster <[email protected]>--- hw/intc/xics_kvm.c | 7 +------ qemu-nbd.c | 6 +----- scripts/coccinelle/use-error_fatal.cocci | 20 ++++++++++++++++++++ vl.c | 7 +------ 4 files changed, 23 insertions(+), 17 deletions(-)create mode 100644
scripts/coccinelle/use-error_fatal.cocci+++
b/scripts/coccinelle/use-error_fatal.cocci
scripts/coccinelle/use-error_fatal.cocci line 5
Quoted 5 lines
scripts/coccinelle/use-error_fatal.cocci new file +5
-0@@ -0,0 +1,20 @@ +@@ +type T; +identifier FUN, RET; +expression list ARGS; +expression ERR, EC, FAIL;
The slight improvement from the original git commit log script is the addition of FAIL,
scripts/coccinelle/use-error_fatal.cocci line 17
Quoted 12 lines
scripts/coccinelle/use-error_fatal.cocci new file +12
-0+@@ +( +- T RET = FUN(ARGS, &ERR); ++ T RET = FUN(ARGS, &error_fatal); +| +- RET = FUN(ARGS, &ERR); ++ RET = FUN(ARGS, &error_fatal); +| +- FUN(ARGS, &ERR); ++ FUN(ARGS, &error_fatal); +) +- if (FAIL) {
and a check for arbitrary condition FAIL rather than a more specific ERR != NULL. Makes sense.
scripts/coccinelle/use-error_fatal.cocci line 20
Quoted 3 lines
scripts/coccinelle/use-error_fatal.cocci new file +3
-0+- error_report_err(ERR); +- exit(EC); +- }
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [Qemu-devel] [PATCH 02/31] block: Use warn_report() & friends to report warnings
In reply to Markus ArmbrusterQuoted 8 lines · Markus Armbruster
Calling
error_report()in a function that takes an Error ** argument is suspicious. Convert a few that are actually warnings towarn_report().While there, split warnings consisting of multiple sentences to conform to conventions spelled out in warn_report()'s contract, and improve a rather useless warning in
sheepdog.c.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [Qemu-devel] [PATCH 18/31] qom: Clean up error reporting in user_creatable_add_opts_foreach()
In reply to Markus ArmbrusterQuoted 5 lines · Markus Armbruster
Calling
error_report()in a function that takes an Error ** argument is suspicious.user_creatable_add_opts_foreach()does that, and then fails without setting an error. Its callermain(), viaqemu_opts_foreach(), is fine with it, but clean it up anyway.
Quoted 8 lines
Cc Daniel P. Berrangé <[email protected]>Signed-off-by Markus Armbruster <[email protected]>--- qemu-io.c | 8 +++----- qemu-nbd.c | 8 +++----- qom/object_interfaces.c | 4 +--- vl.c | 16 ++++++---------- 4 files changed, 13 insertions(+), 23 deletions(-)
While I could take this through my NBD tree, I think it makes more sense to go through your error tree with the rest of the series.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [Qemu-devel] [PATCH 28/31] fsdev: Clean up error reporting in qemu_fsdev_add()
In reply to Markus ArmbrusterQuoted 1 line · Markus Armbruster
Calling
error_report()from within a a function that takes an Error **
s/a a/a/
Quoted 5 lines
argument is suspicious.
qemu_fsdev_add()does that, and its callerfsdev_init_func()then fails without setting an error. Its callermain(), viaqemu_opts_foreach(), is fine with it, but clean it up anyway.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [Qemu-devel] [PATCH 30/31] blockdev: Convert drive_new() to Error
In reply to Markus ArmbrusterQuoted 1 line · Markus Armbruster
Calling
error_report()from within a a function that takes an Error **
s/a a/a/
Quoted 18 lines
argument is suspicious.
drive_new()does that, and its callerdrive_init_func()then exit()s. Its callermain(), viaqemu_opts_foreach(), is fine with it, but clean it up anyway:* Convert
drive_new()to Error* Update
add_init_drive()to report the error received fromdrive_new().* Make
main()pass&error_fatalthroughqemu_opts_foreach(),drive_init_func()todrive_new()* Make
default_drive()pass&error_abortthroughqemu_opts_foreach(),drive_init_func()todrive_new()Cc Kevin Wolf <[email protected]>Cc Max Reitz <[email protected]>Signed-off-by Markus Armbruster <[email protected]>
Quoted 7 lines
--- blockdev.c | 27 ++++++++++++++------------- device-hotplug.c | 5 ++++- include/sysemu/blockdev.h | 3 ++- vl.c | 11 ++++------- 4 files changed, 24 insertions(+), 22 deletions(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [Qemu-devel] [PATCH 29/31] vl: Assert drive_new() does not fail in default_drive()
In reply to Markus ArmbrusterQuoted 9 lines · Markus Armbruster
If creating (empty) default drives fails, it's a bug. Therefore,
assert()is more appropriate than exit(1).Cc Kevin Wolf <[email protected]>Cc Max Reitz <[email protected]>Signed-off-by Markus Armbruster <[email protected]>--- vl.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
The assert disappears in the next patch (replaced by an &error_fatal), but the separation of patches makes sense.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [Qemu-devel] [PATCH 29/31] vl: Assert drive_new() does not fail in default_drive()
In reply to Markus ArmbrusterQuoted 9 lines · Markus Armbruster
If creating (empty) default drives fails, it's a bug. Therefore,
assert()is more appropriate than exit(1).Cc Kevin Wolf <[email protected]>Cc Max Reitz <[email protected]>Signed-off-by Markus Armbruster <[email protected]>--- vl.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
Re: [Qemu-devel] [PATCH 30/31] blockdev: Convert drive_new() to Error
In reply to Markus ArmbrusterQuoted 3 lines · Markus Armbruster
Calling
error_report()from within a a function that takes an Error ** argument is suspicious.drive_new()does that, and its callerdrive_init_func()then exit()s.
I'm afraid I don't quite follow you here. There is no function here that takes an Error ** already and then calls error_report(). There is however drive_new() that does not take an Error **, consequentially calls error_report(), and there is its caller drive_init_func() which does take an Error ** but does not set it.
So while I fully agree with you to make drive_new() take an Error ** (and thus effectively fix drive_init_func()), I don't quite understand this explanation.
(Furthermore, drive_init_func() does not exit(). It's main() that exit()s after calling drive_init_func().)
Quoted 29 lines
Its caller
main(), viaqemu_opts_foreach(), is fine with it, but clean it up anyway:* Convert
drive_new()to Error* Update
add_init_drive()to report the error received fromdrive_new().* Make
main()pass&error_fatalthroughqemu_opts_foreach(),drive_init_func()todrive_new()* Make
default_drive()pass&error_abortthroughqemu_opts_foreach(),drive_init_func()todrive_new()Cc Kevin Wolf <[email protected]>Cc Max Reitz <[email protected]>Signed-off-by Markus Armbruster <[email protected]>--- blockdev.c | 27 ++++++++++++++------------- device-hotplug.c | 5 ++++- include/sysemu/blockdev.h | 3 ++- vl.c | 11 ++++------- 4 files changed, 24 insertions(+), 22 deletions(-)blockdev.c +0
-0@@ -759,7 +759,8 @@ QemuOptsList qemu_legacy_drive_opts = {
[...]
blockdev.c DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type) · line 996
Quoted 7 lines
blockdev.c +1
-1@@ -991,7 +992,7 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type) bs_opts =NULL ;if (!blk) {if (local_err) { -error_report_err (local_err); +error_propagate (errp, local_err); }
Wait, what would be the case where blockdev_init() returns NULL but *errp remains unse——— oh no.
There is only one case which is someone specified "format=help". Hm. I suppose you are as unhappy as me about the fact that because of this drive_new() cannot guarantee that *errp is set in case of an error.
I think it's ""fine"" (*gnashing teeth*) to keep it this way, but it means that callers need to continue to check the return value and not *errp alone.
Quoted 61 lines
blockdev.c +0
-0goto fail; }else {device-hotplug.c +4
-1@@ -28,6 +28,7 @@#include "sysemu/block-backend.h" #include "sysemu/blockdev.h" #include "qapi/qmp/qdict.h" +#include "qapi/error.h" #include "qemu/config-file.h" #include "qemu/option.h" #include "sysemu/sysemu.h" @@ -36,6 +37,7 @@static DriveInfo *add_init_drive (const char *optstr) { +Error *err =NULL ;DriveInfo *dinfo;QemuOpts *opts;MachineClass *mc;@@ -45,8 +47,9 @@ static DriveInfo *add_init_drive(const char *optstr)return NULL ; mc =MACHINE_GET_CLASS (current_machine); - dinfo =drive_new (opts, mc->block_default_type); + dinfo =drive_new (opts, mc->block_default_type, &err);if (!dinfo) { +error_report_err (err);qemu_opts_del (opts);return NULL ; }include/sysemu/blockdev.h +2
-1@@ -54,7 +54,8 @@ DriveInfo *drive_get_next(BlockInterfaceType type);QemuOpts *drive_def (const char *optstr);QemuOpts *drive_add (BlockInterfaceType type,int index,const char *file,const char *optstr); -DriveInfo *drive_new (QemuOpts *arg,BlockInterfaceType block_default_type); +DriveInfo *drive_new (QemuOpts *arg,BlockInterfaceType block_default_type, +Error **errp);/* device-hotplug */ vl.c +1
-1@@ -1129,7 +1129,7 @@ static int drive_init_func(void *opaque, QemuOpts *opts, Error **errp) {BlockInterfaceType *block_default_type = opaque; -return drive_new (opts, *block_default_type) ==NULL ; +return drive_new (opts, *block_default_type, errp) ==NULL ; }static int drive_enable_snapshot (void *opaque,QemuOpts *opts,Error **errp)
vl.c static void default_drive(int enable, int snapshot, BlockInterfaceType type, · line 1158
Quoted 6 lines
vl.c +1
-2@@ -1155,8 +1155,7 @@ static void default_drive(int enable, int snapshot, BlockInterfaceType type,drive_enable_snapshot (NULL , opts,NULL ); } - dinfo =drive_new (opts, type); -assert (dinfo); + dinfo =drive_new (opts, type, &error_abort);
Which means the assertion is still necessary here.
vl.c int main(int argc, char **argv, char **envp) · line 4351
Quoted 13 lines
vl.c +2
-4dinfo->is_default = true; }@@ -4348,10 +4347,8 @@ int main(int argc, char **argv, char **envp)qemu_opts_foreach (qemu_find_opts ("drive" ), drive_enable_snapshot,NULL ,NULL ); } -if (qemu_opts_foreach (qemu_find_opts ("drive" ), drive_init_func, - &machine_class->block_default_type,NULL )) { -exit (1 ); - } +qemu_opts_foreach (qemu_find_opts ("drive" ), drive_init_func, + &machine_class->block_default_type, &error_fatal);
And we still have to keep an exit() here.
Alternative: You transform blockdev_init()'s format=help into an error (or construct a new error in drive_new() if blockdev_init() returned NULL but no error).
Max
Quoted 4 lines
vl.c +0
-0default_drive (default_cdrom, snapshot, machine_class->block_default_type,2 ,CDROM_OPTS );
Re: [Qemu-devel] [PATCH 01/31] Use error_fatal to simplify obvious fatal errors (again)
In reply to Markus ArmbrusterQuoted 9 lines · Markus Armbruster
Add a slight improvement of the Coccinelle semantic patch from commit
07d04a0219b, and use it to clean up. It leaves dead Error * variables behind, cleaned up manually.Cc David Gibson <[email protected]>Cc Alexander Graf <[email protected]>Cc Eric Blake <[email protected]>Cc Paolo Bonzini <[email protected]>Signed-off-by Markus Armbruster <[email protected]>
ppc part
Quoted 95 lines
--- hw/intc/xics_kvm.c | 7 +------ qemu-nbd.c | 6 +----- scripts/coccinelle/use-error_fatal.cocci | 20 ++++++++++++++++++++ vl.c | 7 +------ 4 files changed, 23 insertions(+), 17 deletions(-) create mode 100644 scripts/coccinelle/use-error_fatal.coccihw/intc/xics_kvm.c +1
-6@@ -198,17 +198,12 @@ static void ics_get_kvm_state(ICSState *ics) {uint64_t state;int i; -Error *local_err =NULL ;for (i =0 ; i < ics->nr_irqs; i++) {ICSIRQState *irq = &ics->irqs[i];kvm_device_access (kernel_xics_fd,KVM_DEV_XICS_GRP_SOURCES , - i + ics->offset, &state, false, &local_err); -if (local_err) { -error_report_err (local_err); -exit (1 ); - } + i + ics->offset, &state, false, &error_fatal); irq->server = state &KVM_XICS_DESTINATION_MASK ; irq->saved_priority = (state >>KVM_XICS_PRIORITY_SHIFT )qemu-nbd.c +1
-5@@ -1002,11 +1002,7 @@ int main(int argc, char **argv) } exp =nbd_export_new (bs, dev_offset, fd_size, nbdflags, nbd_export_closed, - writethrough,NULL , &local_err); -if (!exp) { -error_report_err (local_err); -exit (EXIT_FAILURE ); - } + writethrough,NULL , &error_fatal);nbd_export_set_name (exp, export_name);nbd_export_set_description (exp, export_description);scripts/coccinelle/use-error_fatal.cocci new file +20
-0@@ -0,0 +1,20 @@ +@@ +type T; +identifier FUN, RET; +expression list ARGS; +expression ERR, EC, FAIL; +@@ +( +- T RET = FUN(ARGS, &ERR); ++ T RET = FUN(ARGS, &error_fatal); +| +- RET = FUN(ARGS, &ERR); ++ RET = FUN(ARGS, &error_fatal); +| +- FUN(ARGS, &ERR); ++ FUN(ARGS, &error_fatal); +) +- if (FAIL) { +- error_report_err(ERR); +- exit(EC); +- }vl.c +1
-6@@ -2002,15 +2002,10 @@ static void select_vgahw(const char *p)static void parse_display_qapi (const char *optarg) { -Error *err =NULL ;DisplayOptions *opts;Visitor *v; - v =qobject_input_visitor_new_str (optarg,"type" , &err); -if (!v) { -error_report_err (err); -exit (1 ); - } + v =qobject_input_visitor_new_str (optarg,"type" , &error_fatal);visit_type_DisplayOptions (v,NULL , &opts, &error_fatal);QAPI_CLONE_MEMBERS (DisplayOptions, &dpy, opts);
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Re: [Qemu-devel] [PATCH 03/31] cpus hw target: Use warn_report() & friends to report warnings
In reply to Markus ArmbrusterQuoted 7 lines · Markus Armbruster
Calling
error_report()in a function that takes an Error ** argument is suspicious. Convert a few that are actually warnings towarn_report().While there, split a warning consisting of multiple sentences to conform to conventions spelled out in warn_report()'s contract.
Quoted 7 lines
Cc Alex Bennée <[email protected]>Cc Mark Cave-Ayland <[email protected]>Cc Alex Williamson <[email protected]>Cc Fam Zheng <[email protected]>Cc Wei Huang <[email protected]>Cc David Gibson <[email protected]>Signed-off-by Markus Armbruster <[email protected]>
ppc part
Quoted 150 lines
--- cpus.c | 8 ++++---- hw/display/cg3.c | 2 +- hw/display/tcx.c | 2 +- hw/misc/ivshmem.c | 4 ++-- hw/net/virtio-net.c | 8 ++++---- hw/virtio/virtio-pci.c | 4 ++-- target/i386/cpu.c | 17 +++++++++-------- target/ppc/translate_init.inc.c | 4 ++-- 8 files changed, 25 insertions(+), 24 deletions(-)cpus.c +4
-4@@ -211,12 +211,12 @@ void qemu_tcg_configure(QemuOpts *opts, Error **errp)error_setg (errp,"No MTTCG when icount is enabled" ); }else {#ifndef TARGET_SUPPORTS_MTTCG -error_report ("Guest not yet converted to MTTCG - " -"you may get unexpected results" ); +warn_report ("Guest not yet converted to MTTCG - " +"you may get unexpected results" );#endif if (!check_tcg_memory_orders_compatible ()) { -error_report ("Guest expects a stronger memory ordering " -"than the host provides" ); +warn_report ("Guest expects a stronger memory ordering " +"than the host provides" );error_printf ("This may cause strange/hard to debug errors\n" ); } mttcg_enabled = true;hw/display/cg3.c +1
-1@@ -307,7 +307,7 @@ static void cg3_realizefn(DeviceState *dev, Error **errp) ret =load_image_mr (fcode_filename, &s->rom);g_free (fcode_filename);if (ret <0 || ret >FCODE_MAX_ROM_SIZE ) { -error_report ("cg3: could not load prom '%s'" ,CG3_ROM_FILE ); +warn_report ("cg3: could not load prom '%s'" ,CG3_ROM_FILE ); } }hw/display/tcx.c +1
-1@@ -823,7 +823,7 @@ static void tcx_realizefn(DeviceState *dev, Error **errp) ret =load_image_mr (fcode_filename, &s->rom);g_free (fcode_filename);if (ret <0 || ret >FCODE_MAX_ROM_SIZE ) { -error_report ("tcx: could not load prom '%s'" ,TCX_ROM_FILE ); +warn_report ("tcx: could not load prom '%s'" ,TCX_ROM_FILE ); } }hw/misc/ivshmem.c +2
-2@@ -1292,8 +1292,8 @@ static void ivshmem_realize(PCIDevice *dev, Error **errp)IVShmemState *s =IVSHMEM_COMMON (dev);if (!qtest_enabled ()) { -error_report ("ivshmem is deprecated, please use ivshmem-plain" -" or ivshmem-doorbell instead" ); +warn_report ("ivshmem is deprecated, please use ivshmem-plain" +" or ivshmem-doorbell instead" ); }if (qemu_chr_fe_backend_connected (&s->server_chr) + !!s->shmobj !=1 ) {hw/net/virtio-net.c +4
-4@@ -2020,10 +2020,10 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp)if (n->net_conf.tx &&strcmp (n->net_conf.tx,"timer" ) &&strcmp (n->net_conf.tx,"bh" )) { -error_report ("virtio-net: " -"Unknown option tx=%s, valid options: \"timer\" \"bh\"" , - n->net_conf.tx); -error_report ("Defaulting to \"bh\"" ); +warn_report ("virtio-net: " +"Unknown option tx=%s, valid options: \"timer\" \"bh\"" , + n->net_conf.tx); +error_printf ("Defaulting to \"bh\"" ); } n->net_conf.tx_queue_size = MIN(virtio_net_max_tx_queue_size(n),hw/virtio/virtio-pci.c +2
-2@@ -1683,8 +1683,8 @@ static void virtio_pci_device_plugged(DeviceState *d, Error **errp)if (err) {/* Notice when a system that supports MSIx can't initialize it */ if (err != -ENOTSUP ) { -error_report ("unable to init msix vectors to %" PRIu32, - proxy->nvectors); +warn_report ("unable to init msix vectors to %" PRIu32, + proxy->nvectors); } proxy->nvectors =0 ; }target/i386/cpu.c +9
-8@@ -5123,14 +5123,15 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)* NOTE: the following code has to follow qemu_init_vcpu(). Otherwise * cs->nr_threads hasn't be populated yet and the checking is incorrect. */ -if (IS_AMD_CPU (env) && - !(env->features[FEAT_8000_0001_ECX ] &CPUID_EXT3_TOPOEXT ) && - cs->nr_threads >1 && !ht_warned) { -error_report ("This family of AMD CPU doesn't support " -"hyperthreading(%d). Please configure -smp " -"options properly or try enabling topoext feature." , - cs->nr_threads); - ht_warned = true; +if (IS_AMD_CPU (env) && + !(env->features[FEAT_8000_0001_ECX ] &CPUID_EXT3_TOPOEXT ) && + cs->nr_threads >1 && !ht_warned) { +warn_report ("This family of AMD CPU doesn't support " +"hyperthreading(%d)" , + cs->nr_threads); +error_printf ("Please configure -smp options properly" +" or try enabling topoext feature.\n" ); + ht_warned = true; }x86_cpu_apic_realize (cpu, &local_err);target/ppc/translate_init.inc.c +2
-2@@ -8381,8 +8381,8 @@ static void getset_compat_deprecated(Object *obj, Visitor *v, const char *name,QNull *null =NULL ;if (!qtest_enabled ()) { -error_report ("CPU 'compat' property is deprecated and has no effect; " -"use max-cpu-compat machine property instead" ); +warn_report ("CPU 'compat' property is deprecated and has no effect; " +"use max-cpu-compat machine property instead" ); }visit_type_null (v, name, &null,NULL );qobject_unref (null);
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Re: [Qemu-devel] [PATCH 09/31] ioapic: Fix error handling in realize()
In reply to Markus ArmbrusterQuoted 7 lines · Markus Armbruster
Calling
error_report()in a function that takes an Error ** argument is suspicious.ioapic_realize()does that, and then exit()s. Currently mostly harmless, as the device cannot be hot-plugged.Fixes 20fd4b7b6d9282fe0cb83601f1821f31bd257458Cc Peter Xu <[email protected]>Signed-off-by Markus Armbruster <[email protected]>
Signature · 1 line
Peter Xu
Re: [Qemu-devel] [PATCH 20/31] vl: Clean up error reporting in machine_set_property()
In reply to Markus ArmbrusterQuoted 6 lines · Markus Armbruster
Calling
error_report()in a function that takes an Error ** argument is suspicious.machine_set_property()does that, and then fails without setting an error. Its callermain(), viaqemu_opts_foreach(), is fine with it, but clean it up anyway.Signed-off-by Markus Armbruster <[email protected]>
Quoted 32 lines
--- vl.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)vl.c +3
-6@@ -2676,7 +2676,7 @@ static int machine_set_property(void *opaque,g_free (qom_name);if (local_err) { -error_report_err (local_err); +error_propagate (errp, local_err);return -1 ; }@@ -4201,11 +4201,8 @@ int main(int argc, char **argv, char **envp) } machine_opts =qemu_get_machine_opts (); -if (qemu_opt_foreach (machine_opts, machine_set_property, current_machine, -NULL )) { -object_unref (OBJECT (current_machine)); -exit (1 ); - } +qemu_opt_foreach (machine_opts, machine_set_property, current_machine, + &error_fatal);configure_accelerator (current_machine);
Re: [Qemu-devel] [PATCH 21/31] vl: Clean up error reporting in mon_init_func()
In reply to Markus ArmbrusterQuoted 6 lines · Markus Armbruster
Calling
error_report()in a function that takes an Error ** argument is suspicious.mon_init_func()does that, and then fails without setting an error. Its callermain(), viaqemu_opts_foreach(), is fine with it, but clean it up anyway.Signed-off-by Markus Armbruster <[email protected]>
Quoted 44 lines
--- vl.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)vl.c +6
-8@@ -2270,8 +2270,8 @@ static int mon_init_func(void *opaque, QemuOpts *opts, Error **errp) }else if (strcmp (mode,"control" ) ==0 ) { flags =MONITOR_USE_CONTROL ; }else { -error_report ("unknown monitor mode \"%s\"" , mode); -exit (1 ); +error_setg (errp,"unknown monitor mode \"%s\"" , mode); +return -1 ; }if (qemu_opt_get_bool (opts,"pretty" ,0 ))@@ -2285,8 +2285,8 @@ static int mon_init_func(void *opaque, QemuOpts *opts, Error **errp) chardev =qemu_opt_get (opts,"chardev" ); chr =qemu_chr_find (chardev);if (chr ==NULL ) { -error_report ("chardev \"%s\" not found" , chardev); -exit (1 ); +error_setg (errp,"chardev \"%s\" not found" , chardev); +return -1 ; }monitor_init (chr, flags);@@ -4365,10 +4365,8 @@ int main(int argc, char **argv, char **envp)default_drive (default_floppy, snapshot,IF_FLOPPY ,0 ,FD_OPTS );default_drive (default_sdcard, snapshot,IF_SD ,0 ,SD_OPTS ); -if (qemu_opts_foreach (qemu_find_opts ("mon" ), - mon_init_func,NULL ,NULL )) { -exit (1 ); - } +qemu_opts_foreach (qemu_find_opts ("mon" ), + mon_init_func,NULL , &error_fatal);if (foreach_device_config (DEV_SERIAL , serial_parse) <0 )exit (1 );
Re: [Qemu-devel] [PATCH 23/31] vl: Clean up error reporting in device_init_func()
In reply to Markus ArmbrusterQuoted 6 lines · Markus Armbruster
Calling
error_report()in a function that takes an Error ** argument is suspicious.device_init_func()does that, and then fails without setting an error. Its callermain(), viaqemu_opts_foreach(), is fine with it, but clean it up anyway.Signed-off-by Markus Armbruster <[email protected]>
Quoted 36 lines
--- vl.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)vl.c +3
-7@@ -2222,12 +2222,10 @@ static int device_help_func(void *opaque, QemuOpts *opts, Error **errp)static int device_init_func (void *opaque,QemuOpts *opts,Error **errp) { -Error *err =NULL ;DeviceState *dev; - dev =qdev_device_add (opts, &err); + dev =qdev_device_add (opts, errp);if (!dev) { -error_report_err (err);return -1 ; }object_unref (OBJECT (dev));@@ -4444,10 +4442,8 @@ int main(int argc, char **argv, char **envp)/* init generic devices */ rom_set_order_override (FW_CFG_ORDER_OVERRIDE_DEVICE ); -if (qemu_opts_foreach (qemu_find_opts ("device" ), - device_init_func,NULL ,NULL )) { -exit (1 ); - } +qemu_opts_foreach (qemu_find_opts ("device" ), + device_init_func,NULL , &error_fatal);cpu_synchronize_all_post_init ();
Re: [Qemu-devel] [PATCH 31/31] vl: Simplify call of parse_name()
In reply to Markus ArmbrusterQuoted 5 lines · Markus Armbruster
main()checks forparse_name()failure even though it can't actually fail. That's okay. Simplify it to check by passing&error_fatal, like the other users ofqemu_opts_foreach().Signed-off-by Markus Armbruster <[email protected]>
Quoted 22 lines
--- vl.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)vl.c +2
-4@@ -3926,10 +3926,8 @@ int main(int argc, char **argv, char **envp) }#endif -if (qemu_opts_foreach (qemu_find_opts ("name" ), - parse_name,NULL ,NULL )) { -exit (1 ); - } +qemu_opts_foreach (qemu_find_opts ("name" ), + parse_name,NULL , &error_fatal);#ifndef _WIN32 qemu_opts_foreach(qemu_find_opts("add-fd"),
Re: [Qemu-devel] [PATCH 19/31] vl: Clean up error reporting in parse_add_fd()
In reply to Markus ArmbrusterQuoted 6 lines · Markus Armbruster
Calling
error_report()in a function that takes an Error ** argument is suspicious.chardev_init_func()does that, and then fails without setting an error. Its callermain(), viaqemu_opts_foreach(), is fine with it, but clean it up anyway.Signed-off-by Markus Armbruster <[email protected]>
Quoted 31 lines
--- vl.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)vl.c +3
-5@@ -2239,7 +2239,7 @@ static int chardev_init_func(void *opaque, QemuOpts *opts, Error **errp)if (!qemu_chr_new_from_opts (opts, &local_err)) {if (local_err) { -error_report_err (local_err); +error_propagate (errp, local_err);return -1 ; }exit (0 );@@ -4185,10 +4185,8 @@ int main(int argc, char **argv, char **envp) user_creatable_add_opts_foreach, object_create_initial, &error_fatal); -if (qemu_opts_foreach (qemu_find_opts ("chardev" ), - chardev_init_func,NULL ,NULL )) { -exit (1 ); - } +qemu_opts_foreach (qemu_find_opts ("chardev" ), + chardev_init_func,NULL , &error_fatal);#ifdef CONFIG_VIRTFS if (qemu_opts_foreach(qemu_find_opts("fsdev"),
Re: [Qemu-devel] [PATCH 06/31] char: Use error_printf() to print help and such
In reply to Markus ArmbrusterQuoted 12 lines · Markus Armbruster
Calling
error_report()in a function that takes an Error ** argument is suspicious. Convert a few that are actually help and such toerror_printf().Improves output of -chardev help from
qemu-system-x86_64: -chardev help: Available chardev backend types:
serial
...to
Quoted 7 lines
Available chardev backend types:
serial
...Cc Paolo Bonzini <[email protected]>Cc "Marc-André Lureau" <[email protected]>Signed-off-by Markus Armbruster <[email protected]>
Quoted 32 lines
--- chardev/char-pty.c | 2 +- chardev/char.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)chardev/char-pty.c +1
-1@@ -259,7 +259,7 @@ static void char_pty_open(Chardev *chr,qemu_set_nonblock (master_fd); chr->filename =g_strdup_printf ("pty:%s" , pty_name); -error_report ("char device redirected to %s (label %s)" , +error_printf ("char device redirected to %s (label %s)\n" , pty_name, chr->label); s =PTY_CHARDEV (chr);chardev/char.c +1
-1@@ -634,7 +634,7 @@ Chardev *qemu_chr_new_from_opts(QemuOpts *opts, Error **errp)chardev_name_foreach (help_string_append, str); -error_report ("Available chardev backend types: %s" , str->str); +error_printf ("Available chardev backend types: %s\n" , str->str);g_string_free (str, true);return NULL ; }
Re: [Qemu-devel] [PATCH 07/31] 9pfs: Fix CLI parsing crash on error
In reply to Markus ArmbrusterQuoted 5 lines · On Mon, 8 Oct 2018 19:31:01 +0200 Markus Armbruster <[email protected]> wrote:
Calling
error_report()in a function that takes an Error ** argument is suspicious. 9p-handle.c'shandle_parse_opts()does that, and then fails without setting an error. Wrong. Its caller crashes when it tries to report the error:
Quoted 8 lines
$ qemu-system-x86_64 -nodefaults -fsdev id=foo,fsdriver=handle qemu-system-x86_64: -fsdev id=foo,fsdriver=handle: warning: handle backend is deprecated qemu-system-x86_64: -fsdev id=foo,fsdriver=handle: fsdev: No path specified Segmentation fault (core dumped)Screwed up when commit
91cda4e8f37(v2.12.0) converted the function to Error. Fix by callingerror_setg()instead oferror_report().
The 9p-handle backend has entered the deprecation process in 2.12... I strongly suspect parapraxis here :) but, you're right, bugs need to be fixed until the code gets removed in 3.2.
Quoted 35 lines
Fixes 91cda4e8f372602795e3a2f4bd2e3adaf9f82255Cc Greg Kurz <[email protected]>Signed-off-by Markus Armbruster <[email protected]>--- hw/9pfs/9p-handle.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)hw/9pfs/9p-handle.c +4
-2@@ -19,6 +19,7 @@#include <grp.h> #include <sys/socket.h> #include <sys/un.h> +#include "qapi/error.h" #include "qemu/xattr.h" #include "qemu/cutils.h" #include "qemu/error-report.h" @@ -655,12 +656,13 @@ static int handle_parse_opts(QemuOpts *opts, FsDriverEntry *fse, Error **errp)warn_report ("handle backend is deprecated" );if (sec_model) { -error_report ("Invalid argument security_model specified with handle fsdriver" ); +error_setg (errp, +"Invalid argument security_model specified with handle fsdriver" );return -1 ; }if (!path) { -error_report ("fsdev: No path specified" ); +error_setg (errp,"fsdev: No path specified" );return -1 ; } fse->path =g_strdup (path);
Re: [Qemu-devel] [PATCH 28/31] fsdev: Clean up error reporting in qemu_fsdev_add()
In reply to Markus ArmbrusterQuoted 9 lines · On Mon, 8 Oct 2018 19:31:22 +0200 Markus Armbruster <[email protected]> wrote:
Calling
error_report()from within a a function that takes an Error ** argument is suspicious.qemu_fsdev_add()does that, and its callerfsdev_init_func()then fails without setting an error. Its callermain(), viaqemu_opts_foreach(), is fine with it, but clean it up anyway.Cc Greg Kurz <[email protected]>Signed-off-by Markus Armbruster <[email protected]>---
Yeah, this was somewhere down in my TODO list. Thanks for the clean up Markus.
Quoted 140 lines
fsdev/qemu-fsdev-dummy.c | 2 +- fsdev/qemu-fsdev.c | 12 +++++------- fsdev/qemu-fsdev.h | 2 +- hw/9pfs/xen-9p-backend.c | 7 ++++++- vl.c | 8 +++----- 5 files changed, 16 insertions(+), 15 deletions(-)fsdev/qemu-fsdev-dummy.c +1
-1@@ -15,7 +15,7 @@#include "qemu/config-file.h" #include "qemu/module.h" -int qemu_fsdev_add (QemuOpts *opts) +int qemu_fsdev_add (QemuOpts *opts,Error **errp) {return 0 ; }fsdev/qemu-fsdev.c +5
-7@@ -30,7 +30,7 @@ static FsDriverTable FsDrivers[] = { { .name = "proxy", .ops = &proxy_ops}, }; -int qemu_fsdev_add (QemuOpts *opts) +int qemu_fsdev_add (QemuOpts *opts,Error **errp) {int i;struct FsDriverListEntry *fsle;@@ -38,10 +38,9 @@ int qemu_fsdev_add(QemuOpts *opts)const char *fsdriver =qemu_opt_get (opts,"fsdriver" );const char *writeout =qemu_opt_get (opts,"writeout" );bool ro =qemu_opt_get_bool (opts,"readonly" ,0 ); -Error *local_err =NULL ;if (!fsdev_id) { -error_report ("fsdev: No id specified" ); +error_setg (errp,"fsdev: No id specified" );return -1 ; }@@ -53,11 +52,11 @@ int qemu_fsdev_add(QemuOpts *opts) }if (i ==ARRAY_SIZE (FsDrivers)) { -error_report ("fsdev: fsdriver %s not found" , fsdriver); +error_setg (errp,"fsdev: fsdriver %s not found" , fsdriver);return -1 ; } }else { -error_report ("fsdev: No fsdriver specified" ); +error_setg (errp,"fsdev: No fsdriver specified" );return -1 ; }@@ -76,8 +75,7 @@ int qemu_fsdev_add(QemuOpts *opts) }if (fsle->fse.ops->parse_opts) { -if (fsle->fse.ops->parse_opts (opts, &fsle->fse, &local_err)) { -error_report_err (local_err); +if (fsle->fse.ops->parse_opts (opts, &fsle->fse, errp)) {g_free (fsle->fse.fsdev_id);g_free (fsle);return -1 ;fsdev/qemu-fsdev.h +1
-1@@ -38,7 +38,7 @@ typedef struct FsDriverListEntry {QTAILQ_ENTRY (FsDriverListEntry) next; } FsDriverListEntry; -int qemu_fsdev_add (QemuOpts *opts); +int qemu_fsdev_add (QemuOpts *opts,Error **errp);FsDriverEntry *get_fsdev_fsentry (char *id);extern FileOperations local_ops;extern FileOperations handle_ops;hw/9pfs/xen-9p-backend.c +6
-1@@ -14,6 +14,7 @@#include "hw/9pfs/9p.h" #include "hw/xen/xen_backend.h" #include "hw/9pfs/xen-9pfs.h" +#include "qapi/error.h" #include "qemu/config-file.h" #include "qemu/option.h" #include "fsdev/qemu-fsdev.h" @@ -355,6 +356,7 @@ static int xen_9pfs_free(struct XenDevice *xendev)static int xen_9pfs_connect (struct XenDevice *xendev) { +Error *err =NULL ;int i;Xen9pfsDev *xen_9pdev =container_of (xendev, Xen9pfsDev, xendev);V9fsState *s = &xen_9pdev->state;@@ -452,7 +454,10 @@ static int xen_9pfs_connect(struct XenDevice *xendev)qemu_opt_set (fsdev,"path" , xen_9pdev->path,NULL );qemu_opt_set (fsdev,"security_model" , xen_9pdev->security_model,NULL );qemu_opts_set_id (fsdev, s->fsconf.fsdev_id); -qemu_fsdev_add (fsdev); +qemu_fsdev_add (fsdev, &err); +if (err) { +error_report_err (err); + }v9fs_device_realize_common (s, &xen_9p_transport,NULL );return 0 ;vl.c +3
-5@@ -2249,7 +2249,7 @@ static int chardev_init_func(void *opaque, QemuOpts *opts, Error **errp)#ifdef CONFIG_VIRTFS static int fsdev_init_func (void *opaque,QemuOpts *opts,Error **errp) { -return qemu_fsdev_add (opts); +return qemu_fsdev_add (opts, errp); }#endif @@ -4188,10 +4188,8 @@ int main(int argc, char **argv, char **envp) chardev_init_func, NULL, &error_fatal);#ifdef CONFIG_VIRTFS -if (qemu_opts_foreach (qemu_find_opts ("fsdev" ), - fsdev_init_func,NULL ,NULL )) { -exit (1 ); - } +qemu_opts_foreach (qemu_find_opts ("fsdev" ), + fsdev_init_func,NULL , &error_fatal);#endif if (qemu_opts_foreach(qemu_find_opts("device"),
Re: [Qemu-devel] [PATCH 08/31] pc: Fix machine property nvdimm-persistence error handling
In reply to Markus ArmbrusterHi
Quoted 15 lines · Markus Armbruster
Calling
error_report()in a function that takes an Error ** argument is suspicious. pc.c'spc_machine_set_nvdimm_persistence()does that, and then exit()s. Wrong. Attempting to set machine property nvdimm-persistence to a bad value instantly kills the VM:$ qemu-system-x86_64 -nodefaults -S -display none -qmp stdio {"QMP": {"version": {"qemu": {"micro": 50, "minor": 0, "major": 3}, "package": "v3.0.0-837-gc5e4e49258"}, "capabilities": []}} {"execute": "qmp_capabilities"} {"return": {}} {"execute": "qom-set", "arguments": {"path": "/machine", "property": "nvdimm-persistence", "value": "instadeath"}} -machine nvdimm-persistence=instadeath: unsupported option $ echo $? 1
Quoted 7 lines
Broken when commit
11c39b5cd96(v3.0.0) replacederror_propagate(); return byerror_report();exit()instead oferror_setg(); return. Fix that.Fixes 11c39b5cd966ddc067a1ca0c5392ec9b666c45b7Cc "Michael S. Tsirkin" <[email protected]>Signed-off-by Markus Armbruster <[email protected]>
Quoted 24 lines
--- hw/i386/pc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)hw/i386/pc.c +3
-3@@ -2209,8 +2209,9 @@ static void pc_machine_set_nvdimm_persistence(Object *obj, const char *value,else if (strcmp (value,"mem-ctrl" ) ==0 ) nvdimm_state->persistence =2 ;else { -error_report ("-machine nvdimm-persistence=%s: unsupported option" , value); -exit (EXIT_FAILURE ); +error_setg (errp,"-machine nvdimm-persistence=%s: unsupported option" , + value); +return ; }g_free (nvdimm_state->persistence_string); --2.17.1
Signature · 1 line
Marc-André Lureau
Re: [Qemu-devel] [PATCH 09/31] ioapic: Fix error handling in realize()
In reply to Markus ArmbrusterQuoted 8 lines · Markus Armbruster
Calling
error_report()in a function that takes an Error ** argument is suspicious.ioapic_realize()does that, and then exit()s. Currently mostly harmless, as the device cannot be hot-plugged.Fixes 20fd4b7b6d9282fe0cb83601f1821f31bd257458Cc Peter Xu <[email protected]>Signed-off-by Markus Armbruster <[email protected]>
Quoted 34 lines
--- hw/intc/ioapic.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)hw/intc/ioapic.c +4
-5@@ -21,7 +21,7 @@*/ #include "qemu/osdep.h" -#include "qemu/error-report.h" +#include "qapi/error.h" #include "monitor/monitor.h" #include "hw/hw.h" #include "hw/i386/pc.h" @@ -393,9 +393,9 @@ static void ioapic_realize(DeviceState *dev, Error **errp)IOAPICCommonState *s =IOAPIC_COMMON (dev);if (s->version !=0x11 && s->version !=0x20 ) { -error_report ("IOAPIC only supports version 0x11 or 0x20 " -"(default: 0x%x)." ,IOAPIC_VER_DEF ); -exit (1 ); +error_setg (errp,"IOAPIC only supports version 0x11 or 0x20 " +"(default: 0x%x)." ,IOAPIC_VER_DEF ); +return ; } memory_region_init_io(&s->io_memory, OBJECT(s), &ioapic_io_ops, s, --2.17.1
Signature · 1 line
Marc-André Lureau
Re: [Qemu-devel] [PATCH 10/31] smbios: Clean up error handling in smbios_add()
In reply to Markus ArmbrusterHi
Quoted 9 lines · Markus Armbruster
Calling
error_report()in a function that takes an Error ** argument is suspicious.smbios_entry_add()does that, and then exit()s. It also passes&error_fataltoqemu_opts_validate(). Both wrong, but currently harmless, as its only caller passes&error_fatal. Messed up in commit1007a37e208. Clean it up.Cc Paolo Bonzini <[email protected]>Signed-off-by Markus Armbruster <[email protected]>
Quoted 200 lines
--- hw/smbios/smbios.c | 90 +++++++++++++++++++++++++++++++--------------- 1 file changed, 62 insertions(+), 28 deletions(-)hw/smbios/smbios.c +62
-29@@ -950,6 +950,7 @@ static void save_opt_list(size_t *ndest, const char ***dest,void smbios_entry_add (QemuOpts *opts,Error **errp) { +Error *err =NULL ;const char *val;assert (!smbios_immutable);@@ -960,12 +961,16 @@ void smbios_entry_add(QemuOpts *opts, Error **errp)int size;struct smbios_table *table;/* legacy mode only */ -qemu_opts_validate (opts, qemu_smbios_file_opts, &error_fatal); +qemu_opts_validate (opts, qemu_smbios_file_opts, &err); +if (err) { +error_propagate (errp, err); +return ; + } size =get_image_size (val);if (size ==-1 || size <sizeof (struct smbios_structure_header )) { -error_report ("Cannot read SMBIOS file %s" , val); -exit (1 ); +error_setg (errp,"Cannot read SMBIOS file %s" , val); +return ; }/* @@ -978,14 +983,15 @@ void smbios_entry_add(QemuOpts *opts, Error **errp) smbios_tables_len);if (load_image (val, (uint8_t *)header) != size) { -error_report ("Failed to load SMBIOS file %s" , val); -exit (1 ); +error_setg (errp,"Failed to load SMBIOS file %s" , val); +return ; }if (test_bit (header->type, have_fields_bitmap)) { -error_report ("can't load type %d struct, fields already specified!" , - header->type); -exit (1 ); +error_setg (errp, +"can't load type %d struct, fields already specified!" , + header->type); +return ; }set_bit (header->type, have_binfile_bitmap);@@ -1030,19 +1036,23 @@ void smbios_entry_add(QemuOpts *opts, Error **errp)unsigned long type =strtoul (val,NULL ,0 );if (type >SMBIOS_MAX_TYPE ) { -error_report ("out of range!" ); -exit (1 ); +error_setg (errp,"out of range!" ); +return ; }if (test_bit (type, have_binfile_bitmap)) { -error_report ("can't add fields, binary file already loaded!" ); -exit (1 ); +error_setg (errp,"can't add fields, binary file already loaded!" ); +return ; }set_bit (type, have_fields_bitmap);switch (type) {case 0 : -qemu_opts_validate (opts, qemu_smbios_type0_opts, &error_fatal); +qemu_opts_validate (opts, qemu_smbios_type0_opts, &err); +if (err) { +error_propagate (errp, err); +return ; + }save_opt (&type0.vendor, opts,"vendor" );save_opt (&type0.version, opts,"version" );save_opt (&type0.date, opts,"date" );@@ -1051,14 +1061,18 @@ void smbios_entry_add(QemuOpts *opts, Error **errp) val =qemu_opt_get (opts,"release" );if (val) {if (sscanf (val,"%hhu.%hhu" , &type0.major, &type0.minor) !=2 ) { -error_report ("Invalid release" ); -exit (1 ); +error_setg (errp,"Invalid release" ); +return ; } type0.have_major_minor = true; }return ;case 1 : -qemu_opts_validate (opts, qemu_smbios_type1_opts, &error_fatal); +qemu_opts_validate (opts, qemu_smbios_type1_opts, &err); +if (err) { +error_propagate (errp, err); +return ; + }save_opt (&type1.manufacturer, opts,"manufacturer" );save_opt (&type1.product, opts,"product" );save_opt (&type1.version, opts,"version" );@@ -1069,14 +1083,18 @@ void smbios_entry_add(QemuOpts *opts, Error **errp) val =qemu_opt_get (opts,"uuid" );if (val) {if (qemu_uuid_parse (val, &qemu_uuid) !=0 ) { -error_report ("Invalid UUID" ); -exit (1 ); +error_setg (errp,"Invalid UUID" ); +return ; } qemu_uuid_set = true; }return ;case 2 : -qemu_opts_validate (opts, qemu_smbios_type2_opts, &error_fatal); +qemu_opts_validate (opts, qemu_smbios_type2_opts, &err); +if (err) { +error_propagate (errp, err); +return ; + }save_opt (&type2.manufacturer, opts,"manufacturer" );save_opt (&type2.product, opts,"product" );save_opt (&type2.version, opts,"version" );@@ -1085,7 +1103,11 @@ void smbios_entry_add(QemuOpts *opts, Error **errp)save_opt (&type2.location, opts,"location" );return ;case 3 : -qemu_opts_validate (opts, qemu_smbios_type3_opts, &error_fatal); +qemu_opts_validate (opts, qemu_smbios_type3_opts, &err); +if (err) { +error_propagate (errp, err); +return ; + }save_opt (&type3.manufacturer, opts,"manufacturer" );save_opt (&type3.version, opts,"version" );save_opt (&type3.serial, opts,"serial" );@@ -1093,7 +1115,11 @@ void smbios_entry_add(QemuOpts *opts, Error **errp)save_opt (&type3.sku, opts,"sku" );return ;case 4 : -qemu_opts_validate (opts, qemu_smbios_type4_opts, &error_fatal); +qemu_opts_validate (opts, qemu_smbios_type4_opts, &err); +if (err) { +error_propagate (errp, err); +return ; + }save_opt (&type4.sock_pfx, opts,"sock_pfx" );save_opt (&type4.manufacturer, opts,"manufacturer" );save_opt (&type4.version, opts,"version" );@@ -1102,11 +1128,19 @@ void smbios_entry_add(QemuOpts *opts, Error **errp)save_opt (&type4.part, opts,"part" );return ;case 11 : -qemu_opts_validate (opts, qemu_smbios_type11_opts, &error_fatal); +qemu_opts_validate (opts, qemu_smbios_type11_opts, &err); +if (err) { +error_propagate (errp, err); +return ; + }save_opt_list (&type11.nvalues, &type11.values, opts,"value" );return ;case 17 : -qemu_opts_validate (opts, qemu_smbios_type17_opts, &error_fatal); +qemu_opts_validate (opts, qemu_smbios_type17_opts, &err); +if (err) { +error_propagate (errp, err); +return ; + }save_opt (&type17.loc_pfx, opts,"loc_pfx" );save_opt (&type17.bank, opts,"bank" );save_opt (&type17.manufacturer, opts,"manufacturer" );@@ -1116,12 +1150,12 @@ void smbios_entry_add(QemuOpts *opts, Error **errp) type17.speed =qemu_opt_get_number (opts,"speed" ,0 );return ;default : -error_report ("Don't know how to build fields for SMBIOS type %ld" , - type); -exit (1 ); +error_setg (errp, +"Don't know how to build fields for SMBIOS type %ld" , + type); +return ; } } -error_report ("Must specify type= or file=" ); -exit (1 ); +error_setg (errp,"Must specify type= or file=" ); } --2.17.1
Signature · 1 line
Marc-André Lureau
Re: [Qemu-devel] [PATCH 11/31] migration: Fix !replay_can_snapshot() error handling
In reply to Markus ArmbrusterHi
Quoted 9 lines · Markus Armbruster
Calling
error_report()in a function that takes an Error ** argument is suspicious.save_snapshot()andload_snapshot()do that, and then fail without setting an error. Wrong. The HMP commands survive this unscathed, sincehmp_handle_error()does nothing when no error has been set. Callersmain()(on behalf of -loadvm) andreplay_vmstate_init()crash, but I'm not sure the error is possible there.
Quoted 7 lines
Screwed up when commit
377b21ccea1(v2.12.0) added incorrect error handling right next to correct examples. Fix by callingerror_setg()instead oferror_report().Fixes 377b21ccea1755a8b0dae822c29567c58dda6939Cc Paolo Bonzini <[email protected]>Signed-off-by Markus Armbruster <[email protected]>
Quoted 34 lines
--- migration/savevm.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)migration/savevm.c +4
-5@@ -2414,8 +2414,8 @@ int save_snapshot(const char *name, Error **errp)AioContext *aio_context;if (!replay_can_snapshot ()) { -error_report ("Record/replay does not allow making snapshot " -"right now. Try once more later." ); +error_setg (errp,"Record/replay does not allow making snapshot " +"right now. Try once more later." );return ret; }@@ -2611,8 +2611,8 @@ int load_snapshot(const char *name, Error **errp)MigrationIncomingState *mis =migration_incoming_get_current ();if (!replay_can_snapshot ()) { -error_report ("Record/replay does not allow loading snapshot " -"right now. Try once more later." ); +error_setg (errp,"Record/replay does not allow loading snapshot " +"right now. Try once more later." );return -EINVAL ; } --2.17.1
Signature · 1 line
Marc-André Lureau
Re: [Qemu-devel] [PATCH 12/31] l2tpv3: Improve -netdev/netdev_add/-net/... error reporting
In reply to Markus ArmbrusterHi
Quoted 51 lines · Markus Armbruster
When -netdev l2tpv3 fails, it first reports a specific error, then a generic one, like this:
$ qemu-system-x86_64 -netdev l2tpv3,id=foo,src=,dst=,txsession=1 qemu-system-x86_64: -netdev l2tpv3,id=foo,src=,dst=,txsession=1: l2tpv3_open : could not resolve src, errno = Name or service not known qemu-system-x86_64: Device 'l2tpv3' could not be initializedWith the command line, the messages go to stderr. In HMP, they go to the monitor. In QMP, the second one becomes the error reply, and the first one goes to stderr.
Convert
net_init_tap()to Error. This suppresses the unwanted second message, and makes the specific error the QMP error reply.Cc Jason Wang <[email protected]>Signed-off-by Markus Armbruster <[email protected]>--- net/l2tpv3.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)net/l2tpv3.c +2
-2@@ -28,6 +28,7 @@#include <netdb.h> #include "net/net.h" #include "clients.h" +#include "qapi/error.h" #include "qemu-common.h" #include "qemu/error-report.h" #include "qemu/option.h" @@ -528,7 +529,6 @@ int net_init_l2tpv3(const Netdev *netdev,const char *name, NetClientState *peer, Error **errp) { - /* FIXME error_setg(errp, ...) on failure */ const NetdevL2TPv3Options *l2tpv3;NetL2TPV3State *s;NetClientState *nc;@@ -555,7 +555,7 @@ int net_init_l2tpv3(const Netdev *netdev, }if ((l2tpv3->has_offset) && (l2tpv3->offset >256 )) { -error_report ("l2tpv3_open : offset must be less than 256 bytes" ); +error_setg (errp,"l2tpv3_open : offset must be less than 256 bytes" ); goto outerr; }
net/l2tpv3.c int net_init_l2tpv3(const Netdev *netdev, · line 567
Quoted 5 lines
net/l2tpv3.c +2
-0@@ -563,6 +563,8 @@ int net_init_l2tpv3(const Netdev *netdev,if (l2tpv3->has_rxcookie && l2tpv3->has_txcookie) { s->cookie = true; }else { +error_setg (errp, +"require both 'rxcookie' and 'txcookie' or neither" );
maybe for consistency it would be a good idea to remove the "l2tpv3_open : " prefix from the other messages while touching it?
looks good otherwise:
Quoted 56 lines
net/l2tpv3.c +9
-12goto outerr; } }else {@@ -578,7 +580,8 @@ int net_init_l2tpv3(const Netdev *netdev,if (l2tpv3->has_udp && l2tpv3->udp) { s->udp = true;if (!(l2tpv3->has_srcport && l2tpv3->has_dstport)) { -error_report ("l2tpv3_open : need both src and dst port for udp" ); +error_setg (errp, +"l2tpv3_open : need both src and dst port for udp" ); goto outerr; }else { srcport = l2tpv3->srcport;@@ -639,20 +642,19 @@ int net_init_l2tpv3(const Netdev *netdev, gairet =getaddrinfo (l2tpv3->src, srcport, &hints, &result);if ((gairet !=0 ) || (result ==NULL )) { -error_report ( -"l2tpv3_open : could not resolve src, errno = %s" , -gai_strerror (gairet) - ); +error_setg (errp,"l2tpv3_open : could not resolve src, errno = %s" , +gai_strerror (gairet)); goto outerr; } fd =socket (result->ai_family, result->ai_socktype, result->ai_protocol);if (fd ==-1 ) { fd = -errno; -error_report ("l2tpv3_open : socket creation failed, errno = %d" , -fd); +error_setg (errp,"l2tpv3_open : socket creation failed, errno = %d" , + -fd); goto outerr; }if (bind (fd, (struct sockaddr *) result->ai_addr, result->ai_addrlen)) { -error_report ("l2tpv3_open : could not bind socket err=%i" , errno); +error_setg (errp,"l2tpv3_open : could not bind socket err=%i" , errno); goto outerr; }if (result) {@@ -677,10 +679,8 @@ int net_init_l2tpv3(const Netdev *netdev, result =NULL ; gairet =getaddrinfo (l2tpv3->dst, dstport, &hints, &result);if ((gairet !=0 ) || (result ==NULL )) { -error_report ( -"l2tpv3_open : could not resolve dst, error = %s" , -gai_strerror (gairet) - ); +error_setg (errp,"l2tpv3_open : could not resolve dst, error = %s" , +gai_strerror (gairet)); goto outerr; } --2.17.1
Signature · 1 line
Marc-André Lureau
Re: [Qemu-devel] [PATCH 13/31] net/socket: Fix invalid socket type error handling
In reply to Markus ArmbrusterHi
Quoted 6 lines · Markus Armbruster
Calling
error_report()in a function that takes an Error ** argument is suspicious.net_socket_fd_init()does that, and then fails without setting an error. Wrong. I didn't analyze how exactly this can break. A caller that reports the error on failure would crash.
Quoted 6 lines
Broken when commit
c37f0bb1d0d(v2.11.0) converted the function to Error. Fix by callingerror_setg()instead oferror_report().Fixes c37f0bb1d0d24e3a6b5f4659bb305913dcb798a6Cc Jason Wang <[email protected]>Signed-off-by Markus Armbruster <[email protected]>
Quoted 23 lines
--- net/socket.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)net/socket.c +2
-3@@ -453,8 +453,8 @@ static NetSocketState *net_socket_fd_init(NetClientState *peer,case SOCK_STREAM :return net_socket_fd_init_stream (peer, model, name, fd, is_connected);default : -error_report ("socket type=%d for fd=%d must be either" -" SOCK_DGRAM or SOCK_STREAM" , so_type, fd); +error_setg (errp,"socket type=%d for fd=%d must be either" +" SOCK_DGRAM or SOCK_STREAM" , so_type, fd);closesocket (fd); }return NULL ; --2.17.1
Signature · 1 line
Marc-André Lureau
Re: [Qemu-devel] [PATCH 16/31] seccomp: Clean up error reporting in parse_sandbox()
In reply to Markus ArmbrusterHi
Quoted 41 lines · Markus Armbruster
Calling
error_report()in a function that takes an Error ** argument is suspicious.parse_sandbox()does that, and then fails without setting an error. Its callermain(), viaqemu_opts_foreach(), is fine with it, but clean it up anyway.Cc Eduardo Otubo <[email protected]>Signed-off-by Markus Armbruster <[email protected]>--- qemu-seccomp.c | 18 +++++++++--------- vl.c | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-)qemu-seccomp.c +3
-2@@ -12,11 +12,12 @@* Contributions after 2012-01-13 are licensed under the terms of the * GNU GPL, version 2 or (at your option) any later version. */ +#include "qemu/osdep.h" +#include "qapi/error.h" #include "qemu/config-file.h" #include "qemu/option.h" #include "qemu/module.h" -#include "qemu/error-report.h" #include <sys/prctl.h> #include <seccomp.h> #include "sysemu/seccomp.h" @@ -190,7 +191,7 @@ int parse_sandbox(void *opaque, QemuOpts *opts, Error **errp)* to provide a little bit of consistency for * the command line */ }else { -error_report ("invalid argument for obsolete" ); +error_setg (errp,"invalid argument for obsolete" );return -1 ; } }
qemu-seccomp.c int parse_sandbox(void *opaque, QemuOpts *opts, Error **errp) · line 209
Quoted 6 lines
qemu-seccomp.c +1
-2@@ -205,14 +206,13 @@ int parse_sandbox(void *opaque, QemuOpts *opts, Error **errp)/* calling prctl directly because we're * not sure if host has CAP_SYS_ADMIN set*/ if (prctl (PR_SET_NO_NEW_PRIVS ,1 )) { -error_report ("failed to set no_new_privs " -"aborting" ); +error_setg (errp,"failed to set no_new_privs " "aborting" );
Extra " "
Quoted 42 lines
qemu-seccomp.c +5
-5return -1 ; } }else if (g_str_equal (value,"allow" )) {/* default value */ }else { -error_report ("invalid argument for elevateprivileges" ); +error_setg (errp,"invalid argument for elevateprivileges" );return -1 ; } }@@ -224,7 +224,7 @@ int parse_sandbox(void *opaque, QemuOpts *opts, Error **errp) }else if (g_str_equal (value,"allow" )) {/* default value */ }else { -error_report ("invalid argument for spawn" ); +error_setg (errp,"invalid argument for spawn" );return -1 ; } }@@ -236,14 +236,14 @@ int parse_sandbox(void *opaque, QemuOpts *opts, Error **errp) }else if (g_str_equal (value,"allow" )) {/* default value */ }else { -error_report ("invalid argument for resourcecontrol" ); +error_setg (errp,"invalid argument for resourcecontrol" );return -1 ; } }if (seccomp_start (seccomp_opts) <0 ) { -error_report ("failed to install seccomp syscall filter " -"in the kernel" ); +error_setg (errp,"failed to install seccomp syscall filter " +"in the kernel" );return -1 ; } }vl.c +0
-0
vl.c int main(int argc, char **argv, char **envp) · line 3932
Quoted 10 lines
vl.c +2
-2@@ -3925,8 +3925,8 @@ int main(int argc, char **argv, char **envp)#ifdef CONFIG_SECCOMP olist =qemu_find_opts_err ("sandbox" ,NULL ); -if (olist &&qemu_opts_foreach (olist, parse_sandbox,NULL ,NULL )) { -exit (1 ); +if (olist) { +qemu_opts_foreach (olist, parse_sandbox,NULL , &error_fatal); }#endif
Other than that,
Quoted 4 lines
--
2.17.1
Signature · 1 line
Marc-André Lureau
Re: [Qemu-devel] [PATCH 03/31] cpus hw target: Use warn_report() & friends to report warnings
In reply to Markus ArmbrusterQuoted 7 lines · Markus Armbruster
Calling
error_report()in a function that takes an Error ** argument is suspicious. Convert a few that are actually warnings towarn_report().While there, split a warning consisting of multiple sentences to conform to conventions spelled out in warn_report()'s contract.
Quoted 7 lines
Cc Alex Bennée <[email protected]>Cc Mark Cave-Ayland <[email protected]>Cc Alex Williamson <[email protected]>Cc Fam Zheng <[email protected]>Cc Wei Huang <[email protected]>Cc David Gibson <[email protected]>Signed-off-by Markus Armbruster <[email protected]>
Quoted 140 lines
--- cpus.c | 8 ++++---- hw/display/cg3.c | 2 +- hw/display/tcx.c | 2 +- hw/misc/ivshmem.c | 4 ++-- hw/net/virtio-net.c | 8 ++++---- hw/virtio/virtio-pci.c | 4 ++-- target/i386/cpu.c | 17 +++++++++-------- target/ppc/translate_init.inc.c | 4 ++-- 8 files changed, 25 insertions(+), 24 deletions(-)cpus.c +4
-4@@ -211,12 +211,12 @@ void qemu_tcg_configure(QemuOpts *opts, Error **errp)error_setg (errp,"No MTTCG when icount is enabled" ); }else {#ifndef TARGET_SUPPORTS_MTTCG -error_report ("Guest not yet converted to MTTCG - " -"you may get unexpected results" ); +warn_report ("Guest not yet converted to MTTCG - " +"you may get unexpected results" );#endif if (!check_tcg_memory_orders_compatible ()) { -error_report ("Guest expects a stronger memory ordering " -"than the host provides" ); +warn_report ("Guest expects a stronger memory ordering " +"than the host provides" );error_printf ("This may cause strange/hard to debug errors\n" ); } mttcg_enabled = true;hw/display/cg3.c +1
-1@@ -307,7 +307,7 @@ static void cg3_realizefn(DeviceState *dev, Error **errp) ret =load_image_mr (fcode_filename, &s->rom);g_free (fcode_filename);if (ret <0 || ret >FCODE_MAX_ROM_SIZE ) { -error_report ("cg3: could not load prom '%s'" ,CG3_ROM_FILE ); +warn_report ("cg3: could not load prom '%s'" ,CG3_ROM_FILE ); } }hw/display/tcx.c +1
-1@@ -823,7 +823,7 @@ static void tcx_realizefn(DeviceState *dev, Error **errp) ret =load_image_mr (fcode_filename, &s->rom);g_free (fcode_filename);if (ret <0 || ret >FCODE_MAX_ROM_SIZE ) { -error_report ("tcx: could not load prom '%s'" ,TCX_ROM_FILE ); +warn_report ("tcx: could not load prom '%s'" ,TCX_ROM_FILE ); } }hw/misc/ivshmem.c +2
-2@@ -1292,8 +1292,8 @@ static void ivshmem_realize(PCIDevice *dev, Error **errp)IVShmemState *s =IVSHMEM_COMMON (dev);if (!qtest_enabled ()) { -error_report ("ivshmem is deprecated, please use ivshmem-plain" -" or ivshmem-doorbell instead" ); +warn_report ("ivshmem is deprecated, please use ivshmem-plain" +" or ivshmem-doorbell instead" ); }if (qemu_chr_fe_backend_connected (&s->server_chr) + !!s->shmobj !=1 ) {hw/net/virtio-net.c +4
-4@@ -2020,10 +2020,10 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp)if (n->net_conf.tx &&strcmp (n->net_conf.tx,"timer" ) &&strcmp (n->net_conf.tx,"bh" )) { -error_report ("virtio-net: " -"Unknown option tx=%s, valid options: \"timer\" \"bh\"" , - n->net_conf.tx); -error_report ("Defaulting to \"bh\"" ); +warn_report ("virtio-net: " +"Unknown option tx=%s, valid options: \"timer\" \"bh\"" , + n->net_conf.tx); +error_printf ("Defaulting to \"bh\"" ); } n->net_conf.tx_queue_size = MIN(virtio_net_max_tx_queue_size(n),hw/virtio/virtio-pci.c +2
-2@@ -1683,8 +1683,8 @@ static void virtio_pci_device_plugged(DeviceState *d, Error **errp)if (err) {/* Notice when a system that supports MSIx can't initialize it */ if (err != -ENOTSUP ) { -error_report ("unable to init msix vectors to %" PRIu32, - proxy->nvectors); +warn_report ("unable to init msix vectors to %" PRIu32, + proxy->nvectors); } proxy->nvectors =0 ; }target/i386/cpu.c +9
-8@@ -5123,14 +5123,15 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)* NOTE: the following code has to follow qemu_init_vcpu(). Otherwise * cs->nr_threads hasn't be populated yet and the checking is incorrect. */ -if (IS_AMD_CPU (env) && - !(env->features[FEAT_8000_0001_ECX ] &CPUID_EXT3_TOPOEXT ) && - cs->nr_threads >1 && !ht_warned) { -error_report ("This family of AMD CPU doesn't support " -"hyperthreading(%d). Please configure -smp " -"options properly or try enabling topoext feature." , - cs->nr_threads); - ht_warned = true; +if (IS_AMD_CPU (env) && + !(env->features[FEAT_8000_0001_ECX ] &CPUID_EXT3_TOPOEXT ) && + cs->nr_threads >1 && !ht_warned) { +warn_report ("This family of AMD CPU doesn't support " +"hyperthreading(%d)" , + cs->nr_threads); +error_printf ("Please configure -smp options properly" +" or try enabling topoext feature.\n" ); + ht_warned = true; }x86_cpu_apic_realize (cpu, &local_err);target/ppc/translate_init.inc.c +0
-0
target/ppc/translate_init.inc.c static void getset_compat_deprecated(Object *obj, Visitor *v, const char *name, · line 8388
Quoted 10 lines
target/ppc/translate_init.inc.c +2
-2@@ -8381,8 +8381,8 @@ static void getset_compat_deprecated(Object *obj, Visitor *v, const char *name,QNull *null =NULL ;if (!qtest_enabled ()) { -error_report ("CPU 'compat' property is deprecated and has no effect; " -"use max-cpu-compat machine property instead" ); +warn_report ("CPU 'compat' property is deprecated and has no effect; " +"use max-cpu-compat machine property instead" ); }visit_type_null (v, name, &null,NULL );qobject_unref (null);
--
Alex Bennée
Re: [Qemu-devel] [PATCH 17/31] vl: Clean up error reporting in parse_add_fd()
In reply to Markus ArmbrusterHi
Quoted 9 lines · Markus Armbruster
Calling
error_report()in a function that takes an Error ** argument is suspicious.parse_add_fd()does that, and then fails without setting an error. Its callermain(), viaqemu_opts_foreach(), is fine with it, but clean it up anyway.Also change call of
cleanup_add_fd(), which can't fail, for symmetry.Signed-off-by Markus Armbruster <[email protected]>
Quoted 71 lines
--- vl.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-)vl.c +9
-14@@ -1059,12 +1059,12 @@ static int parse_add_fd(void *opaque, QemuOpts *opts, Error **errp) fd_opaque =qemu_opt_get (opts,"opaque" );if (fd <0 ) { -error_report ("fd option is required and must be non-negative" ); +error_setg (errp,"fd option is required and must be non-negative" );return -1 ; }if (fd <=STDERR_FILENO ) { -error_report ("fd cannot be a standard I/O stream" ); +error_setg (errp,"fd cannot be a standard I/O stream" );return -1 ; }@@ -1074,12 +1074,12 @@ static int parse_add_fd(void *opaque, QemuOpts *opts, Error **errp)*/ flags =fcntl (fd,F_GETFD );if (flags ==-1 || (flags &FD_CLOEXEC )) { -error_report ("fd is not valid or already in use" ); +error_setg (errp,"fd is not valid or already in use" );return -1 ; }if (fdset_id <0 ) { -error_report ("set option is required and must be non-negative" ); +error_setg (errp,"set option is required and must be non-negative" );return -1 ; }@@ -1092,7 +1092,7 @@ static int parse_add_fd(void *opaque, QemuOpts *opts, Error **errp) }#endif if (dupfd ==-1 ) { -error_report ("error duplicating fd: %s" ,strerror (errno)); +error_setg (errp,"error duplicating fd: %s" ,strerror (errno));return -1 ; }@@ -3936,15 +3936,11 @@ int main(int argc, char **argv, char **envp) }#ifndef _WIN32 -if (qemu_opts_foreach (qemu_find_opts ("add-fd" ), - parse_add_fd,NULL ,NULL )) { -exit (1 ); - } +qemu_opts_foreach (qemu_find_opts ("add-fd" ), + parse_add_fd,NULL , &error_fatal); -if (qemu_opts_foreach (qemu_find_opts ("add-fd" ), - cleanup_add_fd,NULL ,NULL )) { -exit (1 ); - } +qemu_opts_foreach (qemu_find_opts ("add-fd" ), + cleanup_add_fd,NULL , &error_fatal);#endif current_machine = MACHINE(object_new(object_class_get_name( --2.17.1
Signature · 1 line
Marc-André Lureau
Re: [Qemu-devel] [PATCH 26/31] tpm: Clean up error reporting in tpm_init_tpmdev()
In reply to Markus ArmbrusterQuoted 7 lines · Markus Armbruster
Calling
error_report()in a function that takes an Error ** argument is suspicious.tpm_init_tpmdev()does that, and then fails without setting an error. Its callermain(), viatpm_init()andqemu_opts_foreach(), is fine with it, but clean it up anyway.Cc Stefan Berger <[email protected]>Signed-off-by Markus Armbruster <[email protected]>
Quoted 116 lines
--- include/sysemu/tpm.h | 2 +- stubs/tpm.c | 3 +-- tpm.c | 22 +++++++++------------- vl.c | 4 +--- 4 files changed, 12 insertions(+), 19 deletions(-)include/sysemu/tpm.h +1
-1@@ -16,7 +16,7 @@#include "qom/object.h" int tpm_config_parse (QemuOptsList *opts_list,const char *optarg); -int tpm_init (void ); +void tpm_init (void );void tpm_cleanup (void ); typedef enum TPMVersion {stubs/tpm.c +1
-2@@ -9,9 +9,8 @@#include "qapi/qapi-commands-tpm.h" #include "sysemu/tpm.h" -int tpm_init (void ) +void tpm_init (void ) { -return 0 ; }void tpm_cleanup (void )tpm.c +9
-13@@ -89,19 +89,19 @@ static int tpm_init_tpmdev(void *dummy, QemuOpts *opts, Error **errp)int i;if (!QLIST_EMPTY (&tpm_backends)) { -error_report ("Only one TPM is allowed." ); +error_setg (errp,"Only one TPM is allowed." );return 1 ; } id =qemu_opts_id (opts);if (id ==NULL ) { -error_report (QERR_MISSING_PARAMETER ,"id" ); +error_setg (errp,QERR_MISSING_PARAMETER ,"id" );return 1 ; } value =qemu_opt_get (opts,"type" );if (!value) { -error_report (QERR_MISSING_PARAMETER ,"type" ); +error_setg (errp,QERR_MISSING_PARAMETER ,"type" );tpm_display_backend_drivers ();return 1 ; }@@ -109,8 +109,8 @@ static int tpm_init_tpmdev(void *dummy, QemuOpts *opts, Error **errp) i =qapi_enum_parse (&TpmType_lookup, value,-1 ,NULL ); be = i >=0 ?tpm_be_find_by_type (i) :NULL ;if (be ==NULL ) { -error_report (QERR_INVALID_PARAMETER_VALUE , -"type" ,"a TPM backend type" ); +error_setg (errp,QERR_INVALID_PARAMETER_VALUE ,"type" , +"a TPM backend type" );tpm_display_backend_drivers ();return 1 ; }@@ -118,7 +118,7 @@ static int tpm_init_tpmdev(void *dummy, QemuOpts *opts, Error **errp)/* validate backend specific opts */ qemu_opts_validate (opts, be->opts, &local_err);if (local_err) { -error_report_err (local_err); +error_propagate (errp, local_err);return 1 ; }@@ -151,14 +151,10 @@ void tpm_cleanup(void)* Initialize the TPM. Process the tpmdev command line options describing the * TPM backend. */ -int tpm_init (void ) +void tpm_init (void ) { -if (qemu_opts_foreach (qemu_find_opts ("tpmdev" ), - tpm_init_tpmdev,NULL ,NULL )) { -return -1 ; - } - -return 0 ; +qemu_opts_foreach (qemu_find_opts ("tpmdev" ), + tpm_init_tpmdev,NULL , &error_fatal); }/* vl.c +1
-3@@ -4312,9 +4312,7 @@ int main(int argc, char **argv, char **envp) user_creatable_add_opts_foreach, object_create_delayed, &error_fatal); -if (tpm_init () <0 ) { -exit (1 ); - } +tpm_init ();/* init the bluetooth world */ if (foreach_device_config (DEV_BT , bt_parse))
Re: [Qemu-devel] [PATCH 18/31] qom: Clean up error reporting in user_creatable_add_opts_foreach()
In reply to Markus ArmbrusterHi
Quoted 8 lines · Markus Armbruster
Calling
error_report()in a function that takes an Error ** argument is suspicious.user_creatable_add_opts_foreach()does that, and then fails without setting an error. Its callermain(), viaqemu_opts_foreach(), is fine with it, but clean it up anyway.Cc Daniel P. Berrangé <[email protected]>Signed-off-by Markus Armbruster <[email protected]>
Quoted 106 lines
--- qemu-io.c | 8 +++----- qemu-nbd.c | 8 +++----- qom/object_interfaces.c | 4 +--- vl.c | 16 ++++++---------- 4 files changed, 13 insertions(+), 23 deletions(-)qemu-io.c +3
-5@@ -620,11 +620,9 @@ int main(int argc, char **argv)exit (1 ); } -if (qemu_opts_foreach (&qemu_object_opts, - user_creatable_add_opts_foreach, -NULL ,NULL )) { -exit (1 ); - } +qemu_opts_foreach (&qemu_object_opts, + user_creatable_add_opts_foreach, +NULL , &error_fatal);if (!trace_init_backends ()) {exit (1 );qemu-nbd.c +3
-5@@ -766,11 +766,9 @@ int main(int argc, char **argv)exit (EXIT_FAILURE ); } -if (qemu_opts_foreach (&qemu_object_opts, - user_creatable_add_opts_foreach, -NULL ,NULL )) { -exit (EXIT_FAILURE ); - } +qemu_opts_foreach (&qemu_object_opts, + user_creatable_add_opts_foreach, +NULL , &error_fatal);if (!trace_init_backends ()) {exit (1 );qom/object_interfaces.c +1
-3@@ -143,7 +143,6 @@ int user_creatable_add_opts_foreach(void *opaque, QemuOpts *opts, Error **errp) {bool (*type_predicate)(const char *) = opaque;Object *obj =NULL ; -Error *err =NULL ;const char *type; type =qemu_opt_get (opts,"qom-type" );@@ -152,9 +151,8 @@ int user_creatable_add_opts_foreach(void *opaque, QemuOpts *opts, Error **errp)return 0 ; } - obj =user_creatable_add_opts (opts, &err); + obj =user_creatable_add_opts (opts, errp);if (!obj) { -error_report_err (err);return -1 ; }object_unref (obj);vl.c +6
-11@@ -4181,11 +4181,9 @@ int main(int argc, char **argv, char **envp)page_size_init ();socket_init (); -if (qemu_opts_foreach (qemu_find_opts ("object" ), - user_creatable_add_opts_foreach, - object_create_initial,NULL )) { -exit (1 ); - } +qemu_opts_foreach (qemu_find_opts ("object" ), + user_creatable_add_opts_foreach, + object_create_initial, &error_fatal);if (qemu_opts_foreach (qemu_find_opts ("chardev" ), chardev_init_func,NULL ,NULL )) {@@ -4316,11 +4314,9 @@ int main(int argc, char **argv, char **envp)exit (1 ); } -if (qemu_opts_foreach (qemu_find_opts ("object" ), - user_creatable_add_opts_foreach, - object_create_delayed,NULL )) { -exit (1 ); - } +qemu_opts_foreach (qemu_find_opts ("object" ), + user_creatable_add_opts_foreach, + object_create_delayed, &error_fatal);if (tpm_init () <0 ) {exit (1 ); --2.17.1
Signature · 1 line
Marc-André Lureau
Re: [Qemu-devel] [PATCH 19/31] vl: Clean up error reporting in parse_add_fd()
In reply to Markus ArmbrusterHi
Quoted 7 lines · Markus Armbruster
Calling
error_report()in a function that takes an Error ** argument is suspicious.chardev_init_func()does that, and then fails without setting an error. Its callermain(), viaqemu_opts_foreach(), is fine with it, but clean it up anyway.Signed-off-by Markus Armbruster <[email protected]>
commit title is wrong, apart from that:
Quoted 34 lines
--- vl.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)vl.c +3
-6@@ -2239,7 +2239,7 @@ static int chardev_init_func(void *opaque, QemuOpts *opts, Error **errp)if (!qemu_chr_new_from_opts (opts, &local_err)) {if (local_err) { -error_report_err (local_err); +error_propagate (errp, local_err);return -1 ; }exit (0 );@@ -4185,10 +4185,8 @@ int main(int argc, char **argv, char **envp) user_creatable_add_opts_foreach, object_create_initial, &error_fatal); -if (qemu_opts_foreach (qemu_find_opts ("chardev" ), - chardev_init_func,NULL ,NULL )) { -exit (1 ); - } +qemu_opts_foreach (qemu_find_opts ("chardev" ), + chardev_init_func,NULL , &error_fatal);#ifdef CONFIG_VIRTFS if (qemu_opts_foreach(qemu_find_opts("fsdev"), --2.17.1
Signature · 1 line
Marc-André Lureau
Re: [Qemu-devel] [PATCH 20/31] vl: Clean up error reporting in machine_set_property()
In reply to Markus ArmbrusterHi
Quoted 7 lines · Markus Armbruster
Calling
error_report()in a function that takes an Error ** argument is suspicious.machine_set_property()does that, and then fails without setting an error. Its callermain(), viaqemu_opts_foreach(), is fine with it, but clean it up anyway.Signed-off-by Markus Armbruster <[email protected]>
Quoted 35 lines
--- vl.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)vl.c +3
-7@@ -2676,7 +2676,7 @@ static int machine_set_property(void *opaque,g_free (qom_name);if (local_err) { -error_report_err (local_err); +error_propagate (errp, local_err);return -1 ; }@@ -4201,11 +4201,8 @@ int main(int argc, char **argv, char **envp) } machine_opts =qemu_get_machine_opts (); -if (qemu_opt_foreach (machine_opts, machine_set_property, current_machine, -NULL )) { -object_unref (OBJECT (current_machine)); -exit (1 ); - } +qemu_opt_foreach (machine_opts, machine_set_property, current_machine, + &error_fatal);configure_accelerator (current_machine); --2.17.1
Signature · 1 line
Marc-André Lureau
Re: [Qemu-devel] [PATCH 21/31] vl: Clean up error reporting in mon_init_func()
In reply to Markus ArmbrusterHi
Quoted 7 lines · Markus Armbruster
Calling
error_report()in a function that takes an Error ** argument is suspicious.mon_init_func()does that, and then fails without setting an error. Its callermain(), viaqemu_opts_foreach(), is fine with it, but clean it up anyway.Signed-off-by Markus Armbruster <[email protected]>
Quoted 47 lines
--- vl.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)vl.c +6
-9@@ -2270,8 +2270,8 @@ static int mon_init_func(void *opaque, QemuOpts *opts, Error **errp) }else if (strcmp (mode,"control" ) ==0 ) { flags =MONITOR_USE_CONTROL ; }else { -error_report ("unknown monitor mode \"%s\"" , mode); -exit (1 ); +error_setg (errp,"unknown monitor mode \"%s\"" , mode); +return -1 ; }if (qemu_opt_get_bool (opts,"pretty" ,0 ))@@ -2285,8 +2285,8 @@ static int mon_init_func(void *opaque, QemuOpts *opts, Error **errp) chardev =qemu_opt_get (opts,"chardev" ); chr =qemu_chr_find (chardev);if (chr ==NULL ) { -error_report ("chardev \"%s\" not found" , chardev); -exit (1 ); +error_setg (errp,"chardev \"%s\" not found" , chardev); +return -1 ; }monitor_init (chr, flags);@@ -4365,10 +4365,8 @@ int main(int argc, char **argv, char **envp)default_drive (default_floppy, snapshot,IF_FLOPPY ,0 ,FD_OPTS );default_drive (default_sdcard, snapshot,IF_SD ,0 ,SD_OPTS ); -if (qemu_opts_foreach (qemu_find_opts ("mon" ), - mon_init_func,NULL ,NULL )) { -exit (1 ); - } +qemu_opts_foreach (qemu_find_opts ("mon" ), + mon_init_func,NULL , &error_fatal);if (foreach_device_config (DEV_SERIAL , serial_parse) <0 )exit (1 ); --2.17.1
Signature · 1 line
Marc-André Lureau
Re: [Qemu-devel] [PATCH 22/31] vl: Clean up error reporting in parse_fw_cfg()
In reply to Markus ArmbrusterHi
Quoted 7 lines · Markus Armbruster
Calling
error_report()in a function that takes an Error ** argument is suspicious.parse_fw_cfg()does that, and then fails without setting an error. Its callermain(), viaqemu_opts_foreach(), is fine with it, but clean it up anyway.Signed-off-by Markus Armbruster <[email protected]>
Quoted 63 lines
--- vl.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)vl.c +8
-10@@ -2174,7 +2174,7 @@ static int parse_fw_cfg(void *opaque, QemuOpts *opts, Error **errp)FWCfgState *fw_cfg = (FWCfgState *) opaque;if (fw_cfg ==NULL ) { -error_report ("fw_cfg device not available" ); +error_setg (errp,"fw_cfg device not available" );return -1 ; } name =qemu_opt_get (opts,"name" );@@ -2183,15 +2183,16 @@ static int parse_fw_cfg(void *opaque, QemuOpts *opts, Error **errp)/* we need name and either a file or the content string */ if (!(nonempty_str (name) && (nonempty_str (file) ||nonempty_str (str)))) { -error_report ("invalid argument(s)" ); +error_setg (errp,"invalid argument(s)" );return -1 ; }if (nonempty_str (file) &&nonempty_str (str)) { -error_report ("file and string are mutually exclusive" ); +error_setg (errp,"file and string are mutually exclusive" );return -1 ; }if (strlen (name) >FW_CFG_MAX_FILE_PATH -1 ) { -error_report ("name too long (max. %d char)" ,FW_CFG_MAX_FILE_PATH -1 ); +error_setg (errp,"name too long (max. %d char)" , +FW_CFG_MAX_FILE_PATH -1 );return -1 ; }if (strncmp (name,"opt/" ,4 ) !=0 ) {@@ -2203,7 +2204,7 @@ static int parse_fw_cfg(void *opaque, QemuOpts *opts, Error **errp) buf =g_memdup (str, size); }else {if (!g_file_get_contents (file, &buf, &size,NULL )) { -error_report ("can't load %s" , file); +error_setg (errp,"can't load %s" , file);return -1 ; } }@@ -4429,10 +4430,8 @@ int main(int argc, char **argv, char **envp)hax_sync_vcpus (); } -if (qemu_opts_foreach (qemu_find_opts ("fw_cfg" ), - parse_fw_cfg,fw_cfg_find (),NULL ) !=0 ) { -exit (1 ); - } +qemu_opts_foreach (qemu_find_opts ("fw_cfg" ), + parse_fw_cfg,fw_cfg_find (), &error_fatal);/* init USB devices */ if (machine_usb (current_machine)) { --2.17.1
Signature · 1 line
Marc-André Lureau
Re: [Qemu-devel] [PATCH 24/31] vl: Clean up error reporting in vnc_init_func()
In reply to Markus ArmbrusterHi
Quoted 8 lines · Markus Armbruster
Calling
error_report()in a function that takes an Error ** argument is suspicious.vnc_init_func()does that, and then fails without setting an error. Its callermain(), viaqemu_opts_foreach(), is fine with it, but clean it up anyway.Cc Gerd Hoffmann <[email protected]>Signed-off-by Markus Armbruster <[email protected]>
Quoted 38 lines
--- ui/vnc.c | 5 +++-- vl.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-)ui/vnc.c +3
-2@@ -4082,8 +4082,9 @@ int vnc_init_func(void *opaque, QemuOpts *opts, Error **errp)vnc_display_init (id);vnc_display_open (id, &local_err);if (local_err !=NULL ) { -error_reportf_err (local_err,"Failed to start VNC server: " ); -exit (1 ); +error_propagate (errp, local_err); +error_prepend (errp,"Failed to start VNC server: " ); +return -1 ; }return 0 ; }vl.c +1
-2@@ -4479,7 +4479,7 @@ int main(int argc, char **argv, char **envp)/* init remote displays */ #ifdef CONFIG_VNC qemu_opts_foreach (qemu_find_opts ("vnc" ), - vnc_init_func,NULL ,NULL ); + vnc_init_func,NULL , &error_fatal);#endif if (using_spice) { --2.17.1
Signature · 1 line
Marc-André Lureau
Re: [Qemu-devel] [PATCH 26/31] tpm: Clean up error reporting in tpm_init_tpmdev()
In reply to Markus ArmbrusterHi
Quoted 8 lines · Markus Armbruster
Calling
error_report()in a function that takes an Error ** argument is suspicious.tpm_init_tpmdev()does that, and then fails without setting an error. Its callermain(), viatpm_init()andqemu_opts_foreach(), is fine with it, but clean it up anyway.Cc Stefan Berger <[email protected]>Signed-off-by Markus Armbruster <[email protected]>
Quoted 119 lines
--- include/sysemu/tpm.h | 2 +- stubs/tpm.c | 3 +-- tpm.c | 22 +++++++++------------- vl.c | 4 +--- 4 files changed, 12 insertions(+), 19 deletions(-)include/sysemu/tpm.h +1
-1@@ -16,7 +16,7 @@#include "qom/object.h" int tpm_config_parse (QemuOptsList *opts_list,const char *optarg); -int tpm_init (void ); +void tpm_init (void );void tpm_cleanup (void ); typedef enum TPMVersion {stubs/tpm.c +1
-2@@ -9,9 +9,8 @@#include "qapi/qapi-commands-tpm.h" #include "sysemu/tpm.h" -int tpm_init (void ) +void tpm_init (void ) { -return 0 ; }void tpm_cleanup (void )tpm.c +9
-13@@ -89,19 +89,19 @@ static int tpm_init_tpmdev(void *dummy, QemuOpts *opts, Error **errp)int i;if (!QLIST_EMPTY (&tpm_backends)) { -error_report ("Only one TPM is allowed." ); +error_setg (errp,"Only one TPM is allowed." );return 1 ; } id =qemu_opts_id (opts);if (id ==NULL ) { -error_report (QERR_MISSING_PARAMETER ,"id" ); +error_setg (errp,QERR_MISSING_PARAMETER ,"id" );return 1 ; } value =qemu_opt_get (opts,"type" );if (!value) { -error_report (QERR_MISSING_PARAMETER ,"type" ); +error_setg (errp,QERR_MISSING_PARAMETER ,"type" );tpm_display_backend_drivers ();return 1 ; }@@ -109,8 +109,8 @@ static int tpm_init_tpmdev(void *dummy, QemuOpts *opts, Error **errp) i =qapi_enum_parse (&TpmType_lookup, value,-1 ,NULL ); be = i >=0 ?tpm_be_find_by_type (i) :NULL ;if (be ==NULL ) { -error_report (QERR_INVALID_PARAMETER_VALUE , -"type" ,"a TPM backend type" ); +error_setg (errp,QERR_INVALID_PARAMETER_VALUE ,"type" , +"a TPM backend type" );tpm_display_backend_drivers ();return 1 ; }@@ -118,7 +118,7 @@ static int tpm_init_tpmdev(void *dummy, QemuOpts *opts, Error **errp)/* validate backend specific opts */ qemu_opts_validate (opts, be->opts, &local_err);if (local_err) { -error_report_err (local_err); +error_propagate (errp, local_err);return 1 ; }@@ -151,14 +151,10 @@ void tpm_cleanup(void)* Initialize the TPM. Process the tpmdev command line options describing the * TPM backend. */ -int tpm_init (void ) +void tpm_init (void ) { -if (qemu_opts_foreach (qemu_find_opts ("tpmdev" ), - tpm_init_tpmdev,NULL ,NULL )) { -return -1 ; - } - -return 0 ; +qemu_opts_foreach (qemu_find_opts ("tpmdev" ), + tpm_init_tpmdev,NULL , &error_fatal); }/* vl.c +1
-4@@ -4312,9 +4312,7 @@ int main(int argc, char **argv, char **envp) user_creatable_add_opts_foreach, object_create_delayed, &error_fatal); -if (tpm_init () <0 ) { -exit (1 ); - } +tpm_init ();/* init the bluetooth world */ if (foreach_device_config (DEV_BT , bt_parse)) --2.17.1
Signature · 1 line
Marc-André Lureau
Re: [Qemu-devel] [PATCH 27/31] spice: Clean up error reporting in add_channel()
In reply to Markus ArmbrusterHi
Quoted 8 lines · Markus Armbruster
Calling
error_report()in a function that takes an Error ** argument is suspicious.add_channel()does that, and then exit()s. Its callermain(), viaqemu_opts_foreach(), is fine with it, but clean it up anyway.Cc Gerd Hoffmann <[email protected]>Signed-off-by Markus Armbruster <[email protected]>
Quoted 46 lines
--- ui/spice-core.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)ui/spice-core.c +7
-7@@ -597,9 +597,9 @@ static int add_channel(void *opaque, const char *name, const char *value,if (strcmp (name,"tls-channel" ) ==0 ) {int *tls_port = opaque;if (!*tls_port) { -error_report ("spice: tried to setup tls-channel" -" without specifying a TLS port" ); -exit (1 ); +error_setg (errp,"spice: tried to setup tls-channel" +" without specifying a TLS port" ); +return -1 ; } security =SPICE_CHANNEL_SECURITY_SSL ; }@@ -615,8 +615,9 @@ static int add_channel(void *opaque, const char *name, const char *value, rc =spice_server_set_channel_security (spice_server, value, security); }if (rc !=0 ) { -error_report ("spice: failed to set channel security for %s" , value); -exit (1 ); +error_setg (errp,"spice: failed to set channel security for %s" , + value); +return -1 ; }return 0 ; }@@ -787,7 +788,7 @@ void qemu_spice_init(void)spice_server_set_playback_compression (spice_server,qemu_opt_get_bool (opts,"playback-compression" ,1 )); -qemu_opt_foreach (opts, add_channel, &tls_port,NULL ); +qemu_opt_foreach (opts, add_channel, &tls_port, &error_fatal);spice_server_set_name (spice_server, qemu_name);spice_server_set_uuid (spice_server, (unsigned char *)&qemu_uuid); --2.17.1
Signature · 1 line
Marc-André Lureau
Re: [Qemu-devel] [PATCH 18/31] qom: Clean up error reporting in user_creatable_add_opts_foreach()
In reply to Markus ArmbrusterQuoted 5 lines · Markus Armbruster
Calling
error_report()in a function that takes an Error ** argument is suspicious.user_creatable_add_opts_foreach()does that, and then fails without setting an error. Its callermain(), viaqemu_opts_foreach(), is fine with it, but clean it up anyway.
Quoted 8 lines
Cc Daniel P. Berrangé <[email protected]>Signed-off-by Markus Armbruster <[email protected]>--- qemu-io.c | 8 +++----- qemu-nbd.c | 8 +++----- qom/object_interfaces.c | 4 +--- vl.c | 16 ++++++---------- 4 files changed, 13 insertions(+), 23 deletions(-)
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Re: [Qemu-devel] [PATCH 10/31] smbios: Clean up error handling in smbios_add()
In reply to Markus ArmbrusterQuoted 195 lines · Markus Armbruster
Calling
error_report()in a function that takes an Error ** argument is suspicious.smbios_entry_add()does that, and then exit()s. It also passes&error_fataltoqemu_opts_validate(). Both wrong, but currently harmless, as its only caller passes&error_fatal. Messed up in commit1007a37e208. Clean it up.Cc Paolo Bonzini <[email protected]>Signed-off-by Markus Armbruster <[email protected]>--- hw/smbios/smbios.c | 90 +++++++++++++++++++++++++++++++--------------- 1 file changed, 62 insertions(+), 28 deletions(-)hw/smbios/smbios.c +58
-26@@ -950,6 +950,7 @@ static void save_opt_list(size_t *ndest, const char ***dest,void smbios_entry_add (QemuOpts *opts,Error **errp) { +Error *err =NULL ;const char *val;assert (!smbios_immutable);@@ -960,12 +961,16 @@ void smbios_entry_add(QemuOpts *opts, Error **errp)int size;struct smbios_table *table;/* legacy mode only */ -qemu_opts_validate (opts, qemu_smbios_file_opts, &error_fatal); +qemu_opts_validate (opts, qemu_smbios_file_opts, &err); +if (err) { +error_propagate (errp, err); +return ; + } size =get_image_size (val);if (size ==-1 || size <sizeof (struct smbios_structure_header )) { -error_report ("Cannot read SMBIOS file %s" , val); -exit (1 ); +error_setg (errp,"Cannot read SMBIOS file %s" , val); +return ; }/* @@ -978,14 +983,15 @@ void smbios_entry_add(QemuOpts *opts, Error **errp) smbios_tables_len);if (load_image (val, (uint8_t *)header) != size) { -error_report ("Failed to load SMBIOS file %s" , val); -exit (1 ); +error_setg (errp,"Failed to load SMBIOS file %s" , val); +return ; }if (test_bit (header->type, have_fields_bitmap)) { -error_report ("can't load type %d struct, fields already specified!" , - header->type); -exit (1 ); +error_setg (errp, +"can't load type %d struct, fields already specified!" , + header->type); +return ; }set_bit (header->type, have_binfile_bitmap);@@ -1030,19 +1036,23 @@ void smbios_entry_add(QemuOpts *opts, Error **errp)unsigned long type =strtoul (val,NULL ,0 );if (type >SMBIOS_MAX_TYPE ) { -error_report ("out of range!" ); -exit (1 ); +error_setg (errp,"out of range!" ); +return ; }if (test_bit (type, have_binfile_bitmap)) { -error_report ("can't add fields, binary file already loaded!" ); -exit (1 ); +error_setg (errp,"can't add fields, binary file already loaded!" ); +return ; }set_bit (type, have_fields_bitmap);switch (type) {case 0 : -qemu_opts_validate (opts, qemu_smbios_type0_opts, &error_fatal); +qemu_opts_validate (opts, qemu_smbios_type0_opts, &err); +if (err) { +error_propagate (errp, err); +return ; + }save_opt (&type0.vendor, opts,"vendor" );save_opt (&type0.version, opts,"version" );save_opt (&type0.date, opts,"date" );@@ -1051,14 +1061,18 @@ void smbios_entry_add(QemuOpts *opts, Error **errp) val =qemu_opt_get (opts,"release" );if (val) {if (sscanf (val,"%hhu.%hhu" , &type0.major, &type0.minor) !=2 ) { -error_report ("Invalid release" ); -exit (1 ); +error_setg (errp,"Invalid release" ); +return ; } type0.have_major_minor = true; }return ;case 1 : -qemu_opts_validate (opts, qemu_smbios_type1_opts, &error_fatal); +qemu_opts_validate (opts, qemu_smbios_type1_opts, &err); +if (err) { +error_propagate (errp, err); +return ; + }save_opt (&type1.manufacturer, opts,"manufacturer" );save_opt (&type1.product, opts,"product" );save_opt (&type1.version, opts,"version" );@@ -1069,14 +1083,18 @@ void smbios_entry_add(QemuOpts *opts, Error **errp) val =qemu_opt_get (opts,"uuid" );if (val) {if (qemu_uuid_parse (val, &qemu_uuid) !=0 ) { -error_report ("Invalid UUID" ); -exit (1 ); +error_setg (errp,"Invalid UUID" ); +return ; } qemu_uuid_set = true; }return ;case 2 : -qemu_opts_validate (opts, qemu_smbios_type2_opts, &error_fatal); +qemu_opts_validate (opts, qemu_smbios_type2_opts, &err); +if (err) { +error_propagate (errp, err); +return ; + }save_opt (&type2.manufacturer, opts,"manufacturer" );save_opt (&type2.product, opts,"product" );save_opt (&type2.version, opts,"version" );@@ -1085,7 +1103,11 @@ void smbios_entry_add(QemuOpts *opts, Error **errp)save_opt (&type2.location, opts,"location" );return ;case 3 : -qemu_opts_validate (opts, qemu_smbios_type3_opts, &error_fatal); +qemu_opts_validate (opts, qemu_smbios_type3_opts, &err); +if (err) { +error_propagate (errp, err); +return ; + }save_opt (&type3.manufacturer, opts,"manufacturer" );save_opt (&type3.version, opts,"version" );save_opt (&type3.serial, opts,"serial" );@@ -1093,7 +1115,11 @@ void smbios_entry_add(QemuOpts *opts, Error **errp)save_opt (&type3.sku, opts,"sku" );return ;case 4 : -qemu_opts_validate (opts, qemu_smbios_type4_opts, &error_fatal); +qemu_opts_validate (opts, qemu_smbios_type4_opts, &err); +if (err) { +error_propagate (errp, err); +return ; + }save_opt (&type4.sock_pfx, opts,"sock_pfx" );save_opt (&type4.manufacturer, opts,"manufacturer" );save_opt (&type4.version, opts,"version" );@@ -1102,11 +1128,19 @@ void smbios_entry_add(QemuOpts *opts, Error **errp)save_opt (&type4.part, opts,"part" );return ;case 11 : -qemu_opts_validate (opts, qemu_smbios_type11_opts, &error_fatal); +qemu_opts_validate (opts, qemu_smbios_type11_opts, &err); +if (err) { +error_propagate (errp, err); +return ; + }save_opt_list (&type11.nvalues, &type11.values, opts,"value" );return ;case 17 : -qemu_opts_validate (opts, qemu_smbios_type17_opts, &error_fatal); +qemu_opts_validate (opts, qemu_smbios_type17_opts, &err); +if (err) { +error_propagate (errp, err); +return ; + }save_opt (&type17.loc_pfx, opts,"loc_pfx" );save_opt (&type17.bank, opts,"bank" );save_opt (&type17.manufacturer, opts,"manufacturer" );@@ -1116,12 +1150,12 @@ void smbios_entry_add(QemuOpts *opts, Error **errp) type17.speed =qemu_opt_get_number (opts,"speed" ,0 );return ;default : -error_report ("Don't know how to build fields for SMBIOS type %ld" , - type); -exit (1 ); + error_setg(errp,
hw/smbios/smbios.c void smbios_entry_add(QemuOpts *opts, Error **errp) · line 1161
Quoted 10 lines
hw/smbios/smbios.c +4
-2+"Don't know how to build fields for SMBIOS type %ld" , + type); +return ; } } -error_report ("Must specify type= or file=" ); -exit (1 ); +error_setg (errp,"Must specify type= or file=" ); }
Re: [Qemu-devel] [PATCH 16/31] seccomp: Clean up error reporting in parse_sandbox()
In reply to Markus ArmbrusterQuoted 40 lines · Markus Armbruster
Calling
error_report()in a function that takes an Error ** argument is suspicious.parse_sandbox()does that, and then fails without setting an error. Its callermain(), viaqemu_opts_foreach(), is fine with it, but clean it up anyway.Cc Eduardo Otubo <[email protected]>Signed-off-by Markus Armbruster <[email protected]>--- qemu-seccomp.c | 18 +++++++++--------- vl.c | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-)qemu-seccomp.c +3
-2@@ -12,11 +12,12 @@* Contributions after 2012-01-13 are licensed under the terms of the * GNU GPL, version 2 or (at your option) any later version. */ +#include "qemu/osdep.h" +#include "qapi/error.h" #include "qemu/config-file.h" #include "qemu/option.h" #include "qemu/module.h" -#include "qemu/error-report.h" #include <sys/prctl.h> #include <seccomp.h> #include "sysemu/seccomp.h" @@ -190,7 +191,7 @@ int parse_sandbox(void *opaque, QemuOpts *opts, Error **errp)* to provide a little bit of consistency for * the command line */ }else { -error_report ("invalid argument for obsolete" ); +error_setg (errp,"invalid argument for obsolete" );return -1 ; } }
qemu-seccomp.c int parse_sandbox(void *opaque, QemuOpts *opts, Error **errp) · line 210
Quoted 7 lines
qemu-seccomp.c +1
-2@@ -205,14 +206,13 @@ int parse_sandbox(void *opaque, QemuOpts *opts, Error **errp)/* calling prctl directly because we're * not sure if host has CAP_SYS_ADMIN set*/ if (prctl (PR_SET_NO_NEW_PRIVS ,1 )) { -error_report ("failed to set no_new_privs " -"aborting" ); +error_setg (errp,"failed to set no_new_privs " "aborting" );return -1 ;
Except for this " " all else is good.
Quoted 54 lines
qemu-seccomp.c +5
-5} }else if (g_str_equal (value,"allow" )) {/* default value */ }else { -error_report ("invalid argument for elevateprivileges" ); +error_setg (errp,"invalid argument for elevateprivileges" );return -1 ; } }@@ -224,7 +224,7 @@ int parse_sandbox(void *opaque, QemuOpts *opts, Error **errp) }else if (g_str_equal (value,"allow" )) {/* default value */ }else { -error_report ("invalid argument for spawn" ); +error_setg (errp,"invalid argument for spawn" );return -1 ; } }@@ -236,14 +236,14 @@ int parse_sandbox(void *opaque, QemuOpts *opts, Error **errp) }else if (g_str_equal (value,"allow" )) {/* default value */ }else { -error_report ("invalid argument for resourcecontrol" ); +error_setg (errp,"invalid argument for resourcecontrol" );return -1 ; } }if (seccomp_start (seccomp_opts) <0 ) { -error_report ("failed to install seccomp syscall filter " -"in the kernel" ); +error_setg (errp,"failed to install seccomp syscall filter " +"in the kernel" );return -1 ; } }vl.c +2
-2@@ -3925,8 +3925,8 @@ int main(int argc, char **argv, char **envp)#ifdef CONFIG_SECCOMP olist =qemu_find_opts_err ("sandbox" ,NULL ); -if (olist &&qemu_opts_foreach (olist, parse_sandbox,NULL ,NULL )) { -exit (1 ); +if (olist) { +qemu_opts_foreach (olist, parse_sandbox,NULL , &error_fatal); }#endif Signature · 1 line
2.17.1
Signature · 1 line
Eduardo Otubo
Re: [Qemu-devel] [PATCH 15/31] xen/pt: Fix incomplete conversion to realize()
In reply to Markus ArmbrusterQuoted 6 lines · Markus Armbruster
The conversion of "xen-pci-passthrough" to
realize()(commit5a11d0f7549, v2.6.0) neglected to convert thexen_pt_config_init()error path. Ifxen_pt_config_init()fails,xen_pt_realize()reports the error, then returns success without completing its job. I don't know the exact impact, but it can't be good.
Quoted 6 lines
Belatedly convert the error path.
Fixes 5a11d0f7549e24a10e178a9dc8ff5e698031d9a6Cc Stefano Stabellini <[email protected]>Cc Anthony Perard <[email protected]>Signed-off-by Markus Armbruster <[email protected]>
Thanks,
Signature · 1 line
Anthony PERARD
Re: [Qemu-devel] [PATCH 26/31] tpm: Clean up error reporting in tpm_init_tpmdev()
In reply to Markus ArmbrusterQuoted 7 lines · Markus Armbruster
Calling
error_report()in a function that takes an Error ** argument is suspicious.tpm_init_tpmdev()does that, and then fails without setting an error. Its callermain(), viatpm_init()andqemu_opts_foreach(), is fine with it, but clean it up anyway.Cc Stefan Berger <[email protected]>Signed-off-by Markus Armbruster <[email protected]>
Re: [Qemu-devel] [PATCH 01/31] Use error_fatal to simplify obvious fatal errors (again)
In reply to Eric BlakeQuoted 10 lines · Eric Blake
Quoted 2 lines · Markus Armbruster
Add a slight improvement of the Coccinelle semantic patch from commit
07d04a0219b,which shares the same commit title, but does not actually have a semantic patch, but rather defers to the even older 007b065. But I'm not too worried about either the duplicated commit title nor the chain of references to follow - as this is a no-semantic-change patch rather than a bugfix, it's less likely to cause confusion to any downstream backport efforts.
I'm changing the reference to 007b06578ab anyway.
Quoted 8 lines
Quoted 2 lines
and use it to clean up. It leaves dead Error * variables behind, cleaned up manually.
Coccinelle can handle that too, if we want to make the .cocci file longer (but off-hand, I don't remember the exact semantic patch formula to express a variable that is initialized but then never used, as a result of applying earlier semantic patches). So the manual cleanup for now still seems tractable.
We can track down the recipe when the manual cleanup becomes tiresome.
Quoted 26 lines
Quoted 17 lines
Cc David Gibson <[email protected]>Cc Alexander Graf <[email protected]>Cc Eric Blake <[email protected]>Cc Paolo Bonzini <[email protected]>Signed-off-by Markus Armbruster <[email protected]>--- hw/intc/xics_kvm.c | 7 +------ qemu-nbd.c | 6 +----- scripts/coccinelle/use-error_fatal.cocci | 20 ++++++++++++++++++++ vl.c | 7 +------ 4 files changed, 23 insertions(+), 17 deletions(-)create mode 100644
scripts/coccinelle/use-error_fatal.cocci+++
b/scripts/coccinelle/use-error_fatal.cocciscripts/coccinelle/use-error_fatal.cocci line 5
Quoted 5 lines
scripts/coccinelle/use-error_fatal.cocci new file +5
-0@@ -0,0 +1,20 @@ +@@ +type T; +identifier FUN, RET; +expression list ARGS; +expression ERR, EC, FAIL;The slight improvement from the original git commit log script is the addition of FAIL,
Quoted 15 lines
scripts/coccinelle/use-error_fatal.cocci line 17
Quoted 12 lines
scripts/coccinelle/use-error_fatal.cocci new file +12
-0+@@ +( +- T RET = FUN(ARGS, &ERR); ++ T RET = FUN(ARGS, &error_fatal); +| +- RET = FUN(ARGS, &ERR); ++ RET = FUN(ARGS, &error_fatal); +| +- FUN(ARGS, &ERR); ++ FUN(ARGS, &error_fatal); +) +- if (FAIL) {and a check for arbitrary condition FAIL rather than a more specific ERR != NULL. Makes sense.
Yes.
Quoted 5 lines
scripts/coccinelle/use-error_fatal.cocci line 20
Quoted 3 lines
scripts/coccinelle/use-error_fatal.cocci new file +3
-0+- error_report_err(ERR); +- exit(EC); +- }Reviewed-by Eric Blake <[email protected]>
Thanks!
Re: [Qemu-devel] [PATCH 12/31] l2tpv3: Improve -netdev/netdev_add/-net/... error reporting
In reply to Marc-André LureauQuoted 52 lines · Marc-André Lureau
Hi
Quoted 50 lines · Markus Armbruster
When -netdev l2tpv3 fails, it first reports a specific error, then a generic one, like this:
$ qemu-system-x86_64 -netdev l2tpv3,id=foo,src=,dst=,txsession=1 qemu-system-x86_64: -netdev l2tpv3,id=foo,src=,dst=,txsession=1: l2tpv3_open : could not resolve src, errno = Name or service not known qemu-system-x86_64: Device 'l2tpv3' could not be initializedWith the command line, the messages go to stderr. In HMP, they go to the monitor. In QMP, the second one becomes the error reply, and the first one goes to stderr.
Convert
net_init_tap()to Error. This suppresses the unwanted second message, and makes the specific error the QMP error reply.Cc Jason Wang <[email protected]>Signed-off-by Markus Armbruster <[email protected]>--- net/l2tpv3.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)net/l2tpv3.c +2
-2@@ -28,6 +28,7 @@#include <netdb.h> #include "net/net.h" #include "clients.h" +#include "qapi/error.h" #include "qemu-common.h" #include "qemu/error-report.h" #include "qemu/option.h" @@ -528,7 +529,6 @@ int net_init_l2tpv3(const Netdev *netdev,const char *name, NetClientState *peer, Error **errp) { - /* FIXME error_setg(errp, ...) on failure */ const NetdevL2TPv3Options *l2tpv3;NetL2TPV3State *s;NetClientState *nc;@@ -555,7 +555,7 @@ int net_init_l2tpv3(const Netdev *netdev, }if ((l2tpv3->has_offset) && (l2tpv3->offset >256 )) { -error_report ("l2tpv3_open : offset must be less than 256 bytes" ); +error_setg (errp,"l2tpv3_open : offset must be less than 256 bytes" ); goto outerr; }
Quoted 9 lines
net/l2tpv3.c int net_init_l2tpv3(const Netdev *netdev, · line 567
Quoted 6 lines
net/l2tpv3.c +2
-0@@ -563,6 +563,8 @@ int net_init_l2tpv3(const Netdev *netdev,if (l2tpv3->has_rxcookie && l2tpv3->has_txcookie) { s->cookie = true; }else { +error_setg (errp, +"require both 'rxcookie' and 'txcookie' or neither" );maybe for consistency it would be a good idea to remove the "
l2tpv3_open: " prefix from the other messages while touching it?
Good idea, not least since the other net_init_FOO() don't use such prefixes.
Quoted 2 lines
looks good otherwise:
Reviewed-by Marc-André Lureau <[email protected]>
Thanks!
Re: [Qemu-devel] [PATCH 14/31] numa: Fix QMP command set-numa-node error handling
In reply to Eduardo HabkostQuoted 29 lines · Eduardo Habkost
Quoted 28 lines · Markus Armbruster
Calling
error_report()in a function that takes an Error ** argument is suspicious.parse_numa_node()does that, and then exit()s. It also passes&error_fataltomachine_set_cpu_numa_node(). Both wrong. Attempting to configure numa when the machine doesn't support it kills the VM:$ qemu-system-x86_64 -nodefaults -S -display none -M none -preconfig -qmp stdio {"QMP": {"version": {"qemu": {"micro": 50, "minor": 0, "major": 3}, "package": "v3.0.0-837-gc5e4e49258"}, "capabilities": []}} {"execute": "qmp_capabilities"} {"return": {}} {"execute": "set-numa-node", "arguments": {"type": "node"}} NUMA is not supported by this machine-type $ echo $? 1Messed up when commit
64c2a8f6d3fand7c88e65d9e9(v2.10.0) added incorrect error handling right next to correct examples. Latent bug until commitf3be67812c2(v3.0.0) made it accessible via QMP. Fairly harmless in practice, because it's limited toRUN_STATE_PRECONFIG. The fix is obvious: replaceerror_report();exit()byerror_setg(); return.This affects parse_numa_node()'s other caller
numa_complete_configuration(): since it ignores errors, the "NUMA is not supported by this machine-type" is now ignored, too. But that error is as unexpected there as any other. Change it to abort on error instead.
Quoted 8 lines
Quoted 5 lines
Fixes f3be67812c226162f86ce92634bd913714445420Cc Igor Mammedov <[email protected]>Signed-off-by Markus Armbruster <[email protected]>fixup! numa: Fix QMP command set-numa-node error handling
I assume this last line was kept by mistake, and I'm removing it while committing.
Oops.
Re: [Qemu-devel] [PATCH 16/31] seccomp: Clean up error reporting in parse_sandbox()
In reply to Marc-André LureauQuoted 44 lines · Marc-André Lureau
Hi
Quoted 41 lines · Markus Armbruster
Calling
error_report()in a function that takes an Error ** argument is suspicious.parse_sandbox()does that, and then fails without setting an error. Its callermain(), viaqemu_opts_foreach(), is fine with it, but clean it up anyway.Cc Eduardo Otubo <[email protected]>Signed-off-by Markus Armbruster <[email protected]>--- qemu-seccomp.c | 18 +++++++++--------- vl.c | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-)qemu-seccomp.c +3
-2@@ -12,11 +12,12 @@* Contributions after 2012-01-13 are licensed under the terms of the * GNU GPL, version 2 or (at your option) any later version. */ +#include "qemu/osdep.h" +#include "qapi/error.h" #include "qemu/config-file.h" #include "qemu/option.h" #include "qemu/module.h" -#include "qemu/error-report.h" #include <sys/prctl.h> #include <seccomp.h> #include "sysemu/seccomp.h" @@ -190,7 +191,7 @@ int parse_sandbox(void *opaque, QemuOpts *opts, Error **errp)* to provide a little bit of consistency for * the command line */ }else { -error_report ("invalid argument for obsolete" ); +error_setg (errp,"invalid argument for obsolete" );return -1 ; } }@@ -205,14 +206,13 @@ int parse_sandbox(void *opaque, QemuOpts *opts, Error **errp)
Quoted 8 lines
qemu-seccomp.c int parse_sandbox(void *opaque, QemuOpts *opts, Error **errp) · line 209
Quoted 6 lines
qemu-seccomp.c +1
-2/* calling prctl directly because we're * not sure if host has CAP_SYS_ADMIN set*/ if (prctl (PR_SET_NO_NEW_PRIVS ,1 )) { -error_report ("failed to set no_new_privs " -"aborting" ); +error_setg (errp,"failed to set no_new_privs " "aborting" );Extra " "
Fixing...
Quoted 56 lines
Quoted 42 lines
qemu-seccomp.c +5
-5return -1 ; } }else if (g_str_equal (value,"allow" )) {/* default value */ }else { -error_report ("invalid argument for elevateprivileges" ); +error_setg (errp,"invalid argument for elevateprivileges" );return -1 ; } }@@ -224,7 +224,7 @@ int parse_sandbox(void *opaque, QemuOpts *opts, Error **errp) }else if (g_str_equal (value,"allow" )) {/* default value */ }else { -error_report ("invalid argument for spawn" ); +error_setg (errp,"invalid argument for spawn" );return -1 ; } }@@ -236,14 +236,14 @@ int parse_sandbox(void *opaque, QemuOpts *opts, Error **errp) }else if (g_str_equal (value,"allow" )) {/* default value */ }else { -error_report ("invalid argument for resourcecontrol" ); +error_setg (errp,"invalid argument for resourcecontrol" );return -1 ; } }if (seccomp_start (seccomp_opts) <0 ) { -error_report ("failed to install seccomp syscall filter " -"in the kernel" ); +error_setg (errp,"failed to install seccomp syscall filter " +"in the kernel" );return -1 ; } }vl.c +0
-0vl.c int main(int argc, char **argv, char **envp) · line 3932
Quoted 10 lines
vl.c +2
-2@@ -3925,8 +3925,8 @@ int main(int argc, char **argv, char **envp)#ifdef CONFIG_SECCOMP olist =qemu_find_opts_err ("sandbox" ,NULL ); -if (olist &&qemu_opts_foreach (olist, parse_sandbox,NULL ,NULL )) { -exit (1 ); +if (olist) { +qemu_opts_foreach (olist, parse_sandbox,NULL , &error_fatal); }#endif Other than that,
Quoted 1 line
Reviewed-by Marc-André Lureau <[email protected]>
Thanks!
Re: [Qemu-devel] [PATCH 19/31] vl: Clean up error reporting in parse_add_fd()
In reply to Marc-André LureauQuoted 4 lines · Marc-André Lureau
Hi
Quoted 1 line · Markus Armbruster
Quoted 8 lines
Quoted 6 lines
Calling
error_report()in a function that takes an Error ** argument is suspicious.chardev_init_func()does that, and then fails without setting an error. Its callermain(), viaqemu_opts_foreach(), is fine with it, but clean it up anyway.Signed-off-by Markus Armbruster <[email protected]>commit title is wrong, apart from that:
Fixing...
Quoted 1 line
Reviewed-by Marc-André Lureau <[email protected]>
Thanks!
Re: [Qemu-devel] [PATCH 24/31] vl: Clean up error reporting in vnc_init_func()
In reply to Markus ArmbrusterQuoted 17 lines · Markus Armbruster
Calling
error_report()in a function that takes an Error ** argument is suspicious.vnc_init_func()does that, and then fails without setting an error. Its callermain(), viaqemu_opts_foreach(), is fine with it, but clean it up anyway.Cc Gerd Hoffmann <[email protected]>Signed-off-by Markus Armbruster <[email protected]>--- ui/vnc.c | 5 +++-- vl.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-)ui/vnc.c +0
-0
ui/vnc.c int vnc_init_func(void *opaque, QemuOpts *opts, Error **errp) · line 4082
Quoted 1 line
ui/vnc.c +0
-0@@ -4082,8 +4082,9 @@ int vnc_init_func(void *opaque, QemuOpts *opts, Error **errp)vnc_display_init (id);
My patch is incomplete, there's fprintf(stderr, ...); exit(1); hiding behind vnc_display_init(). See my review of "[PATCH RFC v5 2/7] ui/vnc.c: polish vnc_init_func"
https://lists.nongnu.org/archive/html/qemu-devel/2018-10/msg02238.html
Message-ID: <[email protected]>
Quoted 23 lines
ui/vnc.c +3
-2vnc_display_open (id, &local_err);if (local_err !=NULL ) { -error_reportf_err (local_err,"Failed to start VNC server: " ); -exit (1 ); +error_propagate (errp, local_err); +error_prepend (errp,"Failed to start VNC server: " ); +return -1 ; }return 0 ; }vl.c +1
-1@@ -4479,7 +4479,7 @@ int main(int argc, char **argv, char **envp)/* init remote displays */ #ifdef CONFIG_VNC qemu_opts_foreach (qemu_find_opts ("vnc" ), - vnc_init_func,NULL ,NULL ); + vnc_init_func,NULL , &error_fatal);#endif if (using_spice) {
Re: [Qemu-devel] [PATCH 28/31] fsdev: Clean up error reporting in qemu_fsdev_add()
In reply to Eric BlakeQuoted 4 lines · Eric Blake
Quoted 1 line · Markus Armbruster
Calling
error_report()from within a a function that takes an Error **s/a a/a/
Fixing, thanks!
Quoted 5 lines
Quoted 5 lines
argument is suspicious.
qemu_fsdev_add()does that, and its callerfsdev_init_func()then fails without setting an error. Its callermain(), viaqemu_opts_foreach(), is fine with it, but clean it up anyway.
Re: [Qemu-devel] [PATCH 30/31] blockdev: Convert drive_new() to Error
In reply to Max ReitzCopying Marc-André for a possible connection to his recent work on improving help. Marc-André, search for "format=help". Just in case you have further observations to offer.
Quoted 11 lines · Max Reitz
Quoted 3 lines · Markus Armbruster
Calling
error_report()from within a a function that takes an Error ** argument is suspicious.drive_new()does that, and its callerdrive_init_func()then exit()s.I'm afraid I don't quite follow you here. There is no function here that takes an Error ** already and then calls
error_report(). There is howeverdrive_new()that does not take an Error **, consequentially callserror_report(), and there is its callerdrive_init_func()which does take an Error ** but does not set it.
Quoted 6 lines
So while I fully agree with you to make
drive_new()take an Error ** (and thus effectively fixdrive_init_func()), I don't quite understand this explanation.(Furthermore,
drive_init_func()does notexit(). It'smain()that exit()s after callingdrive_init_func().)
You're right.
There's about a dozen patches cleaning up pretty much the same thing, and I reused the same commit message with the appropriate variations. I failed to vary this instance appropriately. Sorry!
I'll fix this for v2.
Quoted 43 lines
Quoted 29 lines
Its caller
main(), viaqemu_opts_foreach(), is fine with it, but clean it up anyway:* Convert
drive_new()to Error* Update
add_init_drive()to report the error received fromdrive_new().* Make
main()pass&error_fatalthroughqemu_opts_foreach(),drive_init_func()todrive_new()* Make
default_drive()pass&error_abortthroughqemu_opts_foreach(),drive_init_func()todrive_new()Cc Kevin Wolf <[email protected]>Cc Max Reitz <[email protected]>Signed-off-by Markus Armbruster <[email protected]>--- blockdev.c | 27 ++++++++++++++------------- device-hotplug.c | 5 ++++- include/sysemu/blockdev.h | 3 ++- vl.c | 11 ++++------- 4 files changed, 24 insertions(+), 22 deletions(-)blockdev.c +0
-0@@ -759,7 +759,8 @@ QemuOptsList qemu_legacy_drive_opts = {[...]
blockdev.c DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type) · line 996
Quoted 7 lines
blockdev.c +1
-1@@ -991,7 +992,7 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type) bs_opts =NULL ;if (!blk) {if (local_err) { -error_report_err (local_err); +error_propagate (errp, local_err); }Wait, what would be the case where
blockdev_init()returns NULL but *errp remains unse——— oh no.
Quoted 3 lines
There is only one case which is someone specified "format=help". Hm. I suppose you are as unhappy as me about the fact that because of this
drive_new()cannot guarantee that *errp is set in case of an error.
That's an ugly interface wart we have in a few places. In a nutshell, either
* succeed and return a value indicating success
* fail, set an error, and return a value indicating failure
* print help, leave error alone, and return a value indicating failure
Quoted 3 lines
I think it's ""fine"" (*gnashing teeth*) to keep it this way, but it means that callers need to continue to check the return value and not *errp alone.
Yes, they need to check both.
Note that -device and -machine use a technique I consider cleaner:
there's a separate function FOO_help_func() to deal with providing help before we do the actual work. If the user asked for help, FOO_help_func() prints some, and returns 1. Else it returns 0. This lets main() call exit(0) after help.
Quoted 64 lines
Quoted 64 lines
blockdev.c +0
-0goto fail; }else {device-hotplug.c +4
-1@@ -28,6 +28,7 @@#include "sysemu/block-backend.h" #include "sysemu/blockdev.h" #include "qapi/qmp/qdict.h" +#include "qapi/error.h" #include "qemu/config-file.h" #include "qemu/option.h" #include "sysemu/sysemu.h" @@ -36,6 +37,7 @@static DriveInfo *add_init_drive (const char *optstr) { +Error *err =NULL ;DriveInfo *dinfo;QemuOpts *opts;MachineClass *mc;@@ -45,8 +47,9 @@ static DriveInfo *add_init_drive(const char *optstr)return NULL ; mc =MACHINE_GET_CLASS (current_machine); - dinfo =drive_new (opts, mc->block_default_type); + dinfo =drive_new (opts, mc->block_default_type, &err);if (!dinfo) { +error_report_err (err);qemu_opts_del (opts);return NULL ; }include/sysemu/blockdev.h +2
-1@@ -54,7 +54,8 @@ DriveInfo *drive_get_next(BlockInterfaceType type);QemuOpts *drive_def (const char *optstr);QemuOpts *drive_add (BlockInterfaceType type,int index,const char *file,const char *optstr); -DriveInfo *drive_new (QemuOpts *arg,BlockInterfaceType block_default_type); +DriveInfo *drive_new (QemuOpts *arg,BlockInterfaceType block_default_type, +Error **errp);/* device-hotplug */ vl.c +1
-1@@ -1129,7 +1129,7 @@ static int drive_init_func(void *opaque, QemuOpts *opts, Error **errp) {BlockInterfaceType *block_default_type = opaque; -return drive_new (opts, *block_default_type) ==NULL ; +return drive_new (opts, *block_default_type, errp) ==NULL ; }static int drive_enable_snapshot (void *opaque,QemuOpts *opts,Error **errp)@@ -1155,8 +1155,7 @@ static void default_drive(int enable, int snapshot, BlockInterfaceType type,drive_enable_snapshot (NULL , opts,NULL ); }
Quoted 5 lines
vl.c static void default_drive(int enable, int snapshot, BlockInterfaceType type, · line 1158
Quoted 3 lines
vl.c +1
-2- dinfo =drive_new (opts, type); -assert (dinfo); + dinfo =drive_new (opts, type, &error_abort);Which means the assertion is still necessary here.
I see very little value in assert(p) right before *p. Matter of taste, I guess. Do you want me to keep it?
Quoted 15 lines
vl.c int main(int argc, char **argv, char **envp) · line 4351
Quoted 13 lines
vl.c +2
-4dinfo->is_default = true; }@@ -4348,10 +4347,8 @@ int main(int argc, char **argv, char **envp)qemu_opts_foreach (qemu_find_opts ("drive" ), drive_enable_snapshot,NULL ,NULL ); } -if (qemu_opts_foreach (qemu_find_opts ("drive" ), drive_init_func, - &machine_class->block_default_type,NULL )) { -exit (1 ); - } +qemu_opts_foreach (qemu_find_opts ("drive" ), drive_init_func, + &machine_class->block_default_type, &error_fatal);And we still have to keep an
exit()here.
You're right. But it should become exit(0).
Quoted 3 lines
Alternative: You transform blockdev_init()'s format=help into an error (or construct a new error in
drive_new()ifblockdev_init()returned NULL but no error).
Another alternative would be separating out help. Since I'd prefer to keep this patch mostly mechanical, I'd rather do that on top if it's desired.
Quoted 7 lines
Max
Quoted 4 lines
vl.c +0
-0default_drive (default_cdrom, snapshot, machine_class->block_default_type,2 ,CDROM_OPTS );
Re: [Qemu-devel] [PATCH 30/31] blockdev: Convert drive_new() to Error
Quoted 91 lines · Markus Armbruster
Copying Marc-André for a possible connection to his recent work on improving help. Marc-André, search for "format=help". Just in case you have further observations to offer.
Quoted 11 lines · Max Reitz
Quoted 3 lines · Markus Armbruster
Calling
error_report()from within a a function that takes an Error ** argument is suspicious.drive_new()does that, and its callerdrive_init_func()then exit()s.I'm afraid I don't quite follow you here. There is no function here that takes an Error ** already and then calls
error_report(). There is howeverdrive_new()that does not take an Error **, consequentially callserror_report(), and there is its callerdrive_init_func()which does take an Error ** but does not set it.Quoted 6 lines
So while I fully agree with you to make
drive_new()take an Error ** (and thus effectively fixdrive_init_func()), I don't quite understand this explanation.(Furthermore,
drive_init_func()does notexit(). It'smain()that exit()s after callingdrive_init_func().)You're right.
There's about a dozen patches cleaning up pretty much the same thing, and I reused the same commit message with the appropriate variations. I failed to vary this instance appropriately. Sorry!
I'll fix this for v2.
Quoted 43 lines
Quoted 29 lines
Its caller
main(), viaqemu_opts_foreach(), is fine with it, but clean it up anyway:* Convert
drive_new()to Error* Update
add_init_drive()to report the error received fromdrive_new().* Make
main()pass&error_fatalthroughqemu_opts_foreach(),drive_init_func()todrive_new()* Make
default_drive()pass&error_abortthroughqemu_opts_foreach(),drive_init_func()todrive_new()Cc Kevin Wolf <[email protected]>Cc Max Reitz <[email protected]>Signed-off-by Markus Armbruster <[email protected]>--- blockdev.c | 27 ++++++++++++++------------- device-hotplug.c | 5 ++++- include/sysemu/blockdev.h | 3 ++- vl.c | 11 ++++------- 4 files changed, 24 insertions(+), 22 deletions(-)blockdev.c +0
-0@@ -759,7 +759,8 @@ QemuOptsList qemu_legacy_drive_opts = {[...]
blockdev.c DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type) · line 996
Quoted 7 lines
blockdev.c +1
-1@@ -991,7 +992,7 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type) bs_opts =NULL ;if (!blk) {if (local_err) { -error_report_err (local_err); +error_propagate (errp, local_err); }Wait, what would be the case where
blockdev_init()returns NULL but *errp remains unse——— oh no.Quoted 3 lines
There is only one case which is someone specified "format=help". Hm. I suppose you are as unhappy as me about the fact that because of this
drive_new()cannot guarantee that *errp is set in case of an error.That's an ugly interface wart we have in a few places. In a nutshell, either
* succeed and return a value indicating success
* fail, set an error, and return a value indicating failure
* print help, leave error alone, and return a value indicating failure
Quoted 3 lines
I think it's ""fine"" (*gnashing teeth*) to keep it this way, but it means that callers need to continue to check the return value and not *errp alone.
Quoted 7 lines
Yes, they need to check both.
Note that -device and -machine use a technique I consider cleaner:
there's a separate functionFOO_help_func()to deal with providing help before we do the actual work. If the user asked for help,FOO_help_func()prints some, and returns 1. Else it returns 0. This letsmain()call exit(0) after help.
It is indeed cleaner. I don't mind the current way too much, though, I mostly just don't like effectively failing without setting the Error object.
Quoted 64 lines
Quoted 64 lines
Quoted 64 lines
blockdev.c +0
-0goto fail; }else {device-hotplug.c +4
-1@@ -28,6 +28,7 @@#include "sysemu/block-backend.h" #include "sysemu/blockdev.h" #include "qapi/qmp/qdict.h" +#include "qapi/error.h" #include "qemu/config-file.h" #include "qemu/option.h" #include "sysemu/sysemu.h" @@ -36,6 +37,7 @@static DriveInfo *add_init_drive (const char *optstr) { +Error *err =NULL ;DriveInfo *dinfo;QemuOpts *opts;MachineClass *mc;@@ -45,8 +47,9 @@ static DriveInfo *add_init_drive(const char *optstr)return NULL ; mc =MACHINE_GET_CLASS (current_machine); - dinfo =drive_new (opts, mc->block_default_type); + dinfo =drive_new (opts, mc->block_default_type, &err);if (!dinfo) { +error_report_err (err);qemu_opts_del (opts);return NULL ; }include/sysemu/blockdev.h +2
-1@@ -54,7 +54,8 @@ DriveInfo *drive_get_next(BlockInterfaceType type);QemuOpts *drive_def (const char *optstr);QemuOpts *drive_add (BlockInterfaceType type,int index,const char *file,const char *optstr); -DriveInfo *drive_new (QemuOpts *arg,BlockInterfaceType block_default_type); +DriveInfo *drive_new (QemuOpts *arg,BlockInterfaceType block_default_type, +Error **errp);/* device-hotplug */ vl.c +1
-1@@ -1129,7 +1129,7 @@ static int drive_init_func(void *opaque, QemuOpts *opts, Error **errp) {BlockInterfaceType *block_default_type = opaque; -return drive_new (opts, *block_default_type) ==NULL ; +return drive_new (opts, *block_default_type, errp) ==NULL ; }static int drive_enable_snapshot (void *opaque,QemuOpts *opts,Error **errp)@@ -1155,8 +1155,7 @@ static void default_drive(int enable, int snapshot, BlockInterfaceType type,drive_enable_snapshot (NULL , opts,NULL ); }
Quoted 8 lines
Quoted 5 lines
vl.c static void default_drive(int enable, int snapshot, BlockInterfaceType type, · line 1158
Quoted 3 lines
vl.c +1
-2- dinfo =drive_new (opts, type); -assert (dinfo); + dinfo =drive_new (opts, type, &error_abort);Which means the assertion is still necessary here.
I see very little value in assert(p) right before *p. Matter of taste, I guess. Do you want me to keep it?
True. "An assertion looks better to the user" isn't an argument, considering the user shouldn't ever see assertions either.
So feel free to drop it indeed.
Quoted 16 lines
Quoted 15 lines
vl.c int main(int argc, char **argv, char **envp) · line 4351
Quoted 13 lines
vl.c +2
-4dinfo->is_default = true; }@@ -4348,10 +4347,8 @@ int main(int argc, char **argv, char **envp)qemu_opts_foreach (qemu_find_opts ("drive" ), drive_enable_snapshot,NULL ,NULL ); } -if (qemu_opts_foreach (qemu_find_opts ("drive" ), drive_init_func, - &machine_class->block_default_type,NULL )) { -exit (1 ); - } +qemu_opts_foreach (qemu_find_opts ("drive" ), drive_init_func, + &machine_class->block_default_type, &error_fatal);And we still have to keep an
exit()here.
Quoted 1 line
You're right. But it should become exit(0).
That makes sense, yes.
Quoted 7 lines
Quoted 3 lines
Alternative: You transform blockdev_init()'s format=help into an error (or construct a new error in
drive_new()ifblockdev_init()returned NULL but no error).Another alternative would be separating out help. Since I'd prefer to keep this patch mostly mechanical, I'd rather do that on top if it's desired.
I'm not sure how much I desire it, so I won't push you to do so. But it's definitely fine to keep it out of this patch.
Max
Re: [Qemu-devel] [PATCH 14/31] numa: Fix QMP command set-numa-node error handling
In reply to Markus ArmbrusterQuoted 74 lines · On Mon, 8 Oct 2018 19:31:08 +0200 Markus Armbruster <[email protected]> wrote:
Calling
error_report()in a function that takes an Error ** argument is suspicious.parse_numa_node()does that, and then exit()s. It also passes&error_fataltomachine_set_cpu_numa_node(). Both wrong. Attempting to configure numa when the machine doesn't support it kills the VM:$ qemu-system-x86_64 -nodefaults -S -display none -M none -preconfig -qmp stdio {"QMP": {"version": {"qemu": {"micro": 50, "minor": 0, "major": 3}, "package": "v3.0.0-837-gc5e4e49258"}, "capabilities": []}} {"execute": "qmp_capabilities"} {"return": {}} {"execute": "set-numa-node", "arguments": {"type": "node"}} NUMA is not supported by this machine-type $ echo $? 1Messed up when commit
64c2a8f6d3fand7c88e65d9e9(v2.10.0) added incorrect error handling right next to correct examples. Latent bug until commitf3be67812c2(v3.0.0) made it accessible via QMP. Fairly harmless in practice, because it's limited toRUN_STATE_PRECONFIG. The fix is obvious: replaceerror_report();exit()byerror_setg(); return.This affects parse_numa_node()'s other caller
numa_complete_configuration(): since it ignores errors, the "NUMA is not supported by this machine-type" is now ignored, too. But that error is as unexpected there as any other. Change it to abort on error instead.Fixes f3be67812c226162f86ce92634bd913714445420Cc Igor Mammedov <[email protected]>Signed-off-by Markus Armbruster <[email protected]>fixup! numa: Fix QMP command set-numa-node error handling
--- numa.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)numa.c +8
-3@@ -60,6 +60,7 @@ NodeInfo numa_info[MAX_NODES];static void parse_numa_node (MachineState *ms,NumaNodeOptions *node,Error **errp) { +Error *err =NULL ;uint16_t nodenr;uint16List *cpus =NULL ;MachineClass *mc =MACHINE_GET_CLASS (ms);@@ -82,8 +83,8 @@ static void parse_numa_node(MachineState *ms, NumaNodeOptions *node, }if (!mc->cpu_index_to_instance_props || !mc->get_default_cpu_node_id) { -error_report ("NUMA is not supported by this machine-type" ); -exit (1 ); +error_setg (errp,"NUMA is not supported by this machine-type" ); +return ; }for (cpus = node->cpus; cpus; cpus = cpus->next) {CpuInstanceProperties props;@@ -97,7 +98,11 @@ static void parse_numa_node(MachineState *ms, NumaNodeOptions *node, props = mc->cpu_index_to_instance_props (ms, cpus->value); props.node_id = nodenr; props.has_node_id = true; -machine_set_cpu_numa_node (ms, &props, &error_fatal); +machine_set_cpu_numa_node (ms, &props, &err); +if (err) { +error_propagate (errp, err); +return ; + } }if (node->has_mem && node->has_memdev) {
numa.c void numa_complete_configuration(MachineState *ms) · line 375
Quoted 5 lines
numa.c +1
-1@@ -367,7 +372,7 @@ void numa_complete_configuration(MachineState *ms)if (ms->ram_slots >0 && nb_numa_nodes ==0 && mc->auto_enable_numa_with_memhp) {NumaNodeOptions node = { }; -parse_numa_node (ms, &node,NULL ); +parse_numa_node (ms, &node, &error_abort);
it won't affect machines with numa support /i.e. no change/, but if machine that doesn't support numa, gets here it fine for it to die.
numa.c void numa_complete_configuration(MachineState *ms) · line 378
Quoted 3 lines
numa.c +0
-0}assert (max_numa_nodeid <=MAX_NODES );
Re: [Qemu-devel] [PATCH 30/31] blockdev: Convert drive_new() to Error
In reply to Max ReitzAm 12.10.2018 um 14:28 hat Max Reitz geschrieben:
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
vl.c static void default_drive(int enable, int snapshot, BlockInterfaceType type, · line 1158
Quoted 7 lines
vl.c +1
-2@@ -1155,8 +1155,7 @@ static void default_drive(int enable, int snapshot, BlockInterfaceType type,drive_enable_snapshot (NULL , opts,NULL ); } - dinfo =drive_new (opts, type); -assert (dinfo); + dinfo =drive_new (opts, type, &error_abort);Which means the assertion is still necessary here.
Quoted 5 lines
Quoted 2 lines
I see very little value in assert(p) right before *p. Matter of taste, I guess. Do you want me to keep it?
True. "An assertion looks better to the user" isn't an argument, considering the user shouldn't ever see assertions either.
The point that could be made is that it documents that we're aware that drive_new() can return NULL generally, but we've made sure that with the specific options passed it doesn't happen here, so not having any error handling is not a bug, but intended.
Quoted 1 line
So feel free to drop it indeed.
I don't mind either way.
Kevin
Re: [Qemu-devel] [PATCH 14/31] numa: Fix QMP command set-numa-node error handling
In reply to Igor MammedovQuoted 75 lines · Igor Mammedov
Quoted 72 lines · On Mon, 8 Oct 2018 19:31:08 +0200 Markus Armbruster <[email protected]> wrote:
Calling
error_report()in a function that takes an Error ** argument is suspicious.parse_numa_node()does that, and then exit()s. It also passes&error_fataltomachine_set_cpu_numa_node(). Both wrong. Attempting to configure numa when the machine doesn't support it kills the VM:$ qemu-system-x86_64 -nodefaults -S -display none -M none -preconfig -qmp stdio {"QMP": {"version": {"qemu": {"micro": 50, "minor": 0, "major": 3}, "package": "v3.0.0-837-gc5e4e49258"}, "capabilities": []}} {"execute": "qmp_capabilities"} {"return": {}} {"execute": "set-numa-node", "arguments": {"type": "node"}} NUMA is not supported by this machine-type $ echo $? 1Messed up when commit
64c2a8f6d3fand7c88e65d9e9(v2.10.0) added incorrect error handling right next to correct examples. Latent bug until commitf3be67812c2(v3.0.0) made it accessible via QMP. Fairly harmless in practice, because it's limited toRUN_STATE_PRECONFIG. The fix is obvious: replaceerror_report();exit()byerror_setg(); return.This affects parse_numa_node()'s other caller
numa_complete_configuration(): since it ignores errors, the "NUMA is not supported by this machine-type" is now ignored, too. But that error is as unexpected there as any other. Change it to abort on error instead.Fixes f3be67812c226162f86ce92634bd913714445420Cc Igor Mammedov <[email protected]>Signed-off-by Markus Armbruster <[email protected]>fixup! numa: Fix QMP command set-numa-node error handling
--- numa.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)numa.c +8
-3@@ -60,6 +60,7 @@ NodeInfo numa_info[MAX_NODES];static void parse_numa_node (MachineState *ms,NumaNodeOptions *node,Error **errp) { +Error *err =NULL ;uint16_t nodenr;uint16List *cpus =NULL ;MachineClass *mc =MACHINE_GET_CLASS (ms);@@ -82,8 +83,8 @@ static void parse_numa_node(MachineState *ms, NumaNodeOptions *node, }if (!mc->cpu_index_to_instance_props || !mc->get_default_cpu_node_id) { -error_report ("NUMA is not supported by this machine-type" ); -exit (1 ); +error_setg (errp,"NUMA is not supported by this machine-type" ); +return ; }for (cpus = node->cpus; cpus; cpus = cpus->next) {CpuInstanceProperties props;@@ -97,7 +98,11 @@ static void parse_numa_node(MachineState *ms, NumaNodeOptions *node, props = mc->cpu_index_to_instance_props (ms, cpus->value); props.node_id = nodenr; props.has_node_id = true; -machine_set_cpu_numa_node (ms, &props, &error_fatal); +machine_set_cpu_numa_node (ms, &props, &err); +if (err) { +error_propagate (errp, err); +return ; + } }
Quoted 9 lines
numa.c void numa_complete_configuration(MachineState *ms) · line 375
Quoted 7 lines
numa.c +1
-1if (node->has_mem && node->has_memdev) {@@ -367,7 +372,7 @@ void numa_complete_configuration(MachineState *ms)if (ms->ram_slots >0 && nb_numa_nodes ==0 && mc->auto_enable_numa_with_memhp) {NumaNodeOptions node = { }; -parse_numa_node (ms, &node,NULL ); +parse_numa_node (ms, &node, &error_abort);it won't affect machines with numa support /i.e. no change/, but if machine that doesn't support numa, gets here it fine for it to die.
Uh, that could be undesirable. Quick test:
$ qemu-system-x86_64 -nodefaults -S -M none -numa node
qemu-system-x86_64: -numa node: NUMA is not supported by this machine-type
[Exit 1 ]Stack backtrace:
#0 0x00007fffec860b10 in _exit () at /lib64/libc.so.6
#1 0x00007fffec7d36ea in __run_exit_handlers () at /lib64/libc.so.6
#2 0x00007fffec7d371c in () at /lib64/libc.so.6
#3 0x0000555555e3cfb9 in error_handle_fatal (errp=0x55555685d8e0 <error_fatal>, err=0x555556a5cbc0) at /work/armbru/qemu/util/error.c:42
#4 0x0000555555e3db6b in error_propagate (dst_errp=0x55555685d8e0 <error_fatal>, local_err=0x555556a5cbc0) at /work/armbru/qemu/util/error.c:288
#5 0x000055555587e4f2 in parse_numa (opaque=0x55555693fc00, opts=0x55555692ee60, errp=0x55555685d8e0 <error_fatal>) at /work/armbru/qemu/numa.c:242
#6 0x0000555555e4c8d1 in qemu_opts_foreach (list=0x555556647140 <qemu_numa_opts>, func=0x55555587e3cf <parse_numa>, opaque=0x55555693fc00, errp=0x55555685d8e0 <error_fatal>) at /work/armbru/qemu/util/qemu-option.c:1151
#7 0x000055555587ed91 in parse_numa_opts (ms=0x55555693fc00)
at /work/armbru/qemu/numa.c:447
#8 0x0000555555a0c648 in main (argc=7, argv=0x7fffffffdf88, envp=0x7fffffffdfc8) at /work/armbru/qemu/vl.c:4454That's before numa_complete_configuration() gets called via machine_run_board_init().
Can you give me a hint how to "get here fine"?
Quoted 5 lines
numa.c void numa_complete_configuration(MachineState *ms) · line 378
Quoted 3 lines
numa.c +0
-0}assert (max_numa_nodeid <=MAX_NODES );Reviewed-by Igor Mammedov <[email protected]>