]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
New cgroups API for atomically creating machine cgroups
authorDaniel P. Berrange <berrange@redhat.com>
Thu, 18 Jul 2013 15:55:37 +0000 (16:55 +0100)
committerDaniel P. Berrange <berrange@redhat.com>
Thu, 25 Jul 2013 10:42:47 +0000 (11:42 +0100)
Instead of requiring one API call to create a cgroup and
another to add a task to it, introduce a new API
virCgroupNewMachine which does both jobs at once. This
will facilitate the later code to talk to systemd to
achieve this job which is also atomic.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
src/libvirt_private.syms
src/util/vircgroup.c
src/util/vircgroup.h

index 4a2f667ef5f38579ac09b250f5b1e26679f245a4..d5ec1466469cd4f0a3dd9fd663802c521bda4946 100644 (file)
@@ -1195,6 +1195,7 @@ virCgroupNewDetect;
 virCgroupNewDomainPartition;
 virCgroupNewEmulator;
 virCgroupNewIgnoreError;
+virCgroupNewMachine;
 virCgroupNewPartition;
 virCgroupNewSelf;
 virCgroupNewVcpu;
index 9727a3e2b5870231746040162f210b5e7bd1ba87..86dc5fe5e959a858b6902d57b851ea47e598c456 100644 (file)
@@ -1565,6 +1565,57 @@ int virCgroupNewDetect(pid_t pid ATTRIBUTE_UNUSED,
 }
 #endif
 
+int virCgroupNewMachine(const char *name,
+                        const char *drivername,
+                        bool privileged ATTRIBUTE_UNUSED,
+                        const unsigned char *uuid ATTRIBUTE_UNUSED,
+                        const char *rootdir ATTRIBUTE_UNUSED,
+                        pid_t pidleader ATTRIBUTE_UNUSED,
+                        bool isContainer ATTRIBUTE_UNUSED,
+                        const char *partition,
+                        int controllers,
+                        virCgroupPtr *group)
+{
+    virCgroupPtr parent = NULL;
+    int ret = -1;
+
+    *group = NULL;
+
+    if (virCgroupNewPartition(partition,
+                              STREQ(partition, "/machine"),
+                              controllers,
+                              &parent) < 0) {
+        if (virCgroupNewIgnoreError())
+            goto done;
+
+        goto cleanup;
+    }
+
+    if (virCgroupNewDomainPartition(parent,
+                                    drivername,
+                                    name,
+                                    true,
+                                    group) < 0)
+        goto cleanup;
+
+    if (virCgroupAddTask(*group, pidleader) < 0) {
+        virErrorPtr saved = virSaveLastError();
+        virCgroupRemove(*group);
+        virCgroupFree(group);
+        if (saved) {
+            virSetError(saved);
+            virFreeError(saved);
+        }
+    }
+
+done:
+    ret = 0;
+
+cleanup:
+    virCgroupFree(&parent);
+    return ret;
+}
+
 bool virCgroupNewIgnoreError(void)
 {
     if (virLastErrorIsSystemErrno(ENXIO) ||
index 3c056048fa3aced1a03b214e554ea0b61025ca66..e47367ce5d73e348508dc940b1850f920aac49e7 100644 (file)
@@ -83,6 +83,19 @@ int virCgroupNewEmulator(virCgroupPtr domain,
 int virCgroupNewDetect(pid_t pid,
                        virCgroupPtr *group);
 
+int virCgroupNewMachine(const char *name,
+                        const char *drivername,
+                        bool privileged,
+                        const unsigned char *uuid,
+                        const char *rootdir,
+                        pid_t pidleader,
+                        bool isContainer,
+                        const char *partition,
+                        int controllers,
+                        virCgroupPtr *group)
+    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2)
+    ATTRIBUTE_NONNULL(4);
+
 bool virCgroupNewIgnoreError(void);
 
 int virCgroupPathOfController(virCgroupPtr group,