From: "Daniel P. Berrange" <berrange(a)redhat.com>
Add virCgroupIsValidMachine API to check whether a auto
detected cgroup is valid for a machine. This lets us
check if a VM has just been placed into some generic
shared cgroup, or worse, the root cgroup
Signed-off-by: Daniel P. Berrange <berrange(a)redhat.com>
---
src/libvirt_private.syms | 1 +
src/util/vircgroup.c | 42 ++++++++++++++++++++++++++++++++++++++++++
src/util/vircgroup.h | 5 +++++
3 files changed, 48 insertions(+)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 49b9f9d..3be604b 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1182,6 +1182,7 @@ virCgroupGetMemSwapHardLimit;
virCgroupGetMemSwapUsage;
virCgroupHasController;
virCgroupIsolateMount;
+virCgroupIsValidMachineGroup;
virCgroupKill;
virCgroupKillPainfully;
virCgroupKillRecursive;
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index 94d19e0..1043318 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -67,6 +67,8 @@ typedef enum {
*/
} virCgroupFlags;
+static int virCgroupPartitionEscape(char **path);
+
bool virCgroupAvailable(void)
{
FILE *mounts = NULL;
@@ -91,6 +93,46 @@ bool virCgroupAvailable(void)
return ret;
}
+bool virCgroupIsValidMachineGroup(virCgroupPtr group,
+ const char *name,
+ const char *drivername)
+{
+ size_t i;
+ bool valid = false;
+ char *partname;
+
+ if (virAsprintf(&partname, "%s.libvirt-%s",
+ name, drivername) < 0)
+ goto cleanup;
+
+ if (virCgroupPartitionEscape(&partname) < 0)
+ goto cleanup;
+
+ for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
+ char *tmp;
+
+ if (!group->controllers[i].placement)
+ continue;
+
+ tmp = strrchr(group->controllers[i].placement, '/');
+ if (!tmp)
+ goto cleanup;
+ tmp++;
+
+ if (STRNEQ(tmp, name) &&
+ STRNEQ(tmp, partname))
+ goto cleanup;
+
+ }
+
+ valid = true;
+
+ cleanup:
+ VIR_FREE(partname);
+ return valid;
+}
+
+
/**
* virCgroupFree:
*
diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h
index 602d4ff..9bf0d7e 100644
--- a/src/util/vircgroup.h
+++ b/src/util/vircgroup.h
@@ -48,6 +48,11 @@ VIR_ENUM_DECL(virCgroupController);
bool virCgroupAvailable(void);
+bool virCgroupIsValidMachineGroup(virCgroupPtr group,
+ const char *machinename,
+ const char *drivername);
+
+
int virCgroupNewPartition(const char *path,
bool create,
int controllers,
--
1.8.1.4