]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
Avoid reporting an error if veth device is already deleted
authorDaniel P. Berrange <berrange@redhat.com>
Wed, 2 Oct 2013 10:16:14 +0000 (11:16 +0100)
committerDaniel P. Berrange <berrange@redhat.com>
Thu, 3 Oct 2013 10:28:06 +0000 (11:28 +0100)
The kernel automatically destroys veth devices when cleaning
up the container network namespace. 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@redhat.com>
po/POTFILES.in
src/util/virnetdevveth.c

index 2a0605b87ff41fd4213c2eee0581dbc5503b2b4a..15afdecf005ef7169e6fbce6eae7a116dfa1c7eb 100644 (file)
@@ -171,6 +171,7 @@ src/util/virnetdevbridge.c
 src/util/virnetdevmacvlan.c
 src/util/virnetdevopenvswitch.c
 src/util/virnetdevtap.c
+src/util/virnetdevveth.c
 src/util/virnetdevvportprofile.c
 src/util/virnetlink.c
 src/util/virnodesuspend.c
index 039767fa2931fe20f9930b66e8cf46cd7ec60e49..c0d32c49549bef551caab9e2cd1629e5daa072fa 100644 (file)
@@ -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;
 }