Skip to content

Commit

Permalink
net: Permit incremental conversion of init functions to Error
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Message-id: [email protected]
Signed-off-by: Stefan Hajnoczi <[email protected]>
  • Loading branch information
Markus Armbruster authored and stefanhaRH committed May 27, 2015
1 parent ca7eb18 commit a30ecde
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 29 deletions.
20 changes: 10 additions & 10 deletions net/clients.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
3 changes: 2 additions & 1 deletion net/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion net/hub.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
5 changes: 2 additions & 3 deletions net/l2tpv3.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 9 additions & 6 deletions net/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
}
Expand Down
3 changes: 2 additions & 1 deletion net/netmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,9 @@ static NetClientInfo net_netmap_info = {
* ... -net netmap,ifname="..."
*/
int net_init_netmap(const NetClientOptions *opts,
const char *name, NetClientState *peer)
const char *name, NetClientState *peer, Error **errp)
{
/* FIXME error_setg(errp, ...) on failure */
const NetdevNetmapOptions *netmap_opts = opts->netmap;
NetClientState *nc;
NetmapPriv me;
Expand Down
3 changes: 2 additions & 1 deletion net/slirp.c
Original file line number Diff line number Diff line change
Expand Up @@ -737,8 +737,9 @@ static const char **slirp_dnssearch(const StringList *dnsname)
}

int net_init_slirp(const NetClientOptions *opts, const char *name,
NetClientState *peer)
NetClientState *peer, Error **errp)
{
/* FIXME error_setg(errp, ...) on failure */
struct slirp_config_str *config;
char *vnet;
int ret;
Expand Down
3 changes: 2 additions & 1 deletion net/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -693,8 +693,9 @@ static int net_socket_udp_init(NetClientState *peer,
}

int net_init_socket(const NetClientOptions *opts, const char *name,
NetClientState *peer)
NetClientState *peer, Error **errp)
{
/* FIXME error_setg(errp, ...) on failure */
Error *err = NULL;
const NetdevSocketOptions *sock;

Expand Down
3 changes: 2 additions & 1 deletion net/tap-win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -752,8 +752,9 @@ static int tap_win32_init(NetClientState *peer, const char *model,
}

int net_init_tap(const NetClientOptions *opts, const char *name,
NetClientState *peer)
NetClientState *peer, Error **errp)
{
/* FIXME error_setg(errp, ...) on failure */
const NetdevTapOptions *tap;

assert(opts->kind == NET_CLIENT_OPTIONS_KIND_TAP);
Expand Down
6 changes: 4 additions & 2 deletions net/tap.c
Original file line number Diff line number Diff line change
Expand Up @@ -531,8 +531,9 @@ static int net_bridge_run_helper(const char *helper, const char *bridge)
}

int net_init_bridge(const NetClientOptions *opts, const char *name,
NetClientState *peer)
NetClientState *peer, Error **errp)
{
/* FIXME error_setg(errp, ...) on failure */
const NetdevBridgeOptions *bridge;
const char *helper, *br;

Expand Down Expand Up @@ -699,8 +700,9 @@ static int get_fds(char *str, char *fds[], int max)
}

int net_init_tap(const NetClientOptions *opts, const char *name,
NetClientState *peer)
NetClientState *peer, Error **errp)
{
/* FIXME error_setg(errp, ...) on failure */
const NetdevTapOptions *tap;
int fd, vnet_hdr = 0, i = 0, queues;
/* for the no-fd, no-helper case */
Expand Down
3 changes: 2 additions & 1 deletion net/vde.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,9 @@ static int net_vde_init(NetClientState *peer, const char *model,
}

int net_init_vde(const NetClientOptions *opts, const char *name,
NetClientState *peer)
NetClientState *peer, Error **errp)
{
/* FIXME error_setg(errp, ...) on failure */
const NetdevVdeOptions *vde;

assert(opts->kind == NET_CLIENT_OPTIONS_KIND_VDE);
Expand Down
3 changes: 2 additions & 1 deletion net/vhost-user.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,9 @@ static int net_vhost_check_net(QemuOpts *opts, void *opaque)
}

int net_init_vhost_user(const NetClientOptions *opts, const char *name,
NetClientState *peer)
NetClientState *peer, Error **errp)
{
/* FIXME error_setg(errp, ...) on failure */
const NetdevVhostUserOptions *vhost_user_opts;
CharDriverState *chr;

Expand Down

0 comments on commit a30ecde

Please sign in to comment.