render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
Pablo Greco 40546a
From d72932998be48ff4eeb1b9d73d6f5d60560be031 Mon Sep 17 00:00:00 2001
Pablo Greco 40546a
Message-Id: <d72932998be48ff4eeb1b9d73d6f5d60560be031@dist-git>
Pablo Greco 40546a
From: Pavel Hrdina <phrdina@redhat.com>
Pablo Greco 40546a
Date: Mon, 1 Jul 2019 17:06:35 +0200
Pablo Greco 40546a
Subject: [PATCH] vircgroup: extract virCgroupV1MakeGroup
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 152c0f0bf52d4f727e09f388fef5c836c3c94db4)
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: <b90114ff10174e747131ddc3dfeb4fe177d4bf21.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        | 141 ++----------------------------------
Pablo Greco 40546a
 src/util/vircgroupbackend.h |  15 ++++
Pablo Greco 40546a
 src/util/vircgrouppriv.h    |  20 +++++
Pablo Greco 40546a
 src/util/vircgroupv1.c      | 132 +++++++++++++++++++++++++++++++++
Pablo Greco 40546a
 4 files changed, 174 insertions(+), 134 deletions(-)
Pablo Greco 40546a
Pablo Greco 40546a
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
Pablo Greco 40546a
index 438d9b4e70..8f0ea4de9a 100644
Pablo Greco 40546a
--- a/src/util/vircgroup.c
Pablo Greco 40546a
+++ b/src/util/vircgroup.c
Pablo Greco 40546a
@@ -80,14 +80,6 @@ VIR_ENUM_IMPL(virCgroupController, VIR_CGROUP_CONTROLLER_LAST,
Pablo Greco 40546a
               "freezer", "blkio", "net_cls", "perf_event",
Pablo Greco 40546a
               "name=systemd");
Pablo Greco 40546a
 
Pablo Greco 40546a
-typedef enum {
Pablo Greco 40546a
-    VIR_CGROUP_NONE = 0, /* create subdir under each cgroup if possible. */
Pablo Greco 40546a
-    VIR_CGROUP_MEM_HIERACHY = 1 << 0, /* call virCgroupSetMemoryUseHierarchy
Pablo Greco 40546a
-                                       * before creating subcgroups and
Pablo Greco 40546a
-                                       * attaching tasks
Pablo Greco 40546a
-                                       */
Pablo Greco 40546a
-} virCgroupFlags;
Pablo Greco 40546a
-
Pablo Greco 40546a
 
Pablo Greco 40546a
 /**
Pablo Greco 40546a
  * virCgroupGetDevicePermsString:
Pablo Greco 40546a
@@ -446,7 +438,7 @@ virCgroupGetBlockDevString(const char *path)
Pablo Greco 40546a
 }
Pablo Greco 40546a
 
Pablo Greco 40546a
 
Pablo Greco 40546a
-static int
Pablo Greco 40546a
+int
Pablo Greco 40546a
 virCgroupSetValueStr(virCgroupPtr group,
Pablo Greco 40546a
                      int controller,
Pablo Greco 40546a
                      const char *key,
Pablo Greco 40546a
@@ -476,7 +468,7 @@ virCgroupSetValueStr(virCgroupPtr group,
Pablo Greco 40546a
 }
Pablo Greco 40546a
 
Pablo Greco 40546a
 
Pablo Greco 40546a
-static int
Pablo Greco 40546a
+int
Pablo Greco 40546a
 virCgroupGetValueStr(virCgroupPtr group,
Pablo Greco 40546a
                      int controller,
Pablo Greco 40546a
                      const char *key,
Pablo Greco 40546a
@@ -537,7 +529,7 @@ virCgroupGetValueForBlkDev(virCgroupPtr group,
Pablo Greco 40546a
 }
Pablo Greco 40546a
 
Pablo Greco 40546a
 
Pablo Greco 40546a
-static int
Pablo Greco 40546a
+int
Pablo Greco 40546a
 virCgroupSetValueU64(virCgroupPtr group,
Pablo Greco 40546a
                      int controller,
Pablo Greco 40546a
                      const char *key,
Pablo Greco 40546a
@@ -589,7 +581,7 @@ virCgroupGetValueI64(virCgroupPtr group,
Pablo Greco 40546a
 }
Pablo Greco 40546a
 
Pablo Greco 40546a
 
Pablo Greco 40546a
-static int
Pablo Greco 40546a
+int
Pablo Greco 40546a
 virCgroupGetValueU64(virCgroupPtr group,
Pablo Greco 40546a
                      int controller,
Pablo Greco 40546a
                      const char *key,
Pablo Greco 40546a
@@ -611,137 +603,18 @@ virCgroupGetValueU64(virCgroupPtr group,
Pablo Greco 40546a
 }
Pablo Greco 40546a
 
Pablo Greco 40546a
 
Pablo Greco 40546a
-static int
Pablo Greco 40546a
-virCgroupCpuSetInherit(virCgroupPtr parent, virCgroupPtr group)
Pablo Greco 40546a
-{
Pablo Greco 40546a
-    size_t i;
Pablo Greco 40546a
-    const char *inherit_values[] = {
Pablo Greco 40546a
-        "cpuset.cpus",
Pablo Greco 40546a
-        "cpuset.mems",
Pablo Greco 40546a
-        "cpuset.memory_migrate",
Pablo Greco 40546a
-    };
Pablo Greco 40546a
-
Pablo Greco 40546a
-    VIR_DEBUG("Setting up inheritance %s -> %s", parent->path, group->path);
Pablo Greco 40546a
-    for (i = 0; i < ARRAY_CARDINALITY(inherit_values); i++) {
Pablo Greco 40546a
-        VIR_AUTOFREE(char *) value = NULL;
Pablo Greco 40546a
-
Pablo Greco 40546a
-        if (virCgroupGetValueStr(parent,
Pablo Greco 40546a
-                                 VIR_CGROUP_CONTROLLER_CPUSET,
Pablo Greco 40546a
-                                 inherit_values[i],
Pablo Greco 40546a
-                                 &value) < 0)
Pablo Greco 40546a
-            return -1;
Pablo Greco 40546a
-
Pablo Greco 40546a
-        VIR_DEBUG("Inherit %s = %s", inherit_values[i], value);
Pablo Greco 40546a
-
Pablo Greco 40546a
-        if (virCgroupSetValueStr(group,
Pablo Greco 40546a
-                                 VIR_CGROUP_CONTROLLER_CPUSET,
Pablo Greco 40546a
-                                 inherit_values[i],
Pablo Greco 40546a
-                                 value) < 0)
Pablo Greco 40546a
-            return -1;
Pablo Greco 40546a
-    }
Pablo Greco 40546a
-
Pablo Greco 40546a
-    return 0;
Pablo Greco 40546a
-}
Pablo Greco 40546a
-
Pablo Greco 40546a
-
Pablo Greco 40546a
-static int
Pablo Greco 40546a
-virCgroupSetMemoryUseHierarchy(virCgroupPtr group)
Pablo Greco 40546a
-{
Pablo Greco 40546a
-    unsigned long long value;
Pablo Greco 40546a
-    const char *filename = "memory.use_hierarchy";
Pablo Greco 40546a
-
Pablo Greco 40546a
-    if (virCgroupGetValueU64(group,
Pablo Greco 40546a
-                             VIR_CGROUP_CONTROLLER_MEMORY,
Pablo Greco 40546a
-                             filename, &value) < 0)
Pablo Greco 40546a
-        return -1;
Pablo Greco 40546a
-
Pablo Greco 40546a
-    /* Setting twice causes error, so if already enabled, skip setting */
Pablo Greco 40546a
-    if (value == 1)
Pablo Greco 40546a
-        return 0;
Pablo Greco 40546a
-
Pablo Greco 40546a
-    VIR_DEBUG("Setting up %s/%s", group->path, filename);
Pablo Greco 40546a
-    if (virCgroupSetValueU64(group,
Pablo Greco 40546a
-                             VIR_CGROUP_CONTROLLER_MEMORY,
Pablo Greco 40546a
-                             filename, 1) < 0)
Pablo Greco 40546a
-        return -1;
Pablo Greco 40546a
-
Pablo Greco 40546a
-    return 0;
Pablo Greco 40546a
-}
Pablo Greco 40546a
-
Pablo Greco 40546a
-
Pablo Greco 40546a
 static int
Pablo Greco 40546a
 virCgroupMakeGroup(virCgroupPtr parent,
Pablo Greco 40546a
                    virCgroupPtr group,
Pablo Greco 40546a
                    bool create,
Pablo Greco 40546a
                    unsigned int flags)
Pablo Greco 40546a
 {
Pablo Greco 40546a
-    size_t i;
Pablo Greco 40546a
-
Pablo Greco 40546a
-    VIR_DEBUG("Make group %s", group->path);
Pablo Greco 40546a
-    for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
Pablo Greco 40546a
-        VIR_AUTOFREE(char *) path = NULL;
Pablo Greco 40546a
-
Pablo Greco 40546a
-        /* We must never mkdir() in systemd's hierarchy */
Pablo Greco 40546a
-        if (i == VIR_CGROUP_CONTROLLER_SYSTEMD) {
Pablo Greco 40546a
-            VIR_DEBUG("Not creating systemd controller group");
Pablo Greco 40546a
-            continue;
Pablo Greco 40546a
-        }
Pablo Greco 40546a
-
Pablo Greco 40546a
-        /* Skip over controllers that aren't mounted */
Pablo Greco 40546a
-        if (!group->controllers[i].mountPoint) {
Pablo Greco 40546a
-            VIR_DEBUG("Skipping unmounted controller %s",
Pablo Greco 40546a
-                      virCgroupControllerTypeToString(i));
Pablo Greco 40546a
-            continue;
Pablo Greco 40546a
-        }
Pablo Greco 40546a
-
Pablo Greco 40546a
-        if (virCgroupPathOfController(group, i, "", &path) < 0)
Pablo Greco 40546a
-            goto error;
Pablo Greco 40546a
-
Pablo Greco 40546a
-        VIR_DEBUG("Make controller %s", path);
Pablo Greco 40546a
-        if (!virFileExists(path)) {
Pablo Greco 40546a
-            if (!create ||
Pablo Greco 40546a
-                mkdir(path, 0755) < 0) {
Pablo Greco 40546a
-                if (errno == EEXIST)
Pablo Greco 40546a
-                    continue;
Pablo Greco 40546a
-                /* With a kernel that doesn't support multi-level directory
Pablo Greco 40546a
-                 * for blkio controller, libvirt will fail and disable all
Pablo Greco 40546a
-                 * other controllers even though they are available. So
Pablo Greco 40546a
-                 * treat blkio as unmounted if mkdir fails. */
Pablo Greco 40546a
-                if (i == VIR_CGROUP_CONTROLLER_BLKIO) {
Pablo Greco 40546a
-                    VIR_DEBUG("Ignoring mkdir failure with blkio controller. Kernel probably too old");
Pablo Greco 40546a
-                    VIR_FREE(group->controllers[i].mountPoint);
Pablo Greco 40546a
-                    continue;
Pablo Greco 40546a
-                } else {
Pablo Greco 40546a
-                    virReportSystemError(errno,
Pablo Greco 40546a
-                                         _("Failed to create controller %s for group"),
Pablo Greco 40546a
-                                         virCgroupControllerTypeToString(i));
Pablo Greco 40546a
-                    goto error;
Pablo Greco 40546a
-                }
Pablo Greco 40546a
-            }
Pablo Greco 40546a
-            if (i == VIR_CGROUP_CONTROLLER_CPUSET &&
Pablo Greco 40546a
-                group->controllers[i].mountPoint != NULL &&
Pablo Greco 40546a
-                virCgroupCpuSetInherit(parent, group) < 0) {
Pablo Greco 40546a
-                goto error;
Pablo Greco 40546a
-            }
Pablo Greco 40546a
-            /*
Pablo Greco 40546a
-             * Note that virCgroupSetMemoryUseHierarchy should always be
Pablo Greco 40546a
-             * called prior to creating subcgroups and attaching tasks.
Pablo Greco 40546a
-             */
Pablo Greco 40546a
-            if ((flags & VIR_CGROUP_MEM_HIERACHY) &&
Pablo Greco 40546a
-                i == VIR_CGROUP_CONTROLLER_MEMORY &&
Pablo Greco 40546a
-                group->controllers[i].mountPoint != NULL &&
Pablo Greco 40546a
-                virCgroupSetMemoryUseHierarchy(group) < 0) {
Pablo Greco 40546a
-                goto error;
Pablo Greco 40546a
-            }
Pablo Greco 40546a
-        }
Pablo Greco 40546a
+    if (group->backend->makeGroup(parent, group, create, flags) < 0) {
Pablo Greco 40546a
+        virCgroupRemove(group);
Pablo Greco 40546a
+        return -1;
Pablo Greco 40546a
     }
Pablo Greco 40546a
 
Pablo Greco 40546a
-    VIR_DEBUG("Done making controllers for group");
Pablo Greco 40546a
     return 0;
Pablo Greco 40546a
-
Pablo Greco 40546a
- error:
Pablo Greco 40546a
-    virCgroupRemove(group);
Pablo Greco 40546a
-    return -1;
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 916227ba6a..b2848c2076 100644
Pablo Greco 40546a
--- a/src/util/vircgroupbackend.h
Pablo Greco 40546a
+++ b/src/util/vircgroupbackend.h
Pablo Greco 40546a
@@ -27,6 +27,14 @@
Pablo Greco 40546a
 
Pablo Greco 40546a
 # define CGROUP_MAX_VAL 512
Pablo Greco 40546a
 
Pablo Greco 40546a
+typedef enum {
Pablo Greco 40546a
+    VIR_CGROUP_NONE = 0, /* create subdir under each cgroup if possible. */
Pablo Greco 40546a
+    VIR_CGROUP_MEM_HIERACHY = 1 << 0, /* call virCgroupSetMemoryUseHierarchy
Pablo Greco 40546a
+                                       * before creating subcgroups and
Pablo Greco 40546a
+                                       * attaching tasks
Pablo Greco 40546a
+                                       */
Pablo Greco 40546a
+} virCgroupBackendFlags;
Pablo Greco 40546a
+
Pablo Greco 40546a
 typedef enum {
Pablo Greco 40546a
     VIR_CGROUP_BACKEND_TYPE_V1 = 0,
Pablo Greco 40546a
     VIR_CGROUP_BACKEND_TYPE_LAST,
Pablo Greco 40546a
@@ -86,6 +94,12 @@ typedef int
Pablo Greco 40546a
                                const char *key,
Pablo Greco 40546a
                                char **path);
Pablo Greco 40546a
 
Pablo Greco 40546a
+typedef int
Pablo Greco 40546a
+(*virCgroupMakeGroupCB)(virCgroupPtr parent,
Pablo Greco 40546a
+                        virCgroupPtr group,
Pablo Greco 40546a
+                        bool create,
Pablo Greco 40546a
+                        unsigned int flags);
Pablo Greco 40546a
+
Pablo Greco 40546a
 struct _virCgroupBackend {
Pablo Greco 40546a
     virCgroupBackendType type;
Pablo Greco 40546a
 
Pablo Greco 40546a
@@ -102,6 +116,7 @@ struct _virCgroupBackend {
Pablo Greco 40546a
     virCgroupHasControllerCB hasController;
Pablo Greco 40546a
     virCgroupGetAnyControllerCB getAnyController;
Pablo Greco 40546a
     virCgroupPathOfControllerCB pathOfController;
Pablo Greco 40546a
+    virCgroupMakeGroupCB makeGroup;
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 e7f4a1f0fc..2e731458d5 100644
Pablo Greco 40546a
--- a/src/util/vircgrouppriv.h
Pablo Greco 40546a
+++ b/src/util/vircgrouppriv.h
Pablo Greco 40546a
@@ -53,6 +53,26 @@ struct _virCgroup {
Pablo Greco 40546a
     virCgroupController controllers[VIR_CGROUP_CONTROLLER_LAST];
Pablo Greco 40546a
 };
Pablo Greco 40546a
 
Pablo Greco 40546a
+int virCgroupSetValueStr(virCgroupPtr group,
Pablo Greco 40546a
+                         int controller,
Pablo Greco 40546a
+                         const char *key,
Pablo Greco 40546a
+                         const char *value);
Pablo Greco 40546a
+
Pablo Greco 40546a
+int virCgroupGetValueStr(virCgroupPtr group,
Pablo Greco 40546a
+                         int controller,
Pablo Greco 40546a
+                         const char *key,
Pablo Greco 40546a
+                         char **value);
Pablo Greco 40546a
+
Pablo Greco 40546a
+int virCgroupSetValueU64(virCgroupPtr group,
Pablo Greco 40546a
+                         int controller,
Pablo Greco 40546a
+                         const char *key,
Pablo Greco 40546a
+                         unsigned long long int value);
Pablo Greco 40546a
+
Pablo Greco 40546a
+int virCgroupGetValueU64(virCgroupPtr group,
Pablo Greco 40546a
+                         int controller,
Pablo Greco 40546a
+                         const char *key,
Pablo Greco 40546a
+                         unsigned long long int *value);
Pablo Greco 40546a
+
Pablo Greco 40546a
 int virCgroupPartitionEscape(char **path);
Pablo Greco 40546a
 
Pablo Greco 40546a
 int virCgroupNewPartition(const char *path,
Pablo Greco 40546a
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
Pablo Greco 40546a
index a6302d71b1..653e848a83 100644
Pablo Greco 40546a
--- a/src/util/vircgroupv1.c
Pablo Greco 40546a
+++ b/src/util/vircgroupv1.c
Pablo Greco 40546a
@@ -537,6 +537,137 @@ virCgroupV1PathOfController(virCgroupPtr group,
Pablo Greco 40546a
 }
Pablo Greco 40546a
 
Pablo Greco 40546a
 
Pablo Greco 40546a
+static int
Pablo Greco 40546a
+virCgroupV1CpuSetInherit(virCgroupPtr parent,
Pablo Greco 40546a
+                         virCgroupPtr group)
Pablo Greco 40546a
+{
Pablo Greco 40546a
+    size_t i;
Pablo Greco 40546a
+    const char *inherit_values[] = {
Pablo Greco 40546a
+        "cpuset.cpus",
Pablo Greco 40546a
+        "cpuset.mems",
Pablo Greco 40546a
+        "cpuset.memory_migrate",
Pablo Greco 40546a
+    };
Pablo Greco 40546a
+
Pablo Greco 40546a
+    VIR_DEBUG("Setting up inheritance %s -> %s", parent->path, group->path);
Pablo Greco 40546a
+    for (i = 0; i < ARRAY_CARDINALITY(inherit_values); i++) {
Pablo Greco 40546a
+        VIR_AUTOFREE(char *) value = NULL;
Pablo Greco 40546a
+
Pablo Greco 40546a
+        if (virCgroupGetValueStr(parent,
Pablo Greco 40546a
+                                 VIR_CGROUP_CONTROLLER_CPUSET,
Pablo Greco 40546a
+                                 inherit_values[i],
Pablo Greco 40546a
+                                 &value) < 0)
Pablo Greco 40546a
+            return -1;
Pablo Greco 40546a
+
Pablo Greco 40546a
+        VIR_DEBUG("Inherit %s = %s", inherit_values[i], value);
Pablo Greco 40546a
+
Pablo Greco 40546a
+        if (virCgroupSetValueStr(group,
Pablo Greco 40546a
+                                 VIR_CGROUP_CONTROLLER_CPUSET,
Pablo Greco 40546a
+                                 inherit_values[i],
Pablo Greco 40546a
+                                 value) < 0)
Pablo Greco 40546a
+            return -1;
Pablo Greco 40546a
+    }
Pablo Greco 40546a
+
Pablo Greco 40546a
+    return 0;
Pablo Greco 40546a
+}
Pablo Greco 40546a
+
Pablo Greco 40546a
+
Pablo Greco 40546a
+static int
Pablo Greco 40546a
+virCgroupV1SetMemoryUseHierarchy(virCgroupPtr group)
Pablo Greco 40546a
+{
Pablo Greco 40546a
+    unsigned long long value;
Pablo Greco 40546a
+    const char *filename = "memory.use_hierarchy";
Pablo Greco 40546a
+
Pablo Greco 40546a
+    if (virCgroupGetValueU64(group,
Pablo Greco 40546a
+                             VIR_CGROUP_CONTROLLER_MEMORY,
Pablo Greco 40546a
+                             filename, &value) < 0)
Pablo Greco 40546a
+        return -1;
Pablo Greco 40546a
+
Pablo Greco 40546a
+    /* Setting twice causes error, so if already enabled, skip setting */
Pablo Greco 40546a
+    if (value == 1)
Pablo Greco 40546a
+        return 0;
Pablo Greco 40546a
+
Pablo Greco 40546a
+    VIR_DEBUG("Setting up %s/%s", group->path, filename);
Pablo Greco 40546a
+    if (virCgroupSetValueU64(group,
Pablo Greco 40546a
+                             VIR_CGROUP_CONTROLLER_MEMORY,
Pablo Greco 40546a
+                             filename, 1) < 0)
Pablo Greco 40546a
+        return -1;
Pablo Greco 40546a
+
Pablo Greco 40546a
+    return 0;
Pablo Greco 40546a
+}
Pablo Greco 40546a
+
Pablo Greco 40546a
+
Pablo Greco 40546a
+static int
Pablo Greco 40546a
+virCgroupV1MakeGroup(virCgroupPtr parent,
Pablo Greco 40546a
+                     virCgroupPtr group,
Pablo Greco 40546a
+                     bool create,
Pablo Greco 40546a
+                     unsigned int flags)
Pablo Greco 40546a
+{
Pablo Greco 40546a
+    size_t i;
Pablo Greco 40546a
+
Pablo Greco 40546a
+    VIR_DEBUG("Make group %s", group->path);
Pablo Greco 40546a
+    for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
Pablo Greco 40546a
+        VIR_AUTOFREE(char *) path = NULL;
Pablo Greco 40546a
+
Pablo Greco 40546a
+        /* We must never mkdir() in systemd's hierarchy */
Pablo Greco 40546a
+        if (i == VIR_CGROUP_CONTROLLER_SYSTEMD) {
Pablo Greco 40546a
+            VIR_DEBUG("Not creating systemd controller group");
Pablo Greco 40546a
+            continue;
Pablo Greco 40546a
+        }
Pablo Greco 40546a
+
Pablo Greco 40546a
+        /* Skip over controllers that aren't mounted */
Pablo Greco 40546a
+        if (!group->controllers[i].mountPoint) {
Pablo Greco 40546a
+            VIR_DEBUG("Skipping unmounted controller %s",
Pablo Greco 40546a
+                      virCgroupV1ControllerTypeToString(i));
Pablo Greco 40546a
+            continue;
Pablo Greco 40546a
+        }
Pablo Greco 40546a
+
Pablo Greco 40546a
+        if (virCgroupV1PathOfController(group, i, "", &path) < 0)
Pablo Greco 40546a
+            return -1;
Pablo Greco 40546a
+
Pablo Greco 40546a
+        VIR_DEBUG("Make controller %s", path);
Pablo Greco 40546a
+        if (!virFileExists(path)) {
Pablo Greco 40546a
+            if (!create ||
Pablo Greco 40546a
+                mkdir(path, 0755) < 0) {
Pablo Greco 40546a
+                if (errno == EEXIST)
Pablo Greco 40546a
+                    continue;
Pablo Greco 40546a
+                /* With a kernel that doesn't support multi-level directory
Pablo Greco 40546a
+                 * for blkio controller, libvirt will fail and disable all
Pablo Greco 40546a
+                 * other controllers even though they are available. So
Pablo Greco 40546a
+                 * treat blkio as unmounted if mkdir fails. */
Pablo Greco 40546a
+                if (i == VIR_CGROUP_CONTROLLER_BLKIO) {
Pablo Greco 40546a
+                    VIR_DEBUG("Ignoring mkdir failure with blkio controller. Kernel probably too old");
Pablo Greco 40546a
+                    VIR_FREE(group->controllers[i].mountPoint);
Pablo Greco 40546a
+                    continue;
Pablo Greco 40546a
+                } else {
Pablo Greco 40546a
+                    virReportSystemError(errno,
Pablo Greco 40546a
+                                         _("Failed to create v1 controller %s for group"),
Pablo Greco 40546a
+                                         virCgroupV1ControllerTypeToString(i));
Pablo Greco 40546a
+                    return -1;
Pablo Greco 40546a
+                }
Pablo Greco 40546a
+            }
Pablo Greco 40546a
+            if (i == VIR_CGROUP_CONTROLLER_CPUSET &&
Pablo Greco 40546a
+                group->controllers[i].mountPoint != NULL &&
Pablo Greco 40546a
+                virCgroupV1CpuSetInherit(parent, group) < 0) {
Pablo Greco 40546a
+                return -1;
Pablo Greco 40546a
+            }
Pablo Greco 40546a
+            /*
Pablo Greco 40546a
+             * Note that virCgroupV1SetMemoryUseHierarchy should always be
Pablo Greco 40546a
+             * called prior to creating subcgroups and attaching tasks.
Pablo Greco 40546a
+             */
Pablo Greco 40546a
+            if ((flags & VIR_CGROUP_MEM_HIERACHY) &&
Pablo Greco 40546a
+                i == VIR_CGROUP_CONTROLLER_MEMORY &&
Pablo Greco 40546a
+                group->controllers[i].mountPoint != NULL &&
Pablo Greco 40546a
+                virCgroupV1SetMemoryUseHierarchy(group) < 0) {
Pablo Greco 40546a
+                return -1;
Pablo Greco 40546a
+            }
Pablo Greco 40546a
+        }
Pablo Greco 40546a
+    }
Pablo Greco 40546a
+
Pablo Greco 40546a
+    VIR_DEBUG("Done making controllers for group");
Pablo Greco 40546a
+    return 0;
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
@@ -552,6 +683,7 @@ virCgroupBackend virCgroupV1Backend = {
Pablo Greco 40546a
     .hasController = virCgroupV1HasController,
Pablo Greco 40546a
     .getAnyController = virCgroupV1GetAnyController,
Pablo Greco 40546a
     .pathOfController = virCgroupV1PathOfController,
Pablo Greco 40546a
+    .makeGroup = virCgroupV1MakeGroup,
Pablo Greco 40546a
 };
Pablo Greco 40546a
 
Pablo Greco 40546a
 
Pablo Greco 40546a
-- 
Pablo Greco 40546a
2.22.0
Pablo Greco 40546a