render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
c480ed
From 251261233d1dcfe086230f6b079c8b3b6518d60f Mon Sep 17 00:00:00 2001
c480ed
Message-Id: <251261233d1dcfe086230f6b079c8b3b6518d60f@dist-git>
c480ed
From: Pavel Hrdina <phrdina@redhat.com>
c480ed
Date: Mon, 1 Jul 2019 17:06:36 +0200
c480ed
Subject: [PATCH] vircgroup: extract virCgroupV1Remove
c480ed
MIME-Version: 1.0
c480ed
Content-Type: text/plain; charset=UTF-8
c480ed
Content-Transfer-Encoding: 8bit
c480ed
c480ed
Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
c480ed
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c480ed
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
c480ed
(cherry picked from commit b148d080495a989db6960ad4ac7e83e576957dfe)
c480ed
c480ed
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297
c480ed
c480ed
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
c480ed
Message-Id: <bf11de0f39d11e0c9122461848a50024b4096553.1561993100.git.phrdina@redhat.com>
c480ed
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c480ed
---
c480ed
 src/util/vircgroup.c        | 35 ++-------------------------------
c480ed
 src/util/vircgroupbackend.h |  4 ++++
c480ed
 src/util/vircgrouppriv.h    |  2 ++
c480ed
 src/util/vircgroupv1.c      | 39 +++++++++++++++++++++++++++++++++++++
c480ed
 4 files changed, 47 insertions(+), 33 deletions(-)
c480ed
c480ed
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
c480ed
index 8f0ea4de9a..33d34d6eda 100644
c480ed
--- a/src/util/vircgroup.c
c480ed
+++ b/src/util/vircgroup.c
c480ed
@@ -2923,7 +2923,7 @@ virCgroupGetCpuacctPercpuUsage(virCgroupPtr group, char **usage)
c480ed
 }
c480ed
 
c480ed
 
c480ed
-static int
c480ed
+int
c480ed
 virCgroupRemoveRecursively(char *grppath)
c480ed
 {
c480ed
     DIR *grpdir;
c480ed
@@ -2986,38 +2986,7 @@ virCgroupRemoveRecursively(char *grppath)
c480ed
 int
c480ed
 virCgroupRemove(virCgroupPtr group)
c480ed
 {
c480ed
-    int rc = 0;
c480ed
-    size_t i;
c480ed
-
c480ed
-    VIR_DEBUG("Removing cgroup %s", group->path);
c480ed
-    for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
c480ed
-        VIR_AUTOFREE(char *) grppath = NULL;
c480ed
-
c480ed
-        /* Skip over controllers not mounted */
c480ed
-        if (!group->controllers[i].mountPoint)
c480ed
-            continue;
c480ed
-
c480ed
-        /* We must never rmdir() in systemd's hierarchy */
c480ed
-        if (i == VIR_CGROUP_CONTROLLER_SYSTEMD)
c480ed
-            continue;
c480ed
-
c480ed
-        /* Don't delete the root group, if we accidentally
c480ed
-           ended up in it for some reason */
c480ed
-        if (STREQ(group->controllers[i].placement, "/"))
c480ed
-            continue;
c480ed
-
c480ed
-        if (virCgroupPathOfController(group,
c480ed
-                                      i,
c480ed
-                                      NULL,
c480ed
-                                      &grppath) != 0)
c480ed
-            continue;
c480ed
-
c480ed
-        VIR_DEBUG("Removing cgroup %s and all child cgroups", grppath);
c480ed
-        rc = virCgroupRemoveRecursively(grppath);
c480ed
-    }
c480ed
-    VIR_DEBUG("Done removing cgroup %s", group->path);
c480ed
-
c480ed
-    return rc;
c480ed
+    return group->backend->remove(group);
c480ed
 }
c480ed
 
c480ed
 
c480ed
diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h
c480ed
index b2848c2076..1f28c51c49 100644
c480ed
--- a/src/util/vircgroupbackend.h
c480ed
+++ b/src/util/vircgroupbackend.h
c480ed
@@ -100,6 +100,9 @@ typedef int
c480ed
                         bool create,
c480ed
                         unsigned int flags);
c480ed
 
c480ed
+typedef int
c480ed
+(*virCgroupRemoveCB)(virCgroupPtr group);
c480ed
+
c480ed
 struct _virCgroupBackend {
c480ed
     virCgroupBackendType type;
c480ed
 
c480ed
@@ -117,6 +120,7 @@ struct _virCgroupBackend {
c480ed
     virCgroupGetAnyControllerCB getAnyController;
c480ed
     virCgroupPathOfControllerCB pathOfController;
c480ed
     virCgroupMakeGroupCB makeGroup;
c480ed
+    virCgroupRemoveCB remove;
c480ed
 };
c480ed
 typedef struct _virCgroupBackend virCgroupBackend;
c480ed
 typedef virCgroupBackend *virCgroupBackendPtr;
c480ed
diff --git a/src/util/vircgrouppriv.h b/src/util/vircgrouppriv.h
c480ed
index 2e731458d5..a760b9bcfd 100644
c480ed
--- a/src/util/vircgrouppriv.h
c480ed
+++ b/src/util/vircgrouppriv.h
c480ed
@@ -88,4 +88,6 @@ int virCgroupNewDomainPartition(virCgroupPtr partition,
c480ed
                                 virCgroupPtr *group)
c480ed
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(5);
c480ed
 
c480ed
+int virCgroupRemoveRecursively(char *grppath);
c480ed
+
c480ed
 #endif /* __VIR_CGROUP_PRIV_H__ */
c480ed
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
c480ed
index 653e848a83..4d4b51094a 100644
c480ed
--- a/src/util/vircgroupv1.c
c480ed
+++ b/src/util/vircgroupv1.c
c480ed
@@ -668,6 +668,44 @@ virCgroupV1MakeGroup(virCgroupPtr parent,
c480ed
 }
c480ed
 
c480ed
 
c480ed
+static int
c480ed
+virCgroupV1Remove(virCgroupPtr group)
c480ed
+{
c480ed
+    int rc = 0;
c480ed
+    size_t i;
c480ed
+
c480ed
+    VIR_DEBUG("Removing cgroup %s", group->path);
c480ed
+    for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
c480ed
+        VIR_AUTOFREE(char *) grppath = NULL;
c480ed
+
c480ed
+        /* Skip over controllers not mounted */
c480ed
+        if (!group->controllers[i].mountPoint)
c480ed
+            continue;
c480ed
+
c480ed
+        /* We must never rmdir() in systemd's hierarchy */
c480ed
+        if (i == VIR_CGROUP_CONTROLLER_SYSTEMD)
c480ed
+            continue;
c480ed
+
c480ed
+        /* Don't delete the root group, if we accidentally
c480ed
+           ended up in it for some reason */
c480ed
+        if (STREQ(group->controllers[i].placement, "/"))
c480ed
+            continue;
c480ed
+
c480ed
+        if (virCgroupV1PathOfController(group,
c480ed
+                                        i,
c480ed
+                                        NULL,
c480ed
+                                        &grppath) != 0)
c480ed
+            continue;
c480ed
+
c480ed
+        VIR_DEBUG("Removing cgroup %s and all child cgroups", grppath);
c480ed
+        rc = virCgroupRemoveRecursively(grppath);
c480ed
+    }
c480ed
+    VIR_DEBUG("Done removing cgroup %s", group->path);
c480ed
+
c480ed
+    return rc;
c480ed
+}
c480ed
+
c480ed
+
c480ed
 virCgroupBackend virCgroupV1Backend = {
c480ed
     .type = VIR_CGROUP_BACKEND_TYPE_V1,
c480ed
 
c480ed
@@ -684,6 +722,7 @@ virCgroupBackend virCgroupV1Backend = {
c480ed
     .getAnyController = virCgroupV1GetAnyController,
c480ed
     .pathOfController = virCgroupV1PathOfController,
c480ed
     .makeGroup = virCgroupV1MakeGroup,
c480ed
+    .remove = virCgroupV1Remove,
c480ed
 };
c480ed
 
c480ed
 
c480ed
-- 
c480ed
2.22.0
c480ed