From nobody Sat May 11 20:57:13 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 1700471154091451.08456938705035; Mon, 20 Nov 2023 01:05:54 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 723D2187D; Mon, 20 Nov 2023 04:05:52 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 743FE17E4; Mon, 20 Nov 2023 04:02:38 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 07BD719FE; Mon, 13 Nov 2023 05:41:41 -0500 (EST) 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 E68FE1974 for ; Mon, 13 Nov 2023 05:41:39 -0500 (EST) Received: from pps.filterd (m0127839.ppops.net [127.0.0.1]) by mx0a-002c1b01.pphosted.com (8.17.1.22/8.17.1.22) with ESMTP id 3AD4x71m006889 for ; Mon, 13 Nov 2023 02:23:15 -0800 Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2168.outbound.protection.outlook.com [104.47.59.168]) by mx0a-002c1b01.pphosted.com (PPS) with ESMTPS id 3ua9jhahm9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 13 Nov 2023 02:23:15 -0800 (PST) Received: from DM6PR02MB6092.namprd02.prod.outlook.com (2603:10b6:5:1fb::24) by PH0PR02MB8568.namprd02.prod.outlook.com (2603:10b6:510:103::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6977.29; Mon, 13 Nov 2023 10:23:12 +0000 Received: from DM6PR02MB6092.namprd02.prod.outlook.com ([fe80::2c50:755d:7f04:ced3]) by DM6PR02MB6092.namprd02.prod.outlook.com ([fe80::2c50:755d:7f04:ced3%7]) with mapi id 15.20.6977.029; Mon, 13 Nov 2023 10:23:12 +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.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-Greylist: delayed 1102 seconds by postgrey-1.37 at lists.libvirt.org; Mon, 13 Nov 2023 05:41:39 EST ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hzy7JK81DOfLwbas3NT+4gI8674l/OQqJPwnKbiIfwaKlc+oVlt3MZOvFAT4+7saIEsVhFG+nZRPdadORunHGfW78POAm8Gg+AoKAJvDY/jtD5JUT0Q5ypKdm6DafpdT3ulwqhz2mrclVxLAoW0ucP5noIshyg/6RXYFU+iNAhKC5mCaDR+z6CvbuT7vsvZSUp/aG61Qys5Svjb8JDuw69Ce86dARrkCR3srQft5jYAJ3RTckMMsEDP4em5CJ1MgI2WGuS/398IcwTiZBt8leG0H7IncD0foANujaQRfWKSf5k8wTuDZGBe+Cl6B2UcFbAvO2HP6FHQ5pr9VPASSNA== 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=y4y0OAoDqUSFTVfSHx/CGM68iEPGwm7Jp5tr6BoWa9E=; b=c2XZ6yZg5tP8C/AIimGHWtVzVKVaZO64N0Mt/jCmj5N/dxx4BnFXStcFzoqoWGHhhyLqO2XCk9l1/I+xEQuT0sQuNPUsG64WBqM6YKv/9X7YKKVHVtkEtINfetJ7l8KsCpDNvy5n1aLtwIitWCe7pf5xT+2711z5SsusZ0EMDcNT64ZbiVpx5tctx7C4w+XlnQNvKIlRo898yCt83aUMyvCc5V83ju8RKIvwQLwZHqFwwV5Ge4SPjWwsgqk0BUIvzSG9Ic2B7A5VnoXAINVucLMQAcnZGX76d6rFRs8z1TR5D7V3lArb6I21J16scYxkgOw75Dtc2/9iFO5Pg68lwg== 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] Extend libvirt-guests to shutdown only persistent VMs Date: Mon, 13 Nov 2023 10:22:59 +0000 Message-Id: <20231113102259.3469-1-benjamin.taubmann@nutanix.com> X-Mailer: git-send-email 2.39.2 X-ClientProxiedBy: BYAPR21CA0006.namprd21.prod.outlook.com (2603:10b6:a03:114::16) To DM6PR02MB6092.namprd02.prod.outlook.com (2603:10b6:5:1fb::24) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR02MB6092:EE_|PH0PR02MB8568:EE_ X-MS-Office365-Filtering-Correlation-Id: e9b8bf1d-9a9a-4043-0c82-08dbe4328a21 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: +NGqgUqTYzvY9YHRQrJP0YBulTTFgbPGX3TFTTKlDGNFHqZTRizxt7Dl1v/GvSA/i08ye3NWE1vqCWquGZa3fppE1FO845jbNJKU3iwx1uUq5AAKqM/bLubDwVAtmdXL7khsrnV2BDmN262vL/FXM80kedgmzZsTfuHxx49ax7WBYVAgWMKLs9+JXV7u7fby2acCnjoGW69QeXVDr+3nsIkjhqNzKLUMTcTknpNA40HBkhh9ZcsK/v081u6E/iOIV15EsSoqs23jol553PNbuwzkBD7e4bqPmqkeK9f4bQ2362EQYoXkFo9QLZI52HiYvhUdAjQ0Oh6xlfxYpwM/Sc9cDgs5rvU3JmB5bW3qonEerkWqlnMKGlTTM24BSqp1LhqA2kuLeZtTQh+FbZlt4H3jjHHNrMe36SmV5nIeP7QoiM0lvS98dlbk1HGMCXvVi+9H5FWAHxWIKvIPFu4m6ex7WyHIWmv5D2BCcexUN0Na0SsGvIIrOZXmkeEk8EDmUkRvOV95inUUqN4caXlrKYuf0GafTr7BqP31twTojEY/HLq9jdc+F6wf+xEZu3MBj+STeI5Vy76Oy9koiFZTcKs/0QWVeOzaHEEh1ckqUS2lCSM3j+YsGkr/VeC/vhQ2 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)(376002)(39860400002)(366004)(396003)(346002)(136003)(230922051799003)(64100799003)(186009)(1800799009)(451199024)(2906002)(83380400001)(38100700002)(38350700005)(36756003)(86362001)(6666004)(8676002)(8936002)(4326008)(6486002)(478600001)(44832011)(6506007)(52116002)(316002)(6916009)(66476007)(66556008)(66946007)(107886003)(5660300002)(2616005)(26005)(1076003)(41300700001)(6512007);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?R0DYT01c/LGy8Xc8fIsusCHDYSTZXbPyCrgVO5697FNkpa27dwarCxd10iEk?=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ZidP+dJzP6+9edKHKkz1Z1GkZ8kR+TGkf?= =?us-ascii?Q?nxImfSTgQLzFKj4xRFgSqyDFxR6yb7KNKuNOO/3qhANhlHGx7nG2tpxZ4gi6?= =?us-ascii?Q?mE5O7WRO8pK/g0odU7K2VwfLKkIeq4Pe6vdXF+Clpsx1dSsx4SnaYSmQ6ip2?= =?us-ascii?Q?FRDnc7O6geKtmkmfGH2ZlTCIvCuotW0UPcxUFNJDEmE3A0pIs9k8xV+0bVyu?= =?us-ascii?Q?5oMc4StepEGnjou9bLtuNtwqW8gMOsPSJbLyq6eW4J2tTvNHHi9z9AaeeM/t?= =?us-ascii?Q?hUDjRJXkmUTQGs5T0GBgfFNuT7mImSLDE7k5bD0VfE+N+tRwA1majrxfSQQB?= =?us-ascii?Q?LtAPWrEouO8nOCfL1CtKk1UXeyfwiCGvLJWNl1rsIBTjTfhAdB98Ilc3O29Y?= =?us-ascii?Q?XHk7yGXrP9+pZ5PTJtLy+7drExROCpwwZM7IVK591ZWyHdDsxVcZHrNI1Wzq?= =?us-ascii?Q?ECp41mtTPNpajoaLGqjg51S/ODmHvh2VXNGonb1wvE7J38pO8uKGMvtcqj19?= =?us-ascii?Q?ruXptQmsX97miMzk7wuDNt0qPFmztL+O08ZAhC76EPPmi45hy3orkXxhLjyb?= =?us-ascii?Q?+FaUdGBA6ipxGeS3kwgICbQg1k73J4LOe73KLBoWO8b/Soqp1KXZlaeGjX4l?= =?us-ascii?Q?HBX9b6ofkEUCc6++im5aKibyeql4AiMGa4xejl5xTTYAqJ6QJB17WetcFYqf?= =?us-ascii?Q?zCMJaJJDXilaQVdJcYJNc1c=3D?= X-OriginatorOrg: nutanix.com X-MS-Exchange-CrossTenant-Network-Message-Id: e9b8bf1d-9a9a-4043-0c82-08dbe4328a21 X-MS-Exchange-CrossTenant-AuthSource: DM6PR02MB6092.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Nov 2023 10:23:12.1464 (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: Jb4iB3NJR7pXj/9bArbLolV73Sit2IMjsZ/BbfWskNBZSuaPju1Q0iI0rr83HxG3yIn0b4O6lnevzn4N6uDrtG5goAbmbZ+kbs55mEYrvDU= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR02MB8568 X-Proofpoint-ORIG-GUID: G5CABw5GgKUGBtycfVqWcSVHR8VMMFoL X-Proofpoint-GUID: G5CABw5GgKUGBtycfVqWcSVHR8VMMFoL X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.987,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-11-12_24,2023-11-09_01,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: T6VEFL37ZMSDEJK4WZW7GZ24LWYEIR5S X-Message-ID-Hash: T6VEFL37ZMSDEJK4WZW7GZ24LWYEIR5S X-Mailman-Approved-At: Mon, 20 Nov 2023 09:02:31 -0500 CC: benjamin.taubmann@nutanix.com, prashanth.sreenivasa@nutanix.com 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: 1700471155709100001 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 Change-Id: Ib03013d00b3ec60716287dad4743a038cf000763 Reviewed-by: Martin Kletzander --- tools/libvirt-guests.sh.in | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) 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