X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=src%2FPVE%2FVZDump%2FLXC.pm;h=57dcbe253610ed5f254cc68ad56db52c9eb94134;hb=2d3f23be68fa1c9f29f78d18fe606ee4e665012f;hp=7f27f0bca4bd62b16c1d07af977c1c76242aa1ea;hpb=c434e3b4498020e91068477383266168003fbfe2;p=pve-container.git diff --git a/src/PVE/VZDump/LXC.pm b/src/PVE/VZDump/LXC.pm index 7f27f0b..57dcbe2 100644 --- a/src/PVE/VZDump/LXC.pm +++ b/src/PVE/VZDump/LXC.pm @@ -110,6 +110,7 @@ sub prepare { my ($id_map, $rootuid, $rootgid) = PVE::LXC::parse_id_maps($conf); $task->{userns_cmd} = PVE::LXC::userns_command($id_map); + my $volid_list = []; PVE::LXC::foreach_mountpoint($conf, sub { my ($name, $data) = @_; my $volid = $data->{volume}; @@ -124,14 +125,17 @@ sub prepare { } push @$disks, $data; + push @$volid_list, $volid + if $type eq 'volume'; }); - my $volid_list = [map { $_->{volume} } @$disks]; if ($mode eq 'snapshot') { - if (!PVE::LXC::has_feature('snapshot', $conf, $storage_cfg)) { - die "mode failure - some volumes does not support snapshots\n"; + if (!PVE::LXC::has_feature('vzdump', $conf, $storage_cfg)) { + die "mode failure - some volumes do not support snapshots\n"; } + unlock_vm($self, $vmid); + if ($conf->{snapshots} && $conf->{snapshots}->{vzdump}) { $self->loginfo("found old vzdump snapshot (force removal)"); PVE::LXC::snapshot_delete($vmid, 'vzdump', 1); @@ -141,7 +145,7 @@ sub prepare { mkpath $rootdir; &$check_mountpoint_empty($rootdir); - # set snapshot_count (freezes CT it snapshot_count > 1) + # set snapshot_count (freezes CT if snapshot_count > 1) $task->{snapshot_count} = scalar(@$volid_list); } elsif ($mode eq 'stop') { my $rootdir = $default_mount_point; @@ -155,11 +159,12 @@ sub prepare { } $task->{snapdir} = $task->{tmpdir}; } else { + unlock_vm($self, $vmid); die "unknown mode '$mode'\n"; # should not happen } if ($mode ne 'suspend') { - # If we preform mount operations, let's unshare the mount namespace + # If we perform mount operations, let's unshare the mount namespace # to not influence the running host. PVE::Tools::unshare(PVE::Tools::CLONE_NEWNS); PVE::Tools::run_command(['mount', '--make-rprivate', '/']); @@ -169,19 +174,41 @@ sub prepare { sub lock_vm { my ($self, $vmid) = @_; - PVE::LXC::lock_aquire($vmid); + 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); + }; + + PVE::LXC::lock_container($vmid, 10, $lockconfig, ($self, $vmid)); } sub unlock_vm { my ($self, $vmid) = @_; - PVE::LXC::lock_release($vmid); + 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); + } + }; + + PVE::LXC::lock_container($vmid, 60, $unlockconfig, ($self, $vmid)); } sub snapshot { my ($self, $task, $vmid) = @_; - $self->loginfo("create storage snapshot snapshot"); + $self->loginfo("create storage snapshot 'vzdump'"); # todo: freeze/unfreeze if we have more than one volid PVE::LXC::snapshot_create($vmid, 'vzdump', "vzdump backup snapshot"); @@ -189,10 +216,11 @@ sub snapshot { # reload config my $conf = $self->{vmlist}->{$vmid} = PVE::LXC::load_config($vmid); - die "unable to read vzdump shanpshot config - internal error" + die "unable to read vzdump snapshot config - internal error" if !($conf->{snapshots} && $conf->{snapshots}->{vzdump}); my $disks = $task->{disks}; + #todo: reevaluate bind/dev mount handling when implementing snapshots for mps my $volid_list = [map { $_->{volume} } @$disks]; my $rootdir = $default_mount_point; @@ -262,6 +290,7 @@ sub assemble { mkpath "$tmpdir/etc/vzdump/"; my $conf = PVE::LXC::load_config($vmid); + delete $conf->{lock}; delete $conf->{snapshots}; delete $conf->{'pve.parent'}; @@ -309,12 +338,12 @@ sub archive { # note: --remove-files does not work because we do not # backup all files (filters). tar complains: # Cannot rmdir: Directory not empty - # we we disable this optimization for now + # we disable this optimization for now #if ($snapdir eq $task->{tmpdir} && $snapdir =~ m|^$opts->{dumpdir}/|) { # push @$tar, "--remove-files"; # try to save space #} - # The directory parameter can give a alternative directory as source. + # The directory parameter can give an alternative directory as source. # the second parameter gives the structure in the tar. push @$tar, "--directory=$tmpdir", './etc/vzdump/pct.conf'; push @$tar, "./etc/vzdump/pct.fw" if $task->{fw};