[pve-devel] [PATCH v3 guest-common 04/22] Add update_volume_ids

Fabian Grünbichler f.gruenbichler at proxmox.com
Mon Mar 16 12:05:43 CET 2020


On March 12, 2020 1:08 pm, Fabian Ebner wrote:
> This function is intened to be used after doing a migration where some
> of the volume IDs changed.
> 
> Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
> ---
>  PVE/AbstractConfig.pm | 30 ++++++++++++++++++++++++++++++
>  1 file changed, 30 insertions(+)
> 
> diff --git a/PVE/AbstractConfig.pm b/PVE/AbstractConfig.pm
> index f2e130c..dc788c2 100644
> --- a/PVE/AbstractConfig.pm
> +++ b/PVE/AbstractConfig.pm
> @@ -457,6 +457,36 @@ sub foreach_volume {
>      $class->foreach_unused_volume($conf, $func, @param) if $opts->{include_unused};
>  }
>  
> +# $volume_map is a hash of 'old_volid' => 'new_volid' pairs.
> +# This method replaces 'old_volid' by 'new_volid' throughout
> +# the config including snapshots and unused and vmstate volumes
> +sub update_volume_ids {
> +    my ($class, $conf, $volume_map) = @_;

$conf here

> +
> +    my $volid_key = $class->volid_key();
> +
> +    my $do_replace = sub {
> +	my ($key, $volume, $conf) = @_;

and $conf here

are easy to confuse. probably makes sense to rename either of them ;)

> +
> +	my $old_volid = $volume->{$volid_key};
> +	if (my $new_volid = $volume_map->{$old_volid}) {
> +	    $volume->{$volid_key} = $new_volid;
> +	    $conf->{$key} = $class->print_volume($key, $volume);
> +	}
> +    };
> +
> +    my $opts = {
> +	'include_unused' => 1,
> +	'extra_keys' => ['vmstate'],
> +    };
> +
> +    $class->foreach_volume($conf, $opts, $do_replace, $conf);
> +    foreach my $snap (keys %{$conf->{snapshots}}) {
> +	my $snap_conf = $conf->{snapshots}->{$snap};
> +	$class->foreach_volume($snap_conf, $opts, $do_replace, $snap_conf);
> +    }
> +}
> +
>  # Returns whether the template parameter is set in $conf.
>  sub is_template {
>      my ($class, $conf) = @_;
> -- 
> 2.20.1
> 
> 
> _______________________________________________
> pve-devel mailing list
> pve-devel at pve.proxmox.com
> https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
> 
> 




More information about the pve-devel mailing list