From 299528668c759f40b2cc78914e2ca2c832f82834 Mon Sep 17 00:00:00 2001 From: Luiz Capitulino Date: Thu, 12 Apr 2012 11:58:57 -0300 Subject: qemu-option: qemu_opts_validate(): use error_set() net_client_init() propagates the error up by calling qerror_report_err(), because its users expect QError semantics. Signed-off-by: Luiz Capitulino Reviewed-By: Laszlo Ersek --- net.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'net.c') diff --git a/net.c b/net.c index 1922d8a..f5d9cc7 100644 --- a/net.c +++ b/net.c @@ -1136,10 +1136,14 @@ int net_client_init(Monitor *mon, QemuOpts *opts, int is_netdev) for (i = 0; i < NET_CLIENT_TYPE_MAX; i++) { if (net_client_types[i].type != NULL && !strcmp(net_client_types[i].type, type)) { + Error *local_err = NULL; VLANState *vlan = NULL; int ret; - if (qemu_opts_validate(opts, &net_client_types[i].desc[0]) == -1) { + qemu_opts_validate(opts, &net_client_types[i].desc[0], &local_err); + if (error_is_set(&local_err)) { + qerror_report_err(local_err); + error_free(local_err); return -1; } -- 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 --- net.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'net.c') diff --git a/net.c b/net.c index f5d9cc7..246209f 100644 --- a/net.c +++ b/net.c @@ -1237,11 +1237,14 @@ void net_host_device_remove(Monitor *mon, const QDict *qdict) int do_netdev_add(Monitor *mon, const QDict *qdict, QObject **ret_data) { + Error *local_err = NULL; QemuOpts *opts; int res; - opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict); + opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &local_err); if (!opts) { + qerror_report_err(local_err); + error_free(local_err); return -1; } -- 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 --- net.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'net.c') diff --git a/net.c b/net.c index 246209f..adb7e20 100644 --- a/net.c +++ b/net.c @@ -745,10 +745,7 @@ int net_handle_fd_param(Monitor *mon, const char *param) return fd; } -static int net_init_nic(QemuOpts *opts, - Monitor *mon, - const char *name, - VLANState *vlan) +static int net_init_nic(QemuOpts *opts, const char *name, VLANState *vlan) { int idx; NICInfo *nd; @@ -821,7 +818,6 @@ static int net_init_nic(QemuOpts *opts, } typedef int (*net_client_init_func)(QemuOpts *opts, - Monitor *mon, const char *name, VLANState *vlan); @@ -1085,7 +1081,7 @@ static const struct { #endif /* CONFIG_NET_BRIDGE */ }; -int net_client_init(Monitor *mon, QemuOpts *opts, int is_netdev) +int net_client_init(QemuOpts *opts, int is_netdev) { const char *name; const char *type; @@ -1156,7 +1152,7 @@ int net_client_init(Monitor *mon, QemuOpts *opts, int is_netdev) ret = 0; if (net_client_types[i].init) { - ret = net_client_types[i].init(opts, mon, name, vlan); + ret = net_client_types[i].init(opts, name, vlan); if (ret < 0) { /* TODO push error reporting into init() methods */ qerror_report(QERR_DEVICE_INIT_FAILED, type); @@ -1213,7 +1209,7 @@ void net_host_device_add(Monitor *mon, const QDict *qdict) qemu_opt_set(opts, "type", device); - if (net_client_init(mon, opts, 0) < 0) { + if (net_client_init(opts, 0) < 0) { monitor_printf(mon, "adding host network device %s failed\n", device); } } @@ -1248,7 +1244,7 @@ int do_netdev_add(Monitor *mon, const QDict *qdict, QObject **ret_data) return -1; } - res = net_client_init(mon, opts, 1); + res = net_client_init(opts, 1); if (res < 0) { qemu_opts_del(opts); } @@ -1431,14 +1427,14 @@ void net_check_clients(void) static int net_init_client(QemuOpts *opts, void *dummy) { - if (net_client_init(NULL, opts, 0) < 0) + if (net_client_init(opts, 0) < 0) return -1; return 0; } static int net_init_netdev(QemuOpts *opts, void *dummy) { - return net_client_init(NULL, opts, 1); + return net_client_init(opts, 1); } int net_init_clients(void) -- 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 --- net.c | 54 ++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 16 deletions(-) (limited to 'net.c') diff --git a/net.c b/net.c index adb7e20..8f7cb40 100644 --- a/net.c +++ b/net.c @@ -1081,7 +1081,7 @@ static const struct { #endif /* CONFIG_NET_BRIDGE */ }; -int net_client_init(QemuOpts *opts, int is_netdev) +int net_client_init(QemuOpts *opts, int is_netdev, Error **errp) { const char *name; const char *type; @@ -1089,7 +1089,7 @@ int net_client_init(QemuOpts *opts, int is_netdev) type = qemu_opt_get(opts, "type"); if (!type) { - qerror_report(QERR_MISSING_PARAMETER, "type"); + error_set(errp, QERR_MISSING_PARAMETER, "type"); return -1; } @@ -1105,21 +1105,21 @@ int net_client_init(QemuOpts *opts, int is_netdev) strcmp(type, "vde") != 0 && #endif strcmp(type, "socket") != 0) { - qerror_report(QERR_INVALID_PARAMETER_VALUE, "type", - "a netdev backend type"); + error_set(errp, QERR_INVALID_PARAMETER_VALUE, "type", + "a netdev backend type"); return -1; } if (qemu_opt_get(opts, "vlan")) { - qerror_report(QERR_INVALID_PARAMETER, "vlan"); + error_set(errp, QERR_INVALID_PARAMETER, "vlan"); return -1; } if (qemu_opt_get(opts, "name")) { - qerror_report(QERR_INVALID_PARAMETER, "name"); + error_set(errp, QERR_INVALID_PARAMETER, "name"); return -1; } if (!qemu_opts_id(opts)) { - qerror_report(QERR_MISSING_PARAMETER, "id"); + error_set(errp, QERR_MISSING_PARAMETER, "id"); return -1; } } @@ -1138,8 +1138,7 @@ int net_client_init(QemuOpts *opts, int is_netdev) qemu_opts_validate(opts, &net_client_types[i].desc[0], &local_err); if (error_is_set(&local_err)) { - qerror_report_err(local_err); - error_free(local_err); + error_propagate(errp, local_err); return -1; } @@ -1155,7 +1154,7 @@ int net_client_init(QemuOpts *opts, int is_netdev) ret = net_client_types[i].init(opts, name, vlan); if (ret < 0) { /* TODO push error reporting into init() methods */ - qerror_report(QERR_DEVICE_INIT_FAILED, type); + error_set(errp, QERR_DEVICE_INIT_FAILED, type); return -1; } } @@ -1163,8 +1162,8 @@ int net_client_init(QemuOpts *opts, int is_netdev) } } - qerror_report(QERR_INVALID_PARAMETER_VALUE, "type", - "a network client type"); + error_set(errp, QERR_INVALID_PARAMETER_VALUE, "type", + "a network client type"); return -1; } @@ -1195,6 +1194,7 @@ void net_host_device_add(Monitor *mon, const QDict *qdict) { const char *device = qdict_get_str(qdict, "device"); const char *opts_str = qdict_get_try_str(qdict, "opts"); + Error *local_err = NULL; QemuOpts *opts; if (!net_host_check_device(device)) { @@ -1209,7 +1209,10 @@ void net_host_device_add(Monitor *mon, const QDict *qdict) qemu_opt_set(opts, "type", device); - if (net_client_init(opts, 0) < 0) { + net_client_init(opts, 0, &local_err); + if (error_is_set(&local_err)) { + qerror_report_err(local_err); + error_free(local_err); monitor_printf(mon, "adding host network device %s failed\n", device); } } @@ -1244,8 +1247,10 @@ int do_netdev_add(Monitor *mon, const QDict *qdict, QObject **ret_data) return -1; } - res = net_client_init(opts, 1); + res = net_client_init(opts, 1, &local_err); if (res < 0) { + qerror_report_err(local_err); + error_free(local_err); qemu_opts_del(opts); } @@ -1427,14 +1432,31 @@ void net_check_clients(void) static int net_init_client(QemuOpts *opts, void *dummy) { - if (net_client_init(opts, 0) < 0) + Error *local_err = NULL; + + net_client_init(opts, 0, &local_err); + if (error_is_set(&local_err)) { + qerror_report_err(local_err); + error_free(local_err); return -1; + } + return 0; } static int net_init_netdev(QemuOpts *opts, void *dummy) { - return net_client_init(opts, 1); + Error *local_err = NULL; + int ret; + + ret = net_client_init(opts, 1, &local_err); + if (error_is_set(&local_err)) { + qerror_report_err(local_err); + error_free(local_err); + return -1; + } + + return ret; } int net_init_clients(void) -- cgit v1.1 From 928059a37b8e1f152962431fb846f39597b63c36 Mon Sep 17 00:00:00 2001 From: Luiz Capitulino Date: Wed, 18 Apr 2012 17:34:15 -0300 Subject: qapi: convert netdev_add This is not a full QAPI conversion, but an intermediate step. In essence, do_netdev_add() is split into three functions: 1. netdev_add(): performs the actual work. This function is fully converted to Error (thus, it's "qapi-friendly") 2. qmp_netdev_add(): the QMP front-end for netdev_add(). This is coded by hand and not auto-generated (gen=no in the schema). The reason for this it's a lot easier and simpler to with QemuOpts this way 3. hmp_netdev_add(): HMP front-end. This design was suggested by Paolo Bonzini. Signed-off-by: Luiz Capitulino Reviewed-By: Laszlo Ersek --- net.c | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) (limited to 'net.c') diff --git a/net.c b/net.c index 8f7cb40..5f0c53c 100644 --- a/net.c +++ b/net.c @@ -1234,27 +1234,39 @@ void net_host_device_remove(Monitor *mon, const QDict *qdict) qemu_del_vlan_client(vc); } -int do_netdev_add(Monitor *mon, const QDict *qdict, QObject **ret_data) +void netdev_add(QemuOpts *opts, Error **errp) +{ + net_client_init(opts, 1, errp); +} + +int qmp_netdev_add(Monitor *mon, const QDict *qdict, QObject **ret) { Error *local_err = NULL; + QemuOptsList *opts_list; QemuOpts *opts; - int res; - opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &local_err); - if (!opts) { - qerror_report_err(local_err); - error_free(local_err); - return -1; + opts_list = qemu_find_opts_err("netdev", &local_err); + if (error_is_set(&local_err)) { + goto exit_err; } - res = net_client_init(opts, 1, &local_err); - if (res < 0) { - qerror_report_err(local_err); - error_free(local_err); + opts = qemu_opts_from_qdict(opts_list, qdict, &local_err); + if (error_is_set(&local_err)) { + goto exit_err; + } + + netdev_add(opts, &local_err); + if (error_is_set(&local_err)) { qemu_opts_del(opts); + goto exit_err; } - return res; + return 0; + +exit_err: + qerror_report_err(local_err); + error_free(local_err); + return -1; } int do_netdev_del(Monitor *mon, const QDict *qdict, QObject **ret_data) -- cgit v1.1 From 5f96415527e4f25dc83cfc458c46e5bcbfee79ba Mon Sep 17 00:00:00 2001 From: Luiz Capitulino Date: Mon, 16 Apr 2012 14:36:32 -0300 Subject: qapi: convert netdev_del Signed-off-by: Anthony Liguori Signed-off-by: Luiz Capitulino Reviewed-By: Laszlo Ersek --- net.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'net.c') diff --git a/net.c b/net.c index 5f0c53c..4aa416c 100644 --- a/net.c +++ b/net.c @@ -1269,19 +1269,18 @@ exit_err: return -1; } -int do_netdev_del(Monitor *mon, const QDict *qdict, QObject **ret_data) +void qmp_netdev_del(const char *id, Error **errp) { - const char *id = qdict_get_str(qdict, "id"); VLANClientState *vc; vc = qemu_find_netdev(id); if (!vc) { - qerror_report(QERR_DEVICE_NOT_FOUND, id); - return -1; + error_set(errp, QERR_DEVICE_NOT_FOUND, id); + return; } + qemu_del_vlan_client(vc); - qemu_opts_del(qemu_opts_find(qemu_find_opts("netdev"), id)); - return 0; + qemu_opts_del(qemu_opts_find(qemu_find_opts_err("netdev", errp), id)); } static void print_net_client(Monitor *mon, VLANClientState *vc) -- cgit v1.1