From 97edaf4f3dc5af717f88e41577a1cda77982f4c1 Mon Sep 17 00:00:00 2001 Message-Id: <97edaf4f3dc5af717f88e41577a1cda77982f4c1.1381871411.git.jdenemar@redhat.com> From: "Daniel P. Berrange" Date: Mon, 7 Oct 2013 17:17:28 +0100 Subject: [PATCH] Avoid reporting an error if veth device is already deleted For https://bugzilla.redhat.com/show_bug.cgi?id=1014604 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 (cherry picked from commit 10caf94ddc568d36561d89ca28fe0c58154a50f9) Signed-off-by: Jiri Denemark --- po/POTFILES.in | 1 + src/util/virnetdevveth.c | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/po/POTFILES.in b/po/POTFILES.in index 884b70a..8afd015 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -168,6 +168,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 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.2