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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 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)
 {
     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
-- 
2.17.1

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



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux