]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu_command: replace vlan= with netdev= for legacy nic
authorCole Robinson <crobinso@redhat.com>
Tue, 19 Jun 2018 15:42:37 +0000 (11:42 -0400)
committerCole Robinson <crobinso@redhat.com>
Wed, 20 Jun 2018 18:26:21 +0000 (14:26 -0400)
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
src/qemu/qemu_command.h
src/qemu/qemu_hotplug.c
tests/qemuxml2argvdata/arm-vexpressa9-basic.args

index 31a0b7761a225e25bdb4b97bd6a21bbd443846db..f2dbb3fadd4402df65c755b7f78fc2673c5f6343 100644 (file)
@@ -3353,16 +3353,15 @@ qemuBuildMemoryDeviceStr(virDomainMemoryDefPtr mem)
 
 
 static char *
-qemuBuildLegacyNicStr(virDomainNetDefPtr net,
-                      int vlan)
+qemuBuildLegacyNicStr(virDomainNetDefPtr net)
 {
     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 +3373,6 @@ qemuBuildLegacyNicStr(virDomainNetDefPtr net,
 char *
 qemuBuildNicDevStr(virDomainDefPtr def,
                    virDomainNetDefPtr net,
-                   int vlan,
                    unsigned int bootindex,
                    size_t vhostfdSize,
                    virQEMUCapsPtr qemuCaps)
@@ -3523,10 +3521,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 +3550,6 @@ qemuBuildNicDevStr(virDomainDefPtr def,
 char *
 qemuBuildHostNetStr(virDomainNetDefPtr net,
                     virQEMUDriverPtr driver,
-                    int vlan,
                     char **tapfd,
                     size_t tapfdSize,
                     char **vhostfd,
@@ -3670,13 +3664,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) {
@@ -8203,7 +8191,6 @@ qemuBuildVhostuserCommandLine(virQEMUDriverPtr driver,
     }
 
     if (!(netdev = qemuBuildHostNetStr(net, driver,
-                                       -1,
                                        NULL, 0, NULL, 0)))
         goto error;
 
@@ -8219,7 +8206,7 @@ qemuBuildVhostuserCommandLine(virQEMUDriverPtr driver,
     virCommandAddArg(cmd, netdev);
     VIR_FREE(netdev);
 
-    if (!(nic = qemuBuildNicDevStr(def, net, -1, bootindex,
+    if (!(nic = qemuBuildNicDevStr(def, net, bootindex,
                                    queues, qemuCaps))) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        "%s", _("Error generating NIC -device string"));
@@ -8248,7 +8235,6 @@ qemuBuildInterfaceCommandLine(virQEMUDriverPtr driver,
                               virDomainDefPtr def,
                               virDomainNetDefPtr net,
                               virQEMUCapsPtr qemuCaps,
-                              int vlan,
                               unsigned int bootindex,
                               virNetDevVPortProfileOp vmop,
                               bool standalone,
@@ -8494,37 +8480,27 @@ qemuBuildInterfaceCommandLine(virQEMUDriverPtr driver,
             goto cleanup;
     }
 
+    if (!(host = qemuBuildHostNetStr(net, driver,
+                                     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,
+        if (!(nic = qemuBuildNicDevStr(def, net, bootindex,
                                        vhostfdSize, qemuCaps)))
             goto cleanup;
         virCommandAddArgList(cmd, "-device", nic, NULL);
     } else {
-        if (!(nic = qemuBuildLegacyNicStr(net, vlan)))
+        if (!(nic = qemuBuildLegacyNicStr(net)))
             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;
@@ -8595,16 +8571,9 @@ qemuBuildNetCommandLine(virQEMUDriverPtr driver,
 
         for (i = 0; i < def->nnets; i++) {
             virDomainNetDefPtr net = def->nets[i];
-            int vlan;
-
-            /* VLANs are not used with -netdev and -device, so don't record them */
-            if (qemuDomainSupportsNicdev(def, net))
-                vlan = -1;
-            else
-                vlan = i;
 
             if (qemuBuildInterfaceCommandLine(driver, logManager, cmd, def, net,
-                                              qemuCaps, vlan, bootNet, vmop,
+                                              qemuCaps, bootNet, vmop,
                                               standalone, nnicindexes,
                                               nicindexes,
                                               chardevStdioLogd) < 0)
index 0bcbf3018b8ee2da5104ffd7daca01debb9741ad..c78282eb097d66d7e02e7b31d8e364fbf85b9ef1 100644 (file)
@@ -83,10 +83,8 @@ qemuBuildChrDeviceStr(char **deviceStr,
                       virDomainChrDefPtr chr,
                       virQEMUCapsPtr qemuCaps);
 
-/* With vlan == -1, use netdev syntax, else old hostnet */
 char *qemuBuildHostNetStr(virDomainNetDefPtr net,
                           virQEMUDriverPtr driver,
-                          int vlan,
                           char **tapfd,
                           size_t tapfdSize,
                           char **vhostfd,
@@ -95,7 +93,6 @@ char *qemuBuildHostNetStr(virDomainNetDefPtr net,
 /* Current, best practice */
 char *qemuBuildNicDevStr(virDomainDefPtr def,
                          virDomainNetDefPtr net,
-                         int vlan,
                          unsigned int bootindex,
                          size_t vhostfdSize,
                          virQEMUCapsPtr qemuCaps);
index 7c0c366b992be15c2994f2bb51f4422187e9dec5..7a1bbc7c8c44c0364755dc058e40aba2e2430ac9 100644 (file)
@@ -994,7 +994,6 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver,
     }
 
     if (!(netstr = qemuBuildHostNetStr(net, driver,
-                                       -1,
                                        tapfdName, tapfdSize,
                                        vhostfdName, vhostfdSize)))
         goto cleanup;
@@ -1027,7 +1026,7 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver,
     for (i = 0; i < vhostfdSize; i++)
         VIR_FORCE_CLOSE(vhostfd[i]);
 
-    if (!(nicstr = qemuBuildNicDevStr(vm->def, net, -1, 0,
+    if (!(nicstr = qemuBuildNicDevStr(vm->def, net, 0,
                                       queueSize, priv->qemuCaps)))
         goto try_remove;
 
index d9689b8ea8eefd2e36e25c6cdfcf53a1946af7d7..1821ed4d389ba30ea92f22de855607c1690941bc 100644 (file)
@@ -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