From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 1708896223 for ; Mon, 23 Jan 2023 16:58:50 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id EA28729E8A for ; Mon, 23 Jan 2023 16:58:49 +0100 (CET) Received: from lana.proxmox.com (unknown [94.136.29.99]) by firstgate.proxmox.com (Proxmox) with ESMTP for ; Mon, 23 Jan 2023 16:58:48 +0100 (CET) Received: by lana.proxmox.com (Postfix, from userid 10043) id 7591A2C23ED; Mon, 23 Jan 2023 16:58:48 +0100 (CET) From: Stefan Hanreich To: pve-devel@lists.proxmox.com Date: Mon, 23 Jan 2023 16:58:45 +0100 Message-Id: <20230123155847.598536-1-s.hanreich@proxmox.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 2.098 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment KAM_LAZY_DOMAIN_SECURITY 1 Sending domain does not have any anti-forgery methods NO_DNS_FOR_FROM 0.001 Envelope sender has no MX or A DNS records RCVD_IN_DNSWL_HI -5 Sender listed at https://www.dnswl.org/, high trust RDNS_NONE 0.793 Delivered to internal network by a host with no rDNS SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_NONE 0.001 SPF: sender does not publish an SPF Record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [abstractconfig.pm, guest-example-hookscript.pl] Subject: [pve-devel] [PATCH-SERIES guest-common/docs v3] add pre/post/failed snapshot hooks X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 23 Jan 2023 15:58:50 -0000 This patch series introduces the pre/post/failed-snapshot hooks that run before/ after a snapshot is taken, or after failing to take a snapshot. I used the new example script from pve-docs as template for my test hookscripts. What I tested: * Normal snapshotting, without VM state, without hookscript * snapshot works, no hooks executed * Normal snapshotting, with VM state, without hookscript * snapshot works, no hooks executed * Normal snapshotting, without VM state, with hookscript * snapshot works, pre/post hooks work * Normal snapshotting, with VM state, with hookscript * snapshot works, pre/post hooks work * Taking snapshot with existing name, with hookscript * fails, no hookscripts get executed * Failed at wrong storage config, with hookscript * pre/failed get executed, lock gets released * Failed at taking RAM Snapshot (simulated with monkey-patched die), with hookscript * pre/failed get executed, lock gets released * pre/post hookscript that detaches/attaches unsnapshottable disk (without --skiplock) * snapshotting fails, attach/detach fails, pre/failed get executed, lock released * pre/post hookscript that detaches/attaches unsnapshottable disk (with --skiplock) * snapshotting works, attach/detach works, pre/post get executed * restoring works, detached disk is detached after restoring * pre-snapshot hookscript exits with code > 0 * pre/failed-snapshot get executed, snapshot fails, lock gets released * post-snapshot hookscript exits with code > 0 * pre/post/failed-snapshot get executed, snapshot fails, lock gets released * Taking snapshot of template * fails, no hookscripts get executed * execute commands in VM in pre/post via qm guest exec * snapshot succeeds, commands get executed, pre/post executed Changes from v2 (thanks fabian!): * added guards, so cfs_update() only gets called when necessary * added PVE_SNAPSHOT_PHASE envvar to failed-snapshot as indicator when the failure occured Changes from v1: * added failed-snapshot hook that runs after a failed snapshot * this enables users to revert any changes made in pre-snapshot hooks in case of errors * running cfs_update() after every hookscript invocation * adjusted the call sites of exec_hookscript() * particularly interesting for pre-snapshot since some checks now run before the hook runs * VM/CT config is now locked during hookscript execution Thanks to Fiona and Fabian for their valuable input/help! pve-guest-common: Stefan Hanreich (1): examples: add pre/post/failed-snapshot hooks to example hookscript examples/guest-example-hookscript.pl | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) pve-docs: Stefan Hanreich (1): partial fix #2530: snapshots: add pre/post/failed-snapshot hooks src/PVE/AbstractConfig.pm | 76 +++++++++++++++++++++++++++++++++++---- 1 file changed, 70 insertions(+), 6 deletions(-) -- 2.30.2