Like this it is possible to determine if the transfer of a volume is possible wihout already having the name of the volume on the target storage. When doing the import, 'volume_import' can then choose a new name automatically.
Signed-off-by: Fabian Ebner <f.eb...@proxmox.com> --- For example, migration with a disk on an LVM storage with --targetstorage to a filesystem-based storage should work with this. For volume_export_formats a similar change could be made, e.g. allow 'raw+size' as an export format for a qcow2 disk. When actually exporting 'qemu-img convert' is used and it doesn't like when the output is piped away, so pvesm export myfs:103/vm-103-disk-1.qcow2 raw+size - -with-snapshots 0 | pvesm import myfs:103/vm-103-disk-1.raw raw+size - -with-snapshots 0 fails with: qemu-img: /dev/stdout: error while converting raw: Could not resize file: Invalid argument command 'qemu-img convert -f qcow2 -O raw /mnt/myfs/images/103/vm-103-disk-1.qcow2 /dev/stdout' failed: exit code 1 Not making such a change and preserving the original format of the volume on export when determining a common transfer format is probably best. PVE/Storage.pm | 10 ++++------ PVE/Storage/Plugin.pm | 18 ++++++++++++------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/PVE/Storage.pm b/PVE/Storage.pm index 7d18b11..d708c03 100755 --- a/PVE/Storage.pm +++ b/PVE/Storage.pm @@ -589,7 +589,7 @@ sub storage_migrate { } } - my @formats = volume_transfer_formats($cfg, $volid, $target_volid, $snapshot, $base_snapshot, $with_snapshots); + my @formats = volume_transfer_formats($cfg, $volid, $target_storeid, $target_volname, $snapshot, $base_snapshot, $with_snapshots); die "cannot migrate from storage type '$scfg->{type}' to '$tcfg->{type}'\n" if !@formats; my $format = $formats[0]; @@ -1441,10 +1441,8 @@ sub volume_export_formats { } sub volume_import_formats { - my ($cfg, $volid, $base_snapshot, $with_snapshots) = @_; + my ($cfg, $storeid, $volname, $base_snapshot, $with_snapshots) = @_; - my ($storeid, $volname) = parse_volume_id($volid, 1); - return if !$storeid; my $scfg = storage_config($cfg, $storeid); my $plugin = PVE::Storage::Plugin->lookup($scfg->{type}); return $plugin->volume_import_formats($scfg, $storeid, $volname, @@ -1452,9 +1450,9 @@ sub volume_import_formats { } sub volume_transfer_formats { - my ($cfg, $src_volid, $dst_volid, $snapshot, $base_snapshot, $with_snapshots) = @_; + my ($cfg, $src_volid, $dst_storeid, $dst_volname, $snapshot, $base_snapshot, $with_snapshots) = @_; my @export_formats = volume_export_formats($cfg, $src_volid, $snapshot, $base_snapshot, $with_snapshots); - my @import_formats = volume_import_formats($cfg, $dst_volid, $base_snapshot, $with_snapshots); + my @import_formats = volume_import_formats($cfg, $dst_storeid, $dst_volname, $base_snapshot, $with_snapshots); my %import_hash = map { $_ => 1 } @import_formats; my @common = grep { $import_hash{$_} } @export_formats; return @common; diff --git a/PVE/Storage/Plugin.pm b/PVE/Storage/Plugin.pm index 4e0ae8f..7d654ca 100644 --- a/PVE/Storage/Plugin.pm +++ b/PVE/Storage/Plugin.pm @@ -1245,13 +1245,19 @@ sub volume_import { sub volume_import_formats { my ($class, $scfg, $storeid, $volname, $base_snapshot, $with_snapshots) = @_; if ($scfg->{path} && !defined($base_snapshot)) { - my $format = ($class->parse_volname($volname))[6]; - if ($with_snapshots) { - return ($format.'+size') if ($format eq 'qcow2' || $format eq 'vmdk'); - return (); + if (defined($volname)) { + my $format = ($class->parse_volname($volname))[6]; + if ($with_snapshots) { + return ($format.'+size') if ($format eq 'qcow2' || $format eq 'vmdk'); + return (); + } + return ('tar+size') if $format eq 'subvol'; + return ('raw+size'); + } else { + my @formats = ('qcow2+size', 'vmdk+size'); + push @formats, 'tar+size', 'raw+size' if !$with_snapshots; + return @formats; } - return ('tar+size') if $format eq 'subvol'; - return ('raw+size'); } return (); } -- 2.20.1 _______________________________________________ pve-devel mailing list pve-devel@pve.proxmox.com https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel