render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
Blob Blame History Raw
From 251261233d1dcfe086230f6b079c8b3b6518d60f Mon Sep 17 00:00:00 2001
Message-Id: <251261233d1dcfe086230f6b079c8b3b6518d60f@dist-git>
From: Pavel Hrdina <phrdina@redhat.com>
Date: Mon, 1 Jul 2019 17:06:36 +0200
Subject: [PATCH] vircgroup: extract virCgroupV1Remove
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
(cherry picked from commit b148d080495a989db6960ad4ac7e83e576957dfe)

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Message-Id: <bf11de0f39d11e0c9122461848a50024b4096553.1561993100.git.phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
 src/util/vircgroup.c        | 35 ++-------------------------------
 src/util/vircgroupbackend.h |  4 ++++
 src/util/vircgrouppriv.h    |  2 ++
 src/util/vircgroupv1.c      | 39 +++++++++++++++++++++++++++++++++++++
 4 files changed, 47 insertions(+), 33 deletions(-)

diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index 8f0ea4de9a..33d34d6eda 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -2923,7 +2923,7 @@ virCgroupGetCpuacctPercpuUsage(virCgroupPtr group, char **usage)
 }
 
 
-static int
+int
 virCgroupRemoveRecursively(char *grppath)
 {
     DIR *grpdir;
@@ -2986,38 +2986,7 @@ virCgroupRemoveRecursively(char *grppath)
 int
 virCgroupRemove(virCgroupPtr group)
 {
-    int rc = 0;
-    size_t i;
-
-    VIR_DEBUG("Removing cgroup %s", group->path);
-    for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
-        VIR_AUTOFREE(char *) grppath = NULL;
-
-        /* Skip over controllers not mounted */
-        if (!group->controllers[i].mountPoint)
-            continue;
-
-        /* We must never rmdir() in systemd's hierarchy */
-        if (i == VIR_CGROUP_CONTROLLER_SYSTEMD)
-            continue;
-
-        /* Don't delete the root group, if we accidentally
-           ended up in it for some reason */
-        if (STREQ(group->controllers[i].placement, "/"))
-            continue;
-
-        if (virCgroupPathOfController(group,
-                                      i,
-                                      NULL,
-                                      &grppath) != 0)
-            continue;
-
-        VIR_DEBUG("Removing cgroup %s and all child cgroups", grppath);
-        rc = virCgroupRemoveRecursively(grppath);
-    }
-    VIR_DEBUG("Done removing cgroup %s", group->path);
-
-    return rc;
+    return group->backend->remove(group);
 }
 
 
diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h
index b2848c2076..1f28c51c49 100644
--- a/src/util/vircgroupbackend.h
+++ b/src/util/vircgroupbackend.h
@@ -100,6 +100,9 @@ typedef int
                         bool create,
                         unsigned int flags);
 
+typedef int
+(*virCgroupRemoveCB)(virCgroupPtr group);
+
 struct _virCgroupBackend {
     virCgroupBackendType type;
 
@@ -117,6 +120,7 @@ struct _virCgroupBackend {
     virCgroupGetAnyControllerCB getAnyController;
     virCgroupPathOfControllerCB pathOfController;
     virCgroupMakeGroupCB makeGroup;
+    virCgroupRemoveCB remove;
 };
 typedef struct _virCgroupBackend virCgroupBackend;
 typedef virCgroupBackend *virCgroupBackendPtr;
diff --git a/src/util/vircgrouppriv.h b/src/util/vircgrouppriv.h
index 2e731458d5..a760b9bcfd 100644
--- a/src/util/vircgrouppriv.h
+++ b/src/util/vircgrouppriv.h
@@ -88,4 +88,6 @@ int virCgroupNewDomainPartition(virCgroupPtr partition,
                                 virCgroupPtr *group)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(5);
 
+int virCgroupRemoveRecursively(char *grppath);
+
 #endif /* __VIR_CGROUP_PRIV_H__ */
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
index 653e848a83..4d4b51094a 100644
--- a/src/util/vircgroupv1.c
+++ b/src/util/vircgroupv1.c
@@ -668,6 +668,44 @@ virCgroupV1MakeGroup(virCgroupPtr parent,
 }
 
 
+static int
+virCgroupV1Remove(virCgroupPtr group)
+{
+    int rc = 0;
+    size_t i;
+
+    VIR_DEBUG("Removing cgroup %s", group->path);
+    for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
+        VIR_AUTOFREE(char *) grppath = NULL;
+
+        /* Skip over controllers not mounted */
+        if (!group->controllers[i].mountPoint)
+            continue;
+
+        /* We must never rmdir() in systemd's hierarchy */
+        if (i == VIR_CGROUP_CONTROLLER_SYSTEMD)
+            continue;
+
+        /* Don't delete the root group, if we accidentally
+           ended up in it for some reason */
+        if (STREQ(group->controllers[i].placement, "/"))
+            continue;
+
+        if (virCgroupV1PathOfController(group,
+                                        i,
+                                        NULL,
+                                        &grppath) != 0)
+            continue;
+
+        VIR_DEBUG("Removing cgroup %s and all child cgroups", grppath);
+        rc = virCgroupRemoveRecursively(grppath);
+    }
+    VIR_DEBUG("Done removing cgroup %s", group->path);
+
+    return rc;
+}
+
+
 virCgroupBackend virCgroupV1Backend = {
     .type = VIR_CGROUP_BACKEND_TYPE_V1,
 
@@ -684,6 +722,7 @@ virCgroupBackend virCgroupV1Backend = {
     .getAnyController = virCgroupV1GetAnyController,
     .pathOfController = virCgroupV1PathOfController,
     .makeGroup = virCgroupV1MakeGroup,
+    .remove = virCgroupV1Remove,
 };
 
 
-- 
2.22.0