]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
vircgroup: extract virCgroupV1Remove
authorPavel Hrdina <phrdina@redhat.com>
Fri, 17 Aug 2018 08:02:05 +0000 (10:02 +0200)
committerPavel Hrdina <phrdina@redhat.com>
Tue, 25 Sep 2018 11:40:22 +0000 (13:40 +0200)
Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
src/util/vircgroup.c
src/util/vircgroupbackend.h
src/util/vircgrouppriv.h
src/util/vircgroupv1.c

index ec9c01aea7cf759c00285766515a0f9b66143fb5..fe90b6038e46bd2523da359c38f354707dbfffd7 100644 (file)
@@ -2919,7 +2919,7 @@ virCgroupGetCpuacctPercpuUsage(virCgroupPtr group, char **usage)
 }
 
 
-static int
+int
 virCgroupRemoveRecursively(char *grppath)
 {
     DIR *grpdir;
@@ -2982,38 +2982,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);
 }
 
 
index b2848c20767ae7dcaad8e382082f2ce82a61c919..1f28c51c49819d6ea0aaa2610364529cff8c4cb6 100644 (file)
@@ -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;
index 2e731458d5920aacfbe3dbb769937bb8eeb84a71..a760b9bcfdbedbd37b267adfe9d9f20293bd5545 100644 (file)
@@ -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__ */
index f2411b415f453059823dbd503bda97d8c2cc6631..90d39e7fbecbd7156325132dcd1e66d45f2a9c07 100644 (file)
@@ -667,6 +667,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,
 
@@ -683,6 +721,7 @@ virCgroupBackend virCgroupV1Backend = {
     .getAnyController = virCgroupV1GetAnyController,
     .pathOfController = virCgroupV1PathOfController,
     .makeGroup = virCgroupV1MakeGroup,
+    .remove = virCgroupV1Remove,
 };