diff mbox series

[4/6] qemu: command: replace vlan= with netdev= for legacy nic

Message ID 0d6bfcf551588a39759879580fb8ab0163fbe589.1529426092.git.crobinso@redhat.com
State New
Headers show
Series qemu: command: Replace vlan= with netdev= | expand

Commit Message

Cole Robinson June 19, 2018, 4:40 p.m. UTC
VMs with hardcoded platform network devices are forced to use old
style '-net nic' command line config. Current we use qemu's vlan
option to hook this with the '-netdev' host side of things.

However since qemu 1.2 there is '-net nic,netdev=X' option for
explicitly referencing a netdev ID, which is more inline with
typical VM commandlines, so let's switch to that

Signed-off-by: Cole Robinson <crobinso@redhat.com>

---
 src/qemu/qemu_command.c                       | 52 ++++++-------------
 .../arm-vexpressa9-basic.args                 |  4 +-
 2 files changed, 19 insertions(+), 37 deletions(-)

-- 
2.17.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Comments

Michal Prívozník June 20, 2018, 1:34 p.m. UTC | #1
On 06/19/2018 06:40 PM, Cole Robinson wrote:
> VMs with hardcoded platform network devices are forced to use old

> style '-net nic' command line config. Current we use qemu's vlan


s/Current/Currently/ perhaps?

> option to hook this with the '-netdev' host side of things.

> 

> However since qemu 1.2 there is '-net nic,netdev=X' option for

> explicitly referencing a netdev ID, which is more inline with

> typical VM commandlines, so let's switch to that

> 

> Signed-off-by: Cole Robinson <crobinso@redhat.com>

> ---

>  src/qemu/qemu_command.c                       | 52 ++++++-------------

>  .../arm-vexpressa9-basic.args                 |  4 +-

>  2 files changed, 19 insertions(+), 37 deletions(-)

> 

> diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c

> index 31a0b7761a..a2687c5693 100644

> --- a/src/qemu/qemu_command.c

> +++ b/src/qemu/qemu_command.c

> @@ -3354,15 +3354,15 @@ qemuBuildMemoryDeviceStr(virDomainMemoryDefPtr mem)

>  

>  static char *

>  qemuBuildLegacyNicStr(virDomainNetDefPtr net,

> -                      int vlan)

> +                      int vlan ATTRIBUTE_UNUSED)


Might as well drop this. Looking into the future at 5/6 and you're doing
just that. My suggestion is to merge 5/6 into this one, but whatever you
prefer.

>  {

>      char *str;

>      char macaddr[VIR_MAC_STRING_BUFLEN];

>  

>      ignore_value(virAsprintf(&str,

> -                             "nic,macaddr=%s,vlan=%d%s%s%s%s",

> +                             "nic,macaddr=%s,netdev=host%s%s%s%s%s",

>                               virMacAddrFormat(&net->mac, macaddr),

> -                             vlan,

> +                             net->info.alias,

>                               (net->model ? ",model=" : ""),

>                               (net->model ? net->model : ""),

>                               (net->info.alias ? ",name=" : ""),


Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
diff mbox series

Patch

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 31a0b7761a..a2687c5693 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3354,15 +3354,15 @@  qemuBuildMemoryDeviceStr(virDomainMemoryDefPtr mem)
 
 static char *
 qemuBuildLegacyNicStr(virDomainNetDefPtr net,
-                      int vlan)
+                      int vlan ATTRIBUTE_UNUSED)
 {
     char *str;
     char macaddr[VIR_MAC_STRING_BUFLEN];
 
     ignore_value(virAsprintf(&str,
-                             "nic,macaddr=%s,vlan=%d%s%s%s%s",
+                             "nic,macaddr=%s,netdev=host%s%s%s%s%s",
                              virMacAddrFormat(&net->mac, macaddr),
-                             vlan,
+                             net->info.alias,
                              (net->model ? ",model=" : ""),
                              (net->model ? net->model : ""),
                              (net->info.alias ? ",name=" : ""),
@@ -3374,7 +3374,7 @@  qemuBuildLegacyNicStr(virDomainNetDefPtr net,
 char *
 qemuBuildNicDevStr(virDomainDefPtr def,
                    virDomainNetDefPtr net,
-                   int vlan,
+                   int vlan ATTRIBUTE_UNUSED,
                    unsigned int bootindex,
                    size_t vhostfdSize,
                    virQEMUCapsPtr qemuCaps)
@@ -3523,10 +3523,7 @@  qemuBuildNicDevStr(virDomainDefPtr def,
         virBufferAsprintf(&buf, ",host_mtu=%u", net->mtu);
     }
 
-    if (vlan == -1)
-        virBufferAsprintf(&buf, ",netdev=host%s", net->info.alias);
-    else
-        virBufferAsprintf(&buf, ",vlan=%d", vlan);
+    virBufferAsprintf(&buf, ",netdev=host%s", net->info.alias);
     virBufferAsprintf(&buf, ",id=%s", net->info.alias);
     virBufferAsprintf(&buf, ",mac=%s",
                       virMacAddrFormat(&net->mac, macaddr));
@@ -3555,7 +3552,7 @@  qemuBuildNicDevStr(virDomainDefPtr def,
 char *
 qemuBuildHostNetStr(virDomainNetDefPtr net,
                     virQEMUDriverPtr driver,
-                    int vlan,
+                    int vlan ATTRIBUTE_UNUSED,
                     char **tapfd,
                     size_t tapfdSize,
                     char **vhostfd,
@@ -3670,13 +3667,7 @@  qemuBuildHostNetStr(virDomainNetDefPtr net,
         break;
     }
 
-    if (vlan >= 0) {
-        virBufferAsprintf(&buf, "vlan=%d,", vlan);
-        if (net->info.alias)
-            virBufferAsprintf(&buf, "name=host%s,", net->info.alias);
-    } else {
-        virBufferAsprintf(&buf, "id=host%s,", net->info.alias);
-    }
+    virBufferAsprintf(&buf, "id=host%s,", net->info.alias);
 
     if (is_tap) {
         if (vhostfdSize) {
@@ -8494,22 +8485,20 @@  qemuBuildInterfaceCommandLine(virQEMUDriverPtr driver,
             goto cleanup;
     }
 
+    if (!(host = qemuBuildHostNetStr(net, driver,
+                                     vlan,
+                                     tapfdName, tapfdSize,
+                                     vhostfdName, vhostfdSize)))
+        goto cleanup;
+    virCommandAddArgList(cmd, "-netdev", host, NULL);
+
     /* Possible combinations:
      *
-     *  1. Old way:   -net nic,model=e1000,vlan=1 -net tap,vlan=1
-     *  2. New way:   -netdev type=tap,id=netdev1 -device e1000,id=netdev1
-     *
-     * NB: The backend and frontend are reversed above
+     *   Old way: -netdev type=tap,id=netdev1 \
+     *              -net nic,model=e1000,netdev=netdev1
+     *   New way: -netdev type=tap,id=netdev1 -device e1000,id=netdev1
      */
-
     if (qemuDomainSupportsNicdev(def, net)) {
-        if (!(host = qemuBuildHostNetStr(net, driver,
-                                         vlan,
-                                         tapfdName, tapfdSize,
-                                         vhostfdName, vhostfdSize)))
-            goto cleanup;
-        virCommandAddArgList(cmd, "-netdev", host, NULL);
-
         if (!(nic = qemuBuildNicDevStr(def, net, vlan, bootindex,
                                        vhostfdSize, qemuCaps)))
             goto cleanup;
@@ -8518,13 +8507,6 @@  qemuBuildInterfaceCommandLine(virQEMUDriverPtr driver,
         if (!(nic = qemuBuildLegacyNicStr(net, vlan)))
             goto cleanup;
         virCommandAddArgList(cmd, "-net", nic, NULL);
-
-        if (!(host = qemuBuildHostNetStr(net, driver,
-                                         vlan,
-                                         tapfdName, tapfdSize,
-                                         vhostfdName, vhostfdSize)))
-            goto cleanup;
-        virCommandAddArgList(cmd, "-net", host, NULL);
     }
 
     ret = 0;
diff --git a/tests/qemuxml2argvdata/arm-vexpressa9-basic.args b/tests/qemuxml2argvdata/arm-vexpressa9-basic.args
index d9689b8ea8..1821ed4d38 100644
--- a/tests/qemuxml2argvdata/arm-vexpressa9-basic.args
+++ b/tests/qemuxml2argvdata/arm-vexpressa9-basic.args
@@ -27,7 +27,7 @@  server,nowait \
 -dtb /arm.dtb \
 -usb \
 -drive file=/arm.raw,format=raw,if=sd,index=0 \
--net nic,macaddr=52:54:00:09:a4:37,vlan=0,model=lan9118,name=net0 \
--net user,vlan=0,name=hostnet0 \
+-netdev user,id=hostnet0 \
+-net nic,macaddr=52:54:00:09:a4:37,netdev=hostnet0,model=lan9118,name=net0 \
 -chardev pty,id=charserial0 \
 -serial chardev:charserial0