[libvirt] [PATCH 3/4] Cope with races while killing processes

Daniel P. Berrange berrange at redhat.com
Fri Jul 26 15:48:23 UTC 2013


From: "Daniel P. Berrange" <berrange at redhat.com>

When systemd is involved in managing processes, it may start
killing off & tearing down croups associated with the process
while we're still doing virCgroupKillPainfully. We must
explicitly check for ENOENT and treat it as if we had finished
killing processes

Signed-off-by: Daniel P. Berrange <berrange at redhat.com>
---
 src/util/vircgroup.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index 5ff8850..94f6692 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -2539,6 +2539,12 @@ static int virCgroupKillInternal(virCgroupPtr group, int signum, virHashTablePtr
     while (!done) {
         done = true;
         if (!(fp = fopen(keypath, "r"))) {
+            if (errno == ENOENT) {
+                VIR_DEBUG("No file %s, assuming done", keypath);
+                killedAny = false;
+                goto done;
+            }
+
             virReportSystemError(errno,
                                  _("Failed to read %s"),
                                  keypath);
@@ -2578,6 +2584,7 @@ static int virCgroupKillInternal(virCgroupPtr group, int signum, virHashTablePtr
         }
     }
 
+ done:
     ret = killedAny ? 1 : 0;
 
 cleanup:
@@ -2647,8 +2654,13 @@ static int virCgroupKillRecursiveInternal(virCgroupPtr group, int signum, virHas
     if (rc == 1)
         killedAny = true;
 
-    VIR_DEBUG("Iterate over children of %s", keypath);
+    VIR_DEBUG("Iterate over children of %s (killedAny=%d)", keypath, killedAny);
     if (!(dp = opendir(keypath))) {
+        if (errno == ENOENT) {
+            VIR_DEBUG("Path %s does not exist, assuming done", keypath);
+            killedAny = false;
+            goto done;
+        }
         virReportSystemError(errno,
                              _("Cannot open %s"), keypath);
         return -1;
@@ -2678,6 +2690,7 @@ static int virCgroupKillRecursiveInternal(virCgroupPtr group, int signum, virHas
         virCgroupFree(&subgroup);
     }
 
+ done:
     ret = killedAny ? 1 : 0;
 
 cleanup:
-- 
1.8.1.4




More information about the libvir-list mailing list