From nobody Sun Feb 8 18:24:27 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=1604407334; cv=none; d=zohomail.com; s=zohoarc; b=fPmAEhLt5zQ/3mjyCjFG0fHn3obwUMNiLq+/xv2D1Jhc4NnSZZ52pRiwcxsgHxDYFeIe36otoXcILpYXBGoGAHGVKNNOyPoUk27Z6sZToz/sw50Qxtux52ISyiGMEt6cVMARYYTgvzf6zey2TOqfGucXHMLMdOvcmiHgNzoMVkA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604407334; 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=KGZ23UDi/H4TSPPrquy5AqtHZ5MfRd2ZeluZ1r/7vas=; b=JSKWiziQXd+RqzooTVGyYjT6TALq9DsQFbwElNeUB/J9eiq1jITLa66MNfm2+QwqWwKH5FugacTJlW0FEb59H3CK6i+/QX1DwRxnHTM2lkaTDwaHUqXmhrSx6WmXf0FXLlRP4b5X4vP3fPgRbtBTo2nc9JS5b4/+rLz2nsUwFd8= 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 160440733426168.82581169518471; Tue, 3 Nov 2020 04:42:14 -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-385-YDuhOH3FP7i4sgZzQmq9tQ-1; Tue, 03 Nov 2020 07:42:10 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E60ED800597; Tue, 3 Nov 2020 12:42:04 +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 C344D7512C; Tue, 3 Nov 2020 12:42:04 +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 8BC088C7CD; Tue, 3 Nov 2020 12:42:04 +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 0A3CfkqO015871 for ; Tue, 3 Nov 2020 07:41:46 -0500 Received: by smtp.corp.redhat.com (Postfix) id C22C01C4; Tue, 3 Nov 2020 12:41:46 +0000 (UTC) Received: from antique-work.redhat.com (unknown [10.40.192.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3DB7373667 for ; Tue, 3 Nov 2020 12:41:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604407333; 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=KGZ23UDi/H4TSPPrquy5AqtHZ5MfRd2ZeluZ1r/7vas=; b=SgRlWPkJ6ggNvFUnES6ITXD+/ofjyQ55vcY6FhziwmJu8ASSGD6p8eBruccByvbuAin4sw VdY0PIITuO0PaJ7xrFPHuHJZHaIu1FkIbWnmXP2kOPKHQ1IlAHGkYLRSQeg2Fiun9Hf+if imBnTg/CbvsokMMRzAk4UQ3F0D3prdQ= X-MC-Unique: YDuhOH3FP7i4sgZzQmq9tQ-1 From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH 05/25] vircgroupv2: properly detect placement of running VM Date: Tue, 3 Nov 2020 13:41:17 +0100 Message-Id: <89ff8c8c1a0ab6739f5a007cf47a0649731b7683.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.15 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 libvirtd starts a VM it internally stores a path to the main cgroup. When we restart libvirtd we should get to the same state. When we start a VM on host with systemd the cgroup is created for us and the process is already placed into that cgroup and we detect the path created by systemd using /proc/$PID/cgroup. After that we create sub-cgroups and move all threads there. Once libvirtd is restarted we again detect the cgroup path using /proc/$PID/cgroup, but in this case we will get a different path because the main thread was moved to a "emulator" cgroup. Instead of ignoring the "emulator" directory when validating cgroups remove it completely when detecting cgroup otherwise cgroups will not work properly when libvirtd is restarted. Signed-off-by: Pavel Hrdina --- src/util/vircgroupv2.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index 65f5cc6bd0..fb97b7fd2a 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -122,12 +122,6 @@ virCgroupV2ValidateMachineGroup(virCgroupPtr group, if (!(tmp =3D strrchr(group->unified.placement, '/'))) return false; =20 - if (STREQ(tmp, "/emulator")) { - *tmp =3D '\0'; - - if (!(tmp =3D strrchr(group->unified.placement, '/'))) - return false; - } tmp++; =20 if (STRNEQ(tmp, partmachinename) && @@ -198,6 +192,9 @@ virCgroupV2DetectPlacement(virCgroupPtr group, const char *controllers, const char *selfpath) { + g_autofree char *placement =3D g_strdup(selfpath); + char *tmp =3D NULL; + if (group->unified.placement) return 0; =20 @@ -208,12 +205,18 @@ virCgroupV2DetectPlacement(virCgroupPtr group, if (STRNEQ(controllers, "")) return 0; =20 + /* Running VM will have the main thread placed in emulator cgroup + * but we need to get the main cgroup. */ + tmp =3D g_strrstr(placement, "/emulator"); + if (tmp) + *tmp =3D '\0'; + /* * selfpath =3D=3D "/" + path=3D"" -> "/" * selfpath =3D=3D "/libvirt.service" + path =3D=3D "" -> "/libvirt.se= rvice" * selfpath =3D=3D "/libvirt.service" + path =3D=3D "foo" -> "/libvirt= .service/foo" */ - group->unified.placement =3D g_strdup_printf("%s%s%s", selfpath, + group->unified.placement =3D g_strdup_printf("%s%s%s", placement, (STREQ(selfpath, "/") || ST= REQ(path, "") ? "" : "/"), path); =20 return 0; --=20 2.26.2