Commit a30ecde6 authored by Markus Armbruster's avatar Markus Armbruster Committed by Stefan Hajnoczi
Browse files

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: default avatarMarkus Armbruster <armbru@redhat.com>
Reviewed-by: default avatarEric Blake <eblake@redhat.com>
Message-id: 1431691143-1015-3-git-send-email-armbru@redhat.com
Signed-off-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
parent ca7eb184
Loading
Loading
Loading
Loading
+10 −10
Original line number Diff line number Diff line
@@ -28,38 +28,38 @@
#include "qapi-types.h"

int net_init_dump(const NetClientOptions *opts, const char *name,
                  NetClientState *peer);
                  NetClientState *peer, Error **errp);

#ifdef CONFIG_SLIRP
int net_init_slirp(const NetClientOptions *opts, const char *name,
                   NetClientState *peer);
                   NetClientState *peer, Error **errp);
#endif

int net_init_hubport(const NetClientOptions *opts, const char *name,
                     NetClientState *peer);
                     NetClientState *peer, Error **errp);

int net_init_socket(const NetClientOptions *opts, const char *name,
                    NetClientState *peer);
                    NetClientState *peer, Error **errp);

int net_init_tap(const NetClientOptions *opts, const char *name,
                 NetClientState *peer);
                 NetClientState *peer, Error **errp);

int net_init_bridge(const NetClientOptions *opts, const char *name,
                    NetClientState *peer);
                    NetClientState *peer, Error **errp);

int net_init_l2tpv3(const NetClientOptions *opts, const char *name,
                    NetClientState *peer);
                    NetClientState *peer, Error **errp);
#ifdef CONFIG_VDE
int net_init_vde(const NetClientOptions *opts, const char *name,
                 NetClientState *peer);
                 NetClientState *peer, Error **errp);
#endif

#ifdef CONFIG_NETMAP
int net_init_netmap(const NetClientOptions *opts, const char *name,
                    NetClientState *peer);
                    NetClientState *peer, Error **errp);
#endif

int net_init_vhost_user(const NetClientOptions *opts, const char *name,
                        NetClientState *peer);
                        NetClientState *peer, Error **errp);

#endif /* QEMU_NET_CLIENTS_H */
+2 −1
Original line number Diff line number Diff line
@@ -146,8 +146,9 @@ static int net_dump_init(NetClientState *peer, const char *device,
}

int net_init_dump(const NetClientOptions *opts, const char *name,
                  NetClientState *peer)
                  NetClientState *peer, Error **errp)
{
    /* FIXME error_setg(errp, ...) on failure */
    int len;
    const char *file;
    char def_file[128];
+1 −1
Original line number Diff line number Diff line
@@ -281,7 +281,7 @@ int net_hub_id_for_client(NetClientState *nc, int *id)
}

int net_init_hubport(const NetClientOptions *opts, const char *name,
                     NetClientState *peer)
                     NetClientState *peer, Error **errp)
{
    const NetdevHubPortOptions *hubport;

+2 −3
Original line number Diff line number Diff line
@@ -536,10 +536,9 @@ static NetClientInfo net_l2tpv3_info = {

int net_init_l2tpv3(const NetClientOptions *opts,
                    const char *name,
                    NetClientState *peer)
                    NetClientState *peer, Error **errp)
{


    /* FIXME error_setg(errp, ...) on failure */
    const NetdevL2TPv3Options *l2tpv3;
    NetL2TPV3State *s;
    NetClientState *nc;
+9 −6
Original line number Diff line number Diff line
@@ -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 */
        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;
        }
    }
Loading