[libvirt] [PATCH 4/9] vircgroup: introduce virCgroupTaskFlags

Pavel Hrdina posted 9 patches 5 years, 12 months ago
There is a newer version of this series
[libvirt] [PATCH 4/9] vircgroup: introduce virCgroupTaskFlags
Posted by Pavel Hrdina 5 years, 12 months ago
Use flags in virCgroupAddTaskInternal instead of boolean parameter.
Following patch will ad new flag to indicate thread instead of process.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
---
 src/util/vircgroup.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index cf510fb019..1d361762c5 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -1156,8 +1156,16 @@ virCgroupNew(pid_t pid,
 }
 
 
+typedef enum {
+    VIR_CGROUP_TASK_PROCESS = 0,
+    VIR_CGROUP_TASK_SYSTEMD = 1 << 0,
+} virCgroupTaskFlags;
+
+
 static int
-virCgroupAddTaskInternal(virCgroupPtr group, pid_t pid, bool withSystemd)
+virCgroupAddTaskInternal(virCgroupPtr group,
+                         pid_t pid,
+                         unsigned int flags)
 {
     int ret = -1;
     size_t i;
@@ -1170,7 +1178,8 @@ virCgroupAddTaskInternal(virCgroupPtr group, pid_t pid, bool withSystemd)
         /* 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 && !withSystemd)
+        if (i == VIR_CGROUP_CONTROLLER_SYSTEMD &&
+            !(flags & VIR_CGROUP_TASK_SYSTEMD))
             continue;
 
         if (virCgroupSetValueI64(group, i, "tasks", pid) < 0)
@@ -1196,7 +1205,7 @@ virCgroupAddTaskInternal(virCgroupPtr group, pid_t pid, bool withSystemd)
 int
 virCgroupAddProcess(virCgroupPtr group, pid_t pid)
 {
-    return virCgroupAddTaskInternal(group, pid, false);
+    return virCgroupAddTaskInternal(group, pid, VIR_CGROUP_TASK_PROCESS);
 }
 
 /**
@@ -1213,7 +1222,9 @@ virCgroupAddProcess(virCgroupPtr group, pid_t pid)
 int
 virCgroupAddMachineProcess(virCgroupPtr group, pid_t pid)
 {
-    return virCgroupAddTaskInternal(group, pid, true);
+    return virCgroupAddTaskInternal(group, pid,
+                                    VIR_CGROUP_TASK_PROCESS |
+                                    VIR_CGROUP_TASK_SYSTEMD);
 }
 
 
-- 
2.17.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 4/9] vircgroup: introduce virCgroupTaskFlags
Posted by Fabiano Fidêncio 5 years, 12 months ago
On Tue, Sep 18, 2018 at 2:17 PM, Pavel Hrdina <phrdina@redhat.com> wrote:

> Use flags in virCgroupAddTaskInternal instead of boolean parameter.
> Following patch will ad new flag to indicate thread instead of process.
>

typo: ad -> add


>
> Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
>
---
>  src/util/vircgroup.c | 19 +++++++++++++++----
>  1 file changed, 15 insertions(+), 4 deletions(-)
>
> diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
> index cf510fb019..1d361762c5 100644
> --- a/src/util/vircgroup.c
> +++ b/src/util/vircgroup.c
> @@ -1156,8 +1156,16 @@ virCgroupNew(pid_t pid,
>  }
>
>
> +typedef enum {
> +    VIR_CGROUP_TASK_PROCESS = 0,
> +    VIR_CGROUP_TASK_SYSTEMD = 1 << 0,
>

Although not strictly needed, would be nice to have a comment describing
what the flags mean.


> +} virCgroupTaskFlags;
> +
> +
>  static int
> -virCgroupAddTaskInternal(virCgroupPtr group, pid_t pid, bool withSystemd)
> +virCgroupAddTaskInternal(virCgroupPtr group,
> +                         pid_t pid,
> +                         unsigned int flags)
>  {
>      int ret = -1;
>      size_t i;
> @@ -1170,7 +1178,8 @@ virCgroupAddTaskInternal(virCgroupPtr group, pid_t
> pid, bool withSystemd)
>          /* 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 && !withSystemd)
> +        if (i == VIR_CGROUP_CONTROLLER_SYSTEMD &&
> +            !(flags & VIR_CGROUP_TASK_SYSTEMD))
>              continue;
>
>          if (virCgroupSetValueI64(group, i, "tasks", pid) < 0)
> @@ -1196,7 +1205,7 @@ virCgroupAddTaskInternal(virCgroupPtr group, pid_t
> pid, bool withSystemd)
>  int
>  virCgroupAddProcess(virCgroupPtr group, pid_t pid)
>  {
> -    return virCgroupAddTaskInternal(group, pid, false);
> +    return virCgroupAddTaskInternal(group, pid, VIR_CGROUP_TASK_PROCESS);
>  }
>
>  /**
> @@ -1213,7 +1222,9 @@ virCgroupAddProcess(virCgroupPtr group, pid_t pid)
>  int
>  virCgroupAddMachineProcess(virCgroupPtr group, pid_t pid)
>  {
> -    return virCgroupAddTaskInternal(group, pid, true);
> +    return virCgroupAddTaskInternal(group, pid,
> +                                    VIR_CGROUP_TASK_PROCESS |
> +                                    VIR_CGROUP_TASK_SYSTEMD);
>  }
>
>
> --
> 2.17.1
>
> --
> libvir-list mailing list
> libvir-list@redhat.com
> https://www.redhat.com/mailman/listinfo/libvir-list
>

Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list