9119d9
From c39165c5465ab2d729b52682c6d23898a49406d5 Mon Sep 17 00:00:00 2001
9119d9
Message-Id: <c39165c5465ab2d729b52682c6d23898a49406d5@dist-git>
9119d9
From: John Ferlan <jferlan@redhat.com>
9119d9
Date: Thu, 18 Sep 2014 09:29:51 -0400
9119d9
Subject: [PATCH] vircgroup: Introduce virCgroupNewIOThread
9119d9
9119d9
https://bugzilla.redhat.com/show_bug.cgi?id=1101574
9119d9
9119d9
Add virCgroupNewIOThread() to mimic virCgroupNewVcpu() except the naming
9119d9
scheme with use "iothread" rather than "vcpu".
9119d9
9119d9
(cherry picked from commit 3abb95cad4d0c452c92e136a4e41f15f60bdd658)
9119d9
Signed-off-by: John Ferlan <jferlan@redhat.com>
9119d9
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
9119d9
---
9119d9
 src/libvirt_private.syms |  1 +
9119d9
 src/util/vircgroup.c     | 43 +++++++++++++++++++++++++++++++++++++++++++
9119d9
 src/util/vircgroup.h     |  6 ++++++
9119d9
 3 files changed, 50 insertions(+)
9119d9
9119d9
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
9119d9
index 18cf0c2..55fff46 100644
9119d9
--- a/src/libvirt_private.syms
9119d9
+++ b/src/libvirt_private.syms
9119d9
@@ -1088,6 +1088,7 @@ virCgroupNewDetectMachine;
9119d9
 virCgroupNewDomainPartition;
9119d9
 virCgroupNewEmulator;
9119d9
 virCgroupNewIgnoreError;
9119d9
+virCgroupNewIOThread;
9119d9
 virCgroupNewMachine;
9119d9
 virCgroupNewPartition;
9119d9
 virCgroupNewSelf;
9119d9
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
9119d9
index 8b554a9..2842831 100644
9119d9
--- a/src/util/vircgroup.c
9119d9
+++ b/src/util/vircgroup.c
9119d9
@@ -1492,6 +1492,49 @@ virCgroupNewEmulator(virCgroupPtr domain,
9119d9
 }
9119d9
 
9119d9
 
9119d9
+/**
9119d9
+ * virCgroupNewIOThread:
9119d9
+ *
9119d9
+ * @domain: group for the domain
9119d9
+ * @iothreadid: id of the iothread
9119d9
+ * @create: true to create if not already existing
9119d9
+ * @group: Pointer to returned virCgroupPtr
9119d9
+ *
9119d9
+ * Returns 0 on success, or -1 on error
9119d9
+ */
9119d9
+int
9119d9
+virCgroupNewIOThread(virCgroupPtr domain,
9119d9
+                     int iothreadid,
9119d9
+                     bool create,
9119d9
+                     virCgroupPtr *group)
9119d9
+{
9119d9
+    int ret = -1;
9119d9
+    char *name = NULL;
9119d9
+    int controllers;
9119d9
+
9119d9
+    if (virAsprintf(&name, "iothread%d", iothreadid) < 0)
9119d9
+        goto cleanup;
9119d9
+
9119d9
+    controllers = ((1 << VIR_CGROUP_CONTROLLER_CPU) |
9119d9
+                   (1 << VIR_CGROUP_CONTROLLER_CPUACCT) |
9119d9
+                   (1 << VIR_CGROUP_CONTROLLER_CPUSET));
9119d9
+
9119d9
+    if (virCgroupNew(-1, name, domain, controllers, group) < 0)
9119d9
+        goto cleanup;
9119d9
+
9119d9
+    if (virCgroupMakeGroup(domain, *group, create, VIR_CGROUP_NONE) < 0) {
9119d9
+        virCgroupRemove(*group);
9119d9
+        virCgroupFree(group);
9119d9
+        goto cleanup;
9119d9
+    }
9119d9
+
9119d9
+    ret = 0;
9119d9
+ cleanup:
9119d9
+    VIR_FREE(name);
9119d9
+    return ret;
9119d9
+}
9119d9
+
9119d9
+
9119d9
 int
9119d9
 virCgroupNewDetect(pid_t pid,
9119d9
                    int controllers,
9119d9
diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h
9119d9
index 90b41f7..19e82d1 100644
9119d9
--- a/src/util/vircgroup.h
9119d9
+++ b/src/util/vircgroup.h
9119d9
@@ -76,6 +76,12 @@ int virCgroupNewEmulator(virCgroupPtr domain,
9119d9
                          virCgroupPtr *group)
9119d9
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3);
9119d9
 
9119d9
+int virCgroupNewIOThread(virCgroupPtr domain,
9119d9
+                         int iothreadid,
9119d9
+                         bool create,
9119d9
+                         virCgroupPtr *group)
9119d9
+    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4);
9119d9
+
9119d9
 int virCgroupNewDetect(pid_t pid,
9119d9
                        int controllers,
9119d9
                        virCgroupPtr *group);
9119d9
-- 
9119d9
2.1.0
9119d9