]> git.proxmox.com Git - pve-container.git/blobdiff - src/PVE/LXC.pm
bwlimit: add parameter to rsync in copy_volume
[pve-container.git] / src / PVE / LXC.pm
index 8f560c5708901037ac6ebe4b755e0b1f9b66a5fd..f1aa9d7ea477b1ce45a0020010f39bc710f923d3 100644 (file)
@@ -162,6 +162,11 @@ our $vmstatus_return_properties = {
        type => 'number',
        optional => 1,
     },
+    lock => {
+       description => "The current config lock, if any.",
+       type => 'string',
+       optional => 1,
+    }
 };
 
 sub vmstatus {
@@ -186,7 +191,7 @@ sub vmstatus {
        eval { $d->{pid} = find_lxc_pid($vmid) if defined($active_hash->{$vmid}); };
        warn $@ if $@; # ignore errors (consider them stopped)
 
-       $d->{status} = $d->{pid} ? 'running' : 'stopped';
+       $d->{status} = $active_hash->{$vmid} ? 'running' : 'stopped';
 
        my $cfspath = PVE::LXC::Config->cfs_config_path($vmid);
        my $conf = PVE::Cluster::cfs_read_file($cfspath) || {};
@@ -231,6 +236,7 @@ sub vmstatus {
        $d->{diskwrite} = 0;
 
        $d->{template} = PVE::LXC::Config->is_template($conf);
+       $d->{lock} = $conf->{lock} if $conf->{lock};
     }
 
     foreach my $vmid (keys %$list) {
@@ -1991,7 +1997,7 @@ sub run_unshared {
 }
 
 my $copy_volume = sub {
-    my ($src_volid, $src, $dst_volid, $dest, $storage_cfg, $snapname) = @_;
+    my ($src_volid, $src, $dst_volid, $dest, $storage_cfg, $snapname, $bwlimit) = @_;
 
     my $src_mp = { volume => $src_volid, mp => '/', ro => 1 };
     $src_mp->{type} = PVE::LXC::Config->classify_mountpoint($src_volid);
@@ -2009,9 +2015,11 @@ my $copy_volume = sub {
        mountpoint_mount($dst_mp, $dest, $storage_cfg);
        push @mounted, $dest;
 
+       $bwlimit //= 0;
+
        PVE::Tools::run_command(['/usr/bin/rsync', '--stats', '-X', '-A', '--numeric-ids',
                                 '-aH', '--whole-file', '--sparse', '--one-file-system',
-                                "$src/", $dest]);
+                                "--bwlimit=$bwlimit", "$src/", $dest]);
     };
     my $err = $@;
     foreach my $mount (reverse @mounted) {
@@ -2029,7 +2037,7 @@ my $copy_volume = sub {
 
 # Should not be called after unsharing the mount namespace!
 sub copy_volume {
-    my ($mp, $vmid, $storage, $storage_cfg, $conf, $snapname) = @_;
+    my ($mp, $vmid, $storage, $storage_cfg, $conf, $snapname, $bwlimit) = @_;
 
     die "cannot copy volumes of type $mp->{type}\n" if $mp->{type} ne 'volume';
     File::Path::make_path("/var/lib/lxc/$vmid");
@@ -2055,7 +2063,7 @@ sub copy_volume {
        }
 
        run_unshared(sub {
-           $copy_volume->($mp->{volume}, $src, $new_volid, $dest, $storage_cfg, $snapname);
+           $copy_volume->($mp->{volume}, $src, $new_volid, $dest, $storage_cfg, $snapname, $bwlimit);
        });
     };
     if (my $err = $@) {