[libvirt] [PATCH 17/53] vircgroup: introduce virCgroupV2HasEmptyTasks

Pavel Hrdina posted 53 patches 6 years, 7 months ago
There is a newer version of this series
[libvirt] [PATCH 17/53] vircgroup: introduce virCgroupV2HasEmptyTasks
Posted by Pavel Hrdina 6 years, 7 months ago
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
---
 src/util/vircgroupv2.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
index e7dbace42b..c6a9e0a7df 100644
--- a/src/util/vircgroupv2.c
+++ b/src/util/vircgroupv2.c
@@ -446,6 +446,22 @@ virCgroupV2AddTask(virCgroupPtr group,
 }
 
 
+static int
+virCgroupV2HasEmptyTasks(virCgroupPtr cgroup,
+                         int controller)
+{
+    int ret = -1;
+    VIR_AUTOFREE(char *) content = NULL;
+
+    ret = virCgroupGetValueStr(cgroup, controller, "cgroup.procs", &content);
+
+    if (ret == 0 && content[0] == '\0')
+        ret = 1;
+
+    return ret;
+}
+
+
 virCgroupBackend virCgroupV2Backend = {
     .type = VIR_CGROUP_BACKEND_TYPE_V2,
 
@@ -464,6 +480,7 @@ virCgroupBackend virCgroupV2Backend = {
     .makeGroup = virCgroupV2MakeGroup,
     .remove = virCgroupV2Remove,
     .addTask = virCgroupV2AddTask,
+    .hasEmptyTasks = virCgroupV2HasEmptyTasks,
 };
 
 
-- 
2.17.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 17/53] vircgroup: introduce virCgroupV2HasEmptyTasks
Posted by Fabiano Fidêncio 6 years, 7 months ago
On Tue, 2018-10-02 at 10:44 +0200, Pavel Hrdina wrote:
> Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
> ---
>  src/util/vircgroupv2.c | 17 +++++++++++++++++
>  1 file changed, 17 insertions(+)
> 
> diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
> index e7dbace42b..c6a9e0a7df 100644
> --- a/src/util/vircgroupv2.c
> +++ b/src/util/vircgroupv2.c
> @@ -446,6 +446,22 @@ virCgroupV2AddTask(virCgroupPtr group,
>  }
>  
>  
> +static int
> +virCgroupV2HasEmptyTasks(virCgroupPtr cgroup,
> +                         int controller)
> +{
> +    int ret = -1;
> +    VIR_AUTOFREE(char *) content = NULL;
> +

Just a nitpick here. I've noticed that in the v1 you're actually
checking whether cgroup is NULL or not.

Shouldn't you consider doing the same here as well?

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 17/53] vircgroup: introduce virCgroupV2HasEmptyTasks
Posted by Pavel Hrdina 6 years, 7 months ago
On Thu, Oct 04, 2018 at 02:55:30PM +0200, Fabiano Fidêncio wrote:
> On Tue, 2018-10-02 at 10:44 +0200, Pavel Hrdina wrote:
> > Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
> > ---
> >  src/util/vircgroupv2.c | 17 +++++++++++++++++
> >  1 file changed, 17 insertions(+)
> > 
> > diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c
> > index e7dbace42b..c6a9e0a7df 100644
> > --- a/src/util/vircgroupv2.c
> > +++ b/src/util/vircgroupv2.c
> > @@ -446,6 +446,22 @@ virCgroupV2AddTask(virCgroupPtr group,
> >  }
> >  
> >  
> > +static int
> > +virCgroupV2HasEmptyTasks(virCgroupPtr cgroup,
> > +                         int controller)
> > +{
> > +    int ret = -1;
> > +    VIR_AUTOFREE(char *) content = NULL;
> > +
> 
> Just a nitpick here. I've noticed that in the v1 you're actually
> checking whether cgroup is NULL or not.
> 
> Shouldn't you consider doing the same here as well?

Sure, good point :) but if cgroup is NULL it will segfault in
virCgroupHasEmptyTasks because there we call
cgroup->backend->hasEmptyTasks(cgroup, controller);

The proper fix would be remove the NULL check from cgroup v1 backend.

Another point to this topic, the code in libvirt using cgroups currently
relies on cgroup to be allocated (LXC) or cgroup to be available and
allocated (QEMU).  So technically it should not never happen unless
there is programming error.

Pavel
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 17/53] vircgroup: introduce virCgroupV2HasEmptyTasks
Posted by Michal Privoznik 6 years, 7 months ago
On 10/02/2018 10:44 AM, Pavel Hrdina wrote:
> Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
> ---
>  src/util/vircgroupv2.c | 17 +++++++++++++++++
>  1 file changed, 17 insertions(+)

ACK

Michal

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