[PATCH 17/47] vircgroup: extract virCgroupV1AddTask

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Pavel Hrdina <phrdina@xxxxxxxxxx>
---
 src/util/vircgroup.c        | 48 +++++--------------------------------
 src/util/vircgroupbackend.h | 12 ++++++++++
 src/util/vircgrouppriv.h    |  5 ++++
 src/util/vircgroupv1.c      | 31 ++++++++++++++++++++++++
 4 files changed, 54 insertions(+), 42 deletions(-)

diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index 37bfd7893c..5dd736930b 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -546,7 +546,7 @@ virCgroupSetValueU64(virCgroupPtr group,
 }
 
 
-static int
+int
 virCgroupSetValueI64(virCgroupPtr group,
                      int controller,
                      const char *key,
@@ -674,42 +674,6 @@ virCgroupNew(pid_t pid,
 }
 
 
-typedef enum {
-    VIR_CGROUP_TASK_PROCESS = 0,
-    VIR_CGROUP_TASK_SYSTEMD = 1 << 0,
-    VIR_CGROUP_TASK_THREAD = 1 << 1,
-} virCgroupTaskFlags;
-
-
-static int
-virCgroupAddTaskInternal(virCgroupPtr group,
-                         pid_t pid,
-                         unsigned int flags)
-{
-    int ret = -1;
-    size_t i;
-
-    for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
-        /* Skip over controllers not mounted */
-        if (!group->controllers[i].mountPoint)
-            continue;
-
-        /* We must never add tasks in systemd's hierarchy
-         * unless we're intentionally trying to move a
-         * task into a systemd machine scope */
-        if (i == VIR_CGROUP_CONTROLLER_SYSTEMD &&
-            !(flags & VIR_CGROUP_TASK_SYSTEMD))
-            continue;
-
-        if (virCgroupSetValueI64(group, i, "tasks", pid) < 0)
-            goto cleanup;
-    }
-
-    ret = 0;
- cleanup:
-    return ret;
-}
-
 /**
  * virCgroupAddProcess:
  *
@@ -724,7 +688,7 @@ virCgroupAddTaskInternal(virCgroupPtr group,
 int
 virCgroupAddProcess(virCgroupPtr group, pid_t pid)
 {
-    return virCgroupAddTaskInternal(group, pid, VIR_CGROUP_TASK_PROCESS);
+    return group->backend->addTask(group, pid, VIR_CGROUP_TASK_PROCESS);
 }
 
 /**
@@ -741,9 +705,9 @@ virCgroupAddProcess(virCgroupPtr group, pid_t pid)
 int
 virCgroupAddMachineProcess(virCgroupPtr group, pid_t pid)
 {
-    return virCgroupAddTaskInternal(group, pid,
-                                    VIR_CGROUP_TASK_PROCESS |
-                                    VIR_CGROUP_TASK_SYSTEMD);
+    return group->backend->addTask(group, pid,
+                                   VIR_CGROUP_TASK_PROCESS |
+                                   VIR_CGROUP_TASK_SYSTEMD);
 }
 
 /**
@@ -761,7 +725,7 @@ int
 virCgroupAddThread(virCgroupPtr group,
                    pid_t pid)
 {
-    return virCgroupAddTaskInternal(group, pid, VIR_CGROUP_TASK_THREAD);
+    return group->backend->addTask(group, pid, VIR_CGROUP_TASK_THREAD);
 }
 
 
diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h
index 11ed8431cf..4661d82132 100644
--- a/src/util/vircgroupbackend.h
+++ b/src/util/vircgroupbackend.h
@@ -35,6 +35,12 @@ typedef enum {
                                        */
 } virCgroupBackendFlags;
 
+typedef enum {
+    VIR_CGROUP_TASK_PROCESS = 0,
+    VIR_CGROUP_TASK_SYSTEMD = 1 << 0,
+    VIR_CGROUP_TASK_THREAD = 1 << 1,
+} virCgroupBackendTaskFlags;
+
 typedef enum {
     VIR_CGROUP_BACKEND_TYPE_V1 = 0,
     VIR_CGROUP_BACKEND_TYPE_LAST,
@@ -103,6 +109,11 @@ typedef int
 typedef int
 (*virCgroupRemoveCB)(virCgroupPtr group);
 
+typedef int
+(*virCgroupAddTaskCB)(virCgroupPtr group,
+                      pid_t pid,
+                      unsigned int flags);
+
 struct _virCgroupBackend {
     virCgroupBackendType type;
 
@@ -121,6 +132,7 @@ struct _virCgroupBackend {
     virCgroupPathOfControllerCB pathOfController;
     virCgroupMakeGroupCB makeGroup;
     virCgroupRemoveCB remove;
+    virCgroupAddTaskCB addTask;
 };
 typedef struct _virCgroupBackend virCgroupBackend;
 typedef virCgroupBackend *virCgroupBackendPtr;
diff --git a/src/util/vircgrouppriv.h b/src/util/vircgrouppriv.h
index a760b9bcfd..01714370be 100644
--- a/src/util/vircgrouppriv.h
+++ b/src/util/vircgrouppriv.h
@@ -73,6 +73,11 @@ int virCgroupGetValueU64(virCgroupPtr group,
                          const char *key,
                          unsigned long long int *value);
 
+int virCgroupSetValueI64(virCgroupPtr group,
+                         int controller,
+                         const char *key,
+                         long long int value);
+
 int virCgroupPartitionEscape(char **path);
 
 int virCgroupNewPartition(const char *path,
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
index 25afd39235..c9f6fd925a 100644
--- a/src/util/vircgroupv1.c
+++ b/src/util/vircgroupv1.c
@@ -705,6 +705,36 @@ virCgroupV1Remove(virCgroupPtr group)
 }
 
 
+static int
+virCgroupV1AddTask(virCgroupPtr group,
+                   pid_t pid,
+                   unsigned int flags)
+{
+    int ret = -1;
+    size_t i;
+
+    for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
+        /* Skip over controllers not mounted */
+        if (!group->controllers[i].mountPoint)
+            continue;
+
+        /* We must never add tasks in systemd's hierarchy
+         * unless we're intentionally trying to move a
+         * task into a systemd machine scope */
+        if (i == VIR_CGROUP_CONTROLLER_SYSTEMD &&
+            !(flags & VIR_CGROUP_TASK_SYSTEMD))
+            continue;
+
+        if (virCgroupSetValueI64(group, i, "tasks", pid) < 0)
+            goto cleanup;
+    }
+
+    ret = 0;
+ cleanup:
+    return ret;
+}
+
+
 virCgroupBackend virCgroupV1Backend = {
     .type = VIR_CGROUP_BACKEND_TYPE_V1,
 
@@ -722,6 +752,7 @@ virCgroupBackend virCgroupV1Backend = {
     .pathOfController = virCgroupV1PathOfController,
     .makeGroup = virCgroupV1MakeGroup,
     .remove = virCgroupV1Remove,
+    .addTask = virCgroupV1AddTask,
 };
 
 
-- 
2.17.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux