aboutsummaryrefslogtreecommitdiff
path: root/net/net.c
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2015-05-15 13:58:50 +0200
committerStefan Hajnoczi <stefanha@redhat.com>2015-05-27 09:51:04 +0100
commita30ecde6e795682d1473c45acae66a60a76fca2f (patch)
treec7e546745660f2427f34a294f44940ce1721fc1f /net/net.c
parentca7eb1848bb06d9b75784d7760b83c7b0beb1102 (diff)
downloadqemu-a30ecde6e795682d1473c45acae66a60a76fca2f.zip
qemu-a30ecde6e795682d1473c45acae66a60a76fca2f.tar.gz
qemu-a30ecde6e795682d1473c45acae66a60a76fca2f.tar.bz2
net: Permit incremental conversion of init functions to Error
Error reporting for netdev_add is broken: the net_client_init_fun[] report the actual errors with (at best) error_report(), and their caller net_client_init1() makes up a generic error on top. For command line and HMP, this produces an mildly ugly error cascade. In QMP, the actual errors go to stderr, and the generic error becomes the command's error reply. To fix this, we need to convert the net_client_init_fun[] to Error. To permit fixing them one by one, add an Error ** parameter to the net_client_init_fun[]. If the call fails without returning an Error, make up the same generic Error as before. But if it returns one, use that instead. Since none of them does so far, no functional change. Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-id: 1431691143-1015-3-git-send-email-armbru@redhat.com Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Diffstat (limited to 'net/net.c')
-rw-r--r--net/net.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/net/net.c b/net/net.c
index d9aaeb5..3295741 100644
--- a/net/net.c
+++ b/net/net.c
@@ -740,8 +740,9 @@ int qemu_find_nic_model(NICInfo *nd, const char * const *models,
}
static int net_init_nic(const NetClientOptions *opts, const char *name,
- NetClientState *peer)
+ NetClientState *peer, Error **errp)
{
+ /* FIXME error_setg(errp, ...) on failure */
int idx;
NICInfo *nd;
const NetLegacyNicOptions *nic;
@@ -809,7 +810,7 @@ static int net_init_nic(const NetClientOptions *opts, const char *name,
static int (* const net_client_init_fun[NET_CLIENT_OPTIONS_KIND_MAX])(
const NetClientOptions *opts,
const char *name,
- NetClientState *peer) = {
+ NetClientState *peer, Error **errp) = {
[NET_CLIENT_OPTIONS_KIND_NIC] = net_init_nic,
#ifdef CONFIG_SLIRP
[NET_CLIENT_OPTIONS_KIND_USER] = net_init_slirp,
@@ -902,10 +903,12 @@ static int net_client_init1(const void *object, int is_netdev, Error **errp)
peer = net_hub_add_port(u.net->has_vlan ? u.net->vlan : 0, NULL);
}
- if (net_client_init_fun[opts->kind](opts, name, peer) < 0) {
- /* TODO push error reporting into init() methods */
- error_set(errp, QERR_DEVICE_INIT_FAILED,
- NetClientOptionsKind_lookup[opts->kind]);
+ if (net_client_init_fun[opts->kind](opts, name, peer, errp) < 0) {
+ /* FIXME drop when all init functions store an Error */
+ if (errp && !*errp) {
+ error_set(errp, QERR_DEVICE_INIT_FAILED,
+ NetClientOptionsKind_lookup[opts->kind]);
+ }
return -1;
}
}