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

[libvirt] [PATCH] lxc: Fix error handlings of veth functions



moveInterfaceToNetNs and vethInterfaceUpOrDown may return a
positive value when they fail. We should check if the value
is not zero instead of checking if it's negative.

This defect may be related to the bug:
https://bugzilla.redhat.com/show_bug.cgi?id=607496 .
It would not fix the bug, but would unveil what happens.

And also, the return value of positive is an exit code, not
an errno. So we should not use virReportSystemError.

Note that there still remains a problem that the descriptions
of the functions are wrong; they say that the return value
will be -1 on failure, however, they would actually return a
positive value. The inconsistent should be fixed at some point.
---
 src/lxc/lxc_container.c  |    7 ++++++-
 src/lxc/lxc_controller.c |    2 +-
 src/lxc/lxc_driver.c     |   12 ++++++------
 3 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
index 4371dba..c77d262 100644
--- a/src/lxc/lxc_container.c
+++ b/src/lxc/lxc_container.c
@@ -273,8 +273,13 @@ static int lxcContainerRenameAndEnableInterfaces(unsigned int nveths,
     }
 
     /* enable lo device only if there were other net devices */
-    if (veths)
+    if (veths) {
         rc = vethInterfaceUpOrDown("lo", 1);
+        if (0 != rc) {
+            VIR_ERROR(_("Failed to enable lo (%d)"), rc);
+            rc = -1;
+        }
+    }
 
 error_out:
     VIR_FREE(newname);
diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c
index d8b7bc7..9829a69 100644
--- a/src/lxc/lxc_controller.c
+++ b/src/lxc/lxc_controller.c
@@ -477,7 +477,7 @@ static int lxcControllerMoveInterfaces(unsigned int nveths,
 {
     unsigned int i;
     for (i = 0 ; i < nveths ; i++)
-        if (moveInterfaceToNetNs(veths[i], container) < 0) {
+        if (moveInterfaceToNetNs(veths[i], container) != 0) {
             lxcError(VIR_ERR_INTERNAL_ERROR,
                      _("Failed to move interface %s to ns %d"),
                      veths[i], container);
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 4fc1ecd..51c273e 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -886,9 +886,9 @@ static int lxcSetupInterfaces(virConnectPtr conn,
             char macaddr[VIR_MAC_STRING_BUFLEN];
             virFormatMacAddr(def->nets[i]->mac, macaddr);
             if (0 != (rc = setMacAddr(containerVeth, macaddr))) {
-                virReportSystemError(rc,
-                                     _("Failed to set %s to %s"),
-                                     macaddr, containerVeth);
+                lxcError(VIR_ERR_INTERNAL_ERROR,
+                         _("Failed to set %s to %s (%d)"),
+                         macaddr, containerVeth, rc);
                 goto error_exit;
             }
         }
@@ -901,9 +901,9 @@ static int lxcSetupInterfaces(virConnectPtr conn,
         }
 
         if (0 != (rc = vethInterfaceUpOrDown(parentVeth, 1))) {
-            virReportSystemError(rc,
-                                 _("Failed to enable %s device"),
-                                 parentVeth);
+            lxcError(VIR_ERR_INTERNAL_ERROR,
+                     _("Failed to enable %s device (%d)"),
+                     parentVeth, rc);
             goto error_exit;
         }
 
-- 
1.6.6.1


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