[pve-devel] [PATCH container] Drop used unused volumes when writing config

Wolfgang Bumiller w.bumiller at proxmox.com
Tue Mar 1 10:14:11 CET 2016


Should we then drop the equivalent part in update_pct_config()?
(Only the removal at the end. Its data ($used_volids) is still required
to prevent accidental deletion of volumes.)

On Tue, Mar 01, 2016 at 09:59:11AM +0100, Fabian Grünbichler wrote:
> This enables us to add unused volumes without calling
> is_volume_in_use and mimics the behaviour in QemuServer.pm
> ---
> Because is_volume_in_use has different signatures in LXC and QemuServer.pm,
> this change allows us to merge more of snapshot_delete into the common code
> base.
> 
>  src/PVE/LXC.pm | 25 ++++++++++++++++++-------
>  1 file changed, 18 insertions(+), 7 deletions(-)
> 
> diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
> index 8e284c0..9002791 100644
> --- a/src/PVE/LXC.pm
> +++ b/src/PVE/LXC.pm
> @@ -431,6 +431,19 @@ sub write_pct_config {
>      my ($filename, $conf) = @_;
>  
>      delete $conf->{snapstate}; # just to be sure
> +    my $volidlist = get_vm_volumes($conf);
> +    my $used_volids = {};
> +    foreach my $vid (@$volidlist) {
> +	$used_volids->{$vid} = 1;
> +    }
> +
> +    # remove 'unusedX' settings if the volume is still used
> +    foreach my $key (keys %$conf) {
> +	my $value = $conf->{$key};
> +	if ($key =~ m/^unused/ && $used_volids->{$value}) {
> +	    delete $conf->{$key};
> +	}
> +    }
>  
>      my $generate_raw_config = sub {
>  	my ($conf) = @_;
> @@ -1303,7 +1316,7 @@ sub update_pct_config {
>  		check_protection($conf, "can't remove CT $vmid drive '$opt'");
>  		my $mp = parse_ct_mountpoint($conf->{$opt});
>  		delete $conf->{$opt};
> -		if ($mp->{type} eq 'volume' && !is_volume_in_use($conf, $mp->{volume})) {
> +		if ($mp->{type} eq 'volume') {
>  		    add_unused_volume($conf, $mp->{volume});
>  		}
>  	    } elsif ($opt eq 'unprivileged') {
> @@ -1390,7 +1403,7 @@ sub update_pct_config {
>  	    $conf->{$opt} = $value;
>  	    if (defined($old)) {
>  		my $mp = parse_ct_mountpoint($old);
> -		if ($mp->{type} eq 'volume' && !is_volume_in_use($conf, $mp->{volume})) {
> +		if ($mp->{type} eq 'volume') {
>  		    add_unused_volume($conf, $mp->{volume});
>  		}
>  	    }
> @@ -1404,7 +1417,7 @@ sub update_pct_config {
>  	    $conf->{$opt} = $value;
>  	    if (defined($old)) {
>  		my $mp = parse_ct_rootfs($old);
> -		if ($mp->{type} eq 'volume' && !is_volume_in_use($conf, $mp->{volume})) {
> +		if ($mp->{type} eq 'volume') {
>  		    add_unused_volume($conf, $mp->{volume});
>  		}
>  	    }
> @@ -2071,8 +2084,7 @@ sub snapshot_delete {
>  		my $value = $snap->{$remove_drive};
>  		my $mountpoint = $remove_drive eq 'rootfs' ? parse_ct_rootfs($value, 1) : parse_ct_mountpoint($value, 1);
>  		delete $snap->{$remove_drive};
> -		add_unused_volume($snap, $mountpoint->{volume})
> -		    if (!is_volume_in_use($snap, $mountpoint->{volume}));
> +		add_unused_volume($snap, $mountpoint->{volume});
>  	    }
>  	}
>  
> @@ -2082,8 +2094,7 @@ sub snapshot_delete {
>  	    delete $conf->{snapshots}->{$snapname};
>  	    delete $conf->{lock} if $drivehash;
>  	    foreach my $volid (@$unused) {
> -		add_unused_volume($conf, $volid)
> -		    if (!is_volume_in_use($conf, $volid));
> +		add_unused_volume($conf, $volid);
>  	    }
>  	}
>  
> -- 
> 2.1.4
> 
> 
> _______________________________________________
> pve-devel mailing list
> pve-devel at pve.proxmox.com
> http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
> 




More information about the pve-devel mailing list