[pve-devel] [PATCH v4 storage 4/4] add volume_import/export_start helpers

Fabian Ebner f.ebner at proxmox.com
Fri Feb 4 12:38:39 CET 2022


Am 03.02.22 um 13:41 schrieb Fabian Grünbichler:
> diff --git a/PVE/Storage.pm b/PVE/Storage.pm
> index 837df1b..682dd38 100755
> --- a/PVE/Storage.pm
> +++ b/PVE/Storage.pm
> @@ -1833,6 +1833,72 @@ sub volume_imported_message {
>      }
>  }
>  
> +# $format and $volname are requests and might be overruled depending on $opts
> +# $opts:
> +# - with_snapshots: passed to `pvesm import` and used to select import format
> +# - allow_rename: passed to `pvesm import`
> +# - export_formats: used to select common transport format
> +# - unix: unix socket path
> +sub volume_import_start {
> +    my ($cfg, $storeid, $volname, $format, $vmid, $opts) = @_;
> +
> +    my $with_snapshots = $opts->{'with_snapshots'} ? 1 : 0;
> +
> +    $volname = $volname_for_storage->($cfg, $storeid, $volname, $vmid, $format);
> +
> +    my $volid = "$storeid:$volname";
> +
> +    if (!defined($opts->{snapshot})) {
> +	$opts->{migration_snapshot} = storage_migrate_snapshot($cfg, $storeid);
> +	$opts->{snapshot} = '__migration__' if $opts->{migration_snapshot};
> +    }

Don't we actually need to have the exporting side tell us whether it's
using a migration snapshot or not? In practice, not many combinations
are affected, but e.g. lvm-thin -> btrfs doesn't work, because the
importing side thinks it needs a common format with snapshot (but the
exporting side wouldn't actually use a snapshot).

> +
> +    # find common import/export format, like volume_transfer_formats
> +    my @import_formats = PVE::Storage::volume_import_formats($cfg, $volid, $opts->{migration_snapshot}, undef, $with_snapshots);

Found while testing: here you need to pass in $opts->{snapshot}. While
plugins are unlikely to base the decision based on the snapshot name,
our plugins use definedness of that parameter and
$opts->{migration_snapshot} can be ''.

Nit: the 'PVE::Storage::' prefix is not necessary.

> +    my @export_formats = PVE::Tools::split_list($opts->{export_formats});
> +    my %import_hash = map { $_ => 1 } @import_formats;
> +    my @common = grep { $import_hash{$_} } @export_formats;
> +    die "no matching import/export format found for storage '$storeid'\n"
> +	if !@common;
> +    $format = $common[0];





More information about the pve-devel mailing list