From nobody Sun Apr 28 19:40:38 2024 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=1612877194; cv=none; d=zohomail.com; s=zohoarc; b=eahcxUWLlatzSEDYQhwbsttgiIOLJpG0LL6rSq/SBXikwHyF2TaRjSv/va4HK3Dgq0mk8zCpnl6we34OTgsESw/JuSQspEr4p7oo0US878n1miMJMcjbY9SRawKOVUKiko/OwVimnPwbp9Tfy1opA+BE4G0KCwhjQerfBkVCRB0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612877194; 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=7MwQBdz6f3ocMdSeCSXxz58ocXD+ZREN2CM6QgOnqjs=; b=g7xOUX5JukOJqYjfbheUqIsZmHnr+manc6zPmZfqSgkc5xBZqL2Pcw0vq2TMUNQjSzxz3R8SOOryU3oF9tehJb+sp6UTyx+wld3+uu7d69in0tDPDoLCo8MewoCNgTK81eGGRh7QOsgciFUX7zBFwCR6SF2Vq7RLIJjzcKalPio= 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 1612877194447781.2107180046936; Tue, 9 Feb 2021 05:26:34 -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-114-N9E_iMdaP8GsZoph4j51mg-1; Tue, 09 Feb 2021 08:26:30 -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 CFF391934105; Tue, 9 Feb 2021 13:26:24 +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 DC9ED5D9CD; Tue, 9 Feb 2021 13:26:23 +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 8085449; Tue, 9 Feb 2021 13:26:22 +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 119DQKxK020388 for ; Tue, 9 Feb 2021 08:26:20 -0500 Received: by smtp.corp.redhat.com (Postfix) id 8DA775D9CD; Tue, 9 Feb 2021 13:26:20 +0000 (UTC) Received: from antique-laptop.redhat.com (unknown [10.40.208.58]) by smtp.corp.redhat.com (Postfix) with ESMTP id E99885D9C0 for ; Tue, 9 Feb 2021 13:26:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612877192; 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=7MwQBdz6f3ocMdSeCSXxz58ocXD+ZREN2CM6QgOnqjs=; b=bh66PcIQlRjfS09TvP17SHfibZPh6a1wUGqK07jlx3VykLQ3sRpYZhoP82h32tcC5RrTiN 1byCW34Y9ZSic9Qz1x56HfJ7hW9SfIHgTGxRCPg/XMAL0piBfsDSKtWugKhFOhhgSEiuU0 8VA793Il+C3Fzdnd+oGARqNulo27wpQ= X-MC-Unique: N9E_iMdaP8GsZoph4j51mg-1 From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH 1/9] virsystemd: export virSystemdHasMachined Date: Tue, 9 Feb 2021 14:26:06 +0100 Message-Id: <8af523ac102f190da88671f37e3cd320193c3355.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.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" Signed-off-by: Pavel Hrdina Reviewed-by: Michal Privoznik --- src/libvirt_private.syms | 1 + src/util/virsystemd.c | 2 +- src/util/virsystemd.h | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 0636b0d8c9..b2d2282ce0 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3304,6 +3304,7 @@ virSystemdGetActivation; virSystemdGetMachineNameByPID; virSystemdHasLogind; virSystemdHasLogindResetCachedValue; +virSystemdHasMachined; virSystemdHasMachinedResetCachedValue; virSystemdMakeScopeName; virSystemdMakeSliceName; diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c index 3f689365e4..58b5c650b5 100644 --- a/src/util/virsystemd.c +++ b/src/util/virsystemd.c @@ -147,7 +147,7 @@ void virSystemdHasLogindResetCachedValue(void) * -1 =3D error * 0 =3D machine1 is available */ -static int +int virSystemdHasMachined(void) { int ret; diff --git a/src/util/virsystemd.h b/src/util/virsystemd.h index dfea75948b..9ce16b7de1 100644 --- a/src/util/virsystemd.h +++ b/src/util/virsystemd.h @@ -57,6 +57,8 @@ int virSystemdTerminateMachine(const char *name); =20 void virSystemdNotifyStartup(void); =20 +int virSystemdHasMachined(void); + int virSystemdHasLogind(void); =20 int virSystemdCanSuspend(bool *result); --=20 2.29.2 From nobody Sun Apr 28 19:40:38 2024 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=1612877194; cv=none; d=zohomail.com; s=zohoarc; b=j7LNueg7UX0sPq7B6rrO/l22dkPJj20nJM49TpuX1SALj+imvpNxgYeUY+m2RSwWZTS0qqGHixCq8VT4/xNqnWR7KUcKFLfuz41psOQPArQ6uaKU1Bk5g+4+9ueEwT5nuToB00mcYylDTJHII7VbyqpUArL9deUtf0drmqxPOPk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612877194; 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=YfI2L06V4wiB49NPdhNrJjM3FzZEP5M5LQafyg4AkLA=; b=PNz8GP/AB9Rp8aY1kyz04LnKhSsSxOLcwT90ClYGBD7cAfVT6GKmPemhJMd7DesSRzuhgfCW466qJWl+yS4LKtwM4FMLaE1RBa4emP+6/1bUYO8+lMupI11aPIeqLrXXVzfYONCeyjrGvVIhIbeG1rNZDnCCR1PNhSk6dp7lVco= 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 1612877194416761.1379964940674; Tue, 9 Feb 2021 05:26:34 -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-142-X6j7MkpJP0aM0qeqyxOppQ-1; Tue, 09 Feb 2021 08:26:31 -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 53B8A1934106; Tue, 9 Feb 2021 13:26:25 +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 C4C115D736; Tue, 9 Feb 2021 13:26:24 +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 BF9C7A6EE; Tue, 9 Feb 2021 13:26:23 +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 119DQLt8020399 for ; Tue, 9 Feb 2021 08:26:21 -0500 Received: by smtp.corp.redhat.com (Postfix) id C8E885D9CD; Tue, 9 Feb 2021 13:26:21 +0000 (UTC) Received: from antique-laptop.redhat.com (unknown [10.40.208.58]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3104F5D9C0 for ; Tue, 9 Feb 2021 13:26:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612877193; 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=YfI2L06V4wiB49NPdhNrJjM3FzZEP5M5LQafyg4AkLA=; b=H1G8JQj+dSJ+Lo5XjmJ0DQ2kiniQxfydHrPJzslkLv7/Sx/9zO2xXOK9B8of5ru6hUla7a Rz74TJoFTw2r5hQZM3SaC4pn+jISpstZAxC+OwA534U6NM0RR9VT1OV1SlbhfUwY/RQ7SP dn+y0+/j7+g/i9+uZ9myUBvJNzUp5qo= X-MC-Unique: X6j7MkpJP0aM0qeqyxOppQ-1 From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH 2/9] virsystemd: introduce virSystemdGetMachineByPID Date: Tue, 9 Feb 2021 14:26:07 +0100 Message-Id: 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.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" Signed-off-by: Pavel Hrdina Reviewed-by: Michal Privoznik --- src/util/virsystemd.c | 52 ++++++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c index 58b5c650b5..d2fcf0bf0c 100644 --- a/src/util/virsystemd.c +++ b/src/util/virsystemd.c @@ -194,21 +194,21 @@ virSystemdHasLogind(void) } =20 =20 -char * -virSystemdGetMachineNameByPID(pid_t pid) +/** + * virSystemdGetMachineByPID: + * @conn: dbus connection + * @pid: pid of running VM + * + * Returns dbus object path to VM registered with machined. + * On error returns NULL. + */ +static char * +virSystemdGetMachineByPID(GDBusConnection *conn, + pid_t pid) { - GDBusConnection *conn; g_autoptr(GVariant) message =3D NULL; g_autoptr(GVariant) reply =3D NULL; - g_autoptr(GVariant) gvar =3D NULL; - g_autofree char *object =3D NULL; - char *name =3D NULL; - - if (virSystemdHasMachined() < 0) - return NULL; - - if (!(conn =3D virGDBusGetSystemBus())) - return NULL; + char *object =3D NULL; =20 message =3D g_variant_new("(u)", pid); =20 @@ -225,13 +225,33 @@ virSystemdGetMachineNameByPID(pid_t pid) =20 g_variant_get(reply, "(o)", &object); =20 - g_variant_unref(reply); - reply =3D NULL; - VIR_DEBUG("Domain with pid %lld has object path '%s'", (long long) pid, object); =20 - g_variant_unref(message); + return object; +} + + +char * +virSystemdGetMachineNameByPID(pid_t pid) +{ + GDBusConnection *conn; + g_autoptr(GVariant) message =3D NULL; + g_autoptr(GVariant) reply =3D NULL; + g_autoptr(GVariant) gvar =3D NULL; + g_autofree char *object =3D NULL; + char *name =3D NULL; + + if (virSystemdHasMachined() < 0) + return NULL; + + if (!(conn =3D virGDBusGetSystemBus())) + return NULL; + + object =3D virSystemdGetMachineByPID(conn, pid); + if (!object) + return NULL; + message =3D g_variant_new("(ss)", "org.freedesktop.machine1.Machine", "Name"); =20 --=20 2.29.2 From nobody Sun Apr 28 19:40:38 2024 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=1612877204; cv=none; d=zohomail.com; s=zohoarc; b=Tn5V16G2rv7xNj4F70B9G52EJd55TZa6YVpxhos7tHGpS5I42Cv0sKAr94sVC7eb3e6egBhm2kFmUhlHNRMIYYhFDJhJQ0q9SkvI4s1/BWq3e1j4GoIP9NxWmUsmZawyZm3GK01bOt+B/knjC9578Hr8LBROVUJPqoomABe2zro= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612877204; 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=HOiTXP5kbNibnyalijZsCfNG3fQG+viJ6OIXU15B/Ck=; b=BzV78m4LqKITjpLO3hUynqG5BwFQxNOclhGM+66eOu7i9RAUJefeZckz9n9uzbknm3D3xY1EGvekIxCLsRdxfnlfuTQqyYrCxOC1OvBof1OY14Vnqzc2PXW2EguWe7QILx9T8u2kuhDIlzhVQDRYTNA8Bb0yKGJLPkT4wdNUhEY= 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 161287720370185.27349275977224; Tue, 9 Feb 2021 05:26:43 -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-562-V-pLUSThMuK6fjhUq9OOtg-1; Tue, 09 Feb 2021 08:26:41 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 77E8B80196E; Tue, 9 Feb 2021 13:26:35 +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 C5C1D60CC4; Tue, 9 Feb 2021 13:26:34 +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 999FB1809C8F; Tue, 9 Feb 2021 13:26:33 +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 119DQMFk020409 for ; Tue, 9 Feb 2021 08:26:22 -0500 Received: by smtp.corp.redhat.com (Postfix) id D9F745D9CD; Tue, 9 Feb 2021 13:26:22 +0000 (UTC) Received: from antique-laptop.redhat.com (unknown [10.40.208.58]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3C1435D9C0 for ; Tue, 9 Feb 2021 13:26:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612877202; 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=HOiTXP5kbNibnyalijZsCfNG3fQG+viJ6OIXU15B/Ck=; b=ioJmkaTOJPxOhSUDtAEvpvQt5ljXCZTt+3sD6n8TklR6+SL4WWc3TsfmPZjBsO0GTG14kx /15bBMiH5PJK6Y45C/tCsjJiIv/Mm0LqsNZ01xQP/GfEwZl94DuyWzI8PJx+2YFiBPXqM7 4qLZWdvboM+zRvBvHELz6n5p8gG0yBU= X-MC-Unique: V-pLUSThMuK6fjhUq9OOtg-1 From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH 3/9] virsystemd: introduce virSystemdGetMachineUnitByPID Date: Tue, 9 Feb 2021 14:26:08 +0100 Message-Id: <07d5f5519b3b85ed34e9752aea3d664d06c7ed99.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.13 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" Signed-off-by: Pavel Hrdina Reviewed-by: Michal Privoznik --- src/libvirt_private.syms | 1 + src/util/virsystemd.c | 51 ++++++++++++++++++++++++++++++++++++++++ src/util/virsystemd.h | 2 ++ tests/virsystemdtest.c | 39 ++++++++++++++++++++++++++---- 4 files changed, 88 insertions(+), 5 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index b2d2282ce0..837986845f 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3302,6 +3302,7 @@ virSystemdCanSuspend; virSystemdCreateMachine; virSystemdGetActivation; virSystemdGetMachineNameByPID; +virSystemdGetMachineUnitByPID; virSystemdHasLogind; virSystemdHasLogindResetCachedValue; virSystemdHasMachined; diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c index d2fcf0bf0c..c109324e96 100644 --- a/src/util/virsystemd.c +++ b/src/util/virsystemd.c @@ -276,6 +276,57 @@ virSystemdGetMachineNameByPID(pid_t pid) } =20 =20 +/** + * virSystemdGetMachineUnitByPID: + * @pid: pid of running VM + * + * Returns systemd Unit name of a running VM registered with machined. + * On error returns NULL. + */ +char * +virSystemdGetMachineUnitByPID(pid_t pid) +{ + GDBusConnection *conn; + g_autoptr(GVariant) message =3D NULL; + g_autoptr(GVariant) reply =3D NULL; + g_autoptr(GVariant) gvar =3D NULL; + g_autofree char *object =3D NULL; + char *unit =3D NULL; + + if (virSystemdHasMachined() < 0) + return NULL; + + if (!(conn =3D virGDBusGetSystemBus())) + return NULL; + + object =3D virSystemdGetMachineByPID(conn, pid); + if (!object) + return NULL; + + message =3D g_variant_new("(ss)", + "org.freedesktop.machine1.Machine", "Unit"); + + if (virGDBusCallMethod(conn, + &reply, + G_VARIANT_TYPE("(v)"), + NULL, + "org.freedesktop.machine1", + object, + "org.freedesktop.DBus.Properties", + "Get", + message) < 0) + return NULL; + + g_variant_get(reply, "(v)", &gvar); + g_variant_get(gvar, "s", &unit); + + VIR_DEBUG("Domain with pid %lld has unit name '%s'", + (long long) pid, unit); + + return unit; +} + + /** * virSystemdCreateMachine: * @name: driver unique name of the machine diff --git a/src/util/virsystemd.h b/src/util/virsystemd.h index 9ce16b7de1..cd329c49f9 100644 --- a/src/util/virsystemd.h +++ b/src/util/virsystemd.h @@ -69,6 +69,8 @@ int virSystemdCanHybridSleep(bool *result); =20 char *virSystemdGetMachineNameByPID(pid_t pid); =20 +char *virSystemdGetMachineUnitByPID(pid_t pid); + int virSystemdGetActivation(virSystemdActivationMap *map, size_t nmap, virSystemdActivationPtr *act); diff --git a/tests/virsystemdtest.c b/tests/virsystemdtest.c index bd0ca51140..b48cdb950c 100644 --- a/tests/virsystemdtest.c +++ b/tests/virsystemdtest.c @@ -53,11 +53,10 @@ VIR_MOCK_WRAP_RET_ARGS(g_dbus_connection_call_sync, GError **, error) { GVariant *reply =3D NULL; + g_autoptr(GVariant) params =3D parameters; =20 - if (parameters) { - g_variant_ref_sink(parameters); - g_variant_unref(parameters); - } + if (params) + g_variant_ref_sink(params); =20 VIR_MOCK_REAL_INIT(g_dbus_connection_call_sync); =20 @@ -71,7 +70,19 @@ VIR_MOCK_WRAP_RET_ARGS(g_dbus_connection_call_sync, reply =3D g_variant_new("(o)", "/org/freedesktop/machine1/machine/q= emu_2ddemo"); } else if (STREQ(method_name, "Get")) { - reply =3D g_variant_new("(v)", g_variant_new_string("qemu-= demo")); + const char *prop; + g_variant_get(params, "(@s&s)", NULL, &prop); + + if (STREQ(prop, "Name")) { + reply =3D g_variant_new("(v)", g_variant_new_string("q= emu-demo")); + } else if (STREQ(prop, "Unit")) { + reply =3D g_variant_new("(v)", + g_variant_new_string("machine-qe= mu-demo.scope")); + } else { + *error =3D g_dbus_error_new_for_dbus_error( + "org.freedesktop.systemd.badthing", + "Unknown machine property"); + } } else { reply =3D g_variant_new("()"); } @@ -330,6 +341,23 @@ testGetMachineName(const void *opaque G_GNUC_UNUSED) } =20 =20 +static int +testGetMachineUnit(const void *opaque G_GNUC_UNUSED) +{ + g_autofree char *tmp =3D virSystemdGetMachineUnitByPID(1234); + + if (!tmp) { + fprintf(stderr, "%s", "Failed to create get machine unit\n"); + return -1; + } + + if (STREQ(tmp, "machine-qemu-demo.scope")) + return 0; + + return -1; +} + + struct testNameData { const char *name; const char *expected; @@ -656,6 +684,7 @@ mymain(void) DO_TEST("Test create bad systemd ", testCreateBadSystemd); DO_TEST("Test create with network ", testCreateNetwork); DO_TEST("Test getting machine name ", testGetMachineName); + DO_TEST("Test getting machine unit ", testGetMachineUnit); =20 # define TEST_SCOPE(_name, unitname, _legacy) \ do { \ --=20 2.29.2 From nobody Sun Apr 28 19:40:38 2024 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=1612877210; cv=none; d=zohomail.com; s=zohoarc; b=YrDAQebAW9sYEXDSdyt4Pz1NSCW+cE6w4rs1OVS0xMMLjOTMc2e40E3gx1zEZDqiiwM/QDBG6Knfa8qquVShfQyMQnVPlIzI4XDx/IC/wWcSItdVuZuwWZbcKTgDbGoCqV5mZhhdivyTRCQHAhP/YjQyXpVlzdZYbnqlqQvAr6o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612877210; 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=2ix0ykJZkZfjcKaDmPg3fdJ8LJl8wG6auG6PB/HK8OQ=; b=UXKEY6YGUBeTGa/pkmwcHqO9XFO9L3eLzU21IWgg8zbbVFkuJIjpIhluatTgOUjgBjhfzncnwZ8aDxJ4cs9kl7It40Z9jO8k+RNZg1Y/gU/HbnzSZhR55XCdZrwZSwT76l3OL1dUQ9fPSLX5Ym+sZ1L3WA6c361FxOMayffEhjE= 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 1612877210125637.7330183098446; Tue, 9 Feb 2021 05:26:50 -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-60-OUa9XNZYNOa463ZGo64w9Q-1; Tue, 09 Feb 2021 08:26:43 -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 34423EC1A5; Tue, 9 Feb 2021 13:26:38 +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 1098860C62; Tue, 9 Feb 2021 13:26:38 +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 CAF9B1809C91; Tue, 9 Feb 2021 13:26:37 +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 119DQNoF020417 for ; Tue, 9 Feb 2021 08:26:24 -0500 Received: by smtp.corp.redhat.com (Postfix) id F09005D9DC; Tue, 9 Feb 2021 13:26:23 +0000 (UTC) Received: from antique-laptop.redhat.com (unknown [10.40.208.58]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4D7085D9C0 for ; Tue, 9 Feb 2021 13:26:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612877209; 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=2ix0ykJZkZfjcKaDmPg3fdJ8LJl8wG6auG6PB/HK8OQ=; b=AvHDEKYA9Z/Z9YRPOzvIfBWCt3LbYbWc/G55XnWlXEmS+Z7wyUKReWNDsPNh+MPzpfANd9 nbSkBDs+NcO+9oGLHNR/gz9B4GboiDouYkNW0hzzJYYgAg9rtk5Iy1xKFPlSmxXcgcuIMH 7r9TdHNHvJ/KTcVGz6pp6Dk+RwJiAvs= X-MC-Unique: OUa9XNZYNOa463ZGo64w9Q-1 From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH 4/9] vircgroup: use DBus call to systemd for some APIs Date: Tue, 9 Feb 2021 14:26:09 +0100 Message-Id: <5fc7a2c20740527ab402d475a3801770929a793e.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 running on host with systemd we register VMs with machined. In this case systemd creates the root VM cgroup for us. This has some implications where one of them is that systemd owns all files inside the root VM cgroup and we should not touch them. If we change any value in file that systemd knows about it will be changed to what systemd thinks it should be when executing `systemctl daemon-reload`. These are the APIs that we need to call using systemd because they set limits that are proportional to sibling cgroups. Signed-off-by: Pavel Hrdina Reviewed-by: Michal Privoznik --- src/util/vircgroup.c | 41 ++++++++++++++++++++++++++++++++++ src/util/vircgrouppriv.h | 6 +++++ src/util/vircgroupv1.c | 48 ++++++++++++++++++++++++++++------------ src/util/vircgroupv2.c | 48 ++++++++++++++++++++++++++++------------ 4 files changed, 115 insertions(+), 28 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index b5c74e94de..7a0e14eb73 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -41,6 +41,7 @@ #include "virerror.h" #include "virlog.h" #include "virfile.h" +#include "virgdbus.h" #include "virhash.h" #include "virstring.h" #include "virsystemd.h" @@ -484,6 +485,37 @@ virCgroupGetBlockDevString(const char *path) } =20 =20 +int +virCgroupSetValueDBus(const char *unitName, + const char *key, + GVariant *value) +{ + GDBusConnection *conn; + g_autoptr(GVariant) message =3D NULL; + GVariantBuilder builder; + GVariant *props =3D NULL; + + g_variant_builder_init(&builder, G_VARIANT_TYPE("a(sv)")); + g_variant_builder_add(&builder, "(sv)", key, value); + props =3D g_variant_builder_end(&builder); + + message =3D g_variant_new("(sb@a(sv))", unitName, true, props); + + if (!(conn =3D virGDBusGetSystemBus())) + return -1; + + return virGDBusCallMethod(conn, + NULL, + NULL, + NULL, + "org.freedesktop.systemd1", + "/org/freedesktop/systemd1", + "org.freedesktop.systemd1.Manager", + "SetUnitProperties", + message); +} + + int virCgroupSetValueRaw(const char *path, const char *value) @@ -1129,6 +1161,10 @@ virCgroupNewDetectMachine(const char *name, } } =20 + newGroup->unitName =3D virSystemdGetMachineUnitByPID(pid); + if (virSystemdHasMachined() =3D=3D 0 && !newGroup->unitName) + return -1; + *group =3D g_steal_pointer(&newGroup); return 0; } @@ -1229,6 +1265,10 @@ virCgroupNewMachineSystemd(const char *name, if (virCgroupEnableMissingControllers(path, controllers, &newGroup) < = 0) return -1; =20 + newGroup->unitName =3D virSystemdGetMachineUnitByPID(pidleader); + if (!newGroup->unitName) + return -1; + if (virCgroupAddProcess(newGroup, pidleader) < 0) { virErrorPtr saved; =20 @@ -3588,6 +3628,7 @@ virCgroupFree(virCgroupPtr group) =20 g_free(group->unified.mountPoint); g_free(group->unified.placement); + g_free(group->unitName); =20 g_free(group); } diff --git a/src/util/vircgrouppriv.h b/src/util/vircgrouppriv.h index 85ba5393e0..f88d00814d 100644 --- a/src/util/vircgrouppriv.h +++ b/src/util/vircgrouppriv.h @@ -64,8 +64,14 @@ struct _virCgroup { =20 virCgroupV1Controller legacy[VIR_CGROUP_CONTROLLER_LAST]; virCgroupV2Controller unified; + + char *unitName; }; =20 +int virCgroupSetValueDBus(const char *unitName, + const char *key, + GVariant *value); + int virCgroupSetValueRaw(const char *path, const char *value); =20 diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index 2b4d625c35..edb2c23bbc 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -946,7 +946,6 @@ virCgroupV1SetBlkioWeight(virCgroupPtr group, unsigned int weight) { g_autofree char *path =3D NULL; - g_autofree char *value =3D NULL; =20 if (virCgroupV1PathOfController(group, VIR_CGROUP_CONTROLLER_BLKIO, "blkio.bfq.weight", &path) < 0) { @@ -968,9 +967,15 @@ virCgroupV1SetBlkioWeight(virCgroupPtr group, return -1; } =20 - value =3D g_strdup_printf("%u", weight); + if (group->unitName) { + GVariant *value =3D g_variant_new("t", weight); =20 - return virCgroupSetValueRaw(path, value); + return virCgroupSetValueDBus(group->unitName, "BlockIOWeight", val= ue); + } else { + g_autofree char *value =3D g_strdup_printf("%u", weight); + + return virCgroupSetValueRaw(path, value); + } } =20 =20 @@ -1203,15 +1208,8 @@ virCgroupV1SetBlkioDeviceWeight(virCgroupPtr group, const char *devPath, unsigned int weight) { - g_autofree char *str =3D NULL; - g_autofree char *blkstr =3D NULL; g_autofree char *path =3D NULL; =20 - if (!(blkstr =3D virCgroupGetBlockDevString(devPath))) - return -1; - - str =3D g_strdup_printf("%s%d", blkstr, weight); - if (virCgroupV1PathOfController(group, VIR_CGROUP_CONTROLLER_BLKIO, "blkio.weight_device", &path) < 0) { return -1; @@ -1223,7 +1221,23 @@ virCgroupV1SetBlkioDeviceWeight(virCgroupPtr group, return -1; } =20 - return virCgroupSetValueRaw(path, str); + if (group->unitName) { + GVariant *value =3D NULL; + + value =3D g_variant_new_parsed("[(%s, uint64 %u)]", path, weight); + + return virCgroupSetValueDBus(group->unitName, "BlockIODeviceWeight= ", value); + } else { + g_autofree char *str =3D NULL; + g_autofree char *blkstr =3D NULL; + + if (!(blkstr =3D virCgroupGetBlockDevString(devPath))) + return -1; + + str =3D g_strdup_printf("%s%d", blkstr, weight); + + return virCgroupSetValueRaw(path, str); + } } =20 =20 @@ -1862,9 +1876,15 @@ static int virCgroupV1SetCpuShares(virCgroupPtr group, unsigned long long shares) { - return virCgroupSetValueU64(group, - VIR_CGROUP_CONTROLLER_CPU, - "cpu.shares", shares); + if (group->unitName) { + GVariant *value =3D g_variant_new("t", shares); + + return virCgroupSetValueDBus(group->unitName, "CPUShares", value); + } else { + return virCgroupSetValueU64(group, + VIR_CGROUP_CONTROLLER_CPU, + "cpu.shares", shares); + } } =20 =20 diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index 4a239f067a..3f3e5ac83d 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -609,7 +609,6 @@ virCgroupV2SetBlkioWeight(virCgroupPtr group, unsigned int weight) { g_autofree char *path =3D NULL; - g_autofree char *value =3D NULL; const char *format =3D "%u"; =20 if (virCgroupV2PathOfController(group, VIR_CGROUP_CONTROLLER_BLKIO, @@ -633,9 +632,15 @@ virCgroupV2SetBlkioWeight(virCgroupPtr group, return -1; } =20 - value =3D g_strdup_printf(format, weight); + if (group->unitName) { + GVariant *value =3D g_variant_new("t", weight); =20 - return virCgroupSetValueRaw(path, value); + return virCgroupSetValueDBus(group->unitName, "IOWeight", value); + } else { + g_autofree char *value =3D g_strdup_printf(format, weight); + + return virCgroupSetValueRaw(path, value); + } } =20 =20 @@ -820,13 +825,6 @@ virCgroupV2SetBlkioDeviceWeight(virCgroupPtr group, unsigned int weight) { g_autofree char *path =3D NULL; - g_autofree char *str =3D NULL; - g_autofree char *blkstr =3D NULL; - - if (!(blkstr =3D virCgroupGetBlockDevString(devPath))) - return -1; - - str =3D g_strdup_printf("%s%d", blkstr, weight); =20 if (virCgroupV2PathOfController(group, VIR_CGROUP_CONTROLLER_BLKIO, "io.weight", &path) < 0) { @@ -839,7 +837,23 @@ virCgroupV2SetBlkioDeviceWeight(virCgroupPtr group, return -1; } =20 - return virCgroupSetValueRaw(path, str); + if (group->unitName) { + GVariant *value =3D NULL; + + value =3D g_variant_new_parsed("[(%s, uint64 %u)]", path, weight); + + return virCgroupSetValueDBus(group->unitName, "IODeviceWeight", va= lue); + } else { + g_autofree char *str =3D NULL; + g_autofree char *blkstr =3D NULL; + + if (!(blkstr =3D virCgroupGetBlockDevString(devPath))) + return -1; + + str =3D g_strdup_printf("%s%d", blkstr, weight); + + return virCgroupSetValueRaw(path, str); + } } =20 =20 @@ -1458,9 +1472,15 @@ static int virCgroupV2SetCpuShares(virCgroupPtr group, unsigned long long shares) { - return virCgroupSetValueU64(group, - VIR_CGROUP_CONTROLLER_CPU, - "cpu.weight", shares); + if (group->unitName) { + GVariant *value =3D g_variant_new("t", shares); + + return virCgroupSetValueDBus(group->unitName, "CPUWeight", value); + } else { + return virCgroupSetValueU64(group, + VIR_CGROUP_CONTROLLER_CPU, + "cpu.weight", shares); + } } =20 =20 --=20 2.29.2 From nobody Sun Apr 28 19:40:38 2024 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=1612877210; cv=none; d=zohomail.com; s=zohoarc; b=AVX1Z+h+/pKZV9PsUx2WANJwnXglzXevSSp7701m0OMOyhowwV30+ubBRBm87bj1BNDsw7iJuplTG4gy6R6gxACX2AjbKNgRjpzCJQ9lWT9M+Rk+mccdK3xmIL242aBXTAK9ItVHUeQTJAIodigH6Klqp0neEKavNElu2FYUivs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612877210; 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=PaIyRBhONHwhZdcwkY/g2X2Ns40vPYQYNxslLAqzTSU=; b=dOh5bAzW7kl3qCv4O3+9sBskQkr0g92hGNR2xICPgZt4uJtMy6UO1r/2SyJMEJ7WvPU6F2mldvAFS/jSgkoVeoQwb00QxtKnKjUctS9MYO+wim73NEuUB2er8auewOUFm6lwNL1TojQFdbxPgpmiGMAhQqn8v02g0OsLrXoN9eY= 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 1612877210689459.0053502564401; Tue, 9 Feb 2021 05:26:50 -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-384-REURWnifP5uhQaZQYJ_SNA-1; Tue, 09 Feb 2021 08:26:47 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 31AD9801979; Tue, 9 Feb 2021 13:26:41 +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 0BFA110016F6; Tue, 9 Feb 2021 13:26: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 C788918089D3; Tue, 9 Feb 2021 13:26: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 119DQPBS020434 for ; Tue, 9 Feb 2021 08:26:25 -0500 Received: by smtp.corp.redhat.com (Postfix) id 1BC8C5D9CD; Tue, 9 Feb 2021 13:26:25 +0000 (UTC) Received: from antique-laptop.redhat.com (unknown [10.40.208.58]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6955E5D9C0 for ; Tue, 9 Feb 2021 13:26:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612877209; 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=PaIyRBhONHwhZdcwkY/g2X2Ns40vPYQYNxslLAqzTSU=; b=MzecAygmefZsx4MSZCfM/T5WFM7gd06nbblUPYr3oAf6UwhV/467T1hM3zqxqcQD6y2P6H v67H3ttTPy58o9QqOnzPohKszabmY1gSqnosyqggDh0IhMkr+EtayioIanIlOAIs/aRS0o jFZzqMI69kLjogkKv3y9T9ucpgctFdg= X-MC-Unique: REURWnifP5uhQaZQYJ_SNA-1 From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH 5/9] vircgroupv1: refactor virCgroupV1DetectPlacement Date: Tue, 9 Feb 2021 14:26:10 +0100 Message-Id: <141f9ef312577b2b085c9eb6469148462be7a51b.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.84 on 10.5.11.22 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" Remove one level of indentation by splitting the condition. Signed-off-by: Pavel Hrdina Reviewed-by: Michal Privoznik --- src/util/vircgroupv1.c | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index edb2c23bbc..f4dd20fd73 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -339,23 +339,28 @@ virCgroupV1DetectPlacement(virCgroupPtr group, for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { const char *typestr =3D virCgroupV1ControllerTypeToString(i); =20 - if (virCgroupV1MountOptsMatchController(controllers, typestr) && - group->legacy[i].mountPoint !=3D NULL && - group->legacy[i].placement =3D=3D NULL) { - /* - * selfpath =3D=3D "/" + path=3D"" -> "/" - * selfpath =3D=3D "/libvirt.service" + path =3D=3D "" -> "/li= bvirt.service" - * selfpath =3D=3D "/libvirt.service" + path =3D=3D "foo" -> "= /libvirt.service/foo" - */ - if (i =3D=3D VIR_CGROUP_CONTROLLER_SYSTEMD) { - group->legacy[i].placement =3D g_strdup(selfpath); - } else { - bool delim =3D STREQ(selfpath, "/") || STREQ(path, ""); + if (!virCgroupV1MountOptsMatchController(controllers, typestr)) + continue; =20 - group->legacy[i].placement =3D g_strdup_printf("%s%s%s", s= elfpath, - delim ? "" : = "/", - path); - } + if (!group->legacy[i].mountPoint) + continue; + + if (group->legacy[i].placement) + continue; + + /* + * selfpath =3D=3D "/" + path=3D"" -> "/" + * selfpath =3D=3D "/libvirt.service" + path =3D=3D "" -> "/libvir= t.service" + * selfpath =3D=3D "/libvirt.service" + path =3D=3D "foo" -> "/lib= virt.service/foo" + */ + if (i =3D=3D VIR_CGROUP_CONTROLLER_SYSTEMD) { + group->legacy[i].placement =3D g_strdup(selfpath); + } else { + bool delim =3D STREQ(selfpath, "/") || STREQ(path, ""); + + group->legacy[i].placement =3D g_strdup_printf("%s%s%s", selfp= ath, + delim ? "" : "/", + path); } } =20 --=20 2.29.2 From nobody Sun Apr 28 19:40:38 2024 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 Reviewed-by: Michal Privoznik --- 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 From nobody Sun Apr 28 19:40:38 2024 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=1612877227; cv=none; d=zohomail.com; s=zohoarc; b=BnIeS5c9HAmqlrBZ+YUQNV8eshChTwfbhqtNjjhYOppsOWzzu28p+KLnriz2zmi4/p+jZj3oIWLYA6zyu91Nvp6dx9DGjCtvUquopkFqRFevYTarsdMN60MtgP8jJPZfLFfQgNYnYqy9NrIj9rCDMxnPHOAiHQLEV469mtcYuts= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612877227; 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=87tNlz/OwZCoQ4lJ7QLkgSjbjpb0XUG8RXpvkOrwakY=; b=bX967jp2a83dEPMhcAd3qfaX6yPqoLNb2AloCCjLRUe70gjGJd7cG/NHMKEtJvp2WEpo6KpRwnXY2TpWgVgfrf/9AVaeDIah8+UMkAZysXt9XtTDhHd6B833EAlFQA4zBSre6WIxevEkloJsnr1Vm/qA6JtbvAWnJC5z4TYdLWg= 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 1612877227250898.3963948034192; Tue, 9 Feb 2021 05:27:07 -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-437-Pey1agenNniZPkpR9CCbuQ-1; Tue, 09 Feb 2021 08:26:41 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AF33D1934100; Tue, 9 Feb 2021 13:26:35 +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 7F3A110016F6; Tue, 9 Feb 2021 13:26:35 +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 7FCDF49; Tue, 9 Feb 2021 13:26:34 +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 119DQR9g020453 for ; Tue, 9 Feb 2021 08:26:27 -0500 Received: by smtp.corp.redhat.com (Postfix) id 493175D9CD; Tue, 9 Feb 2021 13:26:27 +0000 (UTC) Received: from antique-laptop.redhat.com (unknown [10.40.208.58]) by smtp.corp.redhat.com (Postfix) with ESMTP id A59005D9C0 for ; Tue, 9 Feb 2021 13:26:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612877226; 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=87tNlz/OwZCoQ4lJ7QLkgSjbjpb0XUG8RXpvkOrwakY=; b=h/o/aX0UXzQKGoJueLQjgZTMIZjyKmn+aRRnOI2GRt7izCJe7ru0RYYWntiYc5r3JQmOKT HC5A0eTqs1wYI8sTnNM0RBbzNiUOUI5CwUyl/aXBIR50rZV2odYv1yHAMXjdctYoOsHCUw LwpI1CYV0NyEmIMu1/AJljRbROaxR50= X-MC-Unique: Pey1agenNniZPkpR9CCbuQ-1 From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH 7/9] vircgroup: introduce virCgroupV1Exists and virCgroupV2Exists Date: Tue, 9 Feb 2021 14:26:12 +0100 Message-Id: <150613e0657b8fc9ecbd59f032dd7cabb154658e.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.84 on 10.5.11.22 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" This will check if the cgroup actually exists on the system. Signed-off-by: Pavel Hrdina Reviewed-by: Michal Privoznik --- src/util/vircgroupbackend.h | 4 ++++ src/util/vircgroupv1.c | 27 +++++++++++++++++++++++++++ src/util/vircgroupv2.c | 15 +++++++++++++++ 3 files changed, 46 insertions(+) diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h index 497dde5625..a338ffb618 100644 --- a/src/util/vircgroupbackend.h +++ b/src/util/vircgroupbackend.h @@ -118,6 +118,9 @@ typedef int const char *key, char **path); =20 +typedef bool +(*virCgroupExistsCB)(virCgroupPtr group); + typedef int (*virCgroupMakeGroupCB)(virCgroupPtr parent, virCgroupPtr group, @@ -382,6 +385,7 @@ struct _virCgroupBackend { virCgroupGetAnyControllerCB getAnyController; virCgroupPathOfControllerCB pathOfController; virCgroupMakeGroupCB makeGroup; + virCgroupExistsCB exists; virCgroupRemoveCB remove; virCgroupAddTaskCB addTask; virCgroupHasEmptyTasksCB hasEmptyTasks; diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index 51ada12f6e..8a9a63e0b7 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -690,6 +690,32 @@ virCgroupV1MakeGroup(virCgroupPtr parent, } =20 =20 +static bool +virCgroupV1Exists(virCgroupPtr group) +{ + size_t i; + + for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { + g_autofree char *path =3D NULL; + + if (i =3D=3D VIR_CGROUP_CONTROLLER_SYSTEMD) + continue; + + if (!group->legacy[i].mountPoint) + continue; + + if (virCgroupV1PathOfController(group, i, "", &path) < 0) + return false; + + if (!virFileExists(path)) { + return false; + } + } + + return true; +} + + static int virCgroupV1Remove(virCgroupPtr group) { @@ -2154,6 +2180,7 @@ virCgroupBackend virCgroupV1Backend =3D { .getAnyController =3D virCgroupV1GetAnyController, .pathOfController =3D virCgroupV1PathOfController, .makeGroup =3D virCgroupV1MakeGroup, + .exists =3D virCgroupV1Exists, .remove =3D virCgroupV1Remove, .addTask =3D virCgroupV1AddTask, .hasEmptyTasks =3D virCgroupV1HasEmptyTasks, diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index d590f83187..c96f405dfa 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -499,6 +499,20 @@ virCgroupV2MakeGroup(virCgroupPtr parent, } =20 =20 +static bool +virCgroupV2Exists(virCgroupPtr group) +{ + g_autofree char *path =3D NULL; + int controller; + + controller =3D virCgroupV2GetAnyController(group); + if (virCgroupV2PathOfController(group, controller, "", &path) < 0) + return false; + + return virFileExists(path); +} + + static int virCgroupV2Remove(virCgroupPtr group) { @@ -1895,6 +1909,7 @@ virCgroupBackend virCgroupV2Backend =3D { .getAnyController =3D virCgroupV2GetAnyController, .pathOfController =3D virCgroupV2PathOfController, .makeGroup =3D virCgroupV2MakeGroup, + .exists =3D virCgroupV2Exists, .remove =3D virCgroupV2Remove, .addTask =3D virCgroupV2AddTask, .hasEmptyTasks =3D virCgroupV2HasEmptyTasks, --=20 2.29.2 From nobody Sun Apr 28 19:40:38 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1612877205; cv=none; d=zohomail.com; s=zohoarc; b=Yl63W9cEz/8gu4aipp1r0sUaJFhM1futeYVToJgpi3+FA9CGr22B/3oSn/lozk0Vn+yidi6Kyb+yNeA0+K9A9ocsbva7ZklzqKCmiu1wd4B3uhOxzf9jmbTVhnQ4s8TXyr7PVzpoOpexgXwfX0EUwV3U9VZxUYpo6hFfA0JosWc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612877205; 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=4aTjj+s5wecZNK+dInxXpKf3iK/wQXK/lmeS9KfGNDw=; b=nAvZpf+yBllXHJnzCwvEhW2cEjQvHevKzHCfMnh3A85khlcjj/BDqpHYslV5s1RX7yOj2bsbup4pKv+IJk+X6EHU3SfL5nCYFqIQYRdEdCcTDht70iI4lyR742sKqpPF8cZI37lpfrW7SY3Ufb0vAimE+wUqS9tus07FrEiqJL4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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 [170.10.133.124]) by mx.zohomail.com with SMTPS id 1612877205525954.1572403677109; Tue, 9 Feb 2021 05:26:45 -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-12-w6EicGUpMYCPQOMppSTuFg-1; Tue, 09 Feb 2021 08:26:41 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id ACC96EC1A7; Tue, 9 Feb 2021 13:26:35 +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 7F42A10016FA; Tue, 9 Feb 2021 13:26:35 +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 CA8F458074; Tue, 9 Feb 2021 13:26:34 +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 119DQSds020471 for ; Tue, 9 Feb 2021 08:26:28 -0500 Received: by smtp.corp.redhat.com (Postfix) id 9CACB5D9CD; Tue, 9 Feb 2021 13:26:28 +0000 (UTC) Received: from antique-laptop.redhat.com (unknown [10.40.208.58]) by smtp.corp.redhat.com (Postfix) with ESMTP id C12575D9C0 for ; Tue, 9 Feb 2021 13:26:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612877203; 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=4aTjj+s5wecZNK+dInxXpKf3iK/wQXK/lmeS9KfGNDw=; b=hSvueB66MbB/eF6yE3kH4HB2iJGV3IKPPXjtAqG8NHFxjzFS8zTWxLJLJdP0BOgxB1X/7q e9gSXNvW3gQS9NX2OF3oD4/X0XT3Bqm2PzwjLWHYLYN/xanlqajsDS1wyS7YdjZQg8E5XC rZVKlSGm5ScxLnlOhtSb4DnaU1Uw3Lw= X-MC-Unique: w6EicGUpMYCPQOMppSTuFg-1 From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH 8/9] vircgroup: introduce nested cgroup to properly work with systemd Date: Tue, 9 Feb 2021 14:26:13 +0100 Message-Id: <3a88c06d0e54b5f6b2f1db6d0d38a7fe51b23dc0.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.84 on 10.5.11.22 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 running on host with systemd we register VMs with machined. In this case systemd creates the root VM cgroup for us. This has some implications where one of them is that systemd owns all files inside the root VM cgroup and we should not touch them. We already use DBus calls for some of the APIs but for the remaining ones we will continue accessing the files directly. Systemd doesn't support threaded cgroups so we need to do this. The reason why we don't use DBus for most of the APIs is that we already have a code that works with files and we would have to check if systemd supports each API. This change introduces new topology on systemd hosts: $ROOT | +- machine.slice | +- machine-qemu\x2d1\x2dvm1.scope | +- libvirt | +- emulator +- vcpu0 +- vcpu0 compared to the previous topology: $ROOT | +- machine.slice | +- machine-qemu\x2d1\x2dvm1.scope | +- emulator +- vcpu0 +- vcpu0 Signed-off-by: Pavel Hrdina Reviewed-by: Michal Privoznik --- docs/cgroups.html.in | 29 +++-- src/util/vircgroup.c | 250 ++++++++++++++++++++++++++++++--------- src/util/vircgrouppriv.h | 4 + src/util/vircgroupv1.c | 15 ++- src/util/vircgroupv2.c | 6 + 5 files changed, 239 insertions(+), 65 deletions(-) diff --git a/docs/cgroups.html.in b/docs/cgroups.html.in index 78dede1bba..412a9360ff 100644 --- a/docs/cgroups.html.in +++ b/docs/cgroups.html.in @@ -117,21 +117,27 @@ $ROOT | +- machine-qemu\x2d1\x2dvm1.scope | | - | +- emulator - | +- vcpu0 - | +- vcpu1 + | +- libvirt + | | + | +- emulator + | +- vcpu0 + | +- vcpu1 | +- machine-qemu\x2d2\x2dvm2.scope | | - | +- emulator - | +- vcpu0 - | +- vcpu1 + | +- libvirt + | | + | +- emulator + | +- vcpu0 + | +- vcpu1 | +- machine-qemu\x2d3\x2dvm3.scope | | - | +- emulator - | +- vcpu0 - | +- vcpu1 + | +- libvirt + | | + | +- emulator + | +- vcpu0 + | +- vcpu1 | +- machine-engineering.slice | | @@ -148,6 +154,11 @@ $ROOT +- machine-lxc\x2d33333\x2dcontainer3.scope =20 +

+ Prior libvirt 7.1.0 the topology doesn't have extra + libvirt directory. +

+

Non-systemd cgroups layout

=20

diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 44a3064876..402224813b 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -711,6 +711,22 @@ virCgroupMakeGroup(virCgroupPtr parent, } =20 =20 +static bool +virCgroupExists(virCgroupPtr group) +{ + size_t i; + + for (i =3D 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) { + if (group->backends[i] && + !group->backends[i]->exists(group)) { + return false; + } + } + + return true; +} + + /** * virCgroupNew: * @path: path for the new group @@ -764,10 +780,11 @@ virCgroupAddTaskInternal(virCgroupPtr group, unsigned int flags) { size_t i; + virCgroupPtr parent =3D virCgroupGetNested(group); =20 for (i =3D 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) { - if (group->backends[i] && - group->backends[i]->addTask(group, pid, flags) < 0) { + if (parent->backends[i] && + parent->backends[i]->addTask(parent, pid, flags) < 0) { return -1; } } @@ -980,6 +997,28 @@ virCgroupNewPartition(const char *path, } =20 =20 +static int +virCgroupNewNested(virCgroupPtr parent, + int controllers, + bool create, + pid_t pid, + virCgroupPtr *nested) +{ + g_autoptr(virCgroup) new =3D NULL; + + if (virCgroupNewFromParent(parent, "libvirt", controllers, &new) < 0) + return -1; + + if (create) { + if (virCgroupMakeGroup(parent, new, create, pid, VIR_CGROUP_NONE) = < 0) + return -1; + } + + *nested =3D g_steal_pointer(&new); + return 0; +} + + /** * virCgroupNewSelf: * @@ -1064,6 +1103,7 @@ virCgroupNewThread(virCgroupPtr domain, { g_autofree char *name =3D NULL; g_autoptr(virCgroup) newGroup =3D NULL; + virCgroupPtr parent =3D NULL; int controllers; =20 *group =3D NULL; @@ -1088,10 +1128,12 @@ virCgroupNewThread(virCgroupPtr domain, (1 << VIR_CGROUP_CONTROLLER_CPUACCT) | (1 << VIR_CGROUP_CONTROLLER_CPUSET)); =20 - if (virCgroupNewFromParent(domain, name, controllers, &newGroup) < 0) + parent =3D virCgroupGetNested(domain); + + if (virCgroupNewFromParent(parent, name, controllers, &newGroup) < 0) return -1; =20 - if (virCgroupMakeGroup(domain, newGroup, create, -1, VIR_CGROUP_THREAD= ) < 0) + if (virCgroupMakeGroup(parent, newGroup, create, -1, VIR_CGROUP_THREAD= ) < 0) return -1; =20 *group =3D g_steal_pointer(&newGroup); @@ -1142,6 +1184,7 @@ virCgroupNewDetectMachine(const char *name, { size_t i; g_autoptr(virCgroup) newGroup =3D NULL; + g_autoptr(virCgroup) nested =3D NULL; =20 *group =3D NULL; =20 @@ -1166,6 +1209,12 @@ virCgroupNewDetectMachine(const char *name, if (virSystemdHasMachined() =3D=3D 0 && !newGroup->unitName) return -1; =20 + if (virCgroupNewNested(newGroup, controllers, false, -1, &nested) < 0) + return -1; + + if (virCgroupExists(nested)) + newGroup->nested =3D g_steal_pointer(&nested); + *group =3D g_steal_pointer(&newGroup); return 0; } @@ -1225,6 +1274,7 @@ virCgroupNewMachineSystemd(const char *name, int rv; g_autoptr(virCgroup) init =3D NULL; g_autoptr(virCgroup) newGroup =3D NULL; + g_autoptr(virCgroup) nested =3D NULL; g_autofree char *path =3D NULL; size_t i; =20 @@ -1270,6 +1320,11 @@ virCgroupNewMachineSystemd(const char *name, if (!newGroup->unitName) return -1; =20 + if (virCgroupNewNested(newGroup, controllers, true, pidleader, &nested= ) < 0) + return -1; + + newGroup->nested =3D g_steal_pointer(&nested); + if (virCgroupAddProcess(newGroup, pidleader) < 0) { virErrorPtr saved; =20 @@ -1457,7 +1512,9 @@ virCgroupGetBlkioIoServiced(virCgroupPtr group, long long *requests_read, long long *requests_write) { - VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_BLKIO, + virCgroupPtr parent =3D virCgroupGetNested(group); + + VIR_CGROUP_BACKEND_CALL(parent, VIR_CGROUP_CONTROLLER_BLKIO, getBlkioIoServiced, -1, bytes_read, bytes_write, requests_read, requests_write); @@ -1484,7 +1541,9 @@ virCgroupGetBlkioIoDeviceServiced(virCgroupPtr group, long long *requests_read, long long *requests_write) { - VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_BLKIO, + virCgroupPtr parent =3D virCgroupGetNested(group); + + VIR_CGROUP_BACKEND_CALL(parent, VIR_CGROUP_CONTROLLER_BLKIO, getBlkioIoDeviceServiced, -1, path, bytes_read, bytes_write, requests_read, requests_write); @@ -1535,7 +1594,9 @@ virCgroupSetBlkioDeviceReadIops(virCgroupPtr group, const char *path, unsigned int riops) { - VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_BLKIO, + virCgroupPtr parent =3D virCgroupGetNested(group); + + VIR_CGROUP_BACKEND_CALL(parent, VIR_CGROUP_CONTROLLER_BLKIO, setBlkioDeviceReadIops, -1, path, riops); } =20 @@ -1553,7 +1614,9 @@ virCgroupSetBlkioDeviceWriteIops(virCgroupPtr group, const char *path, unsigned int wiops) { - VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_BLKIO, + virCgroupPtr parent =3D virCgroupGetNested(group); + + VIR_CGROUP_BACKEND_CALL(parent, VIR_CGROUP_CONTROLLER_BLKIO, setBlkioDeviceWriteIops, -1, path, wiops); } =20 @@ -1571,7 +1634,9 @@ virCgroupSetBlkioDeviceReadBps(virCgroupPtr group, const char *path, unsigned long long rbps) { - VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_BLKIO, + virCgroupPtr parent =3D virCgroupGetNested(group); + + VIR_CGROUP_BACKEND_CALL(parent, VIR_CGROUP_CONTROLLER_BLKIO, setBlkioDeviceReadBps, -1, path, rbps); } =20 @@ -1588,7 +1653,9 @@ virCgroupSetBlkioDeviceWriteBps(virCgroupPtr group, const char *path, unsigned long long wbps) { - VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_BLKIO, + virCgroupPtr parent =3D virCgroupGetNested(group); + + VIR_CGROUP_BACKEND_CALL(parent, VIR_CGROUP_CONTROLLER_BLKIO, setBlkioDeviceWriteBps, -1, path, wbps); } =20 @@ -1624,7 +1691,9 @@ virCgroupGetBlkioDeviceReadIops(virCgroupPtr group, const char *path, unsigned int *riops) { - VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_BLKIO, + virCgroupPtr parent =3D virCgroupGetNested(group); + + VIR_CGROUP_BACKEND_CALL(parent, VIR_CGROUP_CONTROLLER_BLKIO, getBlkioDeviceReadIops, -1, path, riops); } =20 @@ -1641,7 +1710,9 @@ virCgroupGetBlkioDeviceWriteIops(virCgroupPtr group, const char *path, unsigned int *wiops) { - VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_BLKIO, + virCgroupPtr parent =3D virCgroupGetNested(group); + + VIR_CGROUP_BACKEND_CALL(parent, VIR_CGROUP_CONTROLLER_BLKIO, getBlkioDeviceWriteIops, -1, path, wiops); } =20 @@ -1658,7 +1729,9 @@ virCgroupGetBlkioDeviceReadBps(virCgroupPtr group, const char *path, unsigned long long *rbps) { - VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_BLKIO, + virCgroupPtr parent =3D virCgroupGetNested(group); + + VIR_CGROUP_BACKEND_CALL(parent, VIR_CGROUP_CONTROLLER_BLKIO, getBlkioDeviceReadBps, -1, path, rbps); } =20 @@ -1675,7 +1748,9 @@ virCgroupGetBlkioDeviceWriteBps(virCgroupPtr group, const char *path, unsigned long long *wbps) { - VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_BLKIO, + virCgroupPtr parent =3D virCgroupGetNested(group); + + VIR_CGROUP_BACKEND_CALL(parent, VIR_CGROUP_CONTROLLER_BLKIO, getBlkioDeviceWriteBps, -1, path, wbps); } =20 @@ -1708,7 +1783,9 @@ virCgroupGetBlkioDeviceWeight(virCgroupPtr group, int virCgroupSetMemory(virCgroupPtr group, unsigned long long kb) { - VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_MEMORY, + virCgroupPtr parent =3D virCgroupGetNested(group); + + VIR_CGROUP_BACKEND_CALL(parent, VIR_CGROUP_CONTROLLER_MEMORY, setMemory, -1, kb); } =20 @@ -1735,7 +1812,9 @@ virCgroupGetMemoryStat(virCgroupPtr group, unsigned long long *inactiveFile, unsigned long long *unevictable) { - VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_MEMORY, + virCgroupPtr parent =3D virCgroupGetNested(group); + + VIR_CGROUP_BACKEND_CALL(parent, VIR_CGROUP_CONTROLLER_MEMORY, getMemoryStat, -1, cache, activeAnon, inactiveAnon, activeFile, inactiveFile, @@ -1754,7 +1833,9 @@ virCgroupGetMemoryStat(virCgroupPtr group, int virCgroupGetMemoryUsage(virCgroupPtr group, unsigned long *kb) { - VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_MEMORY, + virCgroupPtr parent =3D virCgroupGetNested(group); + + VIR_CGROUP_BACKEND_CALL(parent, VIR_CGROUP_CONTROLLER_MEMORY, getMemoryUsage, -1, kb); } =20 @@ -1770,7 +1851,9 @@ virCgroupGetMemoryUsage(virCgroupPtr group, unsigned = long *kb) int virCgroupSetMemoryHardLimit(virCgroupPtr group, unsigned long long kb) { - VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_MEMORY, + virCgroupPtr parent =3D virCgroupGetNested(group); + + VIR_CGROUP_BACKEND_CALL(parent, VIR_CGROUP_CONTROLLER_MEMORY, setMemoryHardLimit, -1, kb); } =20 @@ -1786,7 +1869,9 @@ virCgroupSetMemoryHardLimit(virCgroupPtr group, unsig= ned long long kb) int virCgroupGetMemoryHardLimit(virCgroupPtr group, unsigned long long *kb) { - VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_MEMORY, + virCgroupPtr parent =3D virCgroupGetNested(group); + + VIR_CGROUP_BACKEND_CALL(parent, VIR_CGROUP_CONTROLLER_MEMORY, getMemoryHardLimit, -1, kb); } =20 @@ -1802,7 +1887,9 @@ virCgroupGetMemoryHardLimit(virCgroupPtr group, unsig= ned long long *kb) int virCgroupSetMemorySoftLimit(virCgroupPtr group, unsigned long long kb) { - VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_MEMORY, + virCgroupPtr parent =3D virCgroupGetNested(group); + + VIR_CGROUP_BACKEND_CALL(parent, VIR_CGROUP_CONTROLLER_MEMORY, setMemorySoftLimit, -1, kb); } =20 @@ -1818,7 +1905,9 @@ virCgroupSetMemorySoftLimit(virCgroupPtr group, unsig= ned long long kb) int virCgroupGetMemorySoftLimit(virCgroupPtr group, unsigned long long *kb) { - VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_MEMORY, + virCgroupPtr parent =3D virCgroupGetNested(group); + + VIR_CGROUP_BACKEND_CALL(parent, VIR_CGROUP_CONTROLLER_MEMORY, getMemorySoftLimit, -1, kb); } =20 @@ -1834,7 +1923,9 @@ virCgroupGetMemorySoftLimit(virCgroupPtr group, unsig= ned long long *kb) int virCgroupSetMemSwapHardLimit(virCgroupPtr group, unsigned long long kb) { - VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_MEMORY, + virCgroupPtr parent =3D virCgroupGetNested(group); + + VIR_CGROUP_BACKEND_CALL(parent, VIR_CGROUP_CONTROLLER_MEMORY, setMemSwapHardLimit, -1, kb); } =20 @@ -1850,7 +1941,9 @@ virCgroupSetMemSwapHardLimit(virCgroupPtr group, unsi= gned long long kb) int virCgroupGetMemSwapHardLimit(virCgroupPtr group, unsigned long long *kb) { - VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_MEMORY, + virCgroupPtr parent =3D virCgroupGetNested(group); + + VIR_CGROUP_BACKEND_CALL(parent, VIR_CGROUP_CONTROLLER_MEMORY, getMemSwapHardLimit, -1, kb); } =20 @@ -1866,7 +1959,9 @@ virCgroupGetMemSwapHardLimit(virCgroupPtr group, unsi= gned long long *kb) int virCgroupGetMemSwapUsage(virCgroupPtr group, unsigned long long *kb) { - VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_MEMORY, + virCgroupPtr parent =3D virCgroupGetNested(group); + + VIR_CGROUP_BACKEND_CALL(parent, VIR_CGROUP_CONTROLLER_MEMORY, getMemSwapUsage, -1, kb); } =20 @@ -1882,7 +1977,9 @@ virCgroupGetMemSwapUsage(virCgroupPtr group, unsigned= long long *kb) int virCgroupSetCpusetMems(virCgroupPtr group, const char *mems) { - VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_CPUSET, + virCgroupPtr parent =3D virCgroupGetNested(group); + + VIR_CGROUP_BACKEND_CALL(parent, VIR_CGROUP_CONTROLLER_CPUSET, setCpusetMems, -1, mems); } =20 @@ -1898,7 +1995,9 @@ virCgroupSetCpusetMems(virCgroupPtr group, const char= *mems) int virCgroupGetCpusetMems(virCgroupPtr group, char **mems) { - VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_CPUSET, + virCgroupPtr parent =3D virCgroupGetNested(group); + + VIR_CGROUP_BACKEND_CALL(parent, VIR_CGROUP_CONTROLLER_CPUSET, getCpusetMems, -1, mems); } =20 @@ -1914,7 +2013,9 @@ virCgroupGetCpusetMems(virCgroupPtr group, char **mem= s) int virCgroupSetCpusetMemoryMigrate(virCgroupPtr group, bool migrate) { - VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_CPUSET, + virCgroupPtr parent =3D virCgroupGetNested(group); + + VIR_CGROUP_BACKEND_CALL(parent, VIR_CGROUP_CONTROLLER_CPUSET, setCpusetMemoryMigrate, -1, migrate); } =20 @@ -1930,7 +2031,9 @@ virCgroupSetCpusetMemoryMigrate(virCgroupPtr group, b= ool migrate) int virCgroupGetCpusetMemoryMigrate(virCgroupPtr group, bool *migrate) { - VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_CPUSET, + virCgroupPtr parent =3D virCgroupGetNested(group); + + VIR_CGROUP_BACKEND_CALL(parent, VIR_CGROUP_CONTROLLER_CPUSET, getCpusetMemoryMigrate, -1, migrate); } =20 @@ -1946,7 +2049,9 @@ virCgroupGetCpusetMemoryMigrate(virCgroupPtr group, b= ool *migrate) int virCgroupSetCpusetCpus(virCgroupPtr group, const char *cpus) { - VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_CPUSET, + virCgroupPtr parent =3D virCgroupGetNested(group); + + VIR_CGROUP_BACKEND_CALL(parent, VIR_CGROUP_CONTROLLER_CPUSET, setCpusetCpus, -1, cpus); } =20 @@ -1962,7 +2067,9 @@ virCgroupSetCpusetCpus(virCgroupPtr group, const char= *cpus) int virCgroupGetCpusetCpus(virCgroupPtr group, char **cpus) { - VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_CPUSET, + virCgroupPtr parent =3D virCgroupGetNested(group); + + VIR_CGROUP_BACKEND_CALL(parent, VIR_CGROUP_CONTROLLER_CPUSET, getCpusetCpus, -1, cpus); } =20 @@ -1977,7 +2084,9 @@ virCgroupGetCpusetCpus(virCgroupPtr group, char **cpu= s) int virCgroupDenyAllDevices(virCgroupPtr group) { - VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_DEVICES, + virCgroupPtr parent =3D virCgroupGetNested(group); + + VIR_CGROUP_BACKEND_CALL(parent, VIR_CGROUP_CONTROLLER_DEVICES, denyAllDevices, -1); } =20 @@ -1998,7 +2107,9 @@ virCgroupDenyAllDevices(virCgroupPtr group) int virCgroupAllowAllDevices(virCgroupPtr group, int perms) { - VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_DEVICES, + virCgroupPtr parent =3D virCgroupGetNested(group); + + VIR_CGROUP_BACKEND_CALL(parent, VIR_CGROUP_CONTROLLER_DEVICES, allowAllDevices, -1, perms); } =20 @@ -2018,7 +2129,9 @@ int virCgroupAllowDevice(virCgroupPtr group, char type, int major, int minor, int perms) { - VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_DEVICES, + virCgroupPtr parent =3D virCgroupGetNested(group); + + VIR_CGROUP_BACKEND_CALL(parent, VIR_CGROUP_CONTROLLER_DEVICES, allowDevice, -1, type, major, minor, perms); } =20 @@ -2044,6 +2157,7 @@ virCgroupAllowDevicePath(virCgroupPtr group, bool ignoreEacces) { struct stat sb; + virCgroupPtr parent =3D virCgroupGetNested(group); =20 if (stat(path, &sb) < 0) { if (errno =3D=3D EACCES && ignoreEacces) @@ -2058,7 +2172,7 @@ virCgroupAllowDevicePath(virCgroupPtr group, if (!S_ISCHR(sb.st_mode) && !S_ISBLK(sb.st_mode)) return 1; =20 - VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_DEVICES, + VIR_CGROUP_BACKEND_CALL(parent, VIR_CGROUP_CONTROLLER_DEVICES, allowDevice, -1, S_ISCHR(sb.st_mode) ? 'c' : 'b', major(sb.st_rdev), @@ -2082,7 +2196,9 @@ int virCgroupDenyDevice(virCgroupPtr group, char type, int major, int minor, int perms) { - VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_DEVICES, + virCgroupPtr parent =3D virCgroupGetNested(group); + + VIR_CGROUP_BACKEND_CALL(parent, VIR_CGROUP_CONTROLLER_DEVICES, denyDevice, -1, type, major, minor, perms); } =20 @@ -2108,6 +2224,7 @@ virCgroupDenyDevicePath(virCgroupPtr group, bool ignoreEacces) { struct stat sb; + virCgroupPtr parent =3D virCgroupGetNested(group); =20 if (stat(path, &sb) < 0) { if (errno =3D=3D EACCES && ignoreEacces) @@ -2122,7 +2239,7 @@ virCgroupDenyDevicePath(virCgroupPtr group, if (!S_ISCHR(sb.st_mode) && !S_ISBLK(sb.st_mode)) return 1; =20 - VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_DEVICES, + VIR_CGROUP_BACKEND_CALL(parent, VIR_CGROUP_CONTROLLER_DEVICES, denyDevice, -1, S_ISCHR(sb.st_mode) ? 'c' : 'b', major(sb.st_rdev), @@ -2383,7 +2500,9 @@ virCgroupGetCpuShares(virCgroupPtr group, unsigned lo= ng long *shares) int virCgroupSetCpuCfsPeriod(virCgroupPtr group, unsigned long long cfs_period) { - VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_CPU, + virCgroupPtr parent =3D virCgroupGetNested(group); + + VIR_CGROUP_BACKEND_CALL(parent, VIR_CGROUP_CONTROLLER_CPU, setCpuCfsPeriod, -1, cfs_period); } =20 @@ -2399,7 +2518,9 @@ virCgroupSetCpuCfsPeriod(virCgroupPtr group, unsigned= long long cfs_period) int virCgroupGetCpuCfsPeriod(virCgroupPtr group, unsigned long long *cfs_perio= d) { - VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_CPU, + virCgroupPtr parent =3D virCgroupGetNested(group); + + VIR_CGROUP_BACKEND_CALL(parent, VIR_CGROUP_CONTROLLER_CPU, getCpuCfsPeriod, -1, cfs_period); } =20 @@ -2416,7 +2537,9 @@ virCgroupGetCpuCfsPeriod(virCgroupPtr group, unsigned= long long *cfs_period) int virCgroupSetCpuCfsQuota(virCgroupPtr group, long long cfs_quota) { - VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_CPU, + virCgroupPtr parent =3D virCgroupGetNested(group); + + VIR_CGROUP_BACKEND_CALL(parent, VIR_CGROUP_CONTROLLER_CPU, setCpuCfsQuota, -1, cfs_quota); } =20 @@ -2424,7 +2547,9 @@ virCgroupSetCpuCfsQuota(virCgroupPtr group, long long= cfs_quota) int virCgroupGetCpuacctPercpuUsage(virCgroupPtr group, char **usage) { - VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_CPUACCT, + virCgroupPtr parent =3D virCgroupGetNested(group); + + VIR_CGROUP_BACKEND_CALL(parent, VIR_CGROUP_CONTROLLER_CPUACCT, getCpuacctPercpuUsage, -1, usage); } =20 @@ -2727,7 +2852,9 @@ virCgroupKillPainfully(virCgroupPtr group) int virCgroupGetCpuCfsQuota(virCgroupPtr group, long long *cfs_quota) { - VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_CPU, + virCgroupPtr parent =3D virCgroupGetNested(group); + + VIR_CGROUP_BACKEND_CALL(parent, VIR_CGROUP_CONTROLLER_CPU, getCpuCfsQuota, -1, cfs_quota); } =20 @@ -2735,7 +2862,9 @@ virCgroupGetCpuCfsQuota(virCgroupPtr group, long long= *cfs_quota) int virCgroupGetCpuacctUsage(virCgroupPtr group, unsigned long long *usage) { - VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_CPUACCT, + virCgroupPtr parent =3D virCgroupGetNested(group); + + VIR_CGROUP_BACKEND_CALL(parent, VIR_CGROUP_CONTROLLER_CPUACCT, getCpuacctUsage, -1, usage); } =20 @@ -2744,7 +2873,9 @@ int virCgroupGetCpuacctStat(virCgroupPtr group, unsigned long long *user, unsigned long long *sys) { - VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_CPUACCT, + virCgroupPtr parent =3D virCgroupGetNested(group); + + VIR_CGROUP_BACKEND_CALL(parent, VIR_CGROUP_CONTROLLER_CPUACCT, getCpuacctStat, -1, user, sys); } =20 @@ -2752,7 +2883,9 @@ virCgroupGetCpuacctStat(virCgroupPtr group, unsigned = long long *user, int virCgroupSetFreezerState(virCgroupPtr group, const char *state) { - VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_FREEZER, + virCgroupPtr parent =3D virCgroupGetNested(group); + + VIR_CGROUP_BACKEND_CALL(parent, VIR_CGROUP_CONTROLLER_FREEZER, setFreezerState, -1, state); } =20 @@ -2760,7 +2893,9 @@ virCgroupSetFreezerState(virCgroupPtr group, const ch= ar *state) int virCgroupGetFreezerState(virCgroupPtr group, char **state) { - VIR_CGROUP_BACKEND_CALL(group, VIR_CGROUP_CONTROLLER_FREEZER, + virCgroupPtr parent =3D virCgroupGetNested(group); + + VIR_CGROUP_BACKEND_CALL(parent, VIR_CGROUP_CONTROLLER_FREEZER, getFreezerState, -1, state); } =20 @@ -2770,10 +2905,11 @@ virCgroupBindMount(virCgroupPtr group, const char *= oldroot, const char *mountopts) { size_t i; + virCgroupPtr parent =3D virCgroupGetNested(group); =20 for (i =3D 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) { - if (group->backends[i] && - group->backends[i]->bindMount(group, oldroot, mountopts) < 0) { + if (parent->backends[i] && + parent->backends[i]->bindMount(parent, oldroot, mountopts) < 0= ) { return -1; } } @@ -2788,10 +2924,11 @@ int virCgroupSetOwner(virCgroupPtr cgroup, int controllers) { size_t i; + virCgroupPtr parent =3D virCgroupGetNested(cgroup); =20 for (i =3D 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) { - if (cgroup->backends[i] && - cgroup->backends[i]->setOwner(cgroup, uid, gid, controllers) <= 0) { + if (parent->backends[i] && + parent->backends[i]->setOwner(parent, uid, gid, controllers) <= 0) { return -1; } } @@ -2810,7 +2947,9 @@ int virCgroupSetOwner(virCgroupPtr cgroup, bool virCgroupSupportsCpuBW(virCgroupPtr cgroup) { - VIR_CGROUP_BACKEND_CALL(cgroup, VIR_CGROUP_CONTROLLER_CPU, + virCgroupPtr parent =3D virCgroupGetNested(cgroup); + + VIR_CGROUP_BACKEND_CALL(parent, VIR_CGROUP_CONTROLLER_CPU, supportsCpuBW, false); } =20 @@ -2818,10 +2957,11 @@ int virCgroupHasEmptyTasks(virCgroupPtr cgroup, int controller) { size_t i; + virCgroupPtr parent =3D virCgroupGetNested(cgroup); =20 for (i =3D 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) { - if (cgroup->backends[i]) { - int rc =3D cgroup->backends[i]->hasEmptyTasks(cgroup, controll= er); + if (parent->backends[i]) { + int rc =3D parent->backends[i]->hasEmptyTasks(parent, controll= er); if (rc <=3D 0) return rc; } @@ -3630,6 +3770,7 @@ virCgroupFree(virCgroupPtr group) g_free(group->unified.mountPoint); g_free(group->unified.placement); g_free(group->unitName); + g_free(group->nested); =20 g_free(group); } @@ -3641,9 +3782,12 @@ virCgroupDelThread(virCgroupPtr cgroup, int idx) { g_autoptr(virCgroup) new_cgroup =3D NULL; + virCgroupPtr parent =3D NULL; =20 if (cgroup) { - if (virCgroupNewThread(cgroup, nameval, idx, false, &new_cgroup) <= 0) + parent =3D virCgroupGetNested(cgroup); + + if (virCgroupNewThread(parent, nameval, idx, false, &new_cgroup) <= 0) return -1; =20 /* Remove the offlined cgroup */ diff --git a/src/util/vircgrouppriv.h b/src/util/vircgrouppriv.h index f88d00814d..7c63780800 100644 --- a/src/util/vircgrouppriv.h +++ b/src/util/vircgrouppriv.h @@ -66,8 +66,12 @@ struct _virCgroup { virCgroupV2Controller unified; =20 char *unitName; + virCgroupPtr nested; }; =20 +#define virCgroupGetNested(cgroup) \ + (cgroup->nested ? cgroup->nested : cgroup) + int virCgroupSetValueDBus(const char *unitName, const char *key, GVariant *value); diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index 8a9a63e0b7..79015ddaa4 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -338,6 +338,8 @@ virCgroupV1DetectPlacement(virCgroupPtr group, =20 for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { const char *typestr =3D virCgroupV1ControllerTypeToString(i); + g_autofree char* placement =3D NULL; + char *tmp =3D NULL; =20 if (!virCgroupV1MountOptsMatchController(controllers, typestr)) continue; @@ -348,17 +350,24 @@ virCgroupV1DetectPlacement(virCgroupPtr group, if (group->legacy[i].placement) continue; =20 + /* On systemd we create a nested cgroup for some cgroup tasks + * but the placement should point to the root cgroup. */ + placement =3D g_strdup(selfpath); + tmp =3D g_strrstr(placement, "/libvirt"); + if (tmp) + *tmp =3D '\0'; + /* * selfpath =3D=3D "/" + path=3D"" -> "/" * selfpath =3D=3D "/libvirt.service" + path =3D=3D "" -> "/libvir= t.service" * selfpath =3D=3D "/libvirt.service" + path =3D=3D "foo" -> "/lib= virt.service/foo" */ if (i =3D=3D VIR_CGROUP_CONTROLLER_SYSTEMD) { - group->legacy[i].placement =3D g_strdup(selfpath); + group->legacy[i].placement =3D g_strdup(placement); } else { - bool delim =3D STREQ(selfpath, "/") || STREQ(path, ""); + bool delim =3D STREQ(placement, "/") || STREQ(path, ""); =20 - group->legacy[i].placement =3D g_strdup_printf("%s%s%s", selfp= ath, + group->legacy[i].placement =3D g_strdup_printf("%s%s%s", place= ment, delim ? "" : "/", path); } diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index c96f405dfa..0fb5188f45 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -208,6 +208,12 @@ virCgroupV2DetectPlacement(virCgroupPtr group, if (tmp) *tmp =3D '\0'; =20 + /* On systemd we create a nested cgroup for some cgroup tasks + * but the placement should point to the root cgroup. */ + tmp =3D g_strrstr(placement, "/libvirt"); + if (tmp) + *tmp =3D '\0'; + /* * selfpath =3D=3D "/" + path=3D"" -> "/" * selfpath =3D=3D "/libvirt.service" + path =3D=3D "" -> "/libvirt.se= rvice" --=20 2.29.2 From nobody Sun Apr 28 19:40:38 2024 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=1612877210; cv=none; d=zohomail.com; s=zohoarc; b=FRaeVU87B2RZXGiljpT2ZsOFmq4hTWyYLO5V9onAAw76h/1UycqsA7L9LpXvrtCqq2dS91eOOq43P15lVNApe9fsLWRXrhZHJSfL/vCIk476tqhpjCvIvtoD9FAbInfNtankr6euncnu9KT49iypAQO9cr8IRaS9/wk9OxXazpM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612877210; 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=HZMj6Ikt+9BEjUkdqDqTak2j+p6EHbvTfVZknw4v4uQ=; b=ndhlRy7it5rn+Yqy7wAZ7wTMXiGObrEoqIRHRO6FfmBOMbJxHFul1V5heHAytkfHeQBrc77Vjo23fn/N7//XAlsBGLfv8scNtKST8XdKSflzXvr10dUPKQHCGje/1Vjj+VJJ15UiHkPSBDj/tGEtkiXhhPv/h5wnY568JDOqlwE= 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 1612877210689370.5036197790863; Tue, 9 Feb 2021 05:26:50 -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-93-rSPP07lrOZ2NON922g203g-1; Tue, 09 Feb 2021 08:26:46 -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 539EAEC1B1; Tue, 9 Feb 2021 13:26:40 +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 ACDB260C62; Tue, 9 Feb 2021 13:26:38 +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 755DC18089CC; Tue, 9 Feb 2021 13:26:38 +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 119DQThg020480 for ; Tue, 9 Feb 2021 08:26:29 -0500 Received: by smtp.corp.redhat.com (Postfix) id A120C5D9CD; Tue, 9 Feb 2021 13:26:29 +0000 (UTC) Received: from antique-laptop.redhat.com (unknown [10.40.208.58]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0E6695D9C0 for ; Tue, 9 Feb 2021 13:26:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612877209; 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=HZMj6Ikt+9BEjUkdqDqTak2j+p6EHbvTfVZknw4v4uQ=; b=OXjGidPOzSIIvDZaIRpA1crWiU/V3//xbcBE6Vo7tLo+4SoEnLlakg0rnJEhq3Gkv43TzV sjnkI0AFloNv6GArfyYWZnEqwQq12f8iQI7xHBfORApvbule3TExC0mACRrUEzfUDsJy/y gQ/dsBBluw2PMwlMBuVwtie+s0cJTNg= X-MC-Unique: rSPP07lrOZ2NON922g203g-1 From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH 9/9] tests: add cgroup nested tests Date: Tue, 9 Feb 2021 14:26:14 +0100 Message-Id: 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" Signed-off-by: Pavel Hrdina Reviewed-by: Michal Privoznik --- tests/vircgroupdata/systemd-legacy.cgroups | 12 ++++ tests/vircgroupdata/systemd-legacy.mounts | 11 +++ .../vircgroupdata/systemd-legacy.self.cgroup | 11 +++ tests/vircgroupdata/systemd-unified.cgroups | 13 ++++ tests/vircgroupdata/systemd-unified.mounts | 1 + .../vircgroupdata/systemd-unified.self.cgroup | 1 + tests/vircgrouptest.c | 72 +++++++++++++++++++ 7 files changed, 121 insertions(+) create mode 100644 tests/vircgroupdata/systemd-legacy.cgroups create mode 100644 tests/vircgroupdata/systemd-legacy.mounts create mode 100644 tests/vircgroupdata/systemd-legacy.self.cgroup create mode 100644 tests/vircgroupdata/systemd-unified.cgroups create mode 100644 tests/vircgroupdata/systemd-unified.mounts create mode 100644 tests/vircgroupdata/systemd-unified.self.cgroup diff --git a/tests/vircgroupdata/systemd-legacy.cgroups b/tests/vircgroupda= ta/systemd-legacy.cgroups new file mode 100644 index 0000000000..444354e3c8 --- /dev/null +++ b/tests/vircgroupdata/systemd-legacy.cgroups @@ -0,0 +1,12 @@ +#subsys_name hierarchy num_cgroups enabled +blkio 1 1 1 +cpu 2 1 1 +cpuacct 3 1 1 +cpuset 4 1 1 +devices 5 1 1 +freezer 6 1 1 +hugetlb 7 1 1 +memory 8 1 1 +net_cls 9 1 1 +perf_event 10 1 1 +pids 11 1 1 diff --git a/tests/vircgroupdata/systemd-legacy.mounts b/tests/vircgroupdat= a/systemd-legacy.mounts new file mode 100644 index 0000000000..23462e9e68 --- /dev/null +++ b/tests/vircgroupdata/systemd-legacy.mounts @@ -0,0 +1,11 @@ +cgroup /not/really/sys/fs/cgroup/blkio cgroup rw,seclabel,nosuid,nodev,noe= xec,relatime,blkio 0 0 +cgroup /not/really/sys/fs/cgroup/cpu cgroup rw,seclabel,nosuid,nodev,noexe= c,relatime,cpu 0 0 +cgroup /not/really/sys/fs/cgroup/cpuacct cgroup rw,seclabel,nosuid,nodev,n= oexec,relatime,cpuacct 0 0 +cgroup /not/really/sys/fs/cgroup/cpuset cgroup rw,seclabel,nosuid,nodev,no= exec,relatime,cpuset 0 0 +cgroup /not/really/sys/fs/cgroup/devices cgroup rw,seclabel,nosuid,nodev,n= oexec,relatime,devices 0 0 +cgroup /not/really/sys/fs/cgroup/freezer cgroup rw,seclabel,nosuid,nodev,n= oexec,relatime,freezer 0 0 +cgroup /not/really/sys/fs/cgroup/hugetlb cgroup rw,seclabel,nosuid,nodev,n= oexec,relatime,hugetlb 0 0 +cgroup /not/really/sys/fs/cgroup/memory cgroup rw,seclabel,nosuid,nodev,no= exec,relatime,memory 0 0 +cgroup /not/really/sys/fs/cgroup/net_cls cgroup rw,seclabel,nosuid,nodev,n= oexec,relatime,net_cls 0 0 +cgroup /not/really/sys/fs/cgroup/perf_event cgroup rw,seclabel,nosuid,node= v,noexec,relatime,perf_event 0 0 +cgroup /not/really/sys/fs/cgroup/pids cgroup rw,seclabel,nosuid,nodev,noex= ec,relatime,pids 0 0 diff --git a/tests/vircgroupdata/systemd-legacy.self.cgroup b/tests/vircgro= updata/systemd-legacy.self.cgroup new file mode 100644 index 0000000000..5c133a3c08 --- /dev/null +++ b/tests/vircgroupdata/systemd-legacy.self.cgroup @@ -0,0 +1,11 @@ +1:blkio:/libvirt +2:cpu:/libvirt/emulator +3:cpuacct:/libvirt/emulator +4:cpuset:/libvirt/emulator +5:devices:/libvirt +6:freezer:/libvirt +7:hugetlb:/ +8:memory:/libvirt +9:net_cls:/libvirt +10:perf_event:/libvirt +11:pids:/ diff --git a/tests/vircgroupdata/systemd-unified.cgroups b/tests/vircgroupd= ata/systemd-unified.cgroups new file mode 100644 index 0000000000..e0d8a3561c --- /dev/null +++ b/tests/vircgroupdata/systemd-unified.cgroups @@ -0,0 +1,13 @@ +#subsys_name hierarchy num_cgroups enabled +cpuset 0 1 1 +cpu 0 1 1 +cpuacct 0 1 1 +blkio 0 1 1 +memory 0 1 1 +devices 0 1 1 +freezer 0 1 1 +net_cls 0 1 1 +perf_event 0 1 1 +net_prio 0 1 1 +hugetlb 0 1 1 +pids 0 1 1 diff --git a/tests/vircgroupdata/systemd-unified.mounts b/tests/vircgroupda= ta/systemd-unified.mounts new file mode 100644 index 0000000000..8225f37f45 --- /dev/null +++ b/tests/vircgroupdata/systemd-unified.mounts @@ -0,0 +1 @@ +cgroup2 /not/really/sys/fs/cgroup cgroup2 rw,seclabel,nosuid,nodev,noexec,= relatime,nsdelegate 0 0 diff --git a/tests/vircgroupdata/systemd-unified.self.cgroup b/tests/vircgr= oupdata/systemd-unified.self.cgroup new file mode 100644 index 0000000000..6007ce7e18 --- /dev/null +++ b/tests/vircgroupdata/systemd-unified.self.cgroup @@ -0,0 +1 @@ +0::/libvirt/emulator diff --git a/tests/vircgrouptest.c b/tests/vircgrouptest.c index 1baa71e61c..85c5a6ebd4 100644 --- a/tests/vircgrouptest.c +++ b/tests/vircgrouptest.c @@ -576,6 +576,64 @@ static int testCgroupNewForSelfHybrid(const void *args= G_GNUC_UNUSED) } =20 =20 +static int testCgroupNewForSelfSystemdLegacy(const void *args G_GNUC_UNUSE= D) +{ + g_autoptr(virCgroup) cgroup =3D NULL; + const char *empty[VIR_CGROUP_CONTROLLER_LAST] =3D { 0 }; + const char *mounts[VIR_CGROUP_CONTROLLER_LAST] =3D { + [VIR_CGROUP_CONTROLLER_BLKIO] =3D "/not/really/sys/fs/cgroup/blkio= ", + [VIR_CGROUP_CONTROLLER_CPU] =3D "/not/really/sys/fs/cgroup/cpu", + [VIR_CGROUP_CONTROLLER_CPUACCT] =3D "/not/really/sys/fs/cgroup/cpu= acct", + [VIR_CGROUP_CONTROLLER_CPUSET] =3D "/not/really/sys/fs/cgroup/cpus= et", + [VIR_CGROUP_CONTROLLER_DEVICES] =3D "/not/really/sys/fs/cgroup/dev= ices", + [VIR_CGROUP_CONTROLLER_FREEZER] =3D "/not/really/sys/fs/cgroup/fre= ezer", + [VIR_CGROUP_CONTROLLER_MEMORY] =3D "/not/really/sys/fs/cgroup/memo= ry", + [VIR_CGROUP_CONTROLLER_NET_CLS] =3D "/not/really/sys/fs/cgroup/net= _cls", + [VIR_CGROUP_CONTROLLER_PERF_EVENT] =3D "/not/really/sys/fs/cgroup/= perf_event", + }; + const char *placement[VIR_CGROUP_CONTROLLER_LAST] =3D { + [VIR_CGROUP_CONTROLLER_BLKIO] =3D "", + [VIR_CGROUP_CONTROLLER_CPU] =3D "", + [VIR_CGROUP_CONTROLLER_CPUACCT] =3D "", + [VIR_CGROUP_CONTROLLER_CPUSET] =3D "", + [VIR_CGROUP_CONTROLLER_DEVICES] =3D "", + [VIR_CGROUP_CONTROLLER_FREEZER] =3D "", + [VIR_CGROUP_CONTROLLER_MEMORY] =3D "", + [VIR_CGROUP_CONTROLLER_NET_CLS] =3D "", + [VIR_CGROUP_CONTROLLER_PERF_EVENT] =3D "", + }; + + if (virCgroupNewSelf(&cgroup) < 0) { + fprintf(stderr, "Cannot create cgroup for self\n"); + return -1; + } + + return validateCgroup(cgroup, mounts, empty, placement, NULL, NULL, 0); +} + + +static int testCgroupNewForSelfSystemdUnified(const void *args G_GNUC_UNUS= ED) +{ + g_autoptr(virCgroup) cgroup =3D NULL; + const char *empty[VIR_CGROUP_CONTROLLER_LAST] =3D { 0 }; + unsigned int controllers =3D + (1 << VIR_CGROUP_CONTROLLER_CPU) | + (1 << VIR_CGROUP_CONTROLLER_CPUACCT) | + (1 << VIR_CGROUP_CONTROLLER_MEMORY) | + (1 << VIR_CGROUP_CONTROLLER_DEVICES) | + (1 << VIR_CGROUP_CONTROLLER_BLKIO); + + if (virCgroupNewSelf(&cgroup) < 0) { + fprintf(stderr, "Cannot create cgroup for self\n"); + return -1; + } + + return validateCgroup(cgroup, empty, empty, empty, + "/not/really/sys/fs/cgroup", "", + controllers); +} + + static int testCgroupAvailable(const void *args) { bool got =3D virCgroupAvailable(); @@ -1046,6 +1104,20 @@ mymain(void) ret =3D -1; cleanupFakeFS(fakerootdir); =20 + fakerootdir =3D initFakeFS("legacy", "systemd-legacy"); + if (virTestRun("New cgroup for self (systemd-legacy)", + testCgroupNewForSelfSystemdLegacy, NULL) < 0) { + ret =3D -1; + } + cleanupFakeFS(fakerootdir); + + fakerootdir =3D initFakeFS("unified", "systemd-unified"); + if (virTestRun("New cgroup for self (systemd-unified)", + testCgroupNewForSelfSystemdUnified, NULL) < 0) { + ret =3D -1; + } + cleanupFakeFS(fakerootdir); + return ret =3D=3D 0 ? EXIT_SUCCESS : EXIT_FAILURE; } =20 --=20 2.29.2