From: Wolfgang Bumiller <w.bumiller@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH storage 21/26] plugins: update volume_import methods
Date: Tue, 29 Jul 2025 13:15:34 +0200 [thread overview]
Message-ID: <20250729111557.136012-22-w.bumiller@proxmox.com> (raw)
In-Reply-To: <20250729111557.136012-1-w.bumiller@proxmox.com>
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
---
src/PVE/Storage/BTRFSPlugin.pm | 11 +++++-
src/PVE/Storage/LVMPlugin.pm | 12 ++++++-
src/PVE/Storage/LvmThinPlugin.pm | 62 ++++++++++++++++++++------------
src/PVE/Storage/Plugin.pm | 12 ++++++-
src/PVE/Storage/RBDPlugin.pm | 13 +++++--
src/PVE/Storage/ZFSPoolPlugin.pm | 14 ++++++--
6 files changed, 94 insertions(+), 30 deletions(-)
diff --git a/src/PVE/Storage/BTRFSPlugin.pm b/src/PVE/Storage/BTRFSPlugin.pm
index a0145bb..0bd5244 100644
--- a/src/PVE/Storage/BTRFSPlugin.pm
+++ b/src/PVE/Storage/BTRFSPlugin.pm
@@ -880,6 +880,7 @@ sub volume_import {
$base_snapshot,
$with_snapshots,
$allow_rename,
+ $import_vtype,
) = @_;
if ($format ne 'btrfs') {
@@ -895,6 +896,14 @@ sub volume_import {
die "btrfs-receiving volumes of type $volume_format ('$volname') is not supported\n"
if $volume_format ne 'raw' && $volume_format ne 'subvol';
+ if (
+ defined($import_vtype)
+ && !PVE::Storage::Common::is_type_change_allowed($import_vtype, $vtype)
+ ) {
+ die "refusing import volume with name '$volname':"
+ . " name implies type '$vtype', import requested type '$import_vtype'\n";
+ }
+
if (defined($base_snapshot)) {
my $path = $class->path($scfg, $volname, $storeid, $base_snapshot);
$path = raw_file_to_subvol($path) if $volume_format eq 'raw';
@@ -909,7 +918,7 @@ sub volume_import {
if (!defined($base_snapshot) && -e $destination) {
die "volume $volname already exists\n" if !$allow_rename;
- $volname = $class->find_free_diskname($storeid, $scfg, $vmid, $volume_format, 1);
+ $volname = $class->find_free_diskname($storeid, $scfg, $vmid, $volume_format, 1, $vtype);
}
my $imagedir = $class->get_subdir($scfg, $vtype);
diff --git a/src/PVE/Storage/LVMPlugin.pm b/src/PVE/Storage/LVMPlugin.pm
index b578ff4..1811e05 100644
--- a/src/PVE/Storage/LVMPlugin.pm
+++ b/src/PVE/Storage/LVMPlugin.pm
@@ -1278,6 +1278,7 @@ sub volume_import {
$base_snapshot,
$with_snapshots,
$allow_rename,
+ $import_vtype,
) = @_;
die "volume import format $format not available for $class\n"
if $format ne 'raw+size';
@@ -1290,6 +1291,14 @@ sub volume_import {
die "cannot import format $format into a file of format $file_format\n"
if $file_format ne 'raw';
+ if (
+ defined($import_vtype)
+ && !PVE::Storage::Common::is_type_change_allowed($import_vtype, $vtype)
+ ) {
+ die "refusing import volume with name '$volname':"
+ . " name implies type '$vtype', import requested type '$import_vtype'\n";
+ }
+
my $vg = $scfg->{vgname};
my $lvs = lvm_list_volumes($vg);
if ($lvs->{$vg}->{$volname}) {
@@ -1302,7 +1311,8 @@ sub volume_import {
$size = PVE::Storage::Common::align_size_up($size, 1024) / 1024;
eval {
- my $allocname = $class->alloc_image($storeid, $scfg, $vmid, 'raw', $name, $size);
+ my $allocname =
+ $class->alloc_image($storeid, $scfg, $vmid, 'raw', $name, $size, $vtype);
my $oldname = $volname;
$volname = $allocname;
if (defined($name) && $allocname ne $oldname) {
diff --git a/src/PVE/Storage/LvmThinPlugin.pm b/src/PVE/Storage/LvmThinPlugin.pm
index 6462c22..c1ff474 100644
--- a/src/PVE/Storage/LvmThinPlugin.pm
+++ b/src/PVE/Storage/LvmThinPlugin.pm
@@ -6,6 +6,7 @@ use warnings;
use IO::File;
use PVE::Tools qw(run_command trim);
+use PVE::Storage::Common;
use PVE::Storage::Plugin;
use PVE::Storage::LVMPlugin;
use PVE::JSONSchema qw(get_standard_option);
@@ -488,6 +489,7 @@ sub volume_import {
$base_snapshot,
$with_snapshots,
$allow_rename,
+ $import_vtype,
) = @_;
my ($vtype, $name, $vmid, $basename, $basevmid, $isBase, $file_format) =
@@ -504,36 +506,50 @@ sub volume_import {
$base_snapshot,
$with_snapshots,
$allow_rename,
+ $import_vtype,
);
+ }
+
+ if (
+ defined($import_vtype)
+ && !PVE::Storage::Common::is_type_change_allowed($import_vtype, $vtype)
+ ) {
+ die "refusing import volume with name '$volname':"
+ . " name implies type '$vtype', import requested type '$import_vtype'\n";
+ }
+
+ my $tempname;
+ my $vg = $scfg->{vgname};
+ my $lvs = PVE::Storage::LVMPlugin::lvm_list_volumes($vg);
+ if ($lvs->{$vg}->{$volname}) {
+ die "volume $vg/$volname already exists\n" if !$allow_rename;
+ warn "volume $vg/$volname already exists - importing with a different name\n";
+
+ $tempname = $class->find_free_diskname($storeid, $scfg, $vmid, undef, 0, $vtype);
} else {
- my $tempname;
- my $vg = $scfg->{vgname};
- my $lvs = PVE::Storage::LVMPlugin::lvm_list_volumes($vg);
- if ($lvs->{$vg}->{$volname}) {
- die "volume $vg/$volname already exists\n" if !$allow_rename;
- warn "volume $vg/$volname already exists - importing with a different name\n";
-
- $tempname = $class->find_free_diskname($storeid, $scfg, $vmid);
+ $tempname = $volname;
+ if ($tempname =~ /^base-vol-/) {
+ $tempname =~ substr($tempname, 5);
} else {
- $tempname = $volname;
$tempname =~ s/base/vm/;
}
+ }
- my $newvolid = $class->SUPER::volume_import(
- $scfg,
- $storeid,
- $fh,
- $tempname,
- $format,
- $snapshot,
- $base_snapshot,
- $with_snapshots,
- $allow_rename,
- );
- ($storeid, my $newname) = PVE::Storage::parse_volume_id($newvolid);
+ my $newvolid = $class->SUPER::volume_import(
+ $scfg,
+ $storeid,
+ $fh,
+ $tempname,
+ $format,
+ $snapshot,
+ $base_snapshot,
+ $with_snapshots,
+ $allow_rename,
+ $import_vtype,
+ );
+ ($storeid, my $newname) = PVE::Storage::parse_volume_id($newvolid);
- $volname = $class->create_base($storeid, $scfg, $newname);
- }
+ $volname = $class->create_base($storeid, $scfg, $newname);
return "$storeid:$volname";
}
diff --git a/src/PVE/Storage/Plugin.pm b/src/PVE/Storage/Plugin.pm
index e418042..fc39df7 100644
--- a/src/PVE/Storage/Plugin.pm
+++ b/src/PVE/Storage/Plugin.pm
@@ -2289,6 +2289,7 @@ sub volume_import {
$base_snapshot,
$with_snapshots,
$allow_rename,
+ $import_vtype,
) = @_;
die "volume import format '$format' not available for $class\n"
@@ -2303,6 +2304,14 @@ sub volume_import {
my ($vtype, $name, $vmid, $basename, $basevmid, $isBase, $file_format) =
$class->parse_volname($volname);
+ if (
+ defined($import_vtype)
+ && !PVE::Storage::Common::is_type_change_allowed($import_vtype, $vtype)
+ ) {
+ die "refusing import volume with name '$volname':"
+ . " name implies type '$vtype', import requested type '$import_vtype'\n";
+ }
+
# XXX: Should we bother with conversion routines at this level? This won't
# happen without manual CLI usage, so for now we just error out...
die "cannot import format $format into a file of format $file_format\n"
@@ -2321,7 +2330,8 @@ sub volume_import {
$size = PVE::Storage::Common::align_size_up($size, 1024) / 1024;
eval {
- my $allocname = $class->alloc_image($storeid, $scfg, $vmid, $file_format, $name, $size);
+ my $allocname =
+ $class->alloc_image($storeid, $scfg, $vmid, $file_format, $name, $size, $vtype);
my $oldname = $volname;
$volname = $allocname;
if (defined($name) && $allocname ne $oldname) {
diff --git a/src/PVE/Storage/RBDPlugin.pm b/src/PVE/Storage/RBDPlugin.pm
index 437dd07..7b54f7c 100644
--- a/src/PVE/Storage/RBDPlugin.pm
+++ b/src/PVE/Storage/RBDPlugin.pm
@@ -1068,20 +1068,29 @@ sub volume_import {
$base_snapshot,
$with_snapshots,
$allow_rename,
+ $import_vtype,
) = @_;
die "volume import format $format not available for $class\n" if $format ne 'raw+size';
die "cannot import volumes together with their snapshots in $class\n" if $with_snapshots;
die "cannot import an incremental stream in $class\n" if defined($base_snapshot);
- my (undef, $name, $vmid, undef, undef, undef, $file_format) = $class->parse_volname($volname);
+ my ($vtype, $name, $vmid, undef, undef, undef, $file_format) = $class->parse_volname($volname);
die "cannot import format $format into a volume of format $file_format\n"
if $file_format ne 'raw';
+ if (
+ defined($import_vtype)
+ && !PVE::Storage::Common::is_type_change_allowed($import_vtype, $vtype)
+ ) {
+ die "refusing import volume with name '$volname':"
+ . " name implies type '$vtype', import requested type '$import_vtype'\n";
+ }
+
if (rbd_volume_exists($scfg, $storeid, $name)) {
die "volume $name already exists\n" if !$allow_rename;
warn "volume $name already exists - importing with a different name\n";
- $volname = $class->find_free_diskname($storeid, $scfg, $vmid, $file_format);
+ $volname = $class->find_free_diskname($storeid, $scfg, $vmid, $file_format, 0, $vtype);
}
my ($size) = PVE::Storage::Plugin::read_common_header($fh);
diff --git a/src/PVE/Storage/ZFSPoolPlugin.pm b/src/PVE/Storage/ZFSPoolPlugin.pm
index 34768d2..2cae090 100644
--- a/src/PVE/Storage/ZFSPoolPlugin.pm
+++ b/src/PVE/Storage/ZFSPoolPlugin.pm
@@ -9,6 +9,7 @@ use POSIX;
use PVE::ProcFSTools;
use PVE::RPCEnvironment;
+use PVE::Storage::Common;
use PVE::Storage::Plugin;
use PVE::Tools qw(run_command);
@@ -890,6 +891,7 @@ sub volume_import {
$base_snapshot,
$with_snapshots,
$allow_rename,
+ $import_vtype,
) = @_;
die "unsupported import stream format for $class: $format\n"
@@ -899,9 +901,17 @@ sub volume_import {
die "internal error: invalid file handle for volume_import\n"
if !defined($fd);
- my (undef, $dataset, $vmid, undef, undef, undef, $volume_format) =
+ my ($vtype, $dataset, $vmid, undef, undef, undef, $volume_format) =
$class->parse_volname($volname);
+ if (
+ defined($import_vtype)
+ && !PVE::Storage::Common::is_type_change_allowed($import_vtype, $vtype)
+ ) {
+ die "refusing import volume with name '$volname':"
+ . " name implies type '$vtype', import requested type '$import_vtype'\n";
+ }
+
my $zfspath = "$scfg->{pool}/$dataset";
my $suffix = defined($base_snapshot) ? "\@$base_snapshot" : '';
my $exists = 0 == run_command(
@@ -914,7 +924,7 @@ sub volume_import {
} elsif ($exists) {
die "volume '$zfspath' already exists\n" if !$allow_rename;
warn "volume '$zfspath' already exists - importing with a different name\n";
- $dataset = $class->find_free_diskname($storeid, $scfg, $vmid, $volume_format);
+ $dataset = $class->find_free_diskname($storeid, $scfg, $vmid, $volume_format, 0, $vtype);
$zfspath = "$scfg->{pool}/$dataset";
}
--
2.47.2
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
next prev parent reply other threads:[~2025-07-29 11:18 UTC|newest]
Thread overview: 74+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-29 11:15 [pve-devel] [RFC storage 00/26+10+3] unify vtype and content-type and Wolfgang Bumiller
2025-07-29 11:15 ` [pve-devel] [PATCH storage 01/26] btrfs: remove unnecessary mkpath call Wolfgang Bumiller
2025-07-29 11:15 ` [pve-devel] [PATCH storage 02/26] parse_volname: remove openvz 'rootdir' case Wolfgang Bumiller
2025-07-29 11:15 ` [pve-devel] [PATCH storage 03/26] drop rootdir case in path_to_volume_id Wolfgang Bumiller
2025-07-29 11:15 ` [pve-devel] [PATCH storage 04/26] escape dirs in path_to_volume_id regexes Wolfgang Bumiller
2025-07-29 11:15 ` [pve-devel] [PATCH storage 05/26] tests: drop rootdir/ tests Wolfgang Bumiller
2025-07-29 11:15 ` [pve-devel] [PATCH storage 06/26] common: use v5.36 Wolfgang Bumiller
2025-07-29 13:59 ` Fiona Ebner
2025-07-29 14:42 ` Thomas Lamprecht
2025-07-29 11:15 ` [pve-devel] [PATCH storage 07/26] common: add pve-storage-vtype standard option with new types Wolfgang Bumiller
2025-07-29 13:50 ` Fiona Ebner
2025-07-29 11:15 ` [pve-devel] [PATCH storage 08/26] prepare for vm-vol and ct-vol content and vtypes Wolfgang Bumiller
2025-07-30 8:38 ` Fabian Grünbichler
2025-08-08 12:01 ` Wolfgang Bumiller
2025-07-30 9:14 ` Fabian Grünbichler
2025-08-08 12:05 ` Wolfgang Bumiller
2025-07-29 11:15 ` [pve-devel] [PATCH storage 09/26] plugins: add new content types to all plugindata Wolfgang Bumiller
2025-07-30 8:38 ` Fabian Grünbichler
2025-08-08 12:10 ` Wolfgang Bumiller
2025-07-29 11:15 ` [pve-devel] [PATCH storage 10/26] plugins: update volname parsing for new naming convention Wolfgang Bumiller
2025-07-30 8:37 ` Fabian Grünbichler
2025-07-30 8:53 ` Wolfgang Bumiller
2025-07-30 8:58 ` Fabian Grünbichler
2025-07-29 11:15 ` [pve-devel] [PATCH storage 11/26] plugin: add vm/ct-vol to 'local' storage default content types Wolfgang Bumiller
2025-07-29 11:15 ` [pve-devel] [PATCH storage 12/26] plugin: support new vtypes in activate_storage checks Wolfgang Bumiller
2025-07-30 8:36 ` Fabian Grünbichler
2025-08-08 13:16 ` Wolfgang Bumiller
2025-07-29 11:15 ` [pve-devel] [PATCH storage 13/26] plugin, btrfs: update list_images and list_volumes Wolfgang Bumiller
2025-07-30 8:36 ` Fabian Grünbichler
2025-07-30 8:41 ` Fiona Ebner
2025-07-29 11:15 ` [pve-devel] [PATCH storage 14/26] plugins: update image/volume listing to support new types Wolfgang Bumiller
2025-07-30 8:36 ` Fabian Grünbichler
2025-07-29 11:15 ` [pve-devel] [PATCH storage 15/26] common: add is_volume_type and is_type_change_allowed helpers Wolfgang Bumiller
2025-07-30 9:01 ` Fabian Grünbichler
2025-07-29 11:15 ` [pve-devel] [PATCH storage 16/26] common: add volume_type_from_name convenience helper Wolfgang Bumiller
2025-07-30 8:36 ` Fabian Grünbichler
2025-07-30 9:09 ` Wolfgang Bumiller
2025-07-29 11:15 ` [pve-devel] [PATCH storage 17/26] plugins: add vtype parameter to alloc_image Wolfgang Bumiller
2025-07-30 9:24 ` Fabian Grünbichler
2025-07-30 14:00 ` Max R. Carrara
2025-07-30 14:05 ` Max R. Carrara
2025-07-30 14:26 ` Fabian Grünbichler
2025-07-30 14:49 ` Max R. Carrara
2025-07-30 15:01 ` Fabian Grünbichler
2025-07-29 11:15 ` [pve-devel] [PATCH storage 18/26] plugins: update create_base methods Wolfgang Bumiller
2025-07-29 11:15 ` [pve-devel] [PATCH storage 19/26] plugins: update clone_image methods Wolfgang Bumiller
2025-07-29 11:15 ` [pve-devel] [PATCH storage 20/26] plugins: update rename_volumes methods Wolfgang Bumiller
2025-07-29 11:15 ` Wolfgang Bumiller [this message]
2025-07-29 11:15 ` [pve-devel] [PATCH storage 22/26] zfs: update 'path' method for new naming scheme Wolfgang Bumiller
2025-07-30 9:31 ` Fabian Grünbichler
2025-07-29 11:15 ` [pve-devel] [PATCH storage 23/26] pvesm: add vtype parameter to import command Wolfgang Bumiller
2025-07-29 11:15 ` [pve-devel] [PATCH storage 24/26] api: add vtype parameter to create call Wolfgang Bumiller
2025-07-29 11:15 ` [pve-devel] [PATCH storage 25/26] update tests Wolfgang Bumiller
2025-07-29 16:33 ` Max R. Carrara
2025-07-29 11:15 ` [pve-devel] [PATCH storage 26/26] update ApiChangeLog Wolfgang Bumiller
2025-07-29 11:15 ` [pve-devel] [PATCH container 1/3] add vtype to vdisk_alloc and vdisk_clone calls Wolfgang Bumiller
2025-07-29 11:15 ` [pve-devel] [PATCH container 2/3] expect 'vm-vol' vtype in get_replicatable_volumes Wolfgang Bumiller
2025-07-29 11:15 ` [pve-devel] [PATCH container 3/3] add vtype to rename_volume call Wolfgang Bumiller
2025-07-29 11:15 ` [pve-devel] [PATCH qemu-server 01/10] add vtype to vdisk_alloc and vdisk_clone calls Wolfgang Bumiller
2025-07-29 11:15 ` [pve-devel] [PATCH qemu-server 02/10] add vtype parameter to rename_volume call Wolfgang Bumiller
2025-07-29 11:15 ` [pve-devel] [PATCH qemu-server 03/10] expect 'vm-vol' vtype in get_replicatable_volumes Wolfgang Bumiller
2025-07-29 11:15 ` [pve-devel] [PATCH qemu-server 04/10] expect 'vm-vol' vtype wherever 'images' was expected Wolfgang Bumiller
2025-07-30 8:40 ` Fabian Grünbichler
2025-07-30 9:17 ` Fiona Ebner
2025-07-30 9:33 ` Fiona Ebner
2025-07-29 11:15 ` [pve-devel] [PATCH qemu-server 05/10] tests: update QmMock to support vtypes Wolfgang Bumiller
2025-07-29 11:15 ` [pve-devel] [PATCH qemu-server 06/10] tests: scripted: update tests to new vtypes and paths Wolfgang Bumiller
2025-07-29 14:13 ` Max R. Carrara
2025-07-29 11:15 ` [pve-devel] [PATCH qemu-server 07/10] make tidy Wolfgang Bumiller
2025-07-29 11:15 ` [pve-devel] [PATCH qemu-server 08/10] tests: fixup restore test to use new volume naming scheme Wolfgang Bumiller
2025-07-29 11:15 ` [pve-devel] [PATCH qemu-server 09/10] tests: update remaining tests to new snapshot paths Wolfgang Bumiller
2025-07-29 11:15 ` [pve-devel] [PATCH qemu-server 10/10] tests: regenerate cfg2cmd files Wolfgang Bumiller
2025-07-29 14:19 ` Max R. Carrara
2025-07-29 15:34 ` [pve-devel] partially-applied: [RFC storage 00/26+10+3] unify vtype and content-type and Fiona Ebner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250729111557.136012-22-w.bumiller@proxmox.com \
--to=w.bumiller@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox