From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id CBFBD1FF16B for ; Tue, 29 Jul 2025 13:18:08 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 40023F16F; Tue, 29 Jul 2025 13:17:04 +0200 (CEST) From: Wolfgang Bumiller To: pve-devel@lists.proxmox.com Date: Tue, 29 Jul 2025 13:15:32 +0200 Message-ID: <20250729111557.136012-20-w.bumiller@proxmox.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250729111557.136012-1-w.bumiller@proxmox.com> References: <20250729111557.136012-1-w.bumiller@proxmox.com> MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1753787750027 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.077 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: [pve-devel] [PATCH storage 19/26] plugins: update clone_image methods 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: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" Signed-off-by: Wolfgang Bumiller --- src/PVE/Storage/BTRFSPlugin.pm | 12 ++++++++++-- src/PVE/Storage/ESXiPlugin.pm | 2 +- src/PVE/Storage/ISCSIDirectPlugin.pm | 2 +- src/PVE/Storage/ISCSIPlugin.pm | 2 +- src/PVE/Storage/LVMPlugin.pm | 2 +- src/PVE/Storage/LvmThinPlugin.pm | 14 ++++++++++++-- src/PVE/Storage/Plugin.pm | 17 +++++++++++++---- src/PVE/Storage/RBDPlugin.pm | 12 ++++++++++-- src/PVE/Storage/ZFSPlugin.pm | 4 ++-- src/PVE/Storage/ZFSPoolPlugin.pm | 13 +++++++++++-- 10 files changed, 62 insertions(+), 18 deletions(-) diff --git a/src/PVE/Storage/BTRFSPlugin.pm b/src/PVE/Storage/BTRFSPlugin.pm index b3a53b0..8417dd6 100644 --- a/src/PVE/Storage/BTRFSPlugin.pm +++ b/src/PVE/Storage/BTRFSPlugin.pm @@ -292,11 +292,19 @@ sub create_base { } sub clone_image { - my ($class, $scfg, $storeid, $volname, $vmid, $snap) = @_; + my ($class, $scfg, $storeid, $volname, $vmid, $snap, $target_vtype) = @_; my ($vtype, $basename, $basevmid, undef, undef, $isBase, $format) = $class->parse_volname($volname); + if ( + defined($target_vtype) + && !PVE::Storage::Common::is_type_change_allowed($vtype, $target_vtype) + ) { + die "refusing to clone image as different vtype:" + . " (source is '$vtype', target '$target_vtype')\n"; + } + # If we're not working with a 'raw' file, which is the only thing that's "different" for btrfs, # or a subvolume, we forward to the DirPlugin if ($format ne 'raw' && $format ne 'subvol') { @@ -308,7 +316,7 @@ sub clone_image { mkpath $imagedir; my $path = $class->filesystem_path($scfg, $volname); - my $newname = $class->find_free_diskname($storeid, $scfg, $vmid, $format, 1); + my $newname = $class->find_free_diskname($storeid, $scfg, $vmid, $format, 1, $vtype); # For btrfs subvolumes we don't actually need the "link": #my $newvolname = "$basevmid/$basename/$vmid/$newname"; diff --git a/src/PVE/Storage/ESXiPlugin.pm b/src/PVE/Storage/ESXiPlugin.pm index d10b156..8cb9193 100644 --- a/src/PVE/Storage/ESXiPlugin.pm +++ b/src/PVE/Storage/ESXiPlugin.pm @@ -460,7 +460,7 @@ sub list_volumes { } sub clone_image { - my ($class, $scfg, $storeid, $volname, $vmid, $snap) = @_; + my ($class, $scfg, $storeid, $volname, $vmid, $snap, $vtype) = @_; die "cloning images is not supported for $class\n"; } diff --git a/src/PVE/Storage/ISCSIDirectPlugin.pm b/src/PVE/Storage/ISCSIDirectPlugin.pm index 0fee541..4fefb3a 100644 --- a/src/PVE/Storage/ISCSIDirectPlugin.pm +++ b/src/PVE/Storage/ISCSIDirectPlugin.pm @@ -134,7 +134,7 @@ sub create_base { } sub clone_image { - my ($class, $scfg, $storeid, $volname, $vmid, $snap) = @_; + my ($class, $scfg, $storeid, $volname, $vmid, $snap, $target_vtype) = @_; die "can't clone images in iscsi storage\n"; } diff --git a/src/PVE/Storage/ISCSIPlugin.pm b/src/PVE/Storage/ISCSIPlugin.pm index 5118d73..a7b1920 100644 --- a/src/PVE/Storage/ISCSIPlugin.pm +++ b/src/PVE/Storage/ISCSIPlugin.pm @@ -396,7 +396,7 @@ sub create_base { } sub clone_image { - my ($class, $scfg, $storeid, $volname, $vmid, $snap) = @_; + my ($class, $scfg, $storeid, $volname, $vmid, $snap, $target_vtype) = @_; die "can't clone images in iscsi storage\n"; } diff --git a/src/PVE/Storage/LVMPlugin.pm b/src/PVE/Storage/LVMPlugin.pm index af789ba..304d411 100644 --- a/src/PVE/Storage/LVMPlugin.pm +++ b/src/PVE/Storage/LVMPlugin.pm @@ -529,7 +529,7 @@ sub create_base { } sub clone_image { - my ($class, $scfg, $storeid, $volname, $vmid, $snap) = @_; + my ($class, $scfg, $storeid, $volname, $vmid, $snap, $target_vtype) = @_; die "can't clone images in lvm storage\n"; } diff --git a/src/PVE/Storage/LvmThinPlugin.pm b/src/PVE/Storage/LvmThinPlugin.pm index 2071822..6462c22 100644 --- a/src/PVE/Storage/LvmThinPlugin.pm +++ b/src/PVE/Storage/LvmThinPlugin.pm @@ -339,7 +339,7 @@ sub deactivate_volume { } sub clone_image { - my ($class, $scfg, $storeid, $volname, $vmid, $snap) = @_; + my ($class, $scfg, $storeid, $volname, $vmid, $snap, $target_vtype) = @_; my $vg = $scfg->{vgname}; @@ -352,10 +352,20 @@ sub clone_image { die "clone_image only works on base images\n" if !$isBase; + if ( + defined($target_vtype) + && !PVE::Storage::Common::is_type_change_allowed($vtype, $target_vtype) + ) { + die "refusing to clone '$volname':" + . " volume has vtype '$vtype', requested vtype is '$target_vtype'\n"; + } else { + $target_vtype = $vtype; + } + $lv = "$vg/$volname"; } - my $name = $class->find_free_diskname($storeid, $scfg, $vmid); + my $name = $class->find_free_diskname($storeid, $scfg, $vmid, undef, 0, $target_vtype); my $cmd = ['/sbin/lvcreate', '-n', $name, '-prw', '-kn', '-s', $lv]; run_command($cmd, errmsg => "clone image '$lv' error"); diff --git a/src/PVE/Storage/Plugin.pm b/src/PVE/Storage/Plugin.pm index e4cf392..1b72a17 100644 --- a/src/PVE/Storage/Plugin.pm +++ b/src/PVE/Storage/Plugin.pm @@ -973,7 +973,7 @@ sub find_free_diskname { } sub clone_image { - my ($class, $scfg, $storeid, $volname, $vmid, $snap) = @_; + my ($class, $scfg, $storeid, $volname, $vmid, $snap, $target_vtype) = @_; # this only works for file based storage types die "storage definition has no path\n" if !$scfg->{path}; @@ -981,7 +981,16 @@ sub clone_image { my ($vtype, $basename, $basevmid, undef, undef, $isBase, $format) = $class->parse_volname($volname); - die "clone_image on wrong vtype '$vtype'\n" if $vtype ne 'images'; + die "clone_image on wrong vtype '$vtype'\n" if !PVE::Storage::Common::is_volume_type($vtype); + + if ( + defined($target_vtype) + && !PVE::Storage::Common::is_type_change_allowed($vtype, $target_vtype) + ) { + die "refusing to clone image as different vtype:" + . " (source is '$vtype', target '$target_vtype')\n"; + } + $target_vtype //= $vtype; die "this storage type does not support clone_image on snapshot\n" if $snap; @@ -989,12 +998,12 @@ sub clone_image { die "clone_image only works on base images\n" if !$isBase; - my $imagedir = $class->get_subdir($scfg, 'images'); + my $imagedir = $class->get_subdir($scfg, $target_vtype); $imagedir .= "/$vmid"; mkpath $imagedir; - my $name = $class->find_free_diskname($storeid, $scfg, $vmid, "qcow2", 1); + my $name = $class->find_free_diskname($storeid, $scfg, $vmid, "qcow2", 1, $target_vtype); warn "clone $volname: $vtype, $name, $vmid to $name (base=../$basevmid/$basename)\n"; diff --git a/src/PVE/Storage/RBDPlugin.pm b/src/PVE/Storage/RBDPlugin.pm index 11639f0..fb97c94 100644 --- a/src/PVE/Storage/RBDPlugin.pm +++ b/src/PVE/Storage/RBDPlugin.pm @@ -697,7 +697,7 @@ sub create_base { } sub clone_image { - my ($class, $scfg, $storeid, $volname, $vmid, $snapname) = @_; + my ($class, $scfg, $storeid, $volname, $vmid, $snapname, $target_vtype) = @_; my $snap = '__base__'; $snap = $snapname if length $snapname; @@ -707,7 +707,15 @@ sub clone_image { die "$volname is not a base image and snapname is not provided\n" if !$isBase && !length($snapname); - my $name = $class->find_free_diskname($storeid, $scfg, $vmid); + if ( + defined($target_vtype) + && !PVE::Storage::Common::is_type_change_allowed($vtype, $target_vtype) + ) { + die "refusing to clone image as different vtype:" + . " (source is '$vtype', target '$target_vtype')\n"; + } + + my $name = $class->find_free_diskname($storeid, $scfg, $vmid, undef, undef $target_vtype); warn "clone $volname: $basename snapname $snap to $name\n"; diff --git a/src/PVE/Storage/ZFSPlugin.pm b/src/PVE/Storage/ZFSPlugin.pm index fdbe80c..721e39e 100644 --- a/src/PVE/Storage/ZFSPlugin.pm +++ b/src/PVE/Storage/ZFSPlugin.pm @@ -345,9 +345,9 @@ sub create_base { } sub clone_image { - my ($class, $scfg, $storeid, $volname, $vmid, $snap) = @_; + my ($class, $scfg, $storeid, $volname, $vmid, $snap, $target_vtype) = @_; - my $name = $class->SUPER::clone_image($scfg, $storeid, $volname, $vmid, $snap); + my $name = $class->SUPER::clone_image($scfg, $storeid, $volname, $vmid, $snap, $target_vtype); # get ZFS dataset name from PVE volname my (undef, $clonedname) = $class->parse_volname($name); diff --git a/src/PVE/Storage/ZFSPoolPlugin.pm b/src/PVE/Storage/ZFSPoolPlugin.pm index f972718..1571310 100644 --- a/src/PVE/Storage/ZFSPoolPlugin.pm +++ b/src/PVE/Storage/ZFSPoolPlugin.pm @@ -706,7 +706,7 @@ sub deactivate_volume { } sub clone_image { - my ($class, $scfg, $storeid, $volname, $vmid, $snap) = @_; + my ($class, $scfg, $storeid, $volname, $vmid, $snap, $target_vtype) = @_; $snap ||= '__base__'; @@ -715,7 +715,16 @@ sub clone_image { die "clone_image only works on base images\n" if !$isBase; - my $name = $class->find_free_diskname($storeid, $scfg, $vmid, $format); + if ( + defined($target_vtype) + && !PVE::Storage::Common::is_type_change_allowed($vtype, $target_vtype) + ) { + die "refusing to clone image as different vtype:" + . " (source is '$vtype', target '$target_vtype')\n"; + } + $target_vtype //= $vtype; + + my $name = $class->find_free_diskname($storeid, $scfg, $vmid, $format, 0, $target_vtype); if ($format eq 'subvol') { my $size = $class->zfs_request( -- 2.47.2 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel