From nobody Sun Feb 8 12:20:33 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 1537285607236348.24591258004966; Tue, 18 Sep 2018 08:46:47 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C1B1580F6C; Tue, 18 Sep 2018 15:46:41 +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 6C423308BDA1; Tue, 18 Sep 2018 15:46:41 +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 E2E704A46C; Tue, 18 Sep 2018 15:46:40 +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 w8IFkK3Z011956 for ; Tue, 18 Sep 2018 11:46:20 -0400 Received: by smtp.corp.redhat.com (Postfix) id 366964DC48; Tue, 18 Sep 2018 15:46:20 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 55BDC5D9C7 for ; Tue, 18 Sep 2018 15:46:19 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 18 Sep 2018 17:45:29 +0200 Message-Id: <55d95eff241d32b8bc9f2857ae151c2e8ae7e33d.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 08/47] vircgroup: extract virCgroupV1CopyPlacement 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.84 on 10.5.11.24 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:42 +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 | 38 +------------------------------------ src/util/vircgroupbackend.h | 6 ++++++ src/util/vircgroupv1.c | 37 ++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 37 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 7557fc5576..0fcb047a0c 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -271,42 +271,6 @@ virCgroupDetectMounts(virCgroupPtr group) } =20 =20 -static int -virCgroupCopyPlacement(virCgroupPtr group, - const char *path, - virCgroupPtr parent) -{ - size_t i; - for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { - if (!group->controllers[i].mountPoint) - continue; - - if (i =3D=3D VIR_CGROUP_CONTROLLER_SYSTEMD) - continue; - - if (path[0] =3D=3D '/') { - if (VIR_STRDUP(group->controllers[i].placement, path) < 0) - return -1; - } else { - /* - * parent =3D=3D "/" + path=3D"" =3D> "/" - * parent =3D=3D "/libvirt.service" + path =3D=3D "" =3D> "/li= bvirt.service" - * parent =3D=3D "/libvirt.service" + path =3D=3D "foo" =3D> "= /libvirt.service/foo" - */ - if (virAsprintf(&group->controllers[i].placement, - "%s%s%s", - parent->controllers[i].placement, - (STREQ(parent->controllers[i].placement, "/") = || - STREQ(path, "") ? "" : "/"), - path) < 0) - return -1; - } - } - - return 0; -} - - /* * virCgroupDetectPlacement: * @group: the group to process @@ -534,7 +498,7 @@ virCgroupDetect(virCgroupPtr group, * based on the parent cgroup... */ if ((parent || path[0] =3D=3D '/') && - virCgroupCopyPlacement(group, path, parent) < 0) + group->backend->copyPlacement(group, path, parent) < 0) return -1; =20 /* ... but use /proc/cgroups to fill in the rest */ diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h index fadc7efdcf..85906e7191 100644 --- a/src/util/vircgroupbackend.h +++ b/src/util/vircgroupbackend.h @@ -45,6 +45,11 @@ typedef int (*virCgroupCopyMountsCB)(virCgroupPtr group, virCgroupPtr parent); =20 +typedef int +(*virCgroupCopyPlacementCB)(virCgroupPtr group, + const char *path, + virCgroupPtr parent); + typedef int (*virCgroupDetectMountsCB)(virCgroupPtr group, const char *mntType, @@ -64,6 +69,7 @@ struct _virCgroupBackend { virCgroupAvailableCB available; virCgroupValidateMachineGroupCB validateMachineGroup; virCgroupCopyMountsCB copyMounts; + virCgroupCopyPlacementCB copyPlacement; virCgroupDetectMountsCB detectMounts; virCgroupDetectPlacementCB detectPlacement; }; diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index 2882a19be2..f73f40db0e 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -182,6 +182,42 @@ virCgroupV1CopyMounts(virCgroupPtr group, } =20 =20 +static int +virCgroupV1CopyPlacement(virCgroupPtr group, + const char *path, + virCgroupPtr parent) +{ + size_t i; + for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { + if (!group->controllers[i].mountPoint) + continue; + + if (i =3D=3D VIR_CGROUP_CONTROLLER_SYSTEMD) + continue; + + if (path[0] =3D=3D '/') { + if (VIR_STRDUP(group->controllers[i].placement, path) < 0) + return -1; + } else { + /* + * parent =3D=3D "/" + path=3D"" =3D> "/" + * parent =3D=3D "/libvirt.service" + path =3D=3D "" =3D> "/li= bvirt.service" + * parent =3D=3D "/libvirt.service" + path =3D=3D "foo" =3D> "= /libvirt.service/foo" + */ + if (virAsprintf(&group->controllers[i].placement, + "%s%s%s", + parent->controllers[i].placement, + (STREQ(parent->controllers[i].placement, "/") = || + STREQ(path, "") ? "" : "/"), + path) < 0) + return -1; + } + } + + return 0; +} + + static int virCgroupV1ResolveMountLink(const char *mntDir, const char *typeStr, @@ -342,6 +378,7 @@ virCgroupBackend virCgroupV1Backend =3D { .available =3D virCgroupV1Available, .validateMachineGroup =3D virCgroupV1ValidateMachineGroup, .copyMounts =3D virCgroupV1CopyMounts, + .copyPlacement =3D virCgroupV1CopyPlacement, .detectMounts =3D virCgroupV1DetectMounts, .detectPlacement =3D virCgroupV1DetectPlacement, }; --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list