render / rpms / libvirt

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