[PATCH] util: do not take it as wrong if no PortData is found while getting migrateData

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

 



The function virNetDevOpenvswitchGetMigrateData() uses the cmd ovs-vsctl to
get portdata. If no portdata is available, rather than failure in running
the cmd, we think we should just print a warning message here, rather than
taking it as wrong, because PortData is just optional for an ovs interface.
If we take it as wrong anyway, in function qemuMigrationBakeCookie() it will
terminate in the middle, and cookies such as NBD would not be baked, further
more errors would happen, such as nbd ports get overflowed, etc.
Thus, we add an if branch in virNetDevOpenvswitchGetMigrateData() to just warn
if portdata is unavailable.

Signed-off-by: Zhang Bo <oscar.zhangbo@xxxxxxxxxx>
Signed-off-by: Zhou Yimin <zhouyimin@xxxxxxxxxx>
---
 src/util/virnetdevopenvswitch.c | 28 ++++++++++++++++++++++++----
 1 file changed, 24 insertions(+), 4 deletions(-)

diff --git a/src/util/virnetdevopenvswitch.c b/src/util/virnetdevopenvswitch.c
index e5c87bb..6116377 100644
--- a/src/util/virnetdevopenvswitch.c
+++ b/src/util/virnetdevopenvswitch.c
@@ -30,9 +30,12 @@
 #include "virerror.h"
 #include "virmacaddr.h"
 #include "virstring.h"
+#include "virlog.h"
 
 #define VIR_FROM_THIS VIR_FROM_NONE
 
+VIR_LOG_INIT("util.netdevopenvswitch");
+
 /**
  * virNetDevOpenvswitchAddPort:
  * @brname: the bridge name
@@ -204,18 +207,29 @@ int virNetDevOpenvswitchRemovePort(const char *brname ATTRIBUTE_UNUSED, const ch
 int virNetDevOpenvswitchGetMigrateData(char **migrate, const char *ifname)
 {
     virCommandPtr cmd = NULL;
+    char *errbuf = NULL;
     int ret = -1;
 
     cmd = virCommandNewArgList(OVSVSCTL, "--timeout=5", "get", "Interface",
                                ifname, "external_ids:PortData", NULL);
 
     virCommandSetOutputBuffer(cmd, migrate);
+    virCommandSetErrorBuffer(cmd, &errbuf);
 
     /* Run the command */
-    if (virCommandRun(cmd, NULL) < 0) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("Unable to run command to get OVS port data for "
-                         "interface %s"), ifname);
+    ret = virCommandRun(cmd, NULL);
+    if (ret < 0) {
+        /*PortData is optional, thus do not take it as wrong if the PortData is not found.*/
+        if (strstr(errbuf, "no key \"PortData\" in Interface record")) {
+            VIR_WARN("Can't find OVS port data for interface %s", ifname);
+            if (*migrate)
+                VIR_FREE(*migrate);
+            ret = 0;
+        } else {
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                                 _("Unable to run command to get OVS port data for "
+                                 "interface %s"), ifname);
+        }
         goto cleanup;
     }
 
@@ -223,6 +237,7 @@ int virNetDevOpenvswitchGetMigrateData(char **migrate, const char *ifname)
     (*migrate)[strlen(*migrate) - 1] = '\0';
     ret = 0;
  cleanup:
+    VIR_FREE(errbuf);
     virCommandFree(cmd);
     return ret;
 }
@@ -241,6 +256,11 @@ int virNetDevOpenvswitchSetMigrateData(char *migrate, const char *ifname)
     virCommandPtr cmd = NULL;
     int ret = -1;
 
+    if (NULL == migrate) {
+        VIR_INFO("There is no need to set OVS port data for interface %s", ifname);
+        return 0;
+    }
+
     cmd = virCommandNewArgList(OVSVSCTL, "--timeout=5", "set",
                                "Interface", ifname, NULL);
     virCommandAddArgFormat(cmd, "external_ids:PortData=%s", migrate);
-- 
1.7.12.4


--
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]