]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Add API for checking if a cgroup is valid for a domain
authorDaniel P. Berrange <berrange@redhat.com>
Tue, 23 Jul 2013 14:26:21 +0000 (15:26 +0100)
committerDaniel P. Berrange <berrange@redhat.com>
Tue, 23 Jul 2013 21:46:31 +0000 (22:46 +0100)
Add virCgroupIsValidMachine API to check whether an 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@redhat.com>
src/libvirt_private.syms
src/util/vircgroup.c
src/util/vircgroup.h

index 49b9f9d9435806fac3906a9f882b9c5879f698be..3be604b9135a985120e81b8b88009b4ec56559b8 100644 (file)
@@ -1182,6 +1182,7 @@ virCgroupGetMemSwapHardLimit;
 virCgroupGetMemSwapUsage;
 virCgroupHasController;
 virCgroupIsolateMount;
+virCgroupIsValidMachineGroup;
 virCgroupKill;
 virCgroupKillPainfully;
 virCgroupKillRecursive;
index 94d19e00f5efb7e945742139cdd40aa79c92cd88..c84caf1ed53166c13e1846826ec664c5752fdd46 100644 (file)
@@ -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:
  *
index 602d4ff7e984311ec0ed3aac7f854f77ab35b4f8..9bf0d7e86aa14cfe58c213835bcecd7055a02c57 100644 (file)
@@ -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,