From nobody Sun Feb 8 22:07:50 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1537285617400718.0196233530129; Tue, 18 Sep 2018 08:46:57 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4C78A811A9; Tue, 18 Sep 2018 15:46:53 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B927F82AEB; Tue, 18 Sep 2018 15:46:52 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 3FD894A46D; Tue, 18 Sep 2018 15:46:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w8IFkR2W012192 for ; Tue, 18 Sep 2018 11:46:27 -0400 Received: by smtp.corp.redhat.com (Postfix) id 50E254DC48; Tue, 18 Sep 2018 15:46:27 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id C97F982AD2 for ; Tue, 18 Sep 2018 15:46:26 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 18 Sep 2018 17:45:37 +0200 Message-Id: <079330bd135229b9eb3e13c3c968c9379bc11eb8.1537285203.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 16/47] vircgroup: extract virCgroupV1Remove X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 18 Sep 2018 15:46:56 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina Reviewed-by: Fabiano Fid=C3=AAncio Reviewed-by: J=EF=BF=BDn Tomko --- src/util/vircgroup.c | 35 ++------------------------------- src/util/vircgroupbackend.h | 4 ++++ src/util/vircgrouppriv.h | 2 ++ src/util/vircgroupv1.c | 39 +++++++++++++++++++++++++++++++++++++ 4 files changed, 47 insertions(+), 33 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 8083e4596d..37bfd7893c 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -2917,7 +2917,7 @@ virCgroupGetCpuacctPercpuUsage(virCgroupPtr group, ch= ar **usage) } =20 =20 -static int +int virCgroupRemoveRecursively(char *grppath) { DIR *grpdir; @@ -2980,38 +2980,7 @@ virCgroupRemoveRecursively(char *grppath) int virCgroupRemove(virCgroupPtr group) { - int rc =3D 0; - size_t i; - - VIR_DEBUG("Removing cgroup %s", group->path); - for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { - VIR_AUTOFREE(char *) grppath =3D NULL; - - /* Skip over controllers not mounted */ - if (!group->controllers[i].mountPoint) - continue; - - /* We must never rmdir() in systemd's hierarchy */ - if (i =3D=3D VIR_CGROUP_CONTROLLER_SYSTEMD) - continue; - - /* Don't delete the root group, if we accidentally - ended up in it for some reason */ - if (STREQ(group->controllers[i].placement, "/")) - continue; - - if (virCgroupPathOfController(group, - i, - NULL, - &grppath) !=3D 0) - continue; - - VIR_DEBUG("Removing cgroup %s and all child cgroups", grppath); - rc =3D virCgroupRemoveRecursively(grppath); - } - VIR_DEBUG("Done removing cgroup %s", group->path); - - return rc; + return group->backend->remove(group); } =20 =20 diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h index 214c9f0726..11ed8431cf 100644 --- a/src/util/vircgroupbackend.h +++ b/src/util/vircgroupbackend.h @@ -100,6 +100,9 @@ typedef int bool create, unsigned int flags); =20 +typedef int +(*virCgroupRemoveCB)(virCgroupPtr group); + struct _virCgroupBackend { virCgroupBackendType type; =20 @@ -117,6 +120,7 @@ struct _virCgroupBackend { virCgroupGetAnyControllerCB getAnyController; virCgroupPathOfControllerCB pathOfController; virCgroupMakeGroupCB makeGroup; + virCgroupRemoveCB remove; }; typedef struct _virCgroupBackend virCgroupBackend; typedef virCgroupBackend *virCgroupBackendPtr; diff --git a/src/util/vircgrouppriv.h b/src/util/vircgrouppriv.h index 2e731458d5..a760b9bcfd 100644 --- a/src/util/vircgrouppriv.h +++ b/src/util/vircgrouppriv.h @@ -88,4 +88,6 @@ int virCgroupNewDomainPartition(virCgroupPtr partition, virCgroupPtr *group) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(5); =20 +int virCgroupRemoveRecursively(char *grppath); + #endif /* __VIR_CGROUP_PRIV_H__ */ diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index cf484216cc..25afd39235 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -667,6 +667,44 @@ virCgroupV1MakeGroup(virCgroupPtr parent, } =20 =20 +static int +virCgroupV1Remove(virCgroupPtr group) +{ + int rc =3D 0; + size_t i; + + VIR_DEBUG("Removing cgroup %s", group->path); + for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { + VIR_AUTOFREE(char *) grppath =3D NULL; + + /* Skip over controllers not mounted */ + if (!group->controllers[i].mountPoint) + continue; + + /* We must never rmdir() in systemd's hierarchy */ + if (i =3D=3D VIR_CGROUP_CONTROLLER_SYSTEMD) + continue; + + /* Don't delete the root group, if we accidentally + ended up in it for some reason */ + if (STREQ(group->controllers[i].placement, "/")) + continue; + + if (virCgroupV1PathOfController(group, + i, + NULL, + &grppath) !=3D 0) + continue; + + VIR_DEBUG("Removing cgroup %s and all child cgroups", grppath); + rc =3D virCgroupRemoveRecursively(grppath); + } + VIR_DEBUG("Done removing cgroup %s", group->path); + + return rc; +} + + virCgroupBackend virCgroupV1Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V1, =20 @@ -683,6 +721,7 @@ virCgroupBackend virCgroupV1Backend =3D { .getAnyController =3D virCgroupV1GetAnyController, .pathOfController =3D virCgroupV1PathOfController, .makeGroup =3D virCgroupV1MakeGroup, + .remove =3D virCgroupV1Remove, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list