Blob Blame History Raw
From 4a95be40b1a56cc0eb6d6f56161d536f22380804 Mon Sep 17 00:00:00 2001
Message-Id: <4a95be40b1a56cc0eb6d6f56161d536f22380804@dist-git>
From: Pavel Hrdina <phrdina@redhat.com>
Date: Mon, 1 Jul 2019 17:07:26 +0200
Subject: [PATCH] vircgroup: introduce virCgroupV2Remove
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
(cherry picked from commit 4fe4847438c8ff042d6d39718b26023199e67c8a)

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

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Message-Id: <a7464dfade07325cf93291200356e33235020a2e.1561993100.git.phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
 src/util/vircgroupv2.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
index cf8bd01317..b5fad47ca0 100644
--- a/src/util/vircgroupv2.c
+++ b/src/util/vircgroupv2.c
@@ -413,6 +413,25 @@ virCgroupV2MakeGroup(virCgroupPtr parent ATTRIBUTE_UNUSED,
 }
 
 
+static int
+virCgroupV2Remove(virCgroupPtr group)
+{
+    VIR_AUTOFREE(char *) grppath = NULL;
+    int controller;
+
+    /* Don't delete the root group, if we accidentally
+       ended up in it for some reason */
+    if (STREQ(group->unified.placement, "/"))
+        return 0;
+
+    controller = virCgroupV2GetAnyController(group);
+    if (virCgroupV2PathOfController(group, controller, "", &grppath) < 0)
+        return 0;
+
+    return virCgroupRemoveRecursively(grppath);
+}
+
+
 virCgroupBackend virCgroupV2Backend = {
     .type = VIR_CGROUP_BACKEND_TYPE_V2,
 
@@ -429,6 +448,7 @@ virCgroupBackend virCgroupV2Backend = {
     .getAnyController = virCgroupV2GetAnyController,
     .pathOfController = virCgroupV2PathOfController,
     .makeGroup = virCgroupV2MakeGroup,
+    .remove = virCgroupV2Remove,
 };
 
 
-- 
2.22.0