[pve-devel] [PATCH 5/7] clean up: make independent mountpoints for different VM

Wolfgang Link w.link at proxmox.com
Mon Aug 24 10:48:34 CEST 2015


---
 src/PVE/VZDump/LXC.pm | 31 +++++++++++++++++--------------
 1 file changed, 17 insertions(+), 14 deletions(-)

diff --git a/src/PVE/VZDump/LXC.pm b/src/PVE/VZDump/LXC.pm
index 359b5c0..d415444 100644
--- a/src/PVE/VZDump/LXC.pm
+++ b/src/PVE/VZDump/LXC.pm
@@ -13,6 +13,8 @@ use PVE::Tools;
 
 use base qw (PVE::VZDump::Plugin);
 
+my $mountpointdir = '/mnt/';
+
 my $rsync_vm = sub {
     my ($self, $task, $from, $to, $text) = @_;
 
@@ -153,7 +155,7 @@ sub prepare {
 
 	if ($scfg->{type} eq 'zfspool') {
 	    sleep(2);
-	    my $mountpoint = "/mnt/vzsnap0";
+	    my $mountpoint = $mountpointdir.$vmid."/rootfs";;
 	    my $path = PVE::Storage::path(PVE::Storage::config(), $volid,);
 
 	    $path = substr($path, 1);
@@ -161,17 +163,17 @@ sub prepare {
 
 	    &$mount_dev($path, $mountpoint, 'zfs');
 
-	    $task->{cleanup}->{snapshot_mount} = 1;
+	    $task->{cleanup}->{snapshot_mount} = $mountpoint;
 	    $diskinfo->{dir} = $diskinfo->{mountpoint} = $mountpoint;
 	}
 
     } else {
 
 	if ($mode eq 'stop') {
-	    my $mountpoint = "/mnt/vzsnap0";
+	    my $mountpoint = $mountpointdir.$vmid."/rootfs";
 	    my $path = PVE::Storage::path($self->{storecfg}, $volid);
 	    &$loop_mount_image($path, $mountpoint);
-	    $task->{cleanup}->{snapshot_mount} = 1;
+	    $task->{cleanup}->{snapshot_mount} = $mountpoint;
 	    $diskinfo->{dir} = $diskinfo->{mountpoint} = $mountpoint;
 	} elsif ($mode eq 'suspend') {
 	    my $tasks_fn = "/sys/fs/cgroup/cpu/lxc/$vmid/tasks";
@@ -247,20 +249,20 @@ sub assemble {
 
     my $dir = $task->{snapdir};
 
-    $task->{cleanup}->{etc_vzdump} = 1;
+    my $dump_conf_dir = $mountpointdir.$vmid."/etc/vzdump/";
 
-    mkpath "$dir/../etc/vzdump/";
+    File::Path::make_path($dump_conf_dir);
 
     my $conf = PVE::LXC::load_config($vmid);
     delete $conf->{snapshots};
     delete $conf->{'pve.parent'};
 
-    PVE::Tools::file_set_contents("$dir/../etc/vzdump/pct.conf", PVE::LXC::write_pct_config("/lxc/$vmid.conf", $conf));
+    PVE::Tools::file_set_contents("$dump_conf_dir/pct.conf", PVE::LXC::write_pct_config("/lxc/$vmid.conf", $conf));
 }
 
 sub archive {
     my ($self, $task, $vmid, $filename, $comp) = @_;
-    
+
     my $findexcl = $self->{vzdump}->{findexcl};
     my $findargs = join (' ', @$findexcl) . ' -print0';
     my $opts = $self->{vzdump}->{opts};
@@ -281,7 +283,9 @@ sub archive {
     my $cmd = "(";
 
     $cmd .= "cd $snapdir;find . $findargs|sed 's/\\\\/\\\\\\\\/g'|";
-    $cmd .= "tar cpf - $taropts ../etc/vzdump/pct.conf --null -T -";
+    $cmd .= "tar cpf - $taropts ";
+    $cmd .= "--directory=".$mountpointdir.$vmid." ./etc/vzdump/pct.conf ";
+    $cmd .= "--directory=$snapdir --null -T -";
     my $bwl = $opts->{bwlimit}*1024; # bandwidth limit for cstream
     $cmd .= "|cstream -t $bwl" if $opts->{bwlimit};
     $cmd .= "|$comp" if $comp;
@@ -306,8 +310,8 @@ sub cleanup {
 	# for example when we stop the tar with kill (stop task)
 	# We use -d to automatically free used loop devices
 	sleep(1); 
-	$self->cmd_noerr("umount -d $di->{mountpoint}");
-	File::Path::remove_tree($di->{mountpoint});
+	$self->cmd_noerr("umount -d $task->{cleanup}->{snapshot_mount}");
+	File::Path::remove_tree($task->{cleanup}->{snapshot_mount});
     }
 
     if (my $volid = $task->{cleanup}->{snap_volid}) {
@@ -315,9 +319,8 @@ sub cleanup {
 	warn $@ if $@;
     }
     
-    if ($task->{cleanup}->{etc_vzdump}) {
-	my $dir = "$task->{snapdir}/../etc/";
-	eval { rmtree $dir if -d $dir; };
+    if ( -d $mountpointdir.$vmid) {
+	eval { File::Path::remove_tree($mountpointdir.$vmid); };
 	$self->logerr ($@) if $@;
     }
 
-- 
2.1.4





More information about the pve-devel mailing list