From nobody Sun Feb 8 07:58:22 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1604407444; cv=none; d=zohomail.com; s=zohoarc; b=SQluoEqtKzmwV70457lLOn8g2mvqFk5sl+v2HNbYLQ+EO0h+Yv5v8kSGSwRB+/ol/EVvtbm08mr6KmsQZDGSBjNtLVg+4WhsldrwoD7xHHkFAFQ9TJndZpb3IRp2bI1N6LEcEMr+xVUSt+1J5To743+RcXranJ8vsSH0Rgi0aI4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604407444; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=PD8OtCtjyCty3Fz1wmVUjh4IwI+zrLK39ECqecFHj84=; b=fn7Vp77SjPl9PDp5fEfnwn6+dRG99YllT/u7wnCO5R8TKFc+HFXxK/l0ul84JhEr5DI3T7N4qYpRtGKqfCWkeadM+eDSKbG9qRnKanKFQja4nbk7Uh3UzWtjnNtYBQzgDO88JrcP0EqsathJZrKWYafd+Sd+miQAy9yQBksszQ4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1604407444094420.90152359363594; Tue, 3 Nov 2020 04:44:04 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-171-3jLsLTdJPVSJjTwkFy3nWA-1; Tue, 03 Nov 2020 07:42:27 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 822F5186DD31; Tue, 3 Nov 2020 12:42:21 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5FEC65DA33; Tue, 3 Nov 2020 12:42:21 +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 2FED0181A89B; Tue, 3 Nov 2020 12:42:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0A3Cg3Rk016262 for ; Tue, 3 Nov 2020 07:42:03 -0500 Received: by smtp.corp.redhat.com (Postfix) id BE3FE73667; Tue, 3 Nov 2020 12:42:03 +0000 (UTC) Received: from antique-work.redhat.com (unknown [10.40.192.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 382FF73664 for ; Tue, 3 Nov 2020 12:42:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604407443; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=PD8OtCtjyCty3Fz1wmVUjh4IwI+zrLK39ECqecFHj84=; b=VO+ReiQG9/URx3k0W4CJ/X49gQoADbWroev2qLOCKdVUzbXjiDQEIC3GKG2bCNrNEgv32n Tp9BbxL7/eChgf6iU7C5ppXWgPtrDHgdzxhy7JqLk9ELHF4xTWtWQgmkZ5lThWeB2ezkP0 GwWaCC0g4kcZWgYE/HmXPjogHTZezX0= X-MC-Unique: 3jLsLTdJPVSJjTwkFy3nWA-1 From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH 20/25] vircgroup: introduce virCgroupSetPlacement Date: Tue, 3 Nov 2020 13:41:32 +0100 Message-Id: <144f9fdf53d91e2453cbc00dce8ffce5e5e07c68.1604407065.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Currently this task is done by virCgroupCopyPlacement when the @path starts with "/". virCgroupNew is always called with @path starting with "/" and there is no parent to copy path from. To make it obvious what the code is doing introduce new helper. Signed-off-by: Pavel Hrdina --- src/util/vircgroup.c | 19 ++++++++++++++++++- src/util/vircgroupbackend.h | 5 +++++ src/util/vircgroupv1.c | 21 +++++++++++++++++++++ src/util/vircgroupv2.c | 11 +++++++++++ 4 files changed, 55 insertions(+), 1 deletion(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 6a34eb4037..00967ea5fa 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -393,6 +393,23 @@ virCgroupDetectPlacement(virCgroupPtr group, } =20 =20 +static int +virCgroupSetPlacement(virCgroupPtr group, + const char *path) +{ + size_t i; + + for (i =3D 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) { + if (group->backends[i] && + group->backends[i]->setPlacement(group, path) < 0) { + return -1; + } + } + + return 0; +} + + static int virCgroupValidatePlacement(virCgroupPtr group, pid_t pid) @@ -689,7 +706,7 @@ virCgroupNew(const char *path, if (virCgroupDetectMounts(newGroup) < 0) return -1; =20 - if (virCgroupCopyPlacement(newGroup, path, NULL) < 0) + if (virCgroupSetPlacement(newGroup, path) < 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 f677157a91..4ca2e38af2 100644 --- a/src/util/vircgroupbackend.h +++ b/src/util/vircgroupbackend.h @@ -88,6 +88,10 @@ typedef int const char *controllers, const char *selfpath); =20 +typedef int +(*virCgroupSetPlacementCB)(virCgroupPtr group, + const char *path); + typedef int (*virCgroupValidatePlacementCB)(virCgroupPtr group, pid_t pid); @@ -369,6 +373,7 @@ struct _virCgroupBackend { virCgroupCopyPlacementCB copyPlacement; virCgroupDetectMountsCB detectMounts; virCgroupDetectPlacementCB detectPlacement; + virCgroupSetPlacementCB setPlacement; virCgroupValidatePlacementCB validatePlacement; virCgroupStealPlacementCB stealPlacement; virCgroupDetectControllersCB detectControllers; diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index 98b5aa047d..ed4b0813f2 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -364,6 +364,26 @@ virCgroupV1DetectPlacement(virCgroupPtr group, } =20 =20 +static int +virCgroupV1SetPlacement(virCgroupPtr group, + const char *path) +{ + size_t i; + + for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { + if (!group->legacy[i].mountPoint) + continue; + + if (i =3D=3D VIR_CGROUP_CONTROLLER_SYSTEMD) + continue; + + group->legacy[i].placement =3D g_strdup(path); + } + + return 0; +} + + static int virCgroupV1ValidatePlacement(virCgroupPtr group, pid_t pid) @@ -2101,6 +2121,7 @@ virCgroupBackend virCgroupV1Backend =3D { .copyPlacement =3D virCgroupV1CopyPlacement, .detectMounts =3D virCgroupV1DetectMounts, .detectPlacement =3D virCgroupV1DetectPlacement, + .setPlacement =3D virCgroupV1SetPlacement, .validatePlacement =3D virCgroupV1ValidatePlacement, .stealPlacement =3D virCgroupV1StealPlacement, .detectControllers =3D virCgroupV1DetectControllers, diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index 0467a72566..8e058ca9c6 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -223,6 +223,16 @@ virCgroupV2DetectPlacement(virCgroupPtr group, } =20 =20 +static int +virCgroupV2SetPlacement(virCgroupPtr group, + const char *path) +{ + group->unified.placement =3D g_strdup(path); + + return 0; +} + + static int virCgroupV2ValidatePlacement(virCgroupPtr group, pid_t pid G_GNUC_UNUSED) @@ -1845,6 +1855,7 @@ virCgroupBackend virCgroupV2Backend =3D { .copyPlacement =3D virCgroupV2CopyPlacement, .detectMounts =3D virCgroupV2DetectMounts, .detectPlacement =3D virCgroupV2DetectPlacement, + .setPlacement =3D virCgroupV2SetPlacement, .validatePlacement =3D virCgroupV2ValidatePlacement, .stealPlacement =3D virCgroupV2StealPlacement, .detectControllers =3D virCgroupV2DetectControllers, --=20 2.26.2