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 4CDCA1FF164 for <inbox@lore.proxmox.com>; Fri, 6 Jun 2025 11:32:34 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 1EEBA8DFC; Fri, 6 Jun 2025 11:32:53 +0200 (CEST) Mime-Version: 1.0 Date: Fri, 06 Jun 2025 11:32:49 +0200 Message-Id: <DAFCHN321BQY.1EGZPV31H2CS0@proxmox.com> To: "Fiona Ebner" <f.ebner@proxmox.com> From: "Christoph Heiss" <c.heiss@proxmox.com> X-Mailer: aerc 0.20.1 References: <20250605115729.62608-1-f.ebner@proxmox.com> In-Reply-To: <20250605115729.62608-1-f.ebner@proxmox.com> X-SPAM-LEVEL: Spam detection results: 0 AWL 0.030 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 SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: Re: [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> Cc: 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> Tested this by setting up a iSCSI target using targetcli(d) on a separate PVE 8.4 system as a base (due to ZFS goodies) and then adding a ZFS-over-iSCSI storage using the LIO provider to a test cluster. Due to #5071 [0], this configuration is currently broken and allocation will fail. I then tried to add a new hard disk to a VM on the ZFS-over-iSCSI storage, which a) failed as expected and logs the error b) the created LUN was cleaned up correctly. Also verified on the target that the previously created zvol is indeed cleaned up. Actual changes are simple enough & look good, so please consider this patch: Tested-by: Christoph Heiss <c.heiss@proxmox.com> Reviewed-by: Christoph Heiss <c.heiss@proxmox.com> [0] https://bugzilla.proxmox.com/show_bug.cgi?id=5071 On Thu Jun 5, 2025 at 1:57 PM CEST, Fiona Ebner wrote: > 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; > } _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel