render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
c313de
From 50c5a71ce4a4400d08deff481c8781f3fca755c8 Mon Sep 17 00:00:00 2001
c313de
Message-Id: <50c5a71ce4a4400d08deff481c8781f3fca755c8@dist-git>
c313de
From: Pavel Hrdina <phrdina@redhat.com>
c313de
Date: Mon, 1 Jul 2019 17:07:53 +0200
c313de
Subject: [PATCH] vircgroup: add support for hybrid configuration
c313de
MIME-Version: 1.0
c313de
Content-Type: text/plain; charset=UTF-8
c313de
Content-Transfer-Encoding: 8bit
c313de
c313de
This enables to use both cgroup v1 and v2 at the same time together
c313de
with libvirt.  It is supported by kernel and there is valid use-case,
c313de
not all controllers are implemented in cgroup v2 so there might be
c313de
configurations where administrator would enable these missing
c313de
controllers in cgroup v1.
c313de
c313de
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
c313de
(cherry picked from commit b79d858518ed15b1a4271457fc9f39463dd99230)
c313de
c313de
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297
c313de
c313de
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
c313de
Message-Id: <c84d8624633d438daa6b4de651eb6bb9e0afa25c.1561993100.git.phrdina@redhat.com>
c313de
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c313de
---
c313de
 src/util/vircgroup.c        | 351 ++++++++++++++++++++++++++----------
c313de
 src/util/vircgroupbackend.c |  20 ++
c313de
 src/util/vircgroupbackend.h |  16 +-
c313de
 src/util/vircgrouppriv.h    |   2 +-
c313de
 4 files changed, 291 insertions(+), 98 deletions(-)
c313de
c313de
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
c313de
index a859628241..069f1ae396 100644
c313de
--- a/src/util/vircgroup.c
c313de
+++ b/src/util/vircgroup.c
c313de
@@ -232,6 +232,7 @@ virCgroupDetectMounts(virCgroupPtr group)
c313de
     struct mntent entry;
c313de
     char buf[CGROUP_MAX_VAL];
c313de
     int ret = -1;
c313de
+    size_t i;
c313de
 
c313de
     mounts = fopen("/proc/mounts", "r");
c313de
     if (mounts == NULL) {
c313de
@@ -240,11 +241,14 @@ virCgroupDetectMounts(virCgroupPtr group)
c313de
     }
c313de
 
c313de
     while (getmntent_r(mounts, &entry, buf, sizeof(buf)) != NULL) {
c313de
-        if (group->backend->detectMounts(group,
c313de
-                                         entry.mnt_type,
c313de
-                                         entry.mnt_opts,
c313de
-                                         entry.mnt_dir) < 0) {
c313de
-            goto cleanup;
c313de
+        for (i = 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) {
c313de
+            if (group->backends[i] &&
c313de
+                group->backends[i]->detectMounts(group,
c313de
+                                                 entry.mnt_type,
c313de
+                                                 entry.mnt_opts,
c313de
+                                                 entry.mnt_dir) < 0) {
c313de
+                goto cleanup;
c313de
+            }
c313de
         }
c313de
     }
c313de
 
c313de
@@ -307,6 +311,7 @@ virCgroupDetectPlacement(virCgroupPtr group,
c313de
     }
c313de
 
c313de
     while (fgets(line, sizeof(line), mapping) != NULL) {
c313de
+        size_t i;
c313de
         char *controllers = strchr(line, ':');
c313de
         char *selfpath = controllers ? strchr(controllers + 1, ':') : NULL;
c313de
         char *nl = selfpath ? strchr(selfpath, '\n') : NULL;
c313de
@@ -321,9 +326,12 @@ virCgroupDetectPlacement(virCgroupPtr group,
c313de
         controllers++;
c313de
         selfpath++;
c313de
 
c313de
-        if (group->backend->detectPlacement(group, path, controllers,
c313de
-                                            selfpath) < 0) {
c313de
-            goto cleanup;
c313de
+        for (i = 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) {
c313de
+            if (group->backends[i] &&
c313de
+                group->backends[i]->detectPlacement(group, path, controllers,
c313de
+                                                    selfpath) < 0) {
c313de
+                goto cleanup;
c313de
+            }
c313de
         }
c313de
     }
c313de
 
c313de
@@ -342,8 +350,9 @@ virCgroupDetect(virCgroupPtr group,
c313de
                 const char *path,
c313de
                 virCgroupPtr parent)
c313de
 {
c313de
-    int rc;
c313de
     size_t i;
c313de
+    bool backendAvailable = false;
c313de
+    int controllersAvailable = 0;
c313de
     virCgroupBackendPtr *backends = virCgroupBackendGetAll();
c313de
 
c313de
     VIR_DEBUG("group=%p controllers=%d path=%s parent=%p",
c313de
@@ -354,31 +363,40 @@ virCgroupDetect(virCgroupPtr group,
c313de
 
c313de
     for (i = 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) {
c313de
         if (backends[i] && backends[i]->available()) {
c313de
-            group->backend = backends[i];
c313de
-            break;
c313de
+            group->backends[i] = backends[i];
c313de
+            backendAvailable = true;
c313de
         }
c313de
     }
c313de
 
c313de
-    if (!group->backend) {
c313de
+    if (!backendAvailable) {
c313de
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
c313de
                        _("no cgroup backend available"));
c313de
         return -1;
c313de
     }
c313de
 
c313de
     if (parent) {
c313de
-        if (group->backend->copyMounts(group, parent) < 0)
c313de
-            return -1;
c313de
+        for (i = 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) {
c313de
+            if (group->backends[i] &&
c313de
+                group->backends[i]->copyMounts(group, parent) < 0) {
c313de
+                return -1;
c313de
+            }
c313de
+        }
c313de
     } else {
c313de
         if (virCgroupDetectMounts(group) < 0)
c313de
             return -1;
c313de
     }
c313de
 
c313de
-    rc = group->backend->detectControllers(group, controllers);
c313de
-    if (rc < 0)
c313de
-        return -1;
c313de
+    for (i = 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) {
c313de
+        if (group->backends[i]) {
c313de
+            int rc = group->backends[i]->detectControllers(group, controllers);
c313de
+            if (rc < 0)
c313de
+                return -1;
c313de
+            controllersAvailable |= rc;
c313de
+        }
c313de
+    }
c313de
 
c313de
     /* Check that at least 1 controller is available */
c313de
-    if (rc == 0) {
c313de
+    if (controllersAvailable == 0) {
c313de
         virReportSystemError(ENXIO, "%s",
c313de
                              _("At least one cgroup controller is required"));
c313de
         return -1;
c313de
@@ -387,17 +405,26 @@ virCgroupDetect(virCgroupPtr group,
c313de
     /* In some cases we can copy part of the placement info
c313de
      * based on the parent cgroup...
c313de
      */
c313de
-    if ((parent || path[0] == '/') &&
c313de
-        group->backend->copyPlacement(group, path, parent) < 0)
c313de
-        return -1;
c313de
+    if (parent || path[0] == '/') {
c313de
+        for (i = 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) {
c313de
+            if (group->backends[i] &&
c313de
+                group->backends[i]->copyPlacement(group, path, parent) < 0) {
c313de
+                return -1;
c313de
+            }
c313de
+        }
c313de
+    }
c313de
 
c313de
     /* ... but use /proc/cgroups to fill in the rest */
c313de
     if (virCgroupDetectPlacement(group, pid, path) < 0)
c313de
         return -1;
c313de
 
c313de
     /* Check that for every mounted controller, we found our placement */
c313de
-    if (group->backend->validatePlacement(group, pid) < 0)
c313de
-        return -1;
c313de
+    for (i = 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) {
c313de
+        if (group->backends[i] &&
c313de
+            group->backends[i]->validatePlacement(group, pid) < 0) {
c313de
+            return -1;
c313de
+        }
c313de
+    }
c313de
 
c313de
     return 0;
c313de
 }
c313de
@@ -603,9 +630,14 @@ virCgroupMakeGroup(virCgroupPtr parent,
c313de
                    bool create,
c313de
                    unsigned int flags)
c313de
 {
c313de
-    if (group->backend->makeGroup(parent, group, create, flags) < 0) {
c313de
-        virCgroupRemove(group);
c313de
-        return -1;
c313de
+    size_t i;
c313de
+
c313de
+    for (i = 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) {
c313de
+        if (group->backends[i] &&
c313de
+            group->backends[i]->makeGroup(parent, group, create, flags) < 0) {
c313de
+            virCgroupRemove(group);
c313de
+            return -1;
c313de
+        }
c313de
     }
c313de
 
c313de
     return 0;
c313de
@@ -666,6 +698,24 @@ virCgroupNew(pid_t pid,
c313de
 }
c313de
 
c313de
 
c313de
+static int
c313de
+virCgroupAddTaskInternal(virCgroupPtr group,
c313de
+                         pid_t pid,
c313de
+                         unsigned int flags)
c313de
+{
c313de
+    size_t i;
c313de
+
c313de
+    for (i = 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) {
c313de
+        if (group->backends[i] &&
c313de
+            group->backends[i]->addTask(group, pid, flags) < 0) {
c313de
+            return -1;
c313de
+        }
c313de
+    }
c313de
+
c313de
+    return 0;
c313de
+}
c313de
+
c313de
+
c313de
 /**
c313de
  * virCgroupAddProcess:
c313de
  *
c313de
@@ -680,7 +730,7 @@ virCgroupNew(pid_t pid,
c313de
 int
c313de
 virCgroupAddProcess(virCgroupPtr group, pid_t pid)
c313de
 {
c313de
-    return group->backend->addTask(group, pid, VIR_CGROUP_TASK_PROCESS);
c313de
+    return virCgroupAddTaskInternal(group, pid, VIR_CGROUP_TASK_PROCESS);
c313de
 }
c313de
 
c313de
 /**
c313de
@@ -697,9 +747,9 @@ virCgroupAddProcess(virCgroupPtr group, pid_t pid)
c313de
 int
c313de
 virCgroupAddMachineProcess(virCgroupPtr group, pid_t pid)
c313de
 {
c313de
-    return group->backend->addTask(group, pid,
c313de
-                                   VIR_CGROUP_TASK_PROCESS |
c313de
-                                   VIR_CGROUP_TASK_SYSTEMD);
c313de
+    return virCgroupAddTaskInternal(group, pid,
c313de
+                                    VIR_CGROUP_TASK_PROCESS |
c313de
+                                    VIR_CGROUP_TASK_SYSTEMD);
c313de
 }
c313de
 
c313de
 /**
c313de
@@ -717,7 +767,7 @@ int
c313de
 virCgroupAddThread(virCgroupPtr group,
c313de
                    pid_t pid)
c313de
 {
c313de
-    return group->backend->addTask(group, pid, VIR_CGROUP_TASK_THREAD);
c313de
+    return virCgroupAddTaskInternal(group, pid, VIR_CGROUP_TASK_THREAD);
c313de
 }
c313de
 
c313de
 
c313de
@@ -971,17 +1021,24 @@ virCgroupNewDetectMachine(const char *name,
c313de
                           char *machinename,
c313de
                           virCgroupPtr *group)
c313de
 {
c313de
+    size_t i;
c313de
+
c313de
     if (virCgroupNewDetect(pid, controllers, group) < 0) {
c313de
         if (virCgroupNewIgnoreError())
c313de
             return 0;
c313de
         return -1;
c313de
     }
c313de
 
c313de
-    if (!(*group)->backend->validateMachineGroup(*group, name, drivername, machinename)) {
c313de
-        VIR_DEBUG("Failed to validate machine name for '%s' driver '%s'",
c313de
-                  name, drivername);
c313de
-        virCgroupFree(group);
c313de
-        return 0;
c313de
+    for (i = 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) {
c313de
+        if ((*group)->backends[i] &&
c313de
+            !(*group)->backends[i]->validateMachineGroup(*group, name,
c313de
+                                                         drivername,
c313de
+                                                         machinename)) {
c313de
+            VIR_DEBUG("Failed to validate machine name for '%s' driver '%s'",
c313de
+                      name, drivername);
c313de
+            virCgroupFree(group);
c313de
+            return 0;
c313de
+        }
c313de
     }
c313de
 
c313de
     return 0;
c313de
@@ -1059,6 +1116,7 @@ virCgroupNewMachineSystemd(const char *name,
c313de
     int rv;
c313de
     virCgroupPtr init;
c313de
     VIR_AUTOFREE(char *) path = NULL;
c313de
+    size_t i;
c313de
 
c313de
     VIR_DEBUG("Trying to setup machine '%s' via systemd", name);
c313de
     if ((rv = virSystemdCreateMachine(name,
c313de
@@ -1081,7 +1139,12 @@ virCgroupNewMachineSystemd(const char *name,
c313de
                            &init) < 0)
c313de
         return -1;
c313de
 
c313de
-    path = init->backend->stealPlacement(init);
c313de
+    for (i = 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) {
c313de
+        if (init->backends[i] &&
c313de
+            (path = init->backends[i]->stealPlacement(init))) {
c313de
+            break;
c313de
+        }
c313de
+    }
c313de
     virCgroupFree(&init);
c313de
 
c313de
     if (!path || STREQ(path, "/") || path[0] != '/') {
c313de
@@ -1260,12 +1323,21 @@ virCgroupFree(virCgroupPtr *group)
c313de
 bool
c313de
 virCgroupHasController(virCgroupPtr cgroup, int controller)
c313de
 {
c313de
+    size_t i;
c313de
+
c313de
     if (!cgroup)
c313de
         return false;
c313de
     if (controller < 0 || controller >= VIR_CGROUP_CONTROLLER_LAST)
c313de
         return false;
c313de
 
c313de
-    return cgroup->backend->hasController(cgroup, controller);
c313de
+    for (i = 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) {
c313de
+        if (cgroup->backends[i] &&
c313de
+            cgroup->backends[i]->hasController(cgroup, controller)) {
c313de
+            return true;
c313de
+        }
c313de
+    }
c313de
+
c313de
+    return false;
c313de
 }
c313de
 
c313de
 
c313de
@@ -1281,7 +1353,8 @@ virCgroupPathOfController(virCgroupPtr group,
c313de
         return -1;
c313de
     }
c313de
 
c313de
-    return group->backend->pathOfController(group, controller, key, path);
c313de
+    VIR_CGROUP_BACKEND_CALL(group, controller, pathOfController, -1,
c313de
+                            controller, key, path);
c313de
 }
c313de
 
c313de
 
c313de
@@ -1303,7 +1376,8 @@ virCgroupGetBlkioIoServiced(virCgroupPtr group,
c313de
                             long long *requests_read,
c313de
                             long long *requests_write)
c313de
 {
c313de
-    VIR_CGROUP_BACKEND_CALL(group, getBlkioIoServiced, -1,
c313de
+    VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_BLKIO,
c313de
+                            getBlkioIoServiced, -1,
c313de
                             bytes_read, bytes_write,
c313de
                             requests_read, requests_write);
c313de
 }
c313de
@@ -1329,7 +1403,8 @@ virCgroupGetBlkioIoDeviceServiced(virCgroupPtr group,
c313de
                                   long long *requests_read,
c313de
                                   long long *requests_write)
c313de
 {
c313de
-    VIR_CGROUP_BACKEND_CALL(group, getBlkioIoDeviceServiced, -1,
c313de
+    VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_BLKIO,
c313de
+                            getBlkioIoDeviceServiced, -1,
c313de
                             path, bytes_read, bytes_write,
c313de
                             requests_read, requests_write);
c313de
 }
c313de
@@ -1346,7 +1421,8 @@ virCgroupGetBlkioIoDeviceServiced(virCgroupPtr group,
c313de
 int
c313de
 virCgroupSetBlkioWeight(virCgroupPtr group, unsigned int weight)
c313de
 {
c313de
-    VIR_CGROUP_BACKEND_CALL(group, setBlkioWeight, -1, weight);
c313de
+    VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_BLKIO,
c313de
+                            setBlkioWeight, -1, weight);
c313de
 }
c313de
 
c313de
 
c313de
@@ -1361,7 +1437,8 @@ virCgroupSetBlkioWeight(virCgroupPtr group, unsigned int weight)
c313de
 int
c313de
 virCgroupGetBlkioWeight(virCgroupPtr group, unsigned int *weight)
c313de
 {
c313de
-    VIR_CGROUP_BACKEND_CALL(group, getBlkioWeight, -1, weight);
c313de
+    VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_BLKIO,
c313de
+                            getBlkioWeight, -1, weight);
c313de
 }
c313de
 
c313de
 /**
c313de
@@ -1377,7 +1454,8 @@ virCgroupSetBlkioDeviceReadIops(virCgroupPtr group,
c313de
                                 const char *path,
c313de
                                 unsigned int riops)
c313de
 {
c313de
-    VIR_CGROUP_BACKEND_CALL(group, setBlkioDeviceReadIops, -1, path, riops);
c313de
+    VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_BLKIO,
c313de
+                            setBlkioDeviceReadIops, -1, path, riops);
c313de
 }
c313de
 
c313de
 
c313de
@@ -1394,7 +1472,8 @@ virCgroupSetBlkioDeviceWriteIops(virCgroupPtr group,
c313de
                                  const char *path,
c313de
                                  unsigned int wiops)
c313de
 {
c313de
-    VIR_CGROUP_BACKEND_CALL(group, setBlkioDeviceWriteIops, -1, path, wiops);
c313de
+    VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_BLKIO,
c313de
+                            setBlkioDeviceWriteIops, -1, path, wiops);
c313de
 }
c313de
 
c313de
 
c313de
@@ -1411,7 +1490,8 @@ virCgroupSetBlkioDeviceReadBps(virCgroupPtr group,
c313de
                                const char *path,
c313de
                                unsigned long long rbps)
c313de
 {
c313de
-    VIR_CGROUP_BACKEND_CALL(group, setBlkioDeviceReadBps, -1, path, rbps);
c313de
+    VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_BLKIO,
c313de
+                            setBlkioDeviceReadBps, -1, path, rbps);
c313de
 }
c313de
 
c313de
 /**
c313de
@@ -1427,7 +1507,8 @@ virCgroupSetBlkioDeviceWriteBps(virCgroupPtr group,
c313de
                                 const char *path,
c313de
                                 unsigned long long wbps)
c313de
 {
c313de
-    VIR_CGROUP_BACKEND_CALL(group, setBlkioDeviceWriteBps, -1, path, wbps);
c313de
+    VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_BLKIO,
c313de
+                            setBlkioDeviceWriteBps, -1, path, wbps);
c313de
 }
c313de
 
c313de
 
c313de
@@ -1445,7 +1526,8 @@ virCgroupSetBlkioDeviceWeight(virCgroupPtr group,
c313de
                               const char *path,
c313de
                               unsigned int weight)
c313de
 {
c313de
-    VIR_CGROUP_BACKEND_CALL(group, setBlkioDeviceWeight, -1, path, weight);
c313de
+    VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_BLKIO,
c313de
+                            setBlkioDeviceWeight, -1, path, weight);
c313de
 }
c313de
 
c313de
 /**
c313de
@@ -1461,7 +1543,8 @@ virCgroupGetBlkioDeviceReadIops(virCgroupPtr group,
c313de
                                 const char *path,
c313de
                                 unsigned int *riops)
c313de
 {
c313de
-    VIR_CGROUP_BACKEND_CALL(group, getBlkioDeviceReadIops, -1, path, riops);
c313de
+    VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_BLKIO,
c313de
+                            getBlkioDeviceReadIops, -1, path, riops);
c313de
 }
c313de
 
c313de
 /**
c313de
@@ -1477,7 +1560,8 @@ virCgroupGetBlkioDeviceWriteIops(virCgroupPtr group,
c313de
                                  const char *path,
c313de
                                  unsigned int *wiops)
c313de
 {
c313de
-    VIR_CGROUP_BACKEND_CALL(group, getBlkioDeviceWriteIops, -1, path, wiops);
c313de
+    VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_BLKIO,
c313de
+                            getBlkioDeviceWriteIops, -1, path, wiops);
c313de
 }
c313de
 
c313de
 /**
c313de
@@ -1493,7 +1577,8 @@ virCgroupGetBlkioDeviceReadBps(virCgroupPtr group,
c313de
                                const char *path,
c313de
                                unsigned long long *rbps)
c313de
 {
c313de
-    VIR_CGROUP_BACKEND_CALL(group, getBlkioDeviceReadBps, -1, path, rbps);
c313de
+    VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_BLKIO,
c313de
+                            getBlkioDeviceReadBps, -1, path, rbps);
c313de
 }
c313de
 
c313de
 /**
c313de
@@ -1509,7 +1594,8 @@ virCgroupGetBlkioDeviceWriteBps(virCgroupPtr group,
c313de
                                 const char *path,
c313de
                                 unsigned long long *wbps)
c313de
 {
c313de
-    VIR_CGROUP_BACKEND_CALL(group, getBlkioDeviceWriteBps, -1, path, wbps);
c313de
+    VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_BLKIO,
c313de
+                            getBlkioDeviceWriteBps, -1, path, wbps);
c313de
 }
c313de
 
c313de
 /**
c313de
@@ -1525,7 +1611,8 @@ virCgroupGetBlkioDeviceWeight(virCgroupPtr group,
c313de
                               const char *path,
c313de
                               unsigned int *weight)
c313de
 {
c313de
-    VIR_CGROUP_BACKEND_CALL(group, getBlkioDeviceWeight, -1, path, weight);
c313de
+    VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_BLKIO,
c313de
+                            getBlkioDeviceWeight, -1, path, weight);
c313de
 }
c313de
 
c313de
 
c313de
@@ -1540,7 +1627,8 @@ virCgroupGetBlkioDeviceWeight(virCgroupPtr group,
c313de
 int
c313de
 virCgroupSetMemory(virCgroupPtr group, unsigned long long kb)
c313de
 {
c313de
-    VIR_CGROUP_BACKEND_CALL(group, setMemory, -1, kb);
c313de
+    VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_MEMORY,
c313de
+                            setMemory, -1, kb);
c313de
 }
c313de
 
c313de
 
c313de
@@ -1566,7 +1654,8 @@ virCgroupGetMemoryStat(virCgroupPtr group,
c313de
                        unsigned long long *inactiveFile,
c313de
                        unsigned long long *unevictable)
c313de
 {
c313de
-    VIR_CGROUP_BACKEND_CALL(group, getMemoryStat, -1, cache,
c313de
+    VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_MEMORY,
c313de
+                            getMemoryStat, -1, cache,
c313de
                             activeAnon, inactiveAnon,
c313de
                             activeFile, inactiveFile,
c313de
                             unevictable);
c313de
@@ -1584,7 +1673,8 @@ virCgroupGetMemoryStat(virCgroupPtr group,
c313de
 int
c313de
 virCgroupGetMemoryUsage(virCgroupPtr group, unsigned long *kb)
c313de
 {
c313de
-    VIR_CGROUP_BACKEND_CALL(group, getMemoryUsage, -1, kb);
c313de
+    VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_MEMORY,
c313de
+                            getMemoryUsage, -1, kb);
c313de
 }
c313de
 
c313de
 
c313de
@@ -1599,7 +1689,8 @@ virCgroupGetMemoryUsage(virCgroupPtr group, unsigned long *kb)
c313de
 int
c313de
 virCgroupSetMemoryHardLimit(virCgroupPtr group, unsigned long long kb)
c313de
 {
c313de
-    VIR_CGROUP_BACKEND_CALL(group, setMemoryHardLimit, -1, kb);
c313de
+    VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_MEMORY,
c313de
+                            setMemoryHardLimit, -1, kb);
c313de
 }
c313de
 
c313de
 
c313de
@@ -1614,7 +1705,8 @@ virCgroupSetMemoryHardLimit(virCgroupPtr group, unsigned long long kb)
c313de
 int
c313de
 virCgroupGetMemoryHardLimit(virCgroupPtr group, unsigned long long *kb)
c313de
 {
c313de
-    VIR_CGROUP_BACKEND_CALL(group, getMemoryHardLimit, -1, kb);
c313de
+    VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_MEMORY,
c313de
+                            getMemoryHardLimit, -1, kb);
c313de
 }
c313de
 
c313de
 
c313de
@@ -1629,7 +1721,8 @@ virCgroupGetMemoryHardLimit(virCgroupPtr group, unsigned long long *kb)
c313de
 int
c313de
 virCgroupSetMemorySoftLimit(virCgroupPtr group, unsigned long long kb)
c313de
 {
c313de
-    VIR_CGROUP_BACKEND_CALL(group, setMemorySoftLimit, -1, kb);
c313de
+    VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_MEMORY,
c313de
+                            setMemorySoftLimit, -1, kb);
c313de
 }
c313de
 
c313de
 
c313de
@@ -1644,7 +1737,8 @@ virCgroupSetMemorySoftLimit(virCgroupPtr group, unsigned long long kb)
c313de
 int
c313de
 virCgroupGetMemorySoftLimit(virCgroupPtr group, unsigned long long *kb)
c313de
 {
c313de
-    VIR_CGROUP_BACKEND_CALL(group, getMemorySoftLimit, -1, kb);
c313de
+    VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_MEMORY,
c313de
+                            getMemorySoftLimit, -1, kb);
c313de
 }
c313de
 
c313de
 
c313de
@@ -1659,7 +1753,8 @@ virCgroupGetMemorySoftLimit(virCgroupPtr group, unsigned long long *kb)
c313de
 int
c313de
 virCgroupSetMemSwapHardLimit(virCgroupPtr group, unsigned long long kb)
c313de
 {
c313de
-    VIR_CGROUP_BACKEND_CALL(group, setMemSwapHardLimit, -1, kb);
c313de
+    VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_MEMORY,
c313de
+                            setMemSwapHardLimit, -1, kb);
c313de
 }
c313de
 
c313de
 
c313de
@@ -1674,7 +1769,8 @@ virCgroupSetMemSwapHardLimit(virCgroupPtr group, unsigned long long kb)
c313de
 int
c313de
 virCgroupGetMemSwapHardLimit(virCgroupPtr group, unsigned long long *kb)
c313de
 {
c313de
-    VIR_CGROUP_BACKEND_CALL(group, getMemSwapHardLimit, -1, kb);
c313de
+    VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_MEMORY,
c313de
+                            getMemSwapHardLimit, -1, kb);
c313de
 }
c313de
 
c313de
 
c313de
@@ -1689,7 +1785,8 @@ virCgroupGetMemSwapHardLimit(virCgroupPtr group, unsigned long long *kb)
c313de
 int
c313de
 virCgroupGetMemSwapUsage(virCgroupPtr group, unsigned long long *kb)
c313de
 {
c313de
-    VIR_CGROUP_BACKEND_CALL(group, getMemSwapUsage, -1, kb);
c313de
+    VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_MEMORY,
c313de
+                            getMemSwapUsage, -1, kb);
c313de
 }
c313de
 
c313de
 
c313de
@@ -1704,7 +1801,8 @@ virCgroupGetMemSwapUsage(virCgroupPtr group, unsigned long long *kb)
c313de
 int
c313de
 virCgroupSetCpusetMems(virCgroupPtr group, const char *mems)
c313de
 {
c313de
-    VIR_CGROUP_BACKEND_CALL(group, setCpusetMems, -1, mems);
c313de
+    VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_CPUSET,
c313de
+                            setCpusetMems, -1, mems);
c313de
 }
c313de
 
c313de
 
c313de
@@ -1719,7 +1817,8 @@ virCgroupSetCpusetMems(virCgroupPtr group, const char *mems)
c313de
 int
c313de
 virCgroupGetCpusetMems(virCgroupPtr group, char **mems)
c313de
 {
c313de
-    VIR_CGROUP_BACKEND_CALL(group, getCpusetMems, -1, mems);
c313de
+    VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_CPUSET,
c313de
+                            getCpusetMems, -1, mems);
c313de
 }
c313de
 
c313de
 
c313de
@@ -1734,7 +1833,8 @@ virCgroupGetCpusetMems(virCgroupPtr group, char **mems)
c313de
 int
c313de
 virCgroupSetCpusetMemoryMigrate(virCgroupPtr group, bool migrate)
c313de
 {
c313de
-    VIR_CGROUP_BACKEND_CALL(group, setCpusetMemoryMigrate, -1, migrate);
c313de
+    VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_CPUSET,
c313de
+                            setCpusetMemoryMigrate, -1, migrate);
c313de
 }
c313de
 
c313de
 
c313de
@@ -1749,7 +1849,8 @@ virCgroupSetCpusetMemoryMigrate(virCgroupPtr group, bool migrate)
c313de
 int
c313de
 virCgroupGetCpusetMemoryMigrate(virCgroupPtr group, bool *migrate)
c313de
 {
c313de
-    VIR_CGROUP_BACKEND_CALL(group, getCpusetMemoryMigrate, -1, migrate);
c313de
+    VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_CPUSET,
c313de
+                            getCpusetMemoryMigrate, -1, migrate);
c313de
 }
c313de
 
c313de
 
c313de
@@ -1764,7 +1865,8 @@ virCgroupGetCpusetMemoryMigrate(virCgroupPtr group, bool *migrate)
c313de
 int
c313de
 virCgroupSetCpusetCpus(virCgroupPtr group, const char *cpus)
c313de
 {
c313de
-    VIR_CGROUP_BACKEND_CALL(group, setCpusetCpus, -1, cpus);
c313de
+    VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_CPUSET,
c313de
+                            setCpusetCpus, -1, cpus);
c313de
 }
c313de
 
c313de
 
c313de
@@ -1779,7 +1881,8 @@ virCgroupSetCpusetCpus(virCgroupPtr group, const char *cpus)
c313de
 int
c313de
 virCgroupGetCpusetCpus(virCgroupPtr group, char **cpus)
c313de
 {
c313de
-    VIR_CGROUP_BACKEND_CALL(group, getCpusetCpus, -1, cpus);
c313de
+    VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_CPUSET,
c313de
+                            getCpusetCpus, -1, cpus);
c313de
 }
c313de
 
c313de
 
c313de
@@ -1793,7 +1896,8 @@ virCgroupGetCpusetCpus(virCgroupPtr group, char **cpus)
c313de
 int
c313de
 virCgroupDenyAllDevices(virCgroupPtr group)
c313de
 {
c313de
-    VIR_CGROUP_BACKEND_CALL(group, denyAllDevices, -1);
c313de
+    VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_DEVICES,
c313de
+                            denyAllDevices, -1);
c313de
 }
c313de
 
c313de
 /**
c313de
@@ -1813,7 +1917,8 @@ virCgroupDenyAllDevices(virCgroupPtr group)
c313de
 int
c313de
 virCgroupAllowAllDevices(virCgroupPtr group, int perms)
c313de
 {
c313de
-    VIR_CGROUP_BACKEND_CALL(group, allowAllDevices, -1, perms);
c313de
+    VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_DEVICES,
c313de
+                            allowAllDevices, -1, perms);
c313de
 }
c313de
 
c313de
 
c313de
@@ -1832,7 +1937,8 @@ int
c313de
 virCgroupAllowDevice(virCgroupPtr group, char type, int major, int minor,
c313de
                      int perms)
c313de
 {
c313de
-    VIR_CGROUP_BACKEND_CALL(group, allowDevice, -1, type, major, minor, perms);
c313de
+    VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_DEVICES,
c313de
+                            allowDevice, -1, type, major, minor, perms);
c313de
 }
c313de
 
c313de
 
c313de
@@ -1871,7 +1977,8 @@ virCgroupAllowDevicePath(virCgroupPtr group,
c313de
     if (!S_ISCHR(sb.st_mode) && !S_ISBLK(sb.st_mode))
c313de
         return 1;
c313de
 
c313de
-    VIR_CGROUP_BACKEND_CALL(group, allowDevice, -1,
c313de
+    VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_DEVICES,
c313de
+                            allowDevice, -1,
c313de
                             S_ISCHR(sb.st_mode) ? 'c' : 'b',
c313de
                             major(sb.st_rdev),
c313de
                             minor(sb.st_rdev),
c313de
@@ -1894,7 +2001,8 @@ int
c313de
 virCgroupDenyDevice(virCgroupPtr group, char type, int major, int minor,
c313de
                     int perms)
c313de
 {
c313de
-    VIR_CGROUP_BACKEND_CALL(group, denyDevice, -1, type, major, minor, perms);
c313de
+    VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_DEVICES,
c313de
+                            denyDevice, -1, type, major, minor, perms);
c313de
 }
c313de
 
c313de
 
c313de
@@ -1933,7 +2041,8 @@ virCgroupDenyDevicePath(virCgroupPtr group,
c313de
     if (!S_ISCHR(sb.st_mode) && !S_ISBLK(sb.st_mode))
c313de
         return 1;
c313de
 
c313de
-    VIR_CGROUP_BACKEND_CALL(group, denyDevice, -1,
c313de
+    VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_DEVICES,
c313de
+                            denyDevice, -1,
c313de
                             S_ISCHR(sb.st_mode) ? 'c' : 'b',
c313de
                             major(sb.st_rdev),
c313de
                             minor(sb.st_rdev),
c313de
@@ -2176,14 +2285,16 @@ virCgroupGetDomainTotalCpuStats(virCgroupPtr group,
c313de
 int
c313de
 virCgroupSetCpuShares(virCgroupPtr group, unsigned long long shares)
c313de
 {
c313de
-    VIR_CGROUP_BACKEND_CALL(group, setCpuShares, -1, shares);
c313de
+    VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_CPU,
c313de
+                            setCpuShares, -1, shares);
c313de
 }
c313de
 
c313de
 
c313de
 int
c313de
 virCgroupGetCpuShares(virCgroupPtr group, unsigned long long *shares)
c313de
 {
c313de
-    VIR_CGROUP_BACKEND_CALL(group, getCpuShares, -1, shares);
c313de
+    VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_CPU,
c313de
+                            getCpuShares, -1, shares);
c313de
 }
c313de
 
c313de
 
c313de
@@ -2198,7 +2309,8 @@ virCgroupGetCpuShares(virCgroupPtr group, unsigned long long *shares)
c313de
 int
c313de
 virCgroupSetCpuCfsPeriod(virCgroupPtr group, unsigned long long cfs_period)
c313de
 {
c313de
-    VIR_CGROUP_BACKEND_CALL(group, setCpuCfsPeriod, -1, cfs_period);
c313de
+    VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_CPU,
c313de
+                            setCpuCfsPeriod, -1, cfs_period);
c313de
 }
c313de
 
c313de
 
c313de
@@ -2213,7 +2325,8 @@ virCgroupSetCpuCfsPeriod(virCgroupPtr group, unsigned long long cfs_period)
c313de
 int
c313de
 virCgroupGetCpuCfsPeriod(virCgroupPtr group, unsigned long long *cfs_period)
c313de
 {
c313de
-    VIR_CGROUP_BACKEND_CALL(group, getCpuCfsPeriod, -1, cfs_period);
c313de
+    VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_CPU,
c313de
+                            getCpuCfsPeriod, -1, cfs_period);
c313de
 }
c313de
 
c313de
 
c313de
@@ -2229,14 +2342,16 @@ virCgroupGetCpuCfsPeriod(virCgroupPtr group, unsigned long long *cfs_period)
c313de
 int
c313de
 virCgroupSetCpuCfsQuota(virCgroupPtr group, long long cfs_quota)
c313de
 {
c313de
-    VIR_CGROUP_BACKEND_CALL(group, setCpuCfsQuota, -1, cfs_quota);
c313de
+    VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_CPU,
c313de
+                            setCpuCfsQuota, -1, cfs_quota);
c313de
 }
c313de
 
c313de
 
c313de
 int
c313de
 virCgroupGetCpuacctPercpuUsage(virCgroupPtr group, char **usage)
c313de
 {
c313de
-    VIR_CGROUP_BACKEND_CALL(group, getCpuacctPercpuUsage, -1, usage);
c313de
+    VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_CPUACCT,
c313de
+                            getCpuacctPercpuUsage, -1, usage);
c313de
 }
c313de
 
c313de
 
c313de
@@ -2303,7 +2418,16 @@ virCgroupRemoveRecursively(char *grppath)
c313de
 int
c313de
 virCgroupRemove(virCgroupPtr group)
c313de
 {
c313de
-    return group->backend->remove(group);
c313de
+    size_t i;
c313de
+
c313de
+    for (i = 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) {
c313de
+        if (group->backends[i] &&
c313de
+            group->backends[i]->remove(group) < 0) {
c313de
+            return -1;
c313de
+        }
c313de
+    }
c313de
+
c313de
+    return 0;
c313de
 }
c313de
 
c313de
 
c313de
@@ -2312,11 +2436,16 @@ virCgroupPathOfAnyController(virCgroupPtr group,
c313de
                              const char *name,
c313de
                              char **keypath)
c313de
 {
c313de
+    size_t i;
c313de
     int controller;
c313de
 
c313de
-    controller = group->backend->getAnyController(group);
c313de
-    if (controller >= 0)
c313de
-        return virCgroupPathOfController(group, controller, name, keypath);
c313de
+    for (i = 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) {
c313de
+        if (group->backends[i]) {
c313de
+            controller = group->backends[i]->getAnyController(group);
c313de
+            if (controller >= 0)
c313de
+                return virCgroupPathOfController(group, controller, name, keypath);
c313de
+        }
c313de
+    }
c313de
 
c313de
     virReportSystemError(ENOSYS, "%s",
c313de
                          _("No controllers are mounted"));
c313de
@@ -2552,14 +2681,16 @@ virCgroupKillPainfully(virCgroupPtr group)
c313de
 int
c313de
 virCgroupGetCpuCfsQuota(virCgroupPtr group, long long *cfs_quota)
c313de
 {
c313de
-    VIR_CGROUP_BACKEND_CALL(group, getCpuCfsQuota, -1, cfs_quota);
c313de
+    VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_CPU,
c313de
+                            getCpuCfsQuota, -1, cfs_quota);
c313de
 }
c313de
 
c313de
 
c313de
 int
c313de
 virCgroupGetCpuacctUsage(virCgroupPtr group, unsigned long long *usage)
c313de
 {
c313de
-    VIR_CGROUP_BACKEND_CALL(group, getCpuacctUsage, -1, usage);
c313de
+    VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_CPUACCT,
c313de
+                            getCpuacctUsage, -1, usage);
c313de
 }
c313de
 
c313de
 
c313de
@@ -2567,21 +2698,24 @@ int
c313de
 virCgroupGetCpuacctStat(virCgroupPtr group, unsigned long long *user,
c313de
                         unsigned long long *sys)
c313de
 {
c313de
-    VIR_CGROUP_BACKEND_CALL(group, getCpuacctStat, -1, user, sys);
c313de
+    VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_CPUACCT,
c313de
+                            getCpuacctStat, -1, user, sys);
c313de
 }
c313de
 
c313de
 
c313de
 int
c313de
 virCgroupSetFreezerState(virCgroupPtr group, const char *state)
c313de
 {
c313de
-    VIR_CGROUP_BACKEND_CALL(group, setFreezerState, -1, state);
c313de
+    VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_FREEZER,
c313de
+                            setFreezerState, -1, state);
c313de
 }
c313de
 
c313de
 
c313de
 int
c313de
 virCgroupGetFreezerState(virCgroupPtr group, char **state)
c313de
 {
c313de
-    VIR_CGROUP_BACKEND_CALL(group, getFreezerState, -1, state);
c313de
+    VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_FREEZER,
c313de
+                            getFreezerState, -1, state);
c313de
 }
c313de
 
c313de
 
c313de
@@ -2589,7 +2723,16 @@ int
c313de
 virCgroupBindMount(virCgroupPtr group, const char *oldroot,
c313de
                    const char *mountopts)
c313de
 {
c313de
-    return group->backend->bindMount(group, oldroot, mountopts);
c313de
+    size_t i;
c313de
+
c313de
+    for (i = 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) {
c313de
+        if (group->backends[i] &&
c313de
+            group->backends[i]->bindMount(group, oldroot, mountopts) < 0) {
c313de
+            return -1;
c313de
+        }
c313de
+    }
c313de
+
c313de
+    return 0;
c313de
 }
c313de
 
c313de
 
c313de
@@ -2598,7 +2741,16 @@ int virCgroupSetOwner(virCgroupPtr cgroup,
c313de
                       gid_t gid,
c313de
                       int controllers)
c313de
 {
c313de
-    return cgroup->backend->setOwner(cgroup, uid, gid, controllers);
c313de
+    size_t i;
c313de
+
c313de
+    for (i = 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) {
c313de
+        if (cgroup->backends[i] &&
c313de
+            cgroup->backends[i]->setOwner(cgroup, uid, gid, controllers) < 0) {
c313de
+            return -1;
c313de
+        }
c313de
+    }
c313de
+
c313de
+    return 0;
c313de
 }
c313de
 
c313de
 
c313de
@@ -2612,13 +2764,24 @@ int virCgroupSetOwner(virCgroupPtr cgroup,
c313de
 bool
c313de
 virCgroupSupportsCpuBW(virCgroupPtr cgroup)
c313de
 {
c313de
-    VIR_CGROUP_BACKEND_CALL(cgroup, supportsCpuBW, false);
c313de
+    VIR_CGROUP_BACKEND_CALL(cgroup, VIR_CGROUP_CONTROLLER_CPU,
c313de
+                            supportsCpuBW, false);
c313de
 }
c313de
 
c313de
 int
c313de
 virCgroupHasEmptyTasks(virCgroupPtr cgroup, int controller)
c313de
 {
c313de
-    return cgroup->backend->hasEmptyTasks(cgroup, controller);
c313de
+    size_t i;
c313de
+
c313de
+    for (i = 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) {
c313de
+        if (cgroup->backends[i]) {
c313de
+            int rc = cgroup->backends[i]->hasEmptyTasks(cgroup, controller);
c313de
+            if (rc <= 0)
c313de
+                return rc;
c313de
+        }
c313de
+    }
c313de
+
c313de
+    return 1;
c313de
 }
c313de
 
c313de
 bool
c313de
diff --git a/src/util/vircgroupbackend.c b/src/util/vircgroupbackend.c
c313de
index 7ee39ac8ca..2e90781dc3 100644
c313de
--- a/src/util/vircgroupbackend.c
c313de
+++ b/src/util/vircgroupbackend.c
c313de
@@ -20,6 +20,9 @@
c313de
 #include <config.h>
c313de
 
c313de
 #include "vircgroupbackend.h"
c313de
+#define __VIR_CGROUP_ALLOW_INCLUDE_PRIV_H__
c313de
+#include "vircgrouppriv.h"
c313de
+#undef __VIR_CGROUP_ALLOW_INCLUDE_PRIV_H__
c313de
 #include "vircgroupv1.h"
c313de
 #include "vircgroupv2.h"
c313de
 #include "virerror.h"
c313de
@@ -67,3 +70,20 @@ virCgroupBackendGetAll(void)
c313de
     }
c313de
     return virCgroupBackends;
c313de
 }
c313de
+
c313de
+
c313de
+virCgroupBackendPtr
c313de
+virCgroupBackendForController(virCgroupPtr group,
c313de
+                              unsigned int controller)
c313de
+{
c313de
+    size_t i;
c313de
+
c313de
+    for (i = 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) {
c313de
+        if (group->backends[i] &&
c313de
+            group->backends[i]->hasController(group, controller)) {
c313de
+            return group->backends[i];
c313de
+        }
c313de
+    }
c313de
+
c313de
+    return NULL;
c313de
+}
c313de
diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h
c313de
index 86d1539e07..bc60b44643 100644
c313de
--- a/src/util/vircgroupbackend.h
c313de
+++ b/src/util/vircgroupbackend.h
c313de
@@ -436,12 +436,22 @@ virCgroupBackendRegister(virCgroupBackendPtr backend);
c313de
 virCgroupBackendPtr *
c313de
 virCgroupBackendGetAll(void);
c313de
 
c313de
-# define VIR_CGROUP_BACKEND_CALL(group, func, ret, ...) \
c313de
-    if (!group->backend->func) { \
c313de
+virCgroupBackendPtr
c313de
+virCgroupBackendForController(virCgroupPtr group,
c313de
+                              unsigned int controller);
c313de
+
c313de
+# define VIR_CGROUP_BACKEND_CALL(group, controller, func, ret, ...) \
c313de
+    virCgroupBackendPtr backend = virCgroupBackendForController(group, controller); \
c313de
+    if (!backend) { \
c313de
+        virReportError(VIR_ERR_INTERNAL_ERROR, \
c313de
+                       _("failed to get cgroup backend for '%s'"), #func); \
c313de
+        return ret; \
c313de
+    } \
c313de
+    if (!backend->func) { \
c313de
         virReportError(VIR_ERR_OPERATION_UNSUPPORTED, \
c313de
                        _("operation '%s' not supported"), #func); \
c313de
         return ret; \
c313de
     } \
c313de
-    return group->backend->func(group, ##__VA_ARGS__);
c313de
+    return backend->func(group, ##__VA_ARGS__);
c313de
 
c313de
 #endif /* __VIR_CGROUP_BACKEND_H__ */
c313de
diff --git a/src/util/vircgrouppriv.h b/src/util/vircgrouppriv.h
c313de
index 4a0d75ddbc..8f24b0891e 100644
c313de
--- a/src/util/vircgrouppriv.h
c313de
+++ b/src/util/vircgrouppriv.h
c313de
@@ -56,7 +56,7 @@ typedef virCgroupV2Controller *virCgroupV2ControllerPtr;
c313de
 struct _virCgroup {
c313de
     char *path;
c313de
 
c313de
-    virCgroupBackendPtr backend;
c313de
+    virCgroupBackendPtr backends[VIR_CGROUP_BACKEND_TYPE_LAST];
c313de
 
c313de
     virCgroupV1Controller legacy[VIR_CGROUP_CONTROLLER_LAST];
c313de
     virCgroupV2Controller unified;
c313de
-- 
c313de
2.22.0
c313de