]> xenbits.xensource.com Git - libvirt.git/commitdiff
Handle hotplug change on VLAN configuration using OVS
authorAntoine Millet <antoine.millet@tdf.fr>
Mon, 17 Jul 2017 15:49:00 +0000 (17:49 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 20 Jul 2017 13:15:03 +0000 (15:15 +0200)
A new function virNetDevOpenvswitchUpdateVlan has been created to instruct
OVS of the changes. qemuDomainChangeNet has been modified to handle the
update of the VLAN configuration for a running guest and rely on
virNetDevOpenvswitchUpdateVlan to do the actual update if needed.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
src/libvirt_private.syms
src/qemu/qemu_hotplug.c
src/util/virnetdevopenvswitch.c
src/util/virnetdevopenvswitch.h

index 187b12b32b43964384f169fd0e9c22d4ff495d27..36caf6fbfda4bb347a5d79610632bf08a8ed97c9 100644 (file)
@@ -2206,6 +2206,7 @@ virNetDevOpenvswitchInterfaceStats;
 virNetDevOpenvswitchRemovePort;
 virNetDevOpenvswitchSetMigrateData;
 virNetDevOpenvswitchSetTimeout;
+virNetDevOpenvswitchUpdateVlan;
 
 
 # util/virnetdevtap.h
index da5aafaab346f5114c16ef07e80fba56941d2e50..4be0f546ca21b192016de2874bb1e1b06c2e2db8 100644 (file)
@@ -3005,6 +3005,7 @@ qemuDomainChangeNet(virQEMUDriverPtr driver,
     bool needReplaceDevDef = false;
     bool needBandwidthSet = false;
     bool needCoalesceChange = false;
+    bool needVlanUpdate = false;
     int ret = -1;
     int changeidx = -1;
 
@@ -3286,12 +3287,15 @@ qemuDomainChangeNet(virQEMUDriverPtr driver,
                         virDomainNetGetActualDirectDev(newdev)) ||
         virDomainNetGetActualDirectMode(olddev) != virDomainNetGetActualDirectMode(newdev) ||
         !virNetDevVPortProfileEqual(virDomainNetGetActualVirtPortProfile(olddev),
-                                    virDomainNetGetActualVirtPortProfile(newdev)) ||
-        !virNetDevVlanEqual(virDomainNetGetActualVlan(olddev),
-                            virDomainNetGetActualVlan(newdev))) {
+                                    virDomainNetGetActualVirtPortProfile(newdev))) {
         needReconnect = true;
     }
 
+    if (!virNetDevVlanEqual(virDomainNetGetActualVlan(olddev),
+                             virDomainNetGetActualVlan(newdev))) {
+        needVlanUpdate = true;
+    }
+
     if (olddev->linkstate != newdev->linkstate)
         needLinkStateChange = true;
 
@@ -3351,6 +3355,12 @@ qemuDomainChangeNet(virQEMUDriverPtr driver,
         goto cleanup;
     }
 
+    if (needVlanUpdate) {
+        if (virNetDevOpenvswitchUpdateVlan(newdev->ifname, &newdev->vlan) < 0)
+            goto cleanup;
+        needReplaceDevDef = true;
+    }
+
     if (needReplaceDevDef) {
         /* the changes above warrant replacing olddev with newdev in
          * the domain's nets list.
index e002af0ba273f23f216159724ed9957696bb3ac9..06ce9d8ee577ead88535a483f5bf2b2b2fb8d3ea 100644 (file)
@@ -460,3 +460,41 @@ virNetDevOpenvswitchGetVhostuserIfname(const char *path,
     VIR_FREE(ovs_timeout);
     return ret;
 }
+
+/**
+ * virNetDevOpenvswitchUpdateVlan:
+ * @ifname: the network interface name
+ * @virtVlan: VLAN configuration to be applied
+ *
+ * Update VLAN configuration of an OVS port.
+ *
+ * Returns 0 in case of success or -1 in case of failure.
+ */
+int virNetDevOpenvswitchUpdateVlan(const char *ifname,
+                                   virNetDevVlanPtr virtVlan)
+{
+    int ret = -1;
+    virCommandPtr cmd = NULL;
+
+    cmd = virCommandNew(OVSVSCTL);
+    virNetDevOpenvswitchAddTimeout(cmd);
+    virCommandAddArgList(cmd,
+                         "--", "--if-exists", "clear", "Port", ifname, "tag",
+                         "--", "--if-exists", "clear", "Port", ifname, "trunk",
+                         "--", "--if-exists", "clear", "Port", ifname, "vlan_mode",
+                         "--", "--if-exists", "set", "Port", ifname, NULL);
+
+    if (virNetDevOpenvswitchConstructVlans(cmd, virtVlan) < 0)
+        goto cleanup;
+
+    if (virCommandRun(cmd, NULL) < 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Unable to set vlan configuration on port %s"), ifname);
+        goto cleanup;
+    }
+
+    ret = 0;
+ cleanup:
+    virCommandFree(cmd);
+    return ret;
+}
index 51bb1dd006b9e2e6328925b2f2bb5131136b3ccf..6f6e620c229dd3a89947ea07dda2f7d7aaa5f25a 100644 (file)
@@ -61,4 +61,8 @@ int virNetDevOpenvswitchGetVhostuserIfname(const char *path,
                                            char **ifname)
     ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK ATTRIBUTE_NOINLINE;
 
+int virNetDevOpenvswitchUpdateVlan(const char *ifname,
+                                   virNetDevVlanPtr virtVlan)
+    ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
+
 #endif /* __VIR_NETDEV_OPENVSWITCH_H__ */