From nobody Fri May 10 08:27:03 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; arc=fail (BodyHash is different from the expected one); dmarc=fail(p=none dis=none) header.from=nutanix.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 171154448361739.78382724555445; Wed, 27 Mar 2024 06:01:23 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 4D5EF1EED; Wed, 27 Mar 2024 09:01:22 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 906D31DC6; Wed, 27 Mar 2024 08:59:36 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id EDC02174D; Tue, 26 Mar 2024 07:47:00 -0400 (EDT) Received: from mx0a-002c1b01.pphosted.com (mx0a-002c1b01.pphosted.com [148.163.151.68]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 0B6BF19E6 for ; Tue, 26 Mar 2024 07:46:54 -0400 (EDT) Received: from pps.filterd (m0127839.ppops.net [127.0.0.1]) by mx0a-002c1b01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 42PN8wlM004096; Tue, 26 Mar 2024 04:37:47 -0700 Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2100.outbound.protection.outlook.com [104.47.55.100]) by mx0a-002c1b01.pphosted.com (PPS) with ESMTPS id 3x1x5edj8u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 26 Mar 2024 04:37:47 -0700 (PDT) Received: from DM6PR02MB6092.namprd02.prod.outlook.com (2603:10b6:5:1fb::24) by SA1PR02MB9758.namprd02.prod.outlook.com (2603:10b6:806:373::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.31; Tue, 26 Mar 2024 11:37:41 +0000 Received: from DM6PR02MB6092.namprd02.prod.outlook.com ([fe80::fc26:b716:de45:56ff]) by DM6PR02MB6092.namprd02.prod.outlook.com ([fe80::fc26:b716:de45:56ff%5]) with mapi id 15.20.7409.031; Tue, 26 Mar 2024 11:37:41 +0000 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 X-Greylist: delayed 547 seconds by postgrey-1.37 at lists.libvirt.org; Tue, 26 Mar 2024 07:46:55 EDT ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PLpb2/Zslbg+EB9Ww2K1caMaKcffoYjnyXhfKacEnqyawWVRZlglCZEXexh2w8U7hdM+99kgGtdOxkhh2HCHhSeWFPVg1Y8hxVX0ewevJeuN1HIWU1Bj/UtWjkFn5nzyCiusG65DNnFNzNH0cEZ9Gvoys0W+091ODFSOErXXlzSuW3Q3swV5Mr3yGmG5mur9DMUDUy8Er4QqsMsAWsLRGK/NVE5largZQkfZyDWtlm7FnCrT14hEzdaZFdIBAgoIlVDN0D5mm5ylx+5fyQzilQLlGMkLUZE3SnK0wi5Zc5seOu82jdFChpgN5yhr1kPSlDPB/AGOjOfDkYmtKvTIqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=1UDgndcbgTt4vfaEeuHGx7Bsvod7x56lJj5sX+T9tkY=; b=nPlD15JEUbo3s1cFccE9RhNgK/f6DWDVmIuPu/Iq6tzrcy2AUFKxoUWXEHVUw3NhsInhHb4VSAepNFE/94IheBqGNd+QLQ/CFC13EmPow6fdoxPtA661aM8RcJ7bzCBXTDp+/5Z4MkFEx/6DaNeGakx6D87E/a+Co4nOmli0CJniA1wAbqaBb78ALOGKVhtn4R3Y+egnmhRBtefLmlNoRJS0NMclupGuPdtvpfHn9ApOm0+WeuOgspraqsLoX5DrU0Q7q/M3pOJqaNr8030z5bXAEw3QETB5r305dZKYrFzTA5+kAmVH5DuMFO7cImy2WkbxZA2xNmGW4RMn55XA8Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nutanix.com; dmarc=pass action=none header.from=nutanix.com; dkim=pass header.d=nutanix.com; arc=none From: Benjamin Taubmann To: devel@lists.libvirt.org Subject: [PATCH v2] Extend libvirt-guests to shutdown only persistent VMs Date: Tue, 26 Mar 2024 11:37:21 +0000 Message-Id: <20240326113721.3597-1-benjamin.taubmann@nutanix.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231113102259.3469-1-benjamin.taubmann@nutanix.com> References: <20231113102259.3469-1-benjamin.taubmann@nutanix.com> X-ClientProxiedBy: SJ0PR03CA0012.namprd03.prod.outlook.com (2603:10b6:a03:33a::17) To DM6PR02MB6092.namprd02.prod.outlook.com (2603:10b6:5:1fb::24) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR02MB6092:EE_|SA1PR02MB9758:EE_ x-proofpoint-crosstenant: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 71K9OadP29PwLT010HQl/PRCqg2u4R1Ld4DZQ6QQbj+nO9ilVbFAWld7muAo4/dTDlPtHW9ZUKQEIl/6hcfR3ZfDOzxvgR1VcM7wM+pW9hV9eY6oJlPpIOs5OVMrb0kKc8Z6c14Ff7aNN0FRiSS/RjZ4PPjpklkx7LtywXqHGu52w/3a+QMj5W1zp5XT29fsj3vg4BNwsZgT2BEXxAmsf2rgS9QlXMH15ypeb/oxDwVRY7hxNcyBMreke2oCxrClbpL+ke2uuGdVPZxox63yuWWmprhORrAKkoiJLRhGiRgDpVHnMMKR0hWZOaXkY/f97HHSyxVajCq53wXntjSv7vziXxbsKmmiuCtf7wAiFGaio6x0VQSUwNXX2epeJIB+4Lz58p5tsE+u3zq1Hrw1b/tD6jR1yNOyTCA9FcVOq4XugwK26HitV1sqnyZnXostqdfOi/CdhahzHViSvMLzerzUGj8OHBiuze5VMMQ4dfe3Co6R0+5mqENeJELTy6rCtoxWOCmZHWkvcFp2uq0WurdjJagFNzwTA8/rXYZJ/6+mGJHY1dO34OAeDJksUtQCC4xY0UOto5TDNH5pEXjO3xGv56ZXCsaPii6gfLP6mTPDtgalkiMgFapHu8xDPvqjOpcnXhlbJyEz2XNgj5vG4WPA616nRuaXJE6rIrktQ8Pi28X6Wfwcj4YfG9CMTjy7aEoJV8fDlkR/fNnlj2O0UnY3aYsjiO1ubmYEueb2Qr0= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR02MB6092.namprd02.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(1800799015)(52116005)(376005)(366007)(38350700005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?wYWBeXklskVlzNAjb9ocpXH6l6fGyy9I7NzFwiCqFkoKr7XiQaHegs/Lbi7O?= =?us-ascii?Q?6IuQKkLvO7bF8PW/ROUGP9zAiuLx93aPVdRTn1kJ14p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wtdAnhS9i/CUP7NOe086SonEsSPBc4+YfjlS/5iZ/Xh/AQm?= =?us-ascii?Q?jF0GhgEp54gaQObqitOxQamUpl/Kf5LmRPVx0UXFdEZyTTPMG/oNkyyy+BYD?= =?us-ascii?Q?G5g/YQ74d7+y8rMnkHt4BeMTKzmNXdumBVRFGcUa7iA4mj8vBwH2JdDvy+zJ?= =?us-ascii?Q?n7TNMSwMOsxXjD5vbWBDne5Ea6c2HzXB3irzLnYMH2mfLOQ3wyMUrXT2SzRy?= =?us-ascii?Q?oDK7G3fStoHl9AluMPTgp3fU9P0Fx3cOgGG7//tX4zdFLF6DTK5RTVkhIAc8?= =?us-ascii?Q?di9di0e5jXYi15mx/sO4h3P9mvuFnI5IiQhjL/qpzP727mamok3g8OBhObqh?= =?us-ascii?Q?kegt3sHRGHzhNLA89GSxXZv0hSPqatQEUTx5fROWVi6bSnwtmb2nDih/nuwx?= =?us-ascii?Q?pMJuDQbqLNyV5rvD13EofHhPWh59JWRtjKUqxtThnQ7jAU+kryJ1eV2LREV4?= =?us-ascii?Q?kgM614txWFAUUetkfV+PYyvbyjyFaGk3uxssZnAYiiLziabb6iHAj8ERwKMS?= =?us-ascii?Q?2kDzim8GXIE7vzAdkZUX/ryFGIkTXDqYBljyShDfV7RZG2o0CXHMpMV1wn6F?= =?us-ascii?Q?85OfyYWoe3w9IzqF54tJev4B1Q0imnra3MA2DlMn4gyduWNjvNboo5IgZFFR?= =?us-ascii?Q?K3/BJ2PtKNQtHwhEH62Np0A=3D?= X-OriginatorOrg: nutanix.com X-MS-Exchange-CrossTenant-Network-Message-Id: 97dc0f34-6482-4801-4a92-08dc4d892593 X-MS-Exchange-CrossTenant-AuthSource: DM6PR02MB6092.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Mar 2024 11:37:41.7260 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: bb047546-786f-4de1-bd75-24e5b6f79043 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: foPEnXGRrkqs8ayYTN/kNP3K2AsifVpCkqvy6bx7N0MOt/IIoh7LjP9LIJboIIgHcRgIXXc9rp6ttXEaQLxY2ez2EIJOkt5HBzlaFJpmTx4= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR02MB9758 X-Proofpoint-GUID: CX_q-HEEz3r7wP9tHN1bjQ-TZRlclnuS X-Proofpoint-ORIG-GUID: CX_q-HEEz3r7wP9tHN1bjQ-TZRlclnuS X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-03-26_05,2024-03-21_02,2023-05-22_02 X-Proofpoint-Spam-Reason: safe X-MailFrom: benjamin.taubmann@nutanix.com X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0 Message-ID-Hash: 4HGOZ4UHBO5GJWKP6HK7ARLFJKP5WHXA X-Message-ID-Hash: 4HGOZ4UHBO5GJWKP6HK7ARLFJKP5WHXA X-Mailman-Approved-At: Wed, 27 Mar 2024 12:59:32 -0400 CC: prashanth.sreenivasa@nutanix.com, Benjamin Taubmann , Martin Kletzander X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1711544485500100001 At the moment, there is no configuration option for the libvirt-guests service that allows users to define that only persistent virtual machines should be shutdown on host shutdown. Currently, the service config allows to choose between two ON_SHUTDOWN actions that are executed on running virtual machines when the host goes down: shutdown, suspend. The ON_SHUTDOWN action should be orthogonal to the type of the virtual machine. However, the existing implementation, does not suspend transient virtual machines. This is the matrix of actions that is executed on virtual machines based on the configured ON_SHUTDOWN action and the type of a virtual machine. | persistent | transient shutdown | shutdown | shutdown (what we want to change) suspend | suspend | nothing Add config option PERSISTENT_ONLY to libvirt-guests config that allows users to define if the ON_SHUTDOWN action should be applied only on persistent virtual machines. PERSISTENT_ONLY can be set to true, false, default. The default option will implement the already existing logic. Case 1: PERSISTENT_ONLY=3Ddefault | persistent | transient shutdown | shutdown | shutdown suspend | suspend | nothing Case 2: PERSISTENT_ONLY=3Dtrue | persistent | transient shutdown | shutdown | nothing suspend | suspend | nothing Case 3: PERSISTENT_ONLY=3Dfalse | persistent | transient shutdown | shutdown | shutdown suspend | suspend | suspend Signed-off-by: Benjamin Taubmann Reviewed-by: Martin Kletzander --- v2: Update libvirt-guests' man page and git commit message --- docs/manpages/libvirt-guests.rst | 22 +++++++++++++++++++ tools/libvirt-guests.sh.in | 37 ++++++++++++++++++++++++++------ 2 files changed, 52 insertions(+), 7 deletions(-) diff --git a/docs/manpages/libvirt-guests.rst b/docs/manpages/libvirt-guest= s.rst index f27eaad6e4..42dae283e3 100644 --- a/docs/manpages/libvirt-guests.rst +++ b/docs/manpages/libvirt-guests.rst @@ -113,6 +113,28 @@ The following variables are supported: this requires guest agent with support for time synchronization running in the guest. By default, this functionality is turned off. =20 +- PERSISTENT_ONLY=3Ddefault + + Defines what type of guest virtual machine ON_SHUTDOWN action is applied= to + + * default + + This implements the already existing default behavior. + If ON_SHUTDOWN action is shutdown, transient and persistent guest virt= ual + machines are asked to shutdown. + If ON_SHUTDOWN action is suspend, only persistent guest virtual machin= es + are asked to suspend. + + * true + + ON_SHUTDOWN action is executed only on persistent guest virtual machin= es. + Transient guest virtual machines are not affected. + + * false + + ON_SHUTDOWN action is executed on persistent and transient guest virtu= al + machines. + =20 BUGS =3D=3D=3D=3D diff --git a/tools/libvirt-guests.sh.in b/tools/libvirt-guests.sh.in index 344b54390a..c3c5954e17 100644 --- a/tools/libvirt-guests.sh.in +++ b/tools/libvirt-guests.sh.in @@ -38,6 +38,7 @@ PARALLEL_SHUTDOWN=3D0 START_DELAY=3D0 BYPASS_CACHE=3D0 SYNC_TIME=3D0 +PERSISTENT_ONLY=3D"default" =20 test -f "$initconfdir"/libvirt-guests && . "$initconfdir"/libvirt-guests @@ -438,14 +439,16 @@ shutdown_guests_parallel() # stop # Shutdown or save guests on the configured uris stop() { - local suspending=3D"true" local uri=3D + local action=3D"suspend" + local persistent_only=3D"default" + =20 # last stop was not followed by start [ -f "$LISTFILE" ] && return 0 =20 if [ "x$ON_SHUTDOWN" =3D xshutdown ]; then - suspending=3D"false" + action=3D"shutdown" if [ $SHUTDOWN_TIMEOUT -lt 0 ]; then gettext "SHUTDOWN_TIMEOUT must be equal or greater than 0" echo @@ -454,6 +457,22 @@ stop() { fi fi =20 + case "x$PERSISTENT_ONLY" in + xtrue) + persistent_only=3D"true" + ;; + xfalse) + persistent_only=3D"false" + ;; + *) + if [ "x$action" =3D xshutdown ]; then + persistent_only=3D"false" + elif [ "x$action" =3D xsuspend ]; then + persistent_only=3D"true" + fi + ;; + esac + : >"$LISTFILE" set -f for uri in $URIS; do @@ -478,7 +497,7 @@ stop() { echo fi =20 - if "$suspending"; then + if "$persistent_only"; then local transient=3D"$(list_guests "$uri" "--transient")" if [ $? -eq 0 ]; then local empty=3D"true" @@ -486,7 +505,11 @@ stop() { =20 for uuid in $transient; do if "$empty"; then - eval_gettext "Not suspending transient guests on U= RI: \$uri: " + if [ "x$action" =3D xsuspend ]; then + eval_gettext "Not suspending transient guests = on URI: \$uri: " + else + eval_gettext "Not shutting down transient gues= ts on URI: \$uri: " + fi empty=3D"false" else printf ", " @@ -520,19 +543,19 @@ stop() { =20 if [ -s "$LISTFILE" ]; then while read uri list; do - if "$suspending"; then + if [ "x$action" =3D xsuspend ]; then eval_gettext "Suspending guests on \$uri URI..."; echo else eval_gettext "Shutting down guests on \$uri URI..."; echo fi =20 if [ "$PARALLEL_SHUTDOWN" -gt 1 ] && - ! "$suspending"; then + [ "x$action" =3D xshutdown ]; then shutdown_guests_parallel "$uri" "$list" else local guest=3D for guest in $list; do - if "$suspending"; then + if [ "x$action" =3D xsuspend ]; then suspend_guest "$uri" "$guest" else shutdown_guest "$uri" "$guest" --=20 2.39.2 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org