From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <pve-devel-bounces@lists.proxmox.com> Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 367501FF165 for <inbox@lore.proxmox.com>; Thu, 5 Jun 2025 13:57:18 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 1579A17A50; Thu, 5 Jun 2025 13:57:36 +0200 (CEST) From: Fiona Ebner <f.ebner@proxmox.com> To: pve-devel@lists.proxmox.com Date: Thu, 5 Jun 2025 13:57:29 +0200 Message-Id: <20250605115729.62608-1-f.ebner@proxmox.com> X-Mailer: git-send-email 2.39.5 MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.032 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches 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. [zfsplugin.pm] Subject: [pve-devel] [PATCH storage] zfs plugin: alloc/clone: cleanup image when creating LU mapping fails X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com> List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe> List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/> List-Post: <mailto:pve-devel@lists.proxmox.com> List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help> List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe> Reply-To: Proxmox VE development discussion <pve-devel@lists.proxmox.com> Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" <pve-devel-bounces@lists.proxmox.com> Avoid leaving behind orphaned images if creating the associated LU mapping fails during image allocation or cloning. Reported-by: Christoph Heiss <c.heiss@proxmox.com> Signed-off-by: Fiona Ebner <f.ebner@proxmox.com> --- src/PVE/Storage/ZFSPlugin.pm | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/PVE/Storage/ZFSPlugin.pm b/src/PVE/Storage/ZFSPlugin.pm index 94cb11f..4118aa4 100644 --- a/src/PVE/Storage/ZFSPlugin.pm +++ b/src/PVE/Storage/ZFSPlugin.pm @@ -6,6 +6,7 @@ use IO::File; use POSIX; use PVE::Tools qw(run_command); use PVE::Storage::ZFSPoolPlugin; +use PVE::RESTEnvironment qw(log_warn); use PVE::RPCEnvironment; use base qw(PVE::Storage::ZFSPoolPlugin); @@ -283,8 +284,16 @@ sub clone_image { # get ZFS dataset name from PVE volname my (undef, $clonedname) = $class->parse_volname($name); - my $guid = $class->zfs_create_lu($scfg, $clonedname); - $class->zfs_add_lun_mapping_entry($scfg, $clonedname, $guid); + eval { + my $guid = $class->zfs_create_lu($scfg, $clonedname); + $class->zfs_add_lun_mapping_entry($scfg, $clonedname, $guid); + }; + if (my $err = $@) { + print "cleaning up allocated image '$clonedname' after failure to create LU mapping\n"; + eval { $class->zfs_delete_zvol($scfg, $clonedname); }; + log_warn("cleanup failed - $@") if $@; + die "error while creating LU mapping was - $err"; + } return $name; } @@ -302,9 +311,17 @@ sub alloc_image { $volname = $class->find_free_diskname($storeid, $scfg, $vmid, $fmt) if !$volname; $class->zfs_create_zvol($scfg, $volname, $size); - - my $guid = $class->zfs_create_lu($scfg, $volname); - $class->zfs_add_lun_mapping_entry($scfg, $volname, $guid); + + eval { + my $guid = $class->zfs_create_lu($scfg, $volname); + $class->zfs_add_lun_mapping_entry($scfg, $volname, $guid); + }; + if (my $err = $@) { + print "cleaning up allocated image '$volname' after failure to create LU mapping\n"; + eval { $class->zfs_delete_zvol($scfg, $volname); }; + log_warn("cleanup failed - $@") if $@; + die "error while creating LU mapping was - $err"; + } return $volname; } -- 2.39.5 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel