[pve-devel] [PATCH container 1/3] Set backup lock during stop and suspend backups

Wolfgang Bumiller w.bumiller at proxmox.com
Fri Jan 15 10:58:11 CET 2016


On Fri, Jan 15, 2016 at 10:03:31AM +0100, Fabian Grünbichler wrote:
> Correctly set a 'backup' lock while a 'stop' or 'suspend'
> mode backup is in progress.
> ---
>  src/PVE/VZDump/LXC.pm | 23 +++++++++++++++++++++++
>  1 file changed, 23 insertions(+)
> 
> diff --git a/src/PVE/VZDump/LXC.pm b/src/PVE/VZDump/LXC.pm
> index 7f27f0b..7cd557c 100644
> --- a/src/PVE/VZDump/LXC.pm
> +++ b/src/PVE/VZDump/LXC.pm
> @@ -94,6 +94,24 @@ my $check_mountpoint_empty = sub {
>      });
>  };
>  
> +my $lockconfig = sub {
> +    my ($self, $vmid) = @_;
> +    my $conf = PVE::LXC::load_config($vmid);
> +    PVE::LXC::check_lock($conf);
> +    $conf->{lock} = 'backup';
> +    PVE::LXC::write_config($vmid, $conf);
> +};
> +
> +my $unlockconfig = sub {
> +    my ($self, $vmid) = @_;
> +    my $conf = PVE::LXC::load_config($vmid);
> +
> +    if ($conf->{lock} && $conf->{lock} eq 'backup') {
> +	delete $conf->{lock};
> +	PVE::LXC::write_config($vmid, $conf);
> +    }
> +};
> +
>  sub prepare {
>      my ($self, $task, $vmid, $mode) = @_;
>  
> @@ -144,11 +163,13 @@ sub prepare {
>  	# set snapshot_count (freezes CT it snapshot_count > 1)
>  	$task->{snapshot_count} = scalar(@$volid_list);
>      } elsif ($mode eq 'stop') {
> +	PVE::LXC::lock_container($vmid, 10, $lockconfig, $self, $vmid);

VZDump is already holding a lock here, so using lock_container() seems
redundant.

>  	my $rootdir = $default_mount_point;
>  	mkpath $rootdir;
>  	&$check_mountpoint_empty($rootdir);
>  	PVE::Storage::activate_volumes($storage_cfg, $volid_list);
>      } elsif ($mode eq 'suspend') {
> +	PVE::LXC::lock_container($vmid, 10, $lockconfig, $self, $vmid);

Same here.

>  	my $pid = PVE::LXC::find_lxc_pid($vmid);
>  	foreach my $disk (@$disks) {
>  	    $disk->{dir} = "/proc/$pid/root$disk->{mp}";
> @@ -175,6 +196,7 @@ sub lock_vm {
>  sub unlock_vm {
>      my ($self, $vmid) = @_;
>  
> +    PVE::LXC::lock_container($vmid, 10, $unlockconfig, $self, $vmid);
>      PVE::LXC::lock_release($vmid);

And here (the lock_release() already hints at it: lock_container() does
lock_acquire() and lock_release()).
Also see the comment below for assemble().

>  }
>  
> @@ -262,6 +284,7 @@ sub assemble {
>      mkpath "$tmpdir/etc/vzdump/";
>  
>      my $conf = PVE::LXC::load_config($vmid);
> +    delete $conf->{lock};

VZDump keeps its file lock a little longer and calls unlock_vm() later
on in its cleanup, so this seems redundant as well.

>      delete $conf->{snapshots};
>      delete $conf->{'pve.parent'};
>  
> -- 
> 2.1.4
> 




More information about the pve-devel mailing list