* [pve-devel] [PATCH storage] zfs plugin: alloc/clone: cleanup image when creating LU mapping fails
@ 2025-06-05 11:57 Fiona Ebner
2025-06-06 9:32 ` Christoph Heiss
0 siblings, 1 reply; 2+ messages in thread
From: Fiona Ebner @ 2025-06-05 11:57 UTC (permalink / raw)
To: pve-devel
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [pve-devel] [PATCH storage] zfs plugin: alloc/clone: cleanup image when creating LU mapping fails
2025-06-05 11:57 [pve-devel] [PATCH storage] zfs plugin: alloc/clone: cleanup image when creating LU mapping fails Fiona Ebner
@ 2025-06-06 9:32 ` Christoph Heiss
0 siblings, 0 replies; 2+ messages in thread
From: Christoph Heiss @ 2025-06-06 9:32 UTC (permalink / raw)
To: Fiona Ebner; +Cc: Proxmox VE development discussion
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-06-06 9:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-06-05 11:57 [pve-devel] [PATCH storage] zfs plugin: alloc/clone: cleanup image when creating LU mapping fails Fiona Ebner
2025-06-06 9:32 ` Christoph Heiss
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal