]> xenbits.xensource.com Git - libvirt.git/commitdiff
cgroup: Introduce virCgroupNewThread
authorJohn Ferlan <jferlan@redhat.com>
Tue, 7 Apr 2015 12:28:05 +0000 (08:28 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Thu, 9 Apr 2015 23:27:08 +0000 (19:27 -0400)
Create a new common API to replace the virCgroupNew{Vcpu|Emulator|IOThread}
API's using an emum to generate the cgroup name

Signed-off-by: John Ferlan <jferlan@redhat.com>
src/libvirt_private.syms
src/util/vircgroup.c
src/util/vircgroup.h

index a092714fedf8ab962a45a4f6694cdf0d285084dc..c302bacf6d49f0bc3624fb1629d16948034fa7d3 100644 (file)
@@ -1188,6 +1188,7 @@ virCgroupNewIOThread;
 virCgroupNewMachine;
 virCgroupNewPartition;
 virCgroupNewSelf;
+virCgroupNewThread;
 virCgroupNewVcpu;
 virCgroupPathOfController;
 virCgroupRemove;
index 00c0bab490a458ab666d0be35b0d57ee54fbf064..f53319db6dfe0900a33e66456732b75b8d0aa8e8 100644 (file)
@@ -1421,6 +1421,67 @@ virCgroupNewDomainPartition(virCgroupPtr partition,
 }
 
 
+/**
+ * virCgroupNewThread:
+ *
+ * @domain: group for the domain
+ * @name: enum to generate the name for the new thread
+ * @id: id of the vcpu or iothread
+ * @create: true to create if not already existing
+ * @group: Pointer to returned virCgroupPtr
+ *
+ * Returns 0 on success, or -1 on error
+ */
+int
+virCgroupNewThread(virCgroupPtr domain,
+                   virCgroupThreadName nameval,
+                   int id,
+                   bool create,
+                   virCgroupPtr *group)
+{
+    int ret = -1;
+    char *name = NULL;
+    int controllers;
+
+    switch (nameval) {
+    case VIR_CGROUP_THREAD_VCPU:
+        if (virAsprintf(&name, "vcpu%d", id) < 0)
+            goto cleanup;
+        break;
+    case VIR_CGROUP_THREAD_EMULATOR:
+        if (VIR_STRDUP(name, "emulator") < 0)
+            goto cleanup;
+        break;
+    case VIR_CGROUP_THREAD_IOTHREAD:
+        if (virAsprintf(&name, "iothread%d", id) < 0)
+            goto cleanup;
+        break;
+    case VIR_CGROUP_THREAD_LAST:
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("unexpected name value %d"), nameval);
+        goto cleanup;
+    }
+
+    controllers = ((1 << VIR_CGROUP_CONTROLLER_CPU) |
+                   (1 << VIR_CGROUP_CONTROLLER_CPUACCT) |
+                   (1 << VIR_CGROUP_CONTROLLER_CPUSET));
+
+    if (virCgroupNew(-1, name, domain, controllers, group) < 0)
+        goto cleanup;
+
+    if (virCgroupMakeGroup(domain, *group, create, VIR_CGROUP_NONE) < 0) {
+        virCgroupRemove(*group);
+        virCgroupFree(group);
+        goto cleanup;
+    }
+
+    ret = 0;
+ cleanup:
+    VIR_FREE(name);
+    return ret;
+}
+
+
 /**
  * virCgroupNewVcpu:
  *
@@ -4079,6 +4140,19 @@ virCgroupNewDomainPartition(virCgroupPtr partition ATTRIBUTE_UNUSED,
 }
 
 
+int
+virCgroupNewThread(virCgroupPtr domain ATTRIBUTE_UNUSED,
+                   virCgroupThreadName nameval ATTRIBUTE_UNUSED,
+                   int id ATTRIBUTE_UNUSED,
+                   bool create ATTRIBUTE_UNUSED,
+                   virCgroupPtr *group ATTRIBUTE_UNUSED)
+{
+    virReportSystemError(ENXIO, "%s",
+                         _("Control groups not supported on this platform"));
+    return -1;
+}
+
+
 int
 virCgroupNewVcpu(virCgroupPtr domain ATTRIBUTE_UNUSED,
                  int vcpuid ATTRIBUTE_UNUSED,
index 5d6356d7b98239a8b3037c7727309dfae8beff4f..7b57afc740f2542507df58d450df76ae0cde2dd0 100644 (file)
@@ -52,6 +52,14 @@ VIR_ENUM_DECL(virCgroupController);
  * Make sure we will not overflow */
 verify(VIR_CGROUP_CONTROLLER_LAST < 8 * sizeof(int));
 
+typedef enum {
+    VIR_CGROUP_THREAD_VCPU = 0,
+    VIR_CGROUP_THREAD_EMULATOR,
+    VIR_CGROUP_THREAD_IOTHREAD,
+
+    VIR_CGROUP_THREAD_LAST
+} virCgroupThreadName;
+
 bool virCgroupAvailable(void);
 
 int virCgroupNewPartition(const char *path,
@@ -70,6 +78,13 @@ int virCgroupNewDomainPartition(virCgroupPtr partition,
                                 virCgroupPtr *group)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(5);
 
+int virCgroupNewThread(virCgroupPtr domain,
+                       virCgroupThreadName nameval,
+                       int id,
+                       bool create,
+                       virCgroupPtr *group)
+    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(5);
+
 int virCgroupNewVcpu(virCgroupPtr domain,
                      int vcpuid,
                      bool create,