[PATCH 2/5] Avoid reporting an error if veth device is already deleted

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

 



From: "Daniel P. Berrange" <berrange@xxxxxxxxxx>

The kernel automatically destroys veth devices when cleaning
up the container network namepace. During normal shutdown, it
is thus likely that the attempt to run 'ip link del vethN'
will fail. If it fails, check if the device exists, and avoid
reporting an error if it has gone. This switches to use the
virCommand APIs instead of virRun too.

Signed-off-by: Daniel P. Berrange <berrange@xxxxxxxxxx>
---
 src/util/virnetdevveth.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/src/util/virnetdevveth.c b/src/util/virnetdevveth.c
index 039767f..c0d32c4 100644
--- a/src/util/virnetdevveth.c
+++ b/src/util/virnetdevveth.c
@@ -161,9 +161,20 @@ cleanup:
  */
 int virNetDevVethDelete(const char *veth)
 {
-    const char *argv[] = {"ip", "link", "del", veth, NULL};
+    virCommandPtr cmd = virCommandNewArgList("ip", "link", "del", veth, NULL);
+    int status;
 
-    VIR_DEBUG("veth: %s", veth);
+    if (virCommandRun(cmd, &status) < 0)
+        return -1;
 
-    return virRun(argv, NULL);
+    if (status != 0) {
+        if (!virNetDevExists(veth)) {
+            VIR_DEBUG("Device %s already deleted (by kernel namespace cleanup)", veth);
+            return 0;
+        }
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Failed to delete veth device %s"), veth);
+        return -1;
+    }
+    return 0;
 }
-- 
1.8.3.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]