[libvirt] [PATCH v3 7/7] util: vircgroupv2: mark only requested controllers as available

Pavel Hrdina posted 7 patches 6 years, 7 months ago
[libvirt] [PATCH v3 7/7] util: vircgroupv2: mark only requested controllers as available
Posted by Pavel Hrdina 6 years, 7 months ago
When detecting available controllers on host we can be limited by list
of controllers from qemu.conf file.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
---

Notes:
    Introduced in v3

 src/util/vircgroupv2.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
index 348c12d5c6..fd883f3c7f 100644
--- a/src/util/vircgroupv2.c
+++ b/src/util/vircgroupv2.c
@@ -302,15 +302,15 @@ virCgroupV2DetectControllers(virCgroupPtr group,
         group->unified.controllers |= 1 << VIR_CGROUP_CONTROLLER_CPUACCT;
     }
 
+    if (controllers >= 0)
+        group->unified.controllers &= controllers;
+
     for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++)
         VIR_DEBUG("Controller '%s' present=%s",
                   virCgroupV2ControllerTypeToString(i),
                   (group->unified.controllers & 1 << i) ? "yes" : "no");
 
-    if (controllers >= 0)
-        return controllers & group->unified.controllers;
-    else
-        return group->unified.controllers;
+    return group->unified.controllers;
 }
 
 
-- 
2.21.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v3 7/7] util: vircgroupv2: mark only requested controllers as available
Posted by Peter Krempa 6 years, 7 months ago
On Tue, Jun 25, 2019 at 13:16:26 +0200, Pavel Hrdina wrote:
> When detecting available controllers on host we can be limited by list
> of controllers from qemu.conf file.
> 
> Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
> ---
> 
> Notes:
>     Introduced in v3
> 
>  src/util/vircgroupv2.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
> index 348c12d5c6..fd883f3c7f 100644
> --- a/src/util/vircgroupv2.c
> +++ b/src/util/vircgroupv2.c
> @@ -302,15 +302,15 @@ virCgroupV2DetectControllers(virCgroupPtr group,
>          group->unified.controllers |= 1 << VIR_CGROUP_CONTROLLER_CPUACCT;
>      }
>  
> +    if (controllers >= 0)
> +        group->unified.controllers &= controllers;

The use of 'int' here for 'controllers' makes it super non-obvious and
super sketchy in what's happening here. Especially since you are then
doing bitwise operations with it afterwards.

It's pre-existing though. Still super ugly.

> +
>      for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++)
>          VIR_DEBUG("Controller '%s' present=%s",
>                    virCgroupV2ControllerTypeToString(i),
>                    (group->unified.controllers & 1 << i) ? "yes" : "no");
>  
> -    if (controllers >= 0)
> -        return controllers & group->unified.controllers;
> -    else
> -        return group->unified.controllers;
> +    return group->unified.controllers;
>  }

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