Net patches
Subsystems (2)
The following changes since commit 0915aed5842bd4dbe396b92d4f3b846ae29ad663:
Merge remote-tracking branch 'remotes/jnsnow/tags/ide-pull-request' into staging (2015-05-26 11:31:03 +0100)
are available in the git repository at:
git://github.com/stefanha/qemu.git tags/net-pull-request
for you to fetch changes up to 2bc22a58e16f0650e56dccfac9495e5aef58e2ef:
net/net: Record usage status of mac address (2015-05-27 10:34:07 +0100)
----------------------------------------------------------------
----------------------------------------------------------------
Markus Armbruster (15):
net: Improve error message for -net hubport a bit
net: Permit incremental conversion of init functions to Error
net: Improve -net nic error reporting
net/dump: Improve -net/host_net_add dump error reporting
tap: net_tap_fd_init() can't fail, drop dead error handling
tap: Improve -netdev/netdev_add/-net/... bridge error reporting
tap: Convert tap_set_sndbuf() to Error
tap: Convert net_init_tap_one() to Error
tap: Convert launch_script() to Error
tap: Permit incremental conversion of tap_open() to Error
tap-linux: Convert tap_open() to Error
tap-bsd: Convert tap_open() to Error
tap-solaris: Convert tap_open() to Error
tap: Finish conversion of tap_open() to Error
tap: Improve -netdev/netdev_add/-net/... tap error reporting
Shannon Zhao (1):
net/net: Record usage status of mac address
Thomas Huth (1):
net: Change help text to list -netdev instead of -net by default
net/clients.h | 20 +++--- net/dump.c | 13 ++-- net/hub.c | 7 +- net/l2tpv3.c | 5 +- net/net.c | 89 +++++++++++++++++++----- net/netmap.c | 3 +- net/slirp.c | 3 +- net/socket.c | 3 +- net/tap-aix.c | 7 +- net/tap-bsd.c | 38 +++++------ net/tap-haiku.c | 7 +- net/tap-linux.c | 24 +++---- net/tap-solaris.c | 63 ++++++++--------- net/tap-win32.c | 3 +- net/tap.c | 198 ++++++++++++++++++++++++++++++------------------------ net/tap_int.h | 4 +- net/vde.c | 3 +- net/vhost-user.c | 3 +- qemu-options.hx | 77 ++++++++++++--------- 19 files changed, 331 insertions(+), 239 deletions(-)
Signature · 1 line
2.4.1
[Qemu-devel] [PULL 01/17] net: Change help text to list -netdev instead of -net by default
From: Thomas Huth <[email protected]>
Looking at the output of "qemu-system-xxx -help", you easily get the impression that "-net" is the preferred way instead of "-netdev" to specify host network interface, since the "-net" option is omnipresent but the "-netdev" option is only listed as a one-liner at the end. This is ugly since "-net" is considered as legacy and even might be removed one day. Thus, this patch switches the output to explain the host network interfaces with the "-netdev" option instead, moving the old "-net" option into some few lines at the end.
Message-id: [email protected]
--- qemu-options.hx | 77 +++++++++++++++++++++++++++++++++------------------------ 1 file changed, 45 insertions(+), 32 deletions(-)
qemu-options.hx +45 -32
@@ -1449,25 +1449,25 @@ DEF("smb", HAS_ARG, QEMU_OPTION_smb, "", QEMU_ARCH_ALL) #endif #endif -DEF("net", HAS_ARG, QEMU_OPTION_net, - "-net nic[,vlan=n][,macaddr=mac][,model=type][,name=str][,addr=str][,vectors=v]\n" - " create a new Network Interface Card and connect it to VLAN 'n'\n" +DEF("netdev", HAS_ARG, QEMU_OPTION_netdev, #ifdef CONFIG_SLIRP - "-net user[,vlan=n][,name=str][,net=addr[/mask]][,host=addr][,restrict=on|off]\n" + "-netdev user,id=str[,net=addr[/mask]][,host=addr][,restrict=on|off]\n" " [,hostname=host][,dhcpstart=addr][,dns=addr][,dnssearch=domain][,tftp=dir]\n" " [,bootfile=f][,hostfwd=rule][,guestfwd=rule]" #ifndef _WIN32 "[,smb=dir[,smbserver=addr]]\n" #endif - " connect the user mode network stack to VLAN 'n', configure its\n" - " DHCP server and enabled optional services\n" + " configure a user mode network backend with ID 'str',\n" + " its DHCP server and optional services\n" #endif #ifdef _WIN32 - "-net tap[,vlan=n][,name=str],ifname=name\n" - " connect the host TAP network interface to VLAN 'n'\n" + "-netdev tap,id=str,ifname=name\n" + " configure a host TAP network backend with ID 'str'\n" #else - "-net tap[,vlan=n][,name=str][,fd=h][,fds=x:y:...:z][,ifname=name][,script=file][,downscript=dfile][,helper=helper][,sndbuf=nbytes][,vnet_hdr=on|off][,vhost=on|off][,vhostfd=h][,vhostfds=x:y:...:z][,vhostforce=on|off][,queues=n]\n" - " connect the host TAP network interface to VLAN 'n'\n" + "-netdev tap,id=str[,fd=h][,fds=x:y:...:z][,ifname=name][,script=file][,downscript=dfile]\n" + " [,helper=helper][,sndbuf=nbytes][,vnet_hdr=on|off][,vhost=on|off]\n" + " [,vhostfd=h][,vhostfds=x:y:...:z][,vhostforce=on|off][,queues=n]\n" + " configure a host TAP network backend with ID 'str'\n" " use network scripts 'file' (default=" DEFAULT_NETWORK_SCRIPT ")\n" " to configure it and 'dfile' (default=" DEFAULT_NETWORK_DOWN_SCRIPT ")\n" " to deconfigure it\n"
@@ -1486,14 +1486,18 @@ DEF("net", HAS_ARG, QEMU_OPTION_net, " use 'vhostfd=h' to connect to an already opened vhost net device\n" " use 'vhostfds=x:y:...:z to connect to multiple already opened vhost net devices\n" " use 'queues=n' to specify the number of queues to be created for multiqueue TAP\n" - "-net bridge[,vlan=n][,name=str][,br=bridge][,helper=helper]\n" - " connects a host TAP network interface to a host bridge device 'br'\n" - " (default=" DEFAULT_BRIDGE_INTERFACE ") using the program 'helper'\n" - " (default=" DEFAULT_BRIDGE_HELPER ")\n" + "-netdev bridge,id=str[,br=bridge][,helper=helper]\n" + " configure a host TAP network backend with ID 'str' that is\n" + " connected to a bridge (default=" DEFAULT_BRIDGE_INTERFACE ")\n" + " using the program 'helper (default=" DEFAULT_BRIDGE_HELPER ")\n" #endif #ifdef __linux__ - "-net l2tpv3[,vlan=n][,name=str],src=srcaddr,dst=dstaddr[,srcport=srcport][,dstport=dstport],txsession=txsession[,rxsession=rxsession][,ipv6=on/off][,udp=on/off][,cookie64=on/off][,counter][,pincounter][,txcookie=txcookie][,rxcookie=rxcookie][,offset=offset]\n" - " connect the VLAN to an Ethernet over L2TPv3 pseudowire\n" + "-netdev l2tpv3,id=str,src=srcaddr,dst=dstaddr[,srcport=srcport][,dstport=dstport]\n" + " [,rxsession=rxsession],txsession=txsession[,ipv6=on/off][,udp=on/off]\n" + " [,cookie64=on/off][,counter][,pincounter][,txcookie=txcookie]\n" + " [,rxcookie=rxcookie][,offset=offset]\n" + " configure a network backend with ID 'str' connected to\n" + " an Ethernet over L2TPv3 pseudowire.\n" " Linux kernel 3.3+ as well as most routers can talk\n" " L2TPv3. This transport allows connecting a VM to a VM,\n" " VM to a router and even VM to Host. It is a nearly-universal\n"
@@ -1514,32 +1518,41 @@ DEF("net", HAS_ARG, QEMU_OPTION_net, " use 'pincounter=on' to work around broken counter handling in peer\n" " use 'offset=X' to add an extra offset between header and data\n" #endif - "-net socket[,vlan=n][,name=str][,fd=h][,listen=[host]:port][,connect=host:port]\n" - " connect the vlan 'n' to another VLAN using a socket connection\n" - "-net socket[,vlan=n][,name=str][,fd=h][,mcast=maddr:port[,localaddr=addr]]\n" - " connect the vlan 'n' to multicast maddr and port\n" + "-netdev socket,id=str[,fd=h][,listen=[host]:port][,connect=host:port]\n" + " configure a network backend to connect to another network\n" + " using a socket connection\n" + "-netdev socket,id=str[,fd=h][,mcast=maddr:port[,localaddr=addr]]\n" + " configure a network backend to connect to a multicast maddr and port\n" " use 'localaddr=addr' to specify the host address to send packets from\n" - "-net socket[,vlan=n][,name=str][,fd=h][,udp=host:port][,localaddr=host:port]\n" - " connect the vlan 'n' to another VLAN using an UDP tunnel\n" + "-netdev socket,id=str[,fd=h][,udp=host:port][,localaddr=host:port]\n" + " configure a network backend to connect to another network\n" + " using an UDP tunnel\n" #ifdef CONFIG_VDE - "-net vde[,vlan=n][,name=str][,sock=socketpath][,port=n][,group=groupname][,mode=octalmode]\n" - " connect the vlan 'n' to port 'n' of a vde switch running\n" - " on host and listening for incoming connections on 'socketpath'.\n" + "-netdev vde,id=str[,sock=socketpath][,port=n][,group=groupname][,mode=octalmode]\n" + " configure a network backend to connect to port 'n' of a vde switch\n" + " running on host and listening for incoming connections on 'socketpath'.\n" " Use group 'groupname' and mode 'octalmode' to change default\n" " ownership and permissions for communication port.\n" #endif #ifdef CONFIG_NETMAP - "-net netmap,ifname=name[,devname=nmname]\n" + "-netdev netmap,id=str,ifname=name[,devname=nmname]\n" " attach to the existing netmap-enabled network interface 'name', or to a\n" " VALE port (created on the fly) called 'name' ('nmname' is name of the \n" " netmap device, defaults to '/dev/netmap')\n" #endif + "-netdev vhost-user,id=str,chardev=dev[,vhostforce=on|off]\n" + " configure a vhost-user network, backed by a chardev 'dev'\n" + "-netdev hubport,id=str,hubid=n\n" + " configure a hub port on QEMU VLAN 'n'\n", QEMU_ARCH_ALL) +DEF("net", HAS_ARG, QEMU_OPTION_net, + "-net nic[,vlan=n][,macaddr=mac][,model=type][,name=str][,addr=str][,vectors=v]\n" + " old way to create a new NIC and connect it to VLAN 'n'\n" + " (use the '-device devtype,netdev=str' option if possible instead)\n" "-net dump[,vlan=n][,file=f][,len=n]\n" " dump traffic on vlan 'n' to file 'f' (max n bytes per packet)\n" "-net none use it alone to have zero network devices. If no -net option\n" - " is provided, the default is '-net nic -net user'\n", QEMU_ARCH_ALL) -DEF("netdev", HAS_ARG, QEMU_OPTION_netdev, - "-netdev [" + " is provided, the default is '-net nic -net user'\n" + "-net [" #ifdef CONFIG_SLIRP "user|" #endif
@@ -1551,9 +1564,9 @@ DEF("netdev", HAS_ARG, QEMU_OPTION_netdev, #ifdef CONFIG_NETMAP "netmap|" #endif - "vhost-user|" - "socket|" - "hubport],id=str[,option][,option][,...]\n", QEMU_ARCH_ALL) + "socket][,vlan=n][,option][,option][,...]\n" + " old way to initialize a host network interface\n" + " (use the -netdev option if possible instead)\n", QEMU_ARCH_ALL) STEXI @item -net nic[,vlan=@var{n}][,macaddr=@var{mac}][,model=@var{type}] [,name=@var{name}][,addr=@var{addr}][,vectors=@var{v}] @findex -net
Signature · 1 line
2.4.1
[Qemu-devel] [PULL 02/17] net: Improve error message for -net hubport a bit
In reply to Stefan HajnocziFrom: Markus Armbruster <[email protected]>
Type "hubport" is valid only with -netdev. Unfortunately, that's detected late and the error message doesn't explain why:
$ qemu-system-i386 -net hubport,id=foo,hubid=0
qemu-system-i386: -net hubport,id=foo,hubid=0: Device 'hubport' could not be initializedImprove the error message to "Parameter 'type' expects a net type".
Not fixed: -net hubport without the parameters required by -netdev hubport still asks for those parameters:
$ qemu-system-i386 -net hubport
qemu-system-i386: -net hubport: Parameter 'hubid' is missingMessage-id: [email protected]
--- net/hub.c | 5 +---- net/net.c | 5 +++++ 2 files changed, 6 insertions(+), 4 deletions(-)
net/hub.c +1 -4
@@ -286,12 +286,9 @@ int net_init_hubport(const NetClientOptions *opts, const char *name,const NetdevHubPortOptions *hubport;assert (opts->kind ==NET_CLIENT_OPTIONS_KIND_HUBPORT ); +assert (!peer); hubport = opts->hubport; -if (peer) { -return -EINVAL ; - } -net_hub_add_port (hubport->hubid, name);return 0 ; }
net/net.c +5 -0
@@ -882,6 +882,11 @@ static int net_client_init1(const void *object, int is_netdev, Error **errp) }else { u.net = object; opts = u.net->opts; +if (opts->kind ==NET_CLIENT_OPTIONS_KIND_HUBPORT ) { +error_set (errp,QERR_INVALID_PARAMETER_VALUE ,"type" , +"a net type" ); +return -1 ; + }/* missing optional values have been initialized to "all bits zero" */ name = u.net->has_id ? u.net->id : u.net->name; }
Signature · 1 line
2.4.1
[Qemu-devel] [PULL 04/17] net: Improve -net nic error reporting
In reply to Stefan HajnocziFrom: Markus Armbruster <[email protected]>
When -net nic fails, it first reports a specific error, then a generic one, like this:
$ qemu-system-x86_64 -net nic,netdev=nonexistent
qemu-system-x86_64: -net nic,netdev=nonexistent: netdev 'nonexistent' not found
qemu-system-x86_64: -net nic,netdev=nonexistent: Device 'nic' could not be initializedConvert net_init_nic() to Error to get rid of the unwanted second error message.
While there, tidy up an Overcapitalized Error Message.
Message-id: [email protected]
--- net/net.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
net/net.c +6 -6
@@ -742,7 +742,6 @@ int qemu_find_nic_model(NICInfo *nd, const char * const *models,static int net_init_nic (const NetClientOptions *opts,const char *name,NetClientState *peer,Error **errp) { -/* FIXME error_setg(errp, ...) on failure */ int idx;NICInfo *nd;const NetLegacyNicOptions *nic;
@@ -752,7 +751,7 @@ static int net_init_nic(const NetClientOptions *opts, const char *name, idx =nic_get_free_idx ();if (idx ==-1 || nb_nics >=MAX_NICS ) { -error_report ("Too Many NICs" ); +error_setg (errp,"too many NICs" );return -1 ; }
@@ -763,7 +762,7 @@ static int net_init_nic(const NetClientOptions *opts, const char *name,if (nic->has_netdev) { nd->netdev =qemu_find_netdev (nic->netdev);if (!nd->netdev) { -error_report ("netdev '%s' not found" , nic->netdev); +error_setg (errp,"netdev '%s' not found" , nic->netdev);return -1 ; } }else {
@@ -780,19 +779,20 @@ static int net_init_nic(const NetClientOptions *opts, const char *name,if (nic->has_macaddr &&net_parse_macaddr (nd->macaddr.a, nic->macaddr) <0 ) { -error_report ("invalid syntax for ethernet address" ); +error_setg (errp,"invalid syntax for ethernet address" );return -1 ; }if (nic->has_macaddr &&is_multicast_ether_addr (nd->macaddr.a)) { -error_report ("NIC cannot have multicast MAC address (odd 1st byte)" ); +error_setg (errp, +"NIC cannot have multicast MAC address (odd 1st byte)" );return -1 ; }qemu_macaddr_default_if_unset (&nd->macaddr);if (nic->has_vectors) {if (nic->vectors >0x7ffffff ) { -error_report ("invalid # of vectors: %" PRIu32, nic->vectors); +error_setg (errp,"invalid # of vectors: %" PRIu32, nic->vectors);return -1 ; } nd->nvectors = nic->vectors;
Signature · 1 line
2.4.1
[Qemu-devel] [PULL 05/17] net/dump: Improve -net/host_net_add dump error reporting
In reply to Stefan HajnocziFrom: Markus Armbruster <[email protected]>
When -net dump fails, it first reports a specific error, then a generic one, like this:
$ qemu-system-x86_64 -net dump,id=foo,file=/eperm
qemu-system-x86_64: -net dump,id=foo,file=/eperm: -net dump: can't open /eperm
qemu-system-x86_64: -net dump,id=foo,file=/eperm: Device 'dump' could not be initializedConvert net_init_tap() to Error. This suppresses the unwanted second message.
Improve the error messages to include strerror(errno) where appropriate.
Message-id: [email protected]
--- net/dump.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
net/dump.c +6 -6
@@ -101,7 +101,8 @@ static NetClientInfo net_dump_info = { };static int net_dump_init (NetClientState *peer,const char *device, -const char *name,const char *filename,int len) +const char *name,const char *filename,int len, +Error **errp) {struct pcap_file_hdr hdr;NetClientState *nc;
@@ -111,7 +112,7 @@ static int net_dump_init(NetClientState *peer, const char *device, fd =open (filename,O_CREAT |O_TRUNC |O_WRONLY |O_BINARY ,0644 );if (fd <0 ) { -error_report ("-net dump: can't open %s" , filename); +error_setg_errno (errp, errno,"-net dump: can't open %s" , filename);return -1 ; }
@@ -124,7 +125,7 @@ static int net_dump_init(NetClientState *peer, const char *device, hdr.linktype =1 ;if (write (fd, &hdr,sizeof (hdr)) <sizeof (hdr)) { -error_report ("-net dump write error: %s" ,strerror (errno)); +error_setg_errno (errp, errno,"-net dump write error" );close (fd);return -1 ; }
@@ -148,7 +149,6 @@ static int net_dump_init(NetClientState *peer, const char *device,int net_init_dump (const NetClientOptions *opts,const char *name,NetClientState *peer,Error **errp) { -/* FIXME error_setg(errp, ...) on failure */ int len;const char *file;char def_file[128 ];
@@ -174,7 +174,7 @@ int net_init_dump(const NetClientOptions *opts, const char *name,if (dump->has_len) {if (dump->len >INT_MAX ) { -error_report ("invalid length: %" PRIu64, dump->len); +error_setg (errp,"invalid length: %" PRIu64, dump->len);return -1 ; } len = dump->len;
@@ -182,5 +182,5 @@ int net_init_dump(const NetClientOptions *opts, const char *name, len =65536 ; } -return net_dump_init (peer,"dump" , name, file, len); +return net_dump_init (peer,"dump" , name, file, len, errp); }
Signature · 1 line
2.4.1
[Qemu-devel] [PULL 03/17] net: Permit incremental conversion of init functions to Error
In reply to Stefan HajnocziFrom: Markus Armbruster <[email protected]>
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.
Message-id: [email protected]
--- net/clients.h | 20 ++++++++++---------- net/dump.c | 3 ++- net/hub.c | 2 +- net/l2tpv3.c | 5 ++--- net/net.c | 15 +++++++++------ net/netmap.c | 3 ++- net/slirp.c | 3 ++- net/socket.c | 3 ++- net/tap-win32.c | 3 ++- net/tap.c | 6 ++++-- net/vde.c | 3 ++- net/vhost-user.c | 3 ++- 12 files changed, 40 insertions(+), 29 deletions(-)
net/clients.h +10 -10
@@ -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 */
net/dump.c +2 -1
@@ -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 ];
net/hub.c +1 -1
@@ -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;
net/l2tpv3.c +2 -3
@@ -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;
net/net.c +9 -6
@@ -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 ; } }
net/netmap.c +2 -1
@@ -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;
net/slirp.c +2 -1
@@ -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;
net/socket.c +2 -1
@@ -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;
net/tap-win32.c +2 -1
@@ -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 );
net/tap.c +4 -2
@@ -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;
@@ -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 */
net/vde.c +2 -1
@@ -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 );
net/vhost-user.c +2 -1
@@ -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;
Signature · 1 line
2.4.1
[Qemu-devel] [PULL 06/17] tap: net_tap_fd_init() can't fail, drop dead error handling
In reply to Stefan HajnocziFrom: Markus Armbruster <[email protected]>
Message-id: [email protected]
--- net/tap.c | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-)
net/tap.c +1 -13
@@ -536,7 +536,6 @@ int net_init_bridge(const NetClientOptions *opts, const char *name,/* FIXME error_setg(errp, ...) on failure */ const NetdevBridgeOptions *bridge;const char *helper, *br; -TAPState *s;int fd, vnet_hdr;
@@ -552,14 +551,8 @@ int net_init_bridge(const NetClientOptions *opts, const char *name, }fcntl (fd,F_SETFL ,O_NONBLOCK ); - vnet_hdr =tap_probe_vnet_hdr (fd); - s =net_tap_fd_init (peer,"bridge" , name, fd, vnet_hdr); -if (!s) { -close (fd); -return -1 ; - }snprintf (s->nc.info_str,sizeof (s->nc.info_str),"helper=%s,br=%s" , helper, br);
@@ -607,14 +600,9 @@ static int net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer, int vnet_hdr, int fd) {Error *err =NULL ; -TAPState *s; +TAPState *s =net_tap_fd_init (peer, model, name, fd, vnet_hdr);int vhostfd; - s =net_tap_fd_init (peer, model, name, fd, vnet_hdr); -if (!s) { -return -1 ; - } -if (tap_set_sndbuf (s->fd, tap) <0 ) {return -1 ; }
Signature · 1 line
2.4.1
[Qemu-devel] [PULL 07/17] tap: Improve -netdev/netdev_add/-net/... bridge error reporting
In reply to Stefan HajnocziFrom: Markus Armbruster <[email protected]>
When -netdev bridge fails, it first reports a specific error, then a generic one, like this:
$ qemu-system-x86_64 -netdev bridge,id=foo
failed to launch bridge helper
qemu-system-x86_64: -netdev bridge,id=foo: Device 'bridge' could not be initializedThe first message goes to stderr. Wrong for HMP, because errors need to go to the monitor there.
The second message goes to stderr for -netdev, to the monitor for HMP netdev_add, and becomes the error reply for QMP netdev_add.
Convert net_bridge_run_helper() to Error, and propagate its errors through net_init_bridge(). This ensures the error gets reported where the user is, and suppresses the unwanted second message.
While there, improve the error messages a bit.
The above example becomes:
$ qemu-system-x86_64 -netdev bridge,id=foo
qemu-system-x86_64: -netdev bridge,id=foo: bridge helper failednet_init_tap() also uses net_bridge_run_helper(). Propagate its errors there as well. Improves reporting these errors with -netdev tap & friends.
Message-id: [email protected]
--- net/tap.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-)
net/tap.c +19 -11
@@ -437,7 +437,8 @@ static int recv_fd(int c)return len; } -static int net_bridge_run_helper (const char *helper,const char *bridge) +static int net_bridge_run_helper (const char *helper,const char *bridge, +Error **errp) {sigset_t oldmask, mask;int pid, status;
@@ -450,11 +451,16 @@ static int net_bridge_run_helper(const char *helper, const char *bridge)sigprocmask (SIG_BLOCK , &mask, &oldmask);if (socketpair (PF_UNIX ,SOCK_STREAM ,0 , sv) ==-1 ) { +error_setg_errno (errp, errno,"socketpair() failed" );return -1 ; }/* try to launch bridge helper */ pid =fork (); +if (pid <0 ) { +error_setg_errno (errp, errno,"Can't fork bridge helper" ); +return -1 ; + }if (pid ==0 ) {int open_max =sysconf (_SC_OPEN_MAX), i;char fd_buf[6 +10 ];
@@ -502,14 +508,16 @@ static int net_bridge_run_helper(const char *helper, const char *bridge) }_exit (1 ); - }else if (pid >0 ) { + }else {int fd; +int saved_errno;close (sv[1 ]);do { fd =recv_fd (sv[0 ]); }while (fd ==-1 && errno ==EINTR ); + saved_errno = errno;close (sv[0 ]);
@@ -518,22 +526,21 @@ static int net_bridge_run_helper(const char *helper, const char *bridge) }sigprocmask (SIG_SETMASK , &oldmask,NULL );if (fd <0 ) { -fprintf (stderr,"failed to recv file descriptor\n" ); +error_setg_errno (errp, saved_errno, +"failed to recv file descriptor" );return -1 ; } - -if (WIFEXITED (status) &&WEXITSTATUS (status) ==0 ) { -return fd; +if (!WIFEXITED (status) ||WEXITSTATUS (status) !=0 ) { +error_setg (errp,"bridge helper failed" ); +return -1 ; } +return fd; } -fprintf (stderr,"failed to launch bridge helper\n" ); -return -1 ; }int net_init_bridge (const NetClientOptions *opts,const char *name,NetClientState *peer,Error **errp) { -/* FIXME error_setg(errp, ...) on failure */ const NetdevBridgeOptions *bridge;const char *helper, *br;TAPState *s;
@@ -545,7 +552,7 @@ int net_init_bridge(const NetClientOptions *opts, const char *name, helper = bridge->has_helper ? bridge->helper :DEFAULT_BRIDGE_HELPER ; br = bridge->has_br ? bridge->br :DEFAULT_BRIDGE_INTERFACE ; - fd =net_bridge_run_helper (helper, br); + fd =net_bridge_run_helper (helper, br, errp);if (fd ==-1 ) {return -1 ; }
@@ -792,7 +799,8 @@ int net_init_tap(const NetClientOptions *opts, const char *name,return -1 ; } - fd =net_bridge_run_helper (tap->helper,DEFAULT_BRIDGE_INTERFACE ); + fd =net_bridge_run_helper (tap->helper,DEFAULT_BRIDGE_INTERFACE , + errp);if (fd ==-1 ) {return -1 ; }
Signature · 1 line
2.4.1
[Qemu-devel] [PULL 09/17] tap: Convert net_init_tap_one() to Error
In reply to Stefan HajnocziFrom: Markus Armbruster <[email protected]>
[Dropped %s from "tap: open vhost char device failed: %s" since error_setg_errno() already prints a human-readable error string and there is no format string argument.
--Stefan]
Message-id: [email protected]
--- net/tap.c | 70 ++++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 38 insertions(+), 32 deletions(-)
net/tap.c +38 -32
@@ -600,11 +600,11 @@ static int net_tap_init(const NetdevTapOptions *tap, int *vnet_hdr,#define MAX_TAP_QUEUES 1024 -static int net_init_tap_one (const NetdevTapOptions *tap,NetClientState *peer, -const char *model,const char *name, -const char *ifname,const char *script, -const char *downscript,const char *vhostfdname, -int vnet_hdr,int fd) +static void net_init_tap_one (const NetdevTapOptions *tap,NetClientState *peer, +const char *model,const char *name, +const char *ifname,const char *script, +const char *downscript,const char *vhostfdname, +int vnet_hdr,int fd,Error **errp) {Error *err =NULL ;TAPState *s =net_tap_fd_init (peer, model, name, fd, vnet_hdr);
@@ -612,8 +612,8 @@ static int net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,tap_set_sndbuf (s->fd, tap, &err);if (err) { -error_report_err (err); -return -1 ; +error_propagate (errp, err); +return ; }if (tap->has_fd || tap->has_fds) {
@@ -644,30 +644,28 @@ static int net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,if (tap->has_vhostfd || tap->has_vhostfds) { vhostfd =monitor_fd_param (cur_mon, vhostfdname, &err);if (vhostfd ==-1 ) { -error_report_err (err); -return -1 ; +error_propagate (errp, err); +return ; } }else { vhostfd =open ("/dev/vhost-net" ,O_RDWR );if (vhostfd <0 ) { -error_report ("tap: open vhost char device failed: %s" , -strerror (errno)); -return -1 ; +error_setg_errno (errp, errno, +"tap: open vhost char device failed" ); +return ; } } options.opaque = (void *)(uintptr_t )vhostfd; s->vhost_net =vhost_net_init (&options);if (!s->vhost_net) { -error_report ("vhost-net requested but could not be initialized" ); -return -1 ; +error_setg (errp, +"vhost-net requested but could not be initialized" ); +return ; } }else if (tap->has_vhostfd || tap->has_vhostfds) { -error_report ("vhostfd= is not valid without vhost" ); -return -1 ; +error_setg (errp,"vhostfd= is not valid without vhost" ); } - -return 0 ; }static int get_fds (char *str,char *fds[],int max)
@@ -741,9 +739,11 @@ int net_init_tap(const NetClientOptions *opts, const char *name, vnet_hdr =tap_probe_vnet_hdr (fd); -if (net_init_tap_one (tap, peer,"tap" , name,NULL , - script, downscript, - vhostfdname, vnet_hdr, fd)) { +net_init_tap_one (tap, peer,"tap" , name,NULL , + script, downscript, + vhostfdname, vnet_hdr, fd, &err); +if (err) { +error_report_err (err);return -1 ; } }else if (tap->has_fds) {
@@ -786,10 +786,12 @@ int net_init_tap(const NetClientOptions *opts, const char *name,return -1 ; } -if (net_init_tap_one (tap, peer,"tap" , name, ifname, - script, downscript, - tap->has_vhostfds ? vhost_fds[i] :NULL , - vnet_hdr, fd)) { +net_init_tap_one (tap, peer,"tap" , name, ifname, + script, downscript, + tap->has_vhostfds ? vhost_fds[i] :NULL , + vnet_hdr, fd, &err); +if (err) { +error_report_err (err);return -1 ; } }
@@ -810,9 +812,11 @@ int net_init_tap(const NetClientOptions *opts, const char *name,fcntl (fd,F_SETFL ,O_NONBLOCK ); vnet_hdr =tap_probe_vnet_hdr (fd); -if (net_init_tap_one (tap, peer,"bridge" , name, ifname, - script, downscript, vhostfdname, - vnet_hdr, fd)) { +net_init_tap_one (tap, peer,"bridge" , name, ifname, + script, downscript, vhostfdname, + vnet_hdr, fd, &err); +if (err) { +error_report_err (err);close (fd);return -1 ; }
@@ -846,10 +850,12 @@ int net_init_tap(const NetClientOptions *opts, const char *name, } } -if (net_init_tap_one (tap, peer,"tap" , name, ifname, - i >=1 ?"no" : script, - i >=1 ?"no" : downscript, - vhostfdname, vnet_hdr, fd)) { +net_init_tap_one (tap, peer,"tap" , name, ifname, + i >=1 ?"no" : script, + i >=1 ?"no" : downscript, + vhostfdname, vnet_hdr, fd, &err); +if (err) { +error_report_err (err);close (fd);return -1 ; }
Signature · 1 line
2.4.1
[Qemu-devel] [PULL 10/17] tap: Convert launch_script() to Error
In reply to Stefan HajnocziFrom: Markus Armbruster <[email protected]>
Fixes inappropriate use of stderr in monitor command handler.
While there, improve the messages some.
[Fixed Error **err -> Error *err local variable that broke the build. --Stefan]
Message-id: [email protected]
--- net/tap.c | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-)
net/tap.c +28 -12
@@ -59,7 +59,8 @@ typedef struct TAPState {unsigned host_vnet_hdr_len; } TAPState; -static int launch_script (const char *setup_script,const char *ifname,int fd); +static void launch_script (const char *setup_script,const char *ifname, +int fd,Error **errp);static int tap_can_send (void *opaque);static void tap_send (void *opaque);
@@ -288,6 +289,7 @@ static void tap_set_offload(NetClientState *nc, int csum, int tso4,static void tap_cleanup (NetClientState *nc) {TAPState *s =DO_UPCAST (TAPState, nc, nc); +Error *err =NULL ;if (s->vhost_net) {vhost_net_cleanup (s->vhost_net);
@@ -296,8 +298,12 @@ static void tap_cleanup(NetClientState *nc)qemu_purge_queued_packets (nc); -if (s->down_script[0 ]) -launch_script (s->down_script, s->down_script_arg, s->fd); +if (s->down_script[0 ]) { +launch_script (s->down_script, s->down_script_arg, s->fd, &err); +if (err) { +error_report_err (err); + } + }tap_read_poll (s, false);tap_write_poll (s, false);
@@ -368,7 +374,8 @@ static TAPState *net_tap_fd_init(NetClientState *peer,return s; } -static int launch_script (const char *setup_script,const char *ifname,int fd) +static void launch_script (const char *setup_script,const char *ifname, +int fd,Error **errp) {int pid, status;char *args[3 ];
@@ -376,6 +383,11 @@ static int launch_script(const char *setup_script, const char *ifname, int fd)/* try to launch network script */ pid =fork (); +if (pid <0 ) { +error_setg_errno (errp, errno,"could not launch network script %s" , + setup_script); +return ; + }if (pid ==0 ) {int open_max =sysconf (_SC_OPEN_MAX), i;
@@ -390,17 +402,17 @@ static int launch_script(const char *setup_script, const char *ifname, int fd) *parg =NULL ;execv (setup_script, args);_exit (1 ); - }else if (pid >0 ) { + }else {while (waitpid (pid, &status,0 ) != pid) {/* loop */ }if (WIFEXITED (status) &&WEXITSTATUS (status) ==0 ) { -return 0 ; +return ; } +error_setg (errp,"network script %s failed with status %d" , + setup_script, status); } -fprintf (stderr,"%s: could not launch network script\n" , setup_script); -return -1 ; }static int recv_fd (int c)
@@ -571,6 +583,7 @@ static int net_tap_init(const NetdevTapOptions *tap, int *vnet_hdr, const char *setup_script, char *ifname, size_t ifname_sz, int mq_required) { + Error *err = NULL;int fd, vnet_hdr_required;if (tap->has_vnet_hdr) {
@@ -589,10 +602,13 @@ static int net_tap_init(const NetdevTapOptions *tap, int *vnet_hdr,if (setup_script && setup_script[0 ] !='\0' && -strcmp (setup_script,"no" ) !=0 && -launch_script (setup_script, ifname, fd)) { -close (fd); -return -1 ; +strcmp (setup_script,"no" ) !=0 ) { +launch_script (setup_script, ifname, fd, &err); +if (err) { +error_report_err (err); +close (fd); +return -1 ; + } }return fd;
Signature · 1 line
2.4.1
[Qemu-devel] [PULL 08/17] tap: Convert tap_set_sndbuf() to Error
In reply to Stefan HajnocziFrom: Markus Armbruster <[email protected]>
Message-id: [email protected]
--- net/tap-aix.c | 3 +-- net/tap-bsd.c | 3 +-- net/tap-haiku.c | 3 +-- net/tap-linux.c | 6 ++---- net/tap-solaris.c | 3 +-- net/tap.c | 4 +++- net/tap_int.h | 2 +- 7 files changed, 10 insertions(+), 14 deletions(-)
net/tap-aix.c +1 -2
@@ -32,9 +32,8 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr,return -1 ; } -int tap_set_sndbuf (int fd,const NetdevTapOptions *tap) +void tap_set_sndbuf (int fd,const NetdevTapOptions *tap,Error **errp) { -return 0 ; }int tap_probe_vnet_hdr (int fd)
net/tap-bsd.c +1 -2
@@ -176,9 +176,8 @@ error: }#endif /* __FreeBSD__ */ -int tap_set_sndbuf (int fd,const NetdevTapOptions *tap) +void tap_set_sndbuf (int fd,const NetdevTapOptions *tap,Error **errp) { -return 0 ; }int tap_probe_vnet_hdr (int fd)
net/tap-haiku.c +1 -2
@@ -32,9 +32,8 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr,return -1 ; } -int tap_set_sndbuf (int fd,const NetdevTapOptions *tap) +void tap_set_sndbuf (int fd,const NetdevTapOptions *tap,Error **errp) { -return 0 ; }int tap_probe_vnet_hdr (int fd)
net/tap-linux.c +2 -4
@@ -126,7 +126,7 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr,*/ #define TAP_DEFAULT_SNDBUF 0 -int tap_set_sndbuf (int fd,const NetdevTapOptions *tap) +void tap_set_sndbuf (int fd,const NetdevTapOptions *tap,Error **errp) {int sndbuf;
@@ -139,10 +139,8 @@ int tap_set_sndbuf(int fd, const NetdevTapOptions *tap) }if (ioctl (fd,TUNSETSNDBUF , &sndbuf) ==-1 && tap->has_sndbuf) { -error_report ("TUNSETSNDBUF ioctl failed: %s" ,strerror (errno)); -return -1 ; +error_setg_errno (errp, errno,"TUNSETSNDBUF ioctl failed" ); } -return 0 ; }int tap_probe_vnet_hdr (int fd)
net/tap-solaris.c +1 -2
@@ -198,9 +198,8 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr,return fd; } -int tap_set_sndbuf (int fd,const NetdevTapOptions *tap) +void tap_set_sndbuf (int fd,const NetdevTapOptions *tap,Error **errp) { -return 0 ; }int tap_probe_vnet_hdr (int fd)
net/tap.c +3 -1
@@ -610,7 +610,9 @@ static int net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,TAPState *s =net_tap_fd_init (peer, model, name, fd, vnet_hdr);int vhostfd; -if (tap_set_sndbuf (s->fd, tap) <0 ) { +tap_set_sndbuf (s->fd, tap, &err); +if (err) { +error_report_err (err);return -1 ; }
net/tap_int.h +1 -1
@@ -34,7 +34,7 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr,ssize_t tap_read_packet (int tapfd,uint8_t *buf,int maxlen); -int tap_set_sndbuf (int fd,const NetdevTapOptions *tap); +void tap_set_sndbuf (int fd,const NetdevTapOptions *tap,Error **errp);int tap_probe_vnet_hdr (int fd);int tap_probe_vnet_hdr_len (int fd,int len);int tap_probe_has_ufo (int fd);
Signature · 1 line
2.4.1
[Qemu-devel] [PULL 11/17] tap: Permit incremental conversion of tap_open() to Error
In reply to Stefan HajnocziFrom: Markus Armbruster <[email protected]>
Convert the trivial ones immediately: tap-aix and tap-haiku.
Message-id: [email protected]
--- net/tap-aix.c | 4 ++-- net/tap-bsd.c | 6 ++++-- net/tap-haiku.c | 4 ++-- net/tap-linux.c | 3 ++- net/tap-solaris.c | 3 ++- net/tap.c | 13 +++++++++---- net/tap_int.h | 2 +- 7 files changed, 22 insertions(+), 13 deletions(-)
net/tap-aix.c +2 -2
@@ -26,9 +26,9 @@#include <stdio.h> int tap_open (char *ifname,int ifname_size,int *vnet_hdr, -int vnet_hdr_required,int mq_required) +int vnet_hdr_required,int mq_required,Error **errp) { -fprintf (stderr,"no tap on AIX\n" ); +error_setg (errp,"no tap on AIX" );return -1 ; }
net/tap-bsd.c +4 -2
@@ -35,8 +35,9 @@#ifndef __FreeBSD__int tap_open (char *ifname,int ifname_size,int *vnet_hdr, -int vnet_hdr_required,int mq_required) +int vnet_hdr_required,int mq_required,Error **errp) { +/* FIXME error_setg(errp, ...) on failure */ int fd;#ifdef TAPGIFNAME struct ifreq ifr;
@@ -114,8 +115,9 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr,#define PATH_NET_TAP "/dev/tap"int tap_open (char *ifname,int ifname_size,int *vnet_hdr, -int vnet_hdr_required,int mq_required) +int vnet_hdr_required,int mq_required,Error **errp) { +/* FIXME error_setg(errp, ...) on failure */ int fd, s, ret;struct ifreq ifr;
net/tap-haiku.c +2 -2
@@ -26,9 +26,9 @@#include <stdio.h> int tap_open (char *ifname,int ifname_size,int *vnet_hdr, -int vnet_hdr_required,int mq_required) +int vnet_hdr_required,int mq_required,Error **errp) { -fprintf (stderr,"no tap on Haiku\n" ); +error_setg (errp,"no tap on Haiku" );return -1 ; }
net/tap-linux.c +2 -1
@@ -37,8 +37,9 @@#define PATH_NET_TUN "/dev/net/tun"int tap_open (char *ifname,int ifname_size,int *vnet_hdr, -int vnet_hdr_required,int mq_required) +int vnet_hdr_required,int mq_required,Error **errp) { +/* FIXME error_setg(errp, ...) on failure */ struct ifreq ifr;int fd, ret;int len =sizeof (struct virtio_net_hdr );
net/tap-solaris.c +2 -1
@@ -174,8 +174,9 @@ static int tap_alloc(char *dev, size_t dev_size) }int tap_open (char *ifname,int ifname_size,int *vnet_hdr, -int vnet_hdr_required,int mq_required) +int vnet_hdr_required,int mq_required,Error **errp) { +/* FIXME error_setg(errp, ...) on failure */ char dev[10 ]="" ;int fd;if ( (fd =tap_alloc (dev,sizeof (dev))) <0 ){
net/tap.c +9 -4
@@ -581,7 +581,7 @@ int net_init_bridge(const NetClientOptions *opts, const char *name,static int net_tap_init (const NetdevTapOptions *tap,int *vnet_hdr,const char *setup_script,char *ifname, -size_t ifname_sz,int mq_required) +size_t ifname_sz,int mq_required,Error **errp) {Error *err =NULL ;int fd, vnet_hdr_required;
@@ -595,8 +595,12 @@ static int net_tap_init(const NetdevTapOptions *tap, int *vnet_hdr, }TFR (fd =tap_open (ifname, ifname_sz, vnet_hdr, vnet_hdr_required, - mq_required)); + mq_required, errp));if (fd <0 ) { +/* FIXME drop when all tap_open() store an Error */ +if (errp && !*errp) { +error_setg (errp,"can't open tap device" ); + }return -1 ; }
@@ -605,7 +609,7 @@ static int net_tap_init(const NetdevTapOptions *tap, int *vnet_hdr, strcmp(setup_script, "no") != 0) {launch_script (setup_script, ifname, fd, &err);if (err) { -error_report_err (err); +error_propagate (errp, err);close (fd);return -1 ; }
@@ -853,8 +857,9 @@ int net_init_tap(const NetClientOptions *opts, const char *name,for (i =0 ; i < queues; i++) { fd =net_tap_init (tap, &vnet_hdr, i >=1 ?"no" : script, - ifname,sizeof ifname, queues >1 ); + ifname,sizeof ifname, queues >1 , &err);if (fd ==-1 ) { +error_report_err (err);return -1 ; }
net/tap_int.h +1 -1
@@ -30,7 +30,7 @@#include "qapi-types.h" int tap_open (char *ifname,int ifname_size,int *vnet_hdr, -int vnet_hdr_required,int mq_required); +int vnet_hdr_required,int mq_required,Error **errp);ssize_t tap_read_packet (int tapfd,uint8_t *buf,int maxlen);
Signature · 1 line
2.4.1
[Qemu-devel] [PULL 12/17] tap-linux: Convert tap_open() to Error
In reply to Stefan HajnocziFrom: Markus Armbruster <[email protected]>
Message-id: [email protected]
--- net/tap-linux.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
net/tap-linux.c +9 -8
@@ -39,7 +39,6 @@int tap_open (char *ifname,int ifname_size,int *vnet_hdr,int vnet_hdr_required,int mq_required,Error **errp) { -/* FIXME error_setg(errp, ...) on failure */ struct ifreq ifr;int fd, ret;int len =sizeof (struct virtio_net_hdr );
@@ -47,7 +46,7 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr,TFR (fd =open (PATH_NET_TUN ,O_RDWR ));if (fd <0 ) { -error_report ("could not open %s: %m" ,PATH_NET_TUN ); +error_setg_errno (errp, errno,"could not open %s" ,PATH_NET_TUN );return -1 ; }memset (&ifr,0 ,sizeof (ifr));
@@ -71,8 +70,8 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr, }if (vnet_hdr_required && !*vnet_hdr) { -error_report ("vnet_hdr=1 requested, but no kernel " -"support for IFF_VNET_HDR available" ); +error_setg (errp,"vnet_hdr=1 requested, but no kernel " +"support for IFF_VNET_HDR available" );close (fd);return -1 ; }
@@ -87,8 +86,8 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr,if (mq_required) {if (!(features &IFF_MULTI_QUEUE )) { -error_report ("multiqueue required, but no kernel " -"support for IFF_MULTI_QUEUE available" ); +error_setg (errp,"multiqueue required, but no kernel " +"support for IFF_MULTI_QUEUE available" );close (fd);return -1 ; }else {
@@ -103,9 +102,11 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr, ret =ioctl (fd,TUNSETIFF , (void *) &ifr);if (ret !=0 ) {if (ifname[0 ] !='\0' ) { -error_report ("could not configure %s (%s): %m" ,PATH_NET_TUN , ifr.ifr_name); +error_setg_errno (errp, errno,"could not configure %s (%s)" , +PATH_NET_TUN , ifr.ifr_name); }else { -error_report ("could not configure %s: %m" ,PATH_NET_TUN ); +error_setg_errno (errp, errno,"could not configure %s" , +PATH_NET_TUN ); }close (fd);return -1 ;
Signature · 1 line
2.4.1
[Qemu-devel] [PULL 13/17] tap-bsd: Convert tap_open() to Error
In reply to Stefan HajnocziFrom: Markus Armbruster <[email protected]>
Fixes inappropriate use of stderr in monitor command handler.
While there, improve some of the messages a bit.
Message-id: [email protected]
--- net/tap-bsd.c | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-)
net/tap-bsd.c +14 -19
@@ -37,7 +37,6 @@int tap_open (char *ifname,int ifname_size,int *vnet_hdr,int vnet_hdr_required,int mq_required,Error **errp) { -/* FIXME error_setg(errp, ...) on failure */ int fd;#ifdef TAPGIFNAME struct ifreq ifr;
@@ -72,23 +71,19 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr, } }if (fd <0 ) { -error_report ("warning: could not open %s (%s): no virtual network emulation" , - dname,strerror (errno)); +error_setg_errno (errp, errno,"could not open %s" , dname);return -1 ; }#ifdef TAPGIFNAME if (ioctl (fd,TAPGIFNAME , (void *)&ifr) <0 ) { -fprintf (stderr,"warning: could not get tap name: %s\n" , -strerror (errno)); +error_setg_errno (errp, errno,"could not get tap name" );return -1 ; }pstrcpy (ifname, ifname_size, ifr.ifr_name);#else if (fstat (fd, &s) <0 ) { -fprintf (stderr, -"warning: could not stat /dev/tap: no virtual network emulation: %s\n" , -strerror (errno)); +error_setg_errno (errp, errno,"could not stat %s" , dname);return -1 ; } dev =devname (s.st_rdev,S_IFCHR );
@@ -100,8 +95,8 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr, *vnet_hdr =0 ;if (vnet_hdr_required && !*vnet_hdr) { -error_report ("vnet_hdr=1 requested, but no kernel " -"support for IFF_VNET_HDR available" ); +error_setg (errp,"vnet_hdr=1 requested, but no kernel " +"support for IFF_VNET_HDR available" );close (fd);return -1 ; }
@@ -117,13 +112,12 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr,int tap_open (char *ifname,int ifname_size,int *vnet_hdr,int vnet_hdr_required,int mq_required,Error **errp) { -/* FIXME error_setg(errp, ...) on failure */ int fd, s, ret;struct ifreq ifr;TFR (fd =open (PATH_NET_TAP ,O_RDWR ));if (fd <0 ) { -error_report ("could not open %s: %s" ,PATH_NET_TAP ,strerror (errno)); +error_setg_errno (errp, errno,"could not open %s" ,PATH_NET_TAP );return -1 ; }
@@ -131,7 +125,7 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr, ret =ioctl (fd,TAPGIFNAME , (void *)&ifr);if (ret <0 ) { -error_report ("could not get tap interface name" ); +error_setg_errno (errp, errno,"could not get tap interface name" ); goto error; }
@@ -139,14 +133,15 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr,/* User requested the interface to have a specific name */ s =socket (AF_LOCAL ,SOCK_DGRAM ,0 );if (s <0 ) { -error_report ("could not open socket to set interface name" ); +error_setg_errno (errp, errno, +"could not open socket to set interface name" ); goto error; } ifr.ifr_data = ifname; ret =ioctl (s,SIOCSIFNAME , (void *)&ifr);close (s);if (ret <0 ) { -error_report ("could not set tap interface name" ); +error_setg (errp,"could not set tap interface name" ); goto error; } }else {
@@ -158,14 +153,14 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr, *vnet_hdr =0 ;if (vnet_hdr_required && !*vnet_hdr) { -error_report ("vnet_hdr=1 requested, but no kernel " -"support for IFF_VNET_HDR available" ); +error_setg (errp,"vnet_hdr=1 requested, but no kernel " +"support for IFF_VNET_HDR available" ); goto error; } }if (mq_required) { -error_report ("mq_required requested, but not kernel support" -"for IFF_MULTI_QUEUE available" ); +error_setg (errp,"mq_required requested, but no kernel support" +" for IFF_MULTI_QUEUE available" ); goto error; }
Signature · 1 line
2.4.1
[Qemu-devel] [PULL 15/17] tap: Finish conversion of tap_open() to Error
In reply to Stefan HajnocziFrom: Markus Armbruster <[email protected]>
Message-id: [email protected]
--- net/tap.c | 4 ---- 1 file changed, 4 deletions(-)
net/tap.c +0 -4
@@ -597,10 +597,6 @@ static int net_tap_init(const NetdevTapOptions *tap, int *vnet_hdr,TFR (fd =tap_open (ifname, ifname_sz, vnet_hdr, vnet_hdr_required, mq_required, errp));if (fd <0 ) { -/* FIXME drop when all tap_open() store an Error */ -if (errp && !*errp) { -error_setg (errp,"can't open tap device" ); - }return -1 ; }
Signature · 1 line
2.4.1
[Qemu-devel] [PULL 14/17] tap-solaris: Convert tap_open() to Error
In reply to Stefan HajnocziFrom: Markus Armbruster <[email protected]>
Fixes inappropriate use of syslog().
Not fixed: leaks on error paths, suspicious non-fatal errors. FIXMEs added instead.
Message-id: [email protected]
--- net/tap-solaris.c | 59 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 29 deletions(-)
net/tap-solaris.c +30 -29
@@ -36,7 +36,6 @@#include <netinet/udp.h> #include <netinet/tcp.h> #include <net/if.h> -#include <syslog.h> #include <stropts.h> #include "qemu/error-report.h"
@@ -56,8 +55,10 @@ ssize_t tap_read_packet(int tapfd, uint8_t *buf, int maxlen)* Allocate TAP device, returns opened fd. * Stores dev name in the first arg(must be large enough). */ -static int tap_alloc (char *dev,size_t dev_size) +static int tap_alloc (char *dev,size_t dev_size,Error **errp) { +/* FIXME leaks like a sieve on error paths */ +/* FIXME suspicious: many errors are reported, then ignored */ int tap_fd, if_fd, ppa =-1 ;static int ip_fd =0 ;char *ptr;
@@ -83,14 +84,14 @@ static int tap_alloc(char *dev, size_t dev_size)TFR (ip_fd =open ("/dev/udp" ,O_RDWR ,0 ));if (ip_fd <0 ) { -syslog (LOG_ERR ,"Can't open /dev/ip (actually /dev/udp)" ); -return -1 ; +error_setg (errp,"Can't open /dev/ip (actually /dev/udp)" ); +return -1 ; }TFR (tap_fd =open ("/dev/tap" ,O_RDWR ,0 ));if (tap_fd <0 ) { -syslog (LOG_ERR ,"Can't open /dev/tap" ); -return -1 ; +error_setg (errp,"Can't open /dev/tap" ); +return -1 ; }/* Assign a new PPA and get its unit number. */
@@ -99,20 +100,20 @@ static int tap_alloc(char *dev, size_t dev_size) strioc_ppa.ic_len =sizeof (ppa); strioc_ppa.ic_dp = (char *)&ppa;if ((ppa =ioctl (tap_fd,I_STR , &strioc_ppa)) <0 ) -syslog (LOG_ERR ,"Can't assign new interface" ); +error_report ("Can't assign new interface" );TFR (if_fd =open ("/dev/tap" ,O_RDWR ,0 ));if (if_fd <0 ) { -syslog (LOG_ERR ,"Can't open /dev/tap (2)" ); -return -1 ; +error_setg (errp,"Can't open /dev/tap (2)" ); +return -1 ; }if (ioctl (if_fd,I_PUSH ,"ip" ) <0 ){ -syslog (LOG_ERR ,"Can't push IP module" ); -return -1 ; +error_setg (errp,"Can't push IP module" ); +return -1 ; }if (ioctl (if_fd,SIOCGLIFFLAGS , &ifr) <0 ) -syslog (LOG_ERR ,"Can't get flags\n" ); +error_report ("Can't get flags" );snprintf (actual_name,32 ,"tap%d" , ppa);pstrcpy (ifr.lifr_name,sizeof (ifr.lifr_name), actual_name);
@@ -121,22 +122,22 @@ static int tap_alloc(char *dev, size_t dev_size)/* Assign ppa according to the unit number returned by tun device */ if (ioctl (if_fd,SIOCSLIFNAME , &ifr) <0 ) -syslog (LOG_ERR ,"Can't set PPA %d" , ppa); +error_report ("Can't set PPA %d" , ppa);if (ioctl (if_fd,SIOCGLIFFLAGS , &ifr) <0 ) -syslog (LOG_ERR ,"Can't get flags\n" ); +error_report ("Can't get flags" );/* Push arp module to if_fd */ if (ioctl (if_fd,I_PUSH ,"arp" ) <0 ) -syslog (LOG_ERR ,"Can't push ARP module (2)" ); +error_report ("Can't push ARP module (2)" );/* Push arp module to ip_fd */ if (ioctl (ip_fd,I_POP ,NULL ) <0 ) -syslog (LOG_ERR ,"I_POP failed\n" ); +error_report ("I_POP failed" );if (ioctl (ip_fd,I_PUSH ,"arp" ) <0 ) -syslog (LOG_ERR ,"Can't push ARP module (3)\n" ); +error_report ("Can't push ARP module (3)" );/* Open arp_fd */ TFR (arp_fd =open ("/dev/tap" ,O_RDWR ,0 ));if (arp_fd <0 ) -syslog (LOG_ERR ,"Can't open %s\n" ,"/dev/tap" ); +error_report ("Can't open %s" ,"/dev/tap" );/* Set ifname to arp */ strioc_if.ic_cmd =SIOCSLIFNAME ;
@@ -144,16 +145,16 @@ static int tap_alloc(char *dev, size_t dev_size) strioc_if.ic_len =sizeof (ifr); strioc_if.ic_dp = (char *)𝔦if (ioctl (arp_fd,I_STR , &strioc_if) <0 ){ -syslog (LOG_ERR ,"Can't set ifname to arp\n" ); +error_report ("Can't set ifname to arp" ); }if ((ip_muxid =ioctl (ip_fd,I_LINK , if_fd)) <0 ){ -syslog (LOG_ERR ,"Can't link TAP device to IP" ); -return -1 ; +error_setg (errp,"Can't link TAP device to IP" ); +return -1 ; }if ((arp_muxid =ioctl (ip_fd, link_type, arp_fd)) <0 ) -syslog (LOG_ERR ,"Can't link TAP device to ARP" ); +error_report ("Can't link TAP device to ARP" );close (if_fd);
@@ -166,7 +167,7 @@ static int tap_alloc(char *dev, size_t dev_size) {ioctl (ip_fd,I_PUNLINK , arp_muxid);ioctl (ip_fd,I_PUNLINK , ip_muxid); -syslog (LOG_ERR ,"Can't set multiplexor id" ); +error_report ("Can't set multiplexor id" ); }snprintf (dev, dev_size,"tap%d" , ppa);
@@ -176,12 +177,12 @@ static int tap_alloc(char *dev, size_t dev_size)int tap_open (char *ifname,int ifname_size,int *vnet_hdr,int vnet_hdr_required,int mq_required,Error **errp) { -/* FIXME error_setg(errp, ...) on failure */ char dev[10 ]="" ;int fd; -if ( (fd =tap_alloc (dev,sizeof (dev))) <0 ){ -fprintf (stderr,"Cannot allocate TAP device\n" ); -return -1 ; + + fd =tap_alloc (dev,sizeof (dev), errp); +if (fd <0 ) { +return -1 ; }pstrcpy (ifname, ifname_size, dev);if (*vnet_hdr) {
@@ -189,8 +190,8 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr, *vnet_hdr =0 ;if (vnet_hdr_required && !*vnet_hdr) { -error_report ("vnet_hdr=1 requested, but no kernel " -"support for IFF_VNET_HDR available" ); +error_setg (errp,"vnet_hdr=1 requested, but no kernel " +"support for IFF_VNET_HDR available" );close (fd);return -1 ; }
Signature · 1 line
2.4.1
[Qemu-devel] [PULL 16/17] tap: Improve -netdev/netdev_add/-net/... tap error reporting
In reply to Stefan HajnocziFrom: Markus Armbruster <[email protected]>
When -netdev tap fails, it first reports a specific error, then a generic one, like this:
$ qemu-system-x86_64 -netdev tap,id=foo
qemu-system-x86_64: -netdev tap,id=foo: could not configure /dev/net/tun: Operation not permitted
qemu-system-x86_64: -netdev tap,id=foo: Device 'tap' could not be initializedWith the command line, the messages go to stderr. In HMP, they go to the monitor. In QMP, the second one becomes the error reply, and the first one goes to stderr.
Convert net_init_tap() to Error. This suppresses the unwanted second message, and makes the specific error the QMP error reply.
[Dropped duplicate "and" from error message as suggested by Eric Blake:
"ifname=, script=, downscript=, and vnet_hdr=, "
"queues=, and vhostfds= are invalid with helper="
--Stefan]
Message-id: [email protected]
--- net/tap.c | 45 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 23 deletions(-)
net/tap.c +22 -23
@@ -713,7 +713,6 @@ static int get_fds(char *str, char *fds[], int max)int net_init_tap (const NetClientOptions *opts,const char *name,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 */
@@ -731,7 +730,7 @@ int net_init_tap(const NetClientOptions *opts, const char *name,/* QEMU vlans does not support multiqueue tap, in this case peer is set. * For -netdev, peer is always NULL. */ if (peer && (tap->has_queues || tap->has_fds || tap->has_vhostfds)) { -error_report ("Multiqueue tap cannot be used with QEMU vlans" ); +error_setg (errp,"Multiqueue tap cannot be used with QEMU vlans" );return -1 ; }
@@ -739,15 +738,15 @@ int net_init_tap(const NetClientOptions *opts, const char *name,if (tap->has_ifname || tap->has_script || tap->has_downscript || tap->has_vnet_hdr || tap->has_helper || tap->has_queues || tap->has_fds || tap->has_vhostfds) { -error_report ("ifname=, script=, downscript=, vnet_hdr=, " -"helper=, queues=, fds=, and vhostfds= " -"are invalid with fd=" ); +error_setg (errp,"ifname=, script=, downscript=, vnet_hdr=, " +"helper=, queues=, fds=, and vhostfds= " +"are invalid with fd=" );return -1 ; } fd =monitor_fd_param (cur_mon, tap->fd, &err);if (fd ==-1 ) { -error_report_err (err); +error_propagate (errp, err);return -1 ; }
@@ -759,7 +758,7 @@ int net_init_tap(const NetClientOptions *opts, const char *name, script, downscript, vhostfdname, vnet_hdr, fd, &err);if (err) { -error_report_err (err); +error_propagate (errp, err);return -1 ; } }else if (tap->has_fds) {
@@ -770,9 +769,9 @@ int net_init_tap(const NetClientOptions *opts, const char *name,if (tap->has_ifname || tap->has_script || tap->has_downscript || tap->has_vnet_hdr || tap->has_helper || tap->has_queues || tap->has_vhostfd) { -error_report ("ifname=, script=, downscript=, vnet_hdr=, " -"helper=, queues=, and vhostfd= " -"are invalid with fds=" ); +error_setg (errp,"ifname=, script=, downscript=, vnet_hdr=, " +"helper=, queues=, and vhostfd= " +"are invalid with fds=" );return -1 ; }
@@ -780,8 +779,8 @@ int net_init_tap(const NetClientOptions *opts, const char *name,if (tap->has_vhostfds) { nvhosts =get_fds (tap->vhostfds, vhost_fds,MAX_TAP_QUEUES );if (nfds != nvhosts) { -error_report ("The number of fds passed does not match the " -"number of vhostfds passed" ); +error_setg (errp,"The number of fds passed does not match " +"the number of vhostfds passed" );return -1 ; } }
@@ -789,7 +788,7 @@ int net_init_tap(const NetClientOptions *opts, const char *name,for (i =0 ; i < nfds; i++) { fd =monitor_fd_param (cur_mon, fds[i], &err);if (fd ==-1 ) { -error_report_err (err); +error_propagate (errp, err);return -1 ; }
@@ -798,7 +797,8 @@ int net_init_tap(const NetClientOptions *opts, const char *name,if (i ==0 ) { vnet_hdr =tap_probe_vnet_hdr (fd); }else if (vnet_hdr !=tap_probe_vnet_hdr (fd)) { -error_report ("vnet_hdr not consistent across given tap fds" ); +error_setg (errp, +"vnet_hdr not consistent across given tap fds" );return -1 ; }
@@ -807,15 +807,15 @@ int net_init_tap(const NetClientOptions *opts, const char *name, tap->has_vhostfds ? vhost_fds[i] :NULL , vnet_hdr, fd, &err);if (err) { -error_report_err (err); +error_propagate (errp, err);return -1 ; } } }else if (tap->has_helper) {if (tap->has_ifname || tap->has_script || tap->has_downscript || tap->has_vnet_hdr || tap->has_queues || tap->has_vhostfds) { -error_report ("ifname=, script=, downscript=, and vnet_hdr= " -"queues=, and vhostfds= are invalid with helper=" ); +error_setg (errp,"ifname=, script=, downscript=, vnet_hdr=, " +"queues=, and vhostfds= are invalid with helper=" );return -1 ; }
@@ -832,13 +832,13 @@ int net_init_tap(const NetClientOptions *opts, const char *name, script, downscript, vhostfdname, vnet_hdr, fd, &err);if (err) { -error_report_err (err); +error_propagate (errp, err);close (fd);return -1 ; } }else {if (tap->has_vhostfds) { -error_report ("vhostfds= is invalid if fds= wasn't specified" ); +error_setg (errp,"vhostfds= is invalid if fds= wasn't specified" );return -1 ; } script = tap->has_script ? tap->script :DEFAULT_NETWORK_SCRIPT ;
@@ -853,15 +853,14 @@ int net_init_tap(const NetClientOptions *opts, const char *name,for (i =0 ; i < queues; i++) { fd =net_tap_init (tap, &vnet_hdr, i >=1 ?"no" : script, - ifname,sizeof ifname, queues >1 , &err); + ifname,sizeof ifname, queues >1 , errp);if (fd ==-1 ) { -error_report_err (err);return -1 ; }if (queues >1 && i ==0 && !tap->has_ifname) {if (tap_fd_get_ifname (fd, ifname)) { -error_report ("Fail to get ifname" ); +error_setg (errp,"Fail to get ifname" );close (fd);return -1 ; }
@@ -872,7 +871,7 @@ int net_init_tap(const NetClientOptions *opts, const char *name, i >=1 ?"no" : downscript, vhostfdname, vnet_hdr, fd, &err);if (err) { -error_report_err (err); +error_propagate (errp, err);close (fd);return -1 ; }
Signature · 1 line
2.4.1
[Qemu-devel] [PULL 17/17] net/net: Record usage status of mac address
In reply to Stefan HajnocziFrom: Shannon Zhao <[email protected]>
Currently QEMU dynamically generates mac address for the NIC which doesn't specify the mac address. But when we hotplug a NIC without specifying mac address, the mac address will increase for the same NIC along with hotplug and hot-unplug, and at last it will overflow. And if we codeplug one NIC with mac address e.g. "52:54:00:12:34:56", then hotplug one NIC without specifying mac address and the mac address of the hotplugged NIC is duplicate of "52:54:00:12:34:56".
This patch add a mac_table to record the usage status and free the mac address when the NIC is unrealized.
--- net/net.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 55 insertions(+), 4 deletions(-)
net/net.c +55 -4
@@ -167,19 +167,68 @@ void qemu_format_nic_info_str(NetClientState *nc, uint8_t macaddr[6]) macaddr[3], macaddr[4], macaddr[5]); } +static int mac_table[256 ] = {0 }; + +static void qemu_macaddr_set_used (MACAddr *macaddr) +{ +int index; + +for (index =0x56 ; index <0xFF ; index++) { +if (macaddr->a[5 ] == index) { + mac_table[index]++; + } + } +} + +static void qemu_macaddr_set_free (MACAddr *macaddr) +{ +int index; +static const MACAddr base = { .a = {0x52 ,0x54 ,0x00 ,0x12 ,0x34 ,0 } }; + +if (memcmp (macaddr->a, &base.a, (sizeof (base.a) -1 )) !=0 ) { +return ; + } +for (index =0x56 ; index <0xFF ; index++) { +if (macaddr->a[5 ] == index) { + mac_table[index]--; + } + } +} + +static int qemu_macaddr_get_free (void ) +{ +int index; + +for (index =0x56 ; index <0xFF ; index++) { +if (mac_table[index] ==0 ) { +return index; + } + } + +return -1 ; +} +void qemu_macaddr_default_if_unset (MACAddr *macaddr) { -static int index =0 ;static const MACAddr zero = { .a = {0 ,0 ,0 ,0 ,0 ,0 } }; +static const MACAddr base = { .a = {0x52 ,0x54 ,0x00 ,0x12 ,0x34 ,0 } }; + +if (memcmp (macaddr, &zero,sizeof (zero)) !=0 ) { +if (memcmp (macaddr->a, &base.a, (sizeof (base.a) -1 )) !=0 ) { +return ; + }else { +qemu_macaddr_set_used (macaddr); +return ; + } + } -if (memcmp (macaddr, &zero,sizeof (zero)) !=0 ) -return ; macaddr->a[0 ] =0x52 ; macaddr->a[1 ] =0x54 ; macaddr->a[2 ] =0x00 ; macaddr->a[3 ] =0x12 ; macaddr->a[4 ] =0x34 ; - macaddr->a[5 ] =0x56 + index++; + macaddr->a[5 ] =qemu_macaddr_get_free (); +qemu_macaddr_set_used (macaddr); }/**
@@ -374,6 +423,8 @@ void qemu_del_nic(NICState *nic) {int i, queues =MAX (nic->conf->peers.queues,1 ); +qemu_macaddr_set_free (&nic->conf->macaddr); +/* If this is a peer NIC and peer has already been deleted, free it now. */ if (nic->peer_deleted) {for (i =0 ; i < queues; i++) {
Signature · 1 line
2.4.1
Peter Maydell
AppliedQuoted 6 lines · Stefan Hajnoczi
The following changes since commit
0915aed5842bd4dbe396b92d4f3b846ae29ad663:Merge remote-tracking branch 'remotes/jnsnow/tags/ide-pull-request' into staging (2015-05-26 11:31:03 +0100)
are available in the git repository at:
Quoted 7 lines
git://github.com/stefanha/qemu.gittags/net-pull-requestfor you to fetch changes up to
2bc22a58e16f0650e56dccfac9495e5aef58e2ef:net/net: Record usage status of mac address (2015-05-27 10:34:07 +0100)
----------------------------------------------------------------
Applied, thanks.
-- PMM