From nobody Mon Feb 9 13:38:35 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1612877285; cv=none; d=zohomail.com; s=zohoarc; b=FRM1GEx7NWgcLNg3WPEDURIN5AotaCXPaKnTTeZ5FH36etdlKHnFIdec7flrwZjZ1CWxxVNH4MUdt6gWwERHZ/EkmW53aBx4EYsT+47DOJKi9gcuDlebNK6QVUA08IkD7u2xzdeqT4yPnfl+uFz6IARs53ne/LYFCH0sU6Z0rgg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612877285; 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=Mmu8akFlqxJ6NN2qa/gf5SAhyJDdT5c7nwQ7D/cAy/c=; b=A034B15ChC5aM8Te57e3QwaXLWj34YXXbveE9scKnXwUVOjNudyQdTWCiHNtoTRkV+L2R56/lyWSlWUIxtPKVwuZ+If1xT9HCCmpVClW4Wxbsv+aXgpG2vcBJiVkPOGX6qHLvOBP0YSHFf/BFYaDurVz5WRpb4UjU4UJTjYCqpo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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 [216.205.24.124]) by mx.zohomail.com with SMTPS id 1612877284866795.7695249262416; Tue, 9 Feb 2021 05:28: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-196-NEkcTmF1PROZGAKl2RvK4A-1; Tue, 09 Feb 2021 08:26:49 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id ED9DC1020C28; Tue, 9 Feb 2021 13:26:43 +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 C9D2560C62; Tue, 9 Feb 2021 13:26:43 +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 90F2158079; Tue, 9 Feb 2021 13:26:43 +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 119DQQYt020445 for ; Tue, 9 Feb 2021 08:26:26 -0500 Received: by smtp.corp.redhat.com (Postfix) id 383A95D9CD; Tue, 9 Feb 2021 13:26:26 +0000 (UTC) Received: from antique-laptop.redhat.com (unknown [10.40.208.58]) by smtp.corp.redhat.com (Postfix) with ESMTP id 96C315D9C0 for ; Tue, 9 Feb 2021 13:26:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612877283; 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=Mmu8akFlqxJ6NN2qa/gf5SAhyJDdT5c7nwQ7D/cAy/c=; b=ikGTC/Of46vQo39qyDy6LPdQbWQDSa7zkILIDzEaFAm/EobOdplarHo1yM0mnStebEXn8e nmZgTwHFcFJk4vE9FLFA66LZi/4HhKhYeQOoDbiSvGuLVNPoUVPqI8Y73D1hC7Xoq4vVw/ ui7OqfJHNW+Tk7Suj9zLOag7W6H2uq8= X-MC-Unique: NEkcTmF1PROZGAKl2RvK4A-1 From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH 6/9] vircgroupv2: move task into cgroup before enabling controllers Date: Tue, 9 Feb 2021 14:26:11 +0100 Message-Id: <687cb6f987e513ab63bab117a9a31cfd0ae13a06.1612875677.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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.12 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" When we create a new child cgroup and the parent cgroup has any process attached to it enabling controllers for the child cgroup fails with error. We need to move the process into the child cgroup first before enabling any controllers. Signed-off-by: Pavel Hrdina --- src/util/vircgroup.c | 11 ++++++----- src/util/vircgroupbackend.h | 1 + src/util/vircgroupv1.c | 1 + src/util/vircgroupv2.c | 13 +++++++++++++ 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 7a0e14eb73..44a3064876 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -694,13 +694,14 @@ static int virCgroupMakeGroup(virCgroupPtr parent, virCgroupPtr group, bool create, + pid_t pid, unsigned int flags) { size_t i; =20 for (i =3D 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) { if (group->backends[i] && - group->backends[i]->makeGroup(parent, group, create, flags) < = 0) { + group->backends[i]->makeGroup(parent, group, create, pid, flag= s) < 0) { virCgroupRemove(group); return -1; } @@ -970,7 +971,7 @@ virCgroupNewPartition(const char *path, return -1; =20 if (parent) { - if (virCgroupMakeGroup(parent, newGroup, create, VIR_CGROUP_NONE) = < 0) + if (virCgroupMakeGroup(parent, newGroup, create, -1, VIR_CGROUP_NO= NE) < 0) return -1; } =20 @@ -1033,7 +1034,7 @@ virCgroupNewDomainPartition(virCgroupPtr partition, * a group for driver, is to avoid overhead to track * cumulative usage that we don't need. */ - if (virCgroupMakeGroup(partition, newGroup, true, + if (virCgroupMakeGroup(partition, newGroup, true, -1, VIR_CGROUP_MEM_HIERACHY) < 0) { return -1; } @@ -1090,7 +1091,7 @@ virCgroupNewThread(virCgroupPtr domain, if (virCgroupNewFromParent(domain, name, controllers, &newGroup) < 0) return -1; =20 - if (virCgroupMakeGroup(domain, newGroup, create, VIR_CGROUP_THREAD) < = 0) + if (virCgroupMakeGroup(domain, newGroup, create, -1, VIR_CGROUP_THREAD= ) < 0) return -1; =20 *group =3D g_steal_pointer(&newGroup); @@ -1192,7 +1193,7 @@ virCgroupEnableMissingControllers(char *path, &tmp) < 0) return -1; =20 - if (virCgroupMakeGroup(parent, tmp, true, VIR_CGROUP_SYSTEMD) < 0) + if (virCgroupMakeGroup(parent, tmp, true, -1, VIR_CGROUP_SYSTEMD) = < 0) return -1; =20 virCgroupFree(parent); diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h index 4ca2e38af2..497dde5625 100644 --- a/src/util/vircgroupbackend.h +++ b/src/util/vircgroupbackend.h @@ -122,6 +122,7 @@ typedef int (*virCgroupMakeGroupCB)(virCgroupPtr parent, virCgroupPtr group, bool create, + pid_t pid, unsigned int flags); =20 typedef int diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index f4dd20fd73..51ada12f6e 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -622,6 +622,7 @@ static int virCgroupV1MakeGroup(virCgroupPtr parent, virCgroupPtr group, bool create, + pid_t pid G_GNUC_UNUSED, unsigned int flags) { size_t i; diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index 3f3e5ac83d..d590f83187 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -406,10 +406,17 @@ virCgroupV2EnableController(virCgroupPtr group, } =20 =20 +static int +virCgroupV2AddTask(virCgroupPtr group, + pid_t pid, + unsigned int flags); + + static int virCgroupV2MakeGroup(virCgroupPtr parent, virCgroupPtr group, bool create, + pid_t pid, unsigned int flags) { g_autofree char *path =3D NULL; @@ -455,6 +462,12 @@ virCgroupV2MakeGroup(virCgroupPtr parent, } } else { size_t i; + + if (pid > 0) { + if (virCgroupV2AddTask(group, pid, VIR_CGROUP_TASK_PROCESS= ) < 0) + return -1; + } + for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { int rc; =20 --=20 2.29.2