From nobody Mon Feb 9 00:56:26 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 1535118376287646.5621588567627; Fri, 24 Aug 2018 06:46:16 -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 BE98285362; Fri, 24 Aug 2018 13:46:13 +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 5E2CE308BDA0; Fri, 24 Aug 2018 13:46:13 +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 E36414A46D; Fri, 24 Aug 2018 13:46:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w7ODk2HE024351 for ; Fri, 24 Aug 2018 09:46:02 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8A9EF2026E03; Fri, 24 Aug 2018 13:46:02 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2A4D42026D6D for ; Fri, 24 Aug 2018 13:46:02 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Fri, 24 Aug 2018 15:45:54 +0200 Message-Id: <26bd24c0fc7aaab721ebcbe5b563051c21e2e7d8.1535118274.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 4/7] vircgroup: Split virCgroupPathOfController into two functions 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.25]); Fri, 24 Aug 2018 13:46:14 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The case where we need path of any controller is only for internal use so move it out to a different function. Signed-off-by: Pavel Hrdina Reviewed-by: J=EF=BF=BDn Tomko --- src/util/vircgroup.c | 54 ++++++++++++++++++++++++++------------------ src/util/vircgroup.h | 2 +- 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 2bc4febf23..8646a4a479 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -1772,28 +1772,13 @@ virCgroupHasController(virCgroupPtr cgroup, int con= troller) =20 int virCgroupPathOfController(virCgroupPtr group, - int controller, + unsigned int controller, const char *key, char **path) { - if (controller =3D=3D -1) { - size_t i; - for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { - /* Reject any controller with a placement - * of '/' to avoid doing bad stuff to the root - * cgroup - */ - if (group->controllers[i].mountPoint && - group->controllers[i].placement && - STRNEQ(group->controllers[i].placement, "/")) { - controller =3D i; - break; - } - } - } - if (controller =3D=3D -1) { - virReportSystemError(ENOSYS, "%s", - _("No controllers are mounted")); + if (controller >=3D VIR_CGROUP_CONTROLLER_LAST) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Invalid controller id '%d'"), controller); return -1; } =20 @@ -3505,6 +3490,31 @@ virCgroupRemove(virCgroupPtr group) } =20 =20 +static int +virCgroupPathOfAnyController(virCgroupPtr group, + const char *name, + char **keypath) +{ + size_t i; + + for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { + /* Reject any controller with a placement + * of '/' to avoid doing bad stuff to the root + * cgroup + */ + if (group->controllers[i].mountPoint && + group->controllers[i].placement && + STRNEQ(group->controllers[i].placement, "/")) { + return virCgroupPathOfController(group, i, name, keypath); + } + } + + virReportSystemError(ENOSYS, "%s", + _("No controllers are mounted")); + return -1; +} + + /* * Returns 1 if some PIDs are killed, 0 if none are killed, or -1 on error */ @@ -3519,7 +3529,7 @@ virCgroupKillInternal(virCgroupPtr group, int signum,= virHashTablePtr pids) VIR_DEBUG("group=3D%p path=3D%s signum=3D%d pids=3D%p", group, group->path, signum, pids); =20 - if (virCgroupPathOfController(group, -1, "tasks", &keypath) < 0) + if (virCgroupPathOfAnyController(group, "tasks", &keypath) < 0) return -1; =20 /* PIDs may be forking as we kill them, so loop @@ -3622,7 +3632,7 @@ virCgroupKillRecursiveInternal(virCgroupPtr group, VIR_DEBUG("group=3D%p path=3D%s signum=3D%d pids=3D%p", group, group->path, signum, pids); =20 - if (virCgroupPathOfController(group, -1, "", &keypath) < 0) + if (virCgroupPathOfAnyController(group, "", &keypath) < 0) return -1; =20 if ((rc =3D virCgroupKillInternal(group, signum, pids)) < 0) @@ -4180,7 +4190,7 @@ virCgroupHasController(virCgroupPtr cgroup ATTRIBUTE_= UNUSED, =20 int virCgroupPathOfController(virCgroupPtr group ATTRIBUTE_UNUSED, - int controller ATTRIBUTE_UNUSED, + unsigned int controller ATTRIBUTE_UNUSED, const char *key ATTRIBUTE_UNUSED, char **path ATTRIBUTE_UNUSED) { diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h index c7fdaaede4..ee3b7c7222 100644 --- a/src/util/vircgroup.h +++ b/src/util/vircgroup.h @@ -114,7 +114,7 @@ void virCgroupFree(virCgroupPtr *group); =20 bool virCgroupHasController(virCgroupPtr cgroup, int controller); int virCgroupPathOfController(virCgroupPtr group, - int controller, + unsigned int controller, const char *key, char **path); =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list