From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id DD5DA1FF16B for ; Tue, 29 Jul 2025 13:23:53 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 76719F985; Tue, 29 Jul 2025 13:25:08 +0200 (CEST) From: Wolfgang Bumiller To: pve-devel@lists.proxmox.com Date: Tue, 29 Jul 2025 13:15:33 +0200 Message-ID: <20250729111557.136012-21-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: 1753787750101 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.075 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. [btrfsplugin.pm, lvmplugin.pm, zfspoolplugin.pm, plugin.pm, rbdplugin.pm] Subject: [pve-devel] [PATCH storage 20/26] plugins: update rename_volumes 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/LVMPlugin.pm | 11 +++++++++-- src/PVE/Storage/Plugin.pm | 26 ++++++++++++++++++++++---- src/PVE/Storage/RBDPlugin.pm | 11 +++++++++-- src/PVE/Storage/ZFSPoolPlugin.pm | 11 +++++++++-- 5 files changed, 59 insertions(+), 12 deletions(-) diff --git a/src/PVE/Storage/BTRFSPlugin.pm b/src/PVE/Storage/BTRFSPlugin.pm index 8417dd6..a0145bb 100644 --- a/src/PVE/Storage/BTRFSPlugin.pm +++ b/src/PVE/Storage/BTRFSPlugin.pm @@ -1031,7 +1031,7 @@ sub rename_volume { my ($class, $scfg, $storeid, $source_volname, $target_vmid, $target_volname) = @_; die "no path found\n" if !$scfg->{path}; - my $format = ($class->parse_volname($source_volname))[6]; + my ($source_vtype, $format) = ($class->parse_volname($source_volname))[0, 6]; if ($format ne 'raw' && $format ne 'subvol') { return $class->SUPER::rename_volume( @@ -1039,8 +1039,16 @@ sub rename_volume { ); } - $target_volname = $class->find_free_diskname($storeid, $scfg, $target_vmid, $format, 1) + $target_volname = + $class->find_free_diskname($storeid, $scfg, $target_vmid, $format, 1, $source_vtype) if !$target_volname; + + my ($target_vtype) = $class->parse_volname($target_volname); + if (!PVE::Storage::Common::is_type_change_allowed($source_vtype, $target_vtype)) { + die "refusing to rename volume '$source_volname' to '$target_volname':" + . " source has vtype '$source_vtype', target name has vtype '$target_vtype'\n"; + } + $target_volname = "$target_vmid/$target_volname"; my $basedir = $class->get_subdir($scfg, 'images'); diff --git a/src/PVE/Storage/LVMPlugin.pm b/src/PVE/Storage/LVMPlugin.pm index 304d411..b578ff4 100644 --- a/src/PVE/Storage/LVMPlugin.pm +++ b/src/PVE/Storage/LVMPlugin.pm @@ -1332,7 +1332,7 @@ sub rename_volume { my ($class, $scfg, $storeid, $source_volname, $target_vmid, $target_volname) = @_; my ( - undef, $source_image, $source_vmid, $base_name, $base_vmid, undef, $format, + $source_vtype, $source_image, $source_vmid, $base_name, $base_vmid, undef, $format, ) = $class->parse_volname($source_volname); if ($format eq 'qcow2') { @@ -1340,9 +1340,16 @@ sub rename_volume { die "we can't rename volume if external snapshot exists" if $snapshots->{current}->{parent}; } - $target_volname = $class->find_free_diskname($storeid, $scfg, $target_vmid, $format) + $target_volname = + $class->find_free_diskname($storeid, $scfg, $target_vmid, $format, 0, $source_vtype) if !$target_volname; + my ($target_vtype) = $class->parse_volname($target_volname); + if (!PVE::Storage::Common::is_type_change_allowed($source_vtype, $target_vtype)) { + die "refusing to rename volume '$source_volname' to '$target_volname':" + . " source has vtype '$source_vtype', target name has vtype '$target_vtype'\n"; + } + my $vg = $scfg->{vgname}; my $lvs = lvm_list_volumes($vg); die "target volume '${target_volname}' already exists\n" diff --git a/src/PVE/Storage/Plugin.pm b/src/PVE/Storage/Plugin.pm index 1b72a17..e418042 100644 --- a/src/PVE/Storage/Plugin.pm +++ b/src/PVE/Storage/Plugin.pm @@ -2367,7 +2367,7 @@ sub volume_import_formats { } sub rename_volume { - my ($class, $scfg, $storeid, $source_volname, $target_vmid, $target_volname) = @_; + my ($class, $scfg, $storeid, $source_volname, $target_vmid, $target_volname, $vtype) = @_; die "not implemented in storage plugin '$class'\n" if $class->can('api') && $class->api() < 10; die "no path found\n" if !$scfg->{path}; @@ -2378,11 +2378,29 @@ sub rename_volume { } my ( - undef, $source_image, $source_vmid, $base_name, $base_vmid, undef, $format, + $source_vtype, $source_image, $source_vmid, $base_name, $base_vmid, undef, $format, ) = $class->parse_volname($source_volname); - $target_volname = $class->find_free_diskname($storeid, $scfg, $target_vmid, $format, 1) - if !$target_volname; + $target_volname = $class->find_free_diskname( + $storeid, + $scfg, + $target_vmid, + $format, + 1, + $vtype // $source_vtype, + ) if !$target_volname; + + my ($target_vtype) = $class->parse_volname($target_volname); + + if (!PVE::Storage::Common::is_type_change_allowed($source_vtype, $target_vtype)) { + die "refusing to rename volume '$source_volname' to '$target_volname':" + . " source has vtype '$source_vtype', target name has vtype '$target_vtype'\n"; + } + + if (defined($vtype) && !PVE::Storage::Common::is_type_change_allowed($vtype, $target_vtype)) { + die "refusing to rename volume '$source_volname' to '$target_volname':" + . " target name has vtype '$target_vtype', but vtype '$vtype' was requested\n"; + } my $basedir = $class->get_subdir($scfg, 'images'); diff --git a/src/PVE/Storage/RBDPlugin.pm b/src/PVE/Storage/RBDPlugin.pm index fb97c94..437dd07 100644 --- a/src/PVE/Storage/RBDPlugin.pm +++ b/src/PVE/Storage/RBDPlugin.pm @@ -1111,11 +1111,18 @@ sub rename_volume { my ($class, $scfg, $storeid, $source_volname, $target_vmid, $target_volname) = @_; my ( - undef, $source_image, $source_vmid, $base_name, $base_vmid, undef, $format, + $source_vtype, $source_image, $source_vmid, $base_name, $base_vmid, undef, $format, ) = $class->parse_volname($source_volname); - $target_volname = $class->find_free_diskname($storeid, $scfg, $target_vmid, $format) + $target_volname = + $class->find_free_diskname($storeid, $scfg, $target_vmid, $format, 0, $source_vtype) if !$target_volname; + my ($target_vtype) = $class->parse_volname($target_volname); + if (!PVE::Storage::Common::is_type_change_allowed($source_vtype, $target_vtype)) { + die "refusing to rename volume '$source_volname' to '$target_volname':" + . " source has vtype '$source_vtype', target name has vtype '$target_vtype'\n"; + } + die "target volume '${target_volname}' already exists\n" if rbd_volume_exists($scfg, $storeid, $target_volname); diff --git a/src/PVE/Storage/ZFSPoolPlugin.pm b/src/PVE/Storage/ZFSPoolPlugin.pm index 1571310..34768d2 100644 --- a/src/PVE/Storage/ZFSPoolPlugin.pm +++ b/src/PVE/Storage/ZFSPoolPlugin.pm @@ -943,11 +943,18 @@ sub rename_volume { my ($class, $scfg, $storeid, $source_volname, $target_vmid, $target_volname) = @_; my ( - undef, $source_image, $source_vmid, $base_name, $base_vmid, undef, $format, + $source_vtype, $source_image, $source_vmid, $base_name, $base_vmid, undef, $format, ) = $class->parse_volname($source_volname); - $target_volname = $class->find_free_diskname($storeid, $scfg, $target_vmid, $format) + $target_volname = + $class->find_free_diskname($storeid, $scfg, $target_vmid, $format, 0, $source_vtype) if !$target_volname; + my ($target_vtype) = $class->parse_volname($target_volname); + if (!PVE::Storage::Common::is_type_change_allowed($source_vtype, $target_vtype)) { + die "refusing to rename volume '$source_volname' to '$target_volname':" + . " source has vtype '$source_vtype', target name has vtype '$target_vtype'\n"; + } + my $pool = $scfg->{pool}; my $source_zfspath = "${pool}/${source_image}"; my $target_zfspath = "${pool}/${target_volname}"; -- 2.47.2 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel