Patchwork [v2] net: make network client name unique

login
register
mail settings
Submitter Amos Kong
Date April 15, 2013, 10:55 a.m.
Message ID <1366023319-9484-1-git-send-email-akong@redhat.com>
Download mbox | patch
Permalink /patch/236560/
State New
Headers show

Comments

Amos Kong - April 15, 2013, 10:55 a.m.
assign_name() creates a name MODEL.NUM, where MODEL is the client's model,
and NUM is the number of MODELs that already exist.

Markus added NIC naming for non-VLAN clients in commit 53e51d85.
commit d33d93b2 incorrectly added a judgement of net-hub. It caused
net clients created with -netdev get same names.

eg:
 # qemu-upstream -device virtio-net-pci,netdev=h1 -netdev tap,id=h1 \
                    -device virtio-net-pci,netdev=h2 -netdev tap,id=h2 ..
 (qemu) info network
 virtio-net-pci.0: index=0,type=nic,model=virtio-net-pci,macaddr=52:54:00:12:34:56
  \ h1: index=0,type=tap,ifname=tap0,script=/etc/qemu-ifup,downscript=/etc/qemu-ifdown
 virtio-net-pci.0: index=0,type=nic,model=virtio-net-pci,macaddr=52:54:00:12:34:57
  \ h2: index=0,type=tap,ifname=tap1,script=/etc/qemu-ifup,downscript=/etc/qemu-ifdown

This patch removed the check of nic-hub, and created unique names for
all net clients that have same model.

v2: update commitlog & comments

Signed-off-by: Amos Kong <akong@redhat.com>
---
 net/net.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
Stefan Hajnoczi - April 18, 2013, 11:25 a.m.
On Mon, Apr 15, 2013 at 06:55:19PM +0800, Amos Kong wrote:
> assign_name() creates a name MODEL.NUM, where MODEL is the client's model,
> and NUM is the number of MODELs that already exist.
> 
> Markus added NIC naming for non-VLAN clients in commit 53e51d85.
> commit d33d93b2 incorrectly added a judgement of net-hub. It caused
> net clients created with -netdev get same names.
> 
> eg:
>  # qemu-upstream -device virtio-net-pci,netdev=h1 -netdev tap,id=h1 \
>                     -device virtio-net-pci,netdev=h2 -netdev tap,id=h2 ..
>  (qemu) info network
>  virtio-net-pci.0: index=0,type=nic,model=virtio-net-pci,macaddr=52:54:00:12:34:56
>   \ h1: index=0,type=tap,ifname=tap0,script=/etc/qemu-ifup,downscript=/etc/qemu-ifdown
>  virtio-net-pci.0: index=0,type=nic,model=virtio-net-pci,macaddr=52:54:00:12:34:57
>   \ h2: index=0,type=tap,ifname=tap1,script=/etc/qemu-ifup,downscript=/etc/qemu-ifdown
> 
> This patch removed the check of nic-hub, and created unique names for
> all net clients that have same model.
> 
> v2: update commitlog & comments
> 
> Signed-off-by: Amos Kong <akong@redhat.com>
> ---
>  net/net.c | 7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)

Thanks, applied to my net tree:
https://github.com/stefanha/qemu/commits/net

Stefan

Patch

diff --git a/net/net.c b/net/net.c
index 67032f5..9011174 100644
--- a/net/net.c
+++ b/net/net.c
@@ -157,8 +157,7 @@  void qemu_macaddr_default_if_unset(MACAddr *macaddr)
 /**
  * Generate a name for net client
  *
- * Only net clients created with the legacy -net option need this.  Naming is
- * mandatory for net clients created with -netdev.
+ * Only net clients created with the legacy -net option and NICs need this.
  */
 static char *assign_name(NetClientState *nc1, const char *model)
 {
@@ -170,9 +169,7 @@  static char *assign_name(NetClientState *nc1, const char *model)
         if (nc == nc1) {
             continue;
         }
-        /* For compatibility only bump id for net clients on a vlan */
-        if (strcmp(nc->model, model) == 0 &&
-            net_hub_id_for_client(nc, NULL) == 0) {
+        if (strcmp(nc->model, model) == 0) {
             id++;
         }
     }