From 8be7e7e4c72c048b90e3482557954a24bba43ba7 Mon Sep 17 00:00:00 2001 From: Luiz Capitulino Date: Tue, 20 Mar 2012 15:51:57 -0300 Subject: qemu-option: qemu_opts_create(): use error_set() This commit converts qemu_opts_create() from qerror_report() to error_set(). Currently, most calls to qemu_opts_create() can't fail, so most callers don't need any changes. The two cases where code checks for qemu_opts_create() erros are: 1. Initialization code in vl.c. All of them print their own error messages directly to stderr, no need to pass the Error object 2. The functions opts_parse(), qemu_opts_from_qdict() and qemu_chr_parse_compat() make use of the error information and they can be called from HMP or QMP. In this case, to allow for incremental conversion, we propagate the error up using qerror_report_err(), which keeps the QError semantics Signed-off-by: Luiz Capitulino Reviewed-By: Laszlo Ersek --- hw/usb/dev-storage.c | 2 +- hw/watchdog.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'hw') diff --git a/hw/usb/dev-storage.c b/hw/usb/dev-storage.c index ae22fb1..a96c0b9 100644 --- a/hw/usb/dev-storage.c +++ b/hw/usb/dev-storage.c @@ -584,7 +584,7 @@ static USBDevice *usb_msd_init(USBBus *bus, const char *filename) /* parse -usbdevice disk: syntax into drive opts */ snprintf(id, sizeof(id), "usb%d", nr++); - opts = qemu_opts_create(qemu_find_opts("drive"), id, 0); + opts = qemu_opts_create(qemu_find_opts("drive"), id, 0, NULL); p1 = strchr(filename, ':'); if (p1++) { diff --git a/hw/watchdog.c b/hw/watchdog.c index 4c18965..a42124d 100644 --- a/hw/watchdog.c +++ b/hw/watchdog.c @@ -66,7 +66,7 @@ int select_watchdog(const char *p) QLIST_FOREACH(model, &watchdog_list, entry) { if (strcasecmp(model->wdt_name, p) == 0) { /* add the device */ - opts = qemu_opts_create(qemu_find_opts("device"), NULL, 0); + opts = qemu_opts_create(qemu_find_opts("device"), NULL, 0, NULL); qemu_opt_set(opts, "driver", p); return 0; } -- cgit v1.1 From 4e89978e2021c0431aad9898823eb9d3526e9018 Mon Sep 17 00:00:00 2001 From: Luiz Capitulino Date: Wed, 18 Apr 2012 17:24:01 -0300 Subject: qemu-option: qemu_opts_from_qdict(): use error_set() do_device_add() and do_netdev_add() call qerror_report_err() to maintain their QError semantics. Signed-off-by: Luiz Capitulino Reviewed-By: Laszlo Ersek --- hw/qdev-monitor.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'hw') diff --git a/hw/qdev-monitor.c b/hw/qdev-monitor.c index eed781d..b01ef06 100644 --- a/hw/qdev-monitor.c +++ b/hw/qdev-monitor.c @@ -554,10 +554,13 @@ void do_info_qdm(Monitor *mon) int do_device_add(Monitor *mon, const QDict *qdict, QObject **ret_data) { + Error *local_err = NULL; QemuOpts *opts; - opts = qemu_opts_from_qdict(qemu_find_opts("device"), qdict); - if (!opts) { + opts = qemu_opts_from_qdict(qemu_find_opts("device"), qdict, &local_err); + if (error_is_set(&local_err)) { + qerror_report_err(local_err); + error_free(local_err); return -1; } if (!monitor_cur_is_qmp() && qdev_device_help(opts)) { -- cgit v1.1 From 42dcc547e1982f31d0f678e02f0aae5be570384a Mon Sep 17 00:00:00 2001 From: Luiz Capitulino Date: Thu, 12 Apr 2012 13:20:40 -0300 Subject: net: purge the monitor object from all init functions The only backend that really uses it is the socket one, which calls monitor_get_fd(). But it can use 'cur_mon' instead. Signed-off-by: Luiz Capitulino Reviewed-By: Laszlo Ersek --- hw/pci-hotplug.c | 2 +- hw/usb/dev-network.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'hw') diff --git a/hw/pci-hotplug.c b/hw/pci-hotplug.c index c55d8b9..785eb3d 100644 --- a/hw/pci-hotplug.c +++ b/hw/pci-hotplug.c @@ -60,7 +60,7 @@ static PCIDevice *qemu_pci_hot_add_nic(Monitor *mon, qemu_opt_set(opts, "type", "nic"); - ret = net_client_init(mon, opts, 0); + ret = net_client_init(opts, 0); if (ret < 0) return NULL; if (nd_table[ret].devaddr) { diff --git a/hw/usb/dev-network.c b/hw/usb/dev-network.c index b238a09..4e26e64 100644 --- a/hw/usb/dev-network.c +++ b/hw/usb/dev-network.c @@ -1367,7 +1367,7 @@ static USBDevice *usb_net_init(USBBus *bus, const char *cmdline) qemu_opt_set(opts, "type", "nic"); qemu_opt_set(opts, "model", "usb"); - idx = net_client_init(NULL, opts, 0); + idx = net_client_init(opts, 0); if (idx == -1) { return NULL; } -- cgit v1.1 From 4559a1dbcc15a10482de822e2839645a1819ef6f Mon Sep 17 00:00:00 2001 From: Luiz Capitulino Date: Fri, 20 Apr 2012 16:50:25 -0300 Subject: net: net_client_init(): use error_set() Callers are changed to use qerror_report_err() to keep their QError semantics. Signed-off-by: Luiz Capitulino Reviewed-By: Laszlo Ersek --- hw/pci-hotplug.c | 8 ++++++-- hw/usb/dev-network.c | 7 +++++-- 2 files changed, 11 insertions(+), 4 deletions(-) (limited to 'hw') diff --git a/hw/pci-hotplug.c b/hw/pci-hotplug.c index 785eb3d..61257f4 100644 --- a/hw/pci-hotplug.c +++ b/hw/pci-hotplug.c @@ -39,6 +39,7 @@ static PCIDevice *qemu_pci_hot_add_nic(Monitor *mon, const char *devaddr, const char *opts_str) { + Error *local_err = NULL; QemuOpts *opts; PCIBus *bus; int ret, devfn; @@ -60,9 +61,12 @@ static PCIDevice *qemu_pci_hot_add_nic(Monitor *mon, qemu_opt_set(opts, "type", "nic"); - ret = net_client_init(opts, 0); - if (ret < 0) + ret = net_client_init(opts, 0, &local_err); + if (error_is_set(&local_err)) { + qerror_report_err(local_err); + error_free(local_err); return NULL; + } if (nd_table[ret].devaddr) { monitor_printf(mon, "Parameter addr not supported\n"); return NULL; diff --git a/hw/usb/dev-network.c b/hw/usb/dev-network.c index 4e26e64..5d2f098 100644 --- a/hw/usb/dev-network.c +++ b/hw/usb/dev-network.c @@ -1356,6 +1356,7 @@ static int usb_net_initfn(USBDevice *dev) static USBDevice *usb_net_init(USBBus *bus, const char *cmdline) { + Error *local_err = NULL; USBDevice *dev; QemuOpts *opts; int idx; @@ -1367,8 +1368,10 @@ static USBDevice *usb_net_init(USBBus *bus, const char *cmdline) qemu_opt_set(opts, "type", "nic"); qemu_opt_set(opts, "model", "usb"); - idx = net_client_init(opts, 0); - if (idx == -1) { + idx = net_client_init(opts, 0, &local_err); + if (error_is_set(&local_err)) { + qerror_report_err(local_err); + error_free(local_err); return NULL; } -- cgit v1.1