[pve-devel] [PATCH v2 container 2/2] restore: support i/o rate limiting

Wolfgang Bumiller w.bumiller at proxmox.com
Wed Mar 21 09:57:48 CET 2018


Signed-off-by: Wolfgang Bumiller <w.bumiller at proxmox.com>
---
Changes to v1:
  * Rebased onto template-reading fix
  * Using the 'restore' limit for both create & restore now as suggested
    by Fabian in the original patch thread. We could of course separate
    it but I'm not sure it makes sense since it's practically the same
    operation anyway.

 src/PVE/API2/LXC.pm   | 14 +++++++++++++-
 src/PVE/LXC/Create.pm |  6 +++++-
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/src/PVE/API2/LXC.pm b/src/PVE/API2/LXC.pm
index 0c9ee40..91dfd14 100644
--- a/src/PVE/API2/LXC.pm
+++ b/src/PVE/API2/LXC.pm
@@ -161,6 +161,12 @@ __PACKAGE__->register_method({
 		description => "Setup public SSH keys (one key per line, " .
 				"OpenSSH format).",
 	    },
+	    bwlimit => {
+		description => "Override i/o bandwidth limit (in KiB/s).",
+		optional => 1,
+		type => 'number',
+		minimum => '0',
+	    },
 	}),
     },
     returns => {
@@ -179,6 +185,8 @@ __PACKAGE__->register_method({
 
 	my $ignore_unpack_errors = extract_param($param, 'ignore-unpack-errors');
 
+	my $bwlimit = extract_param($param, 'bwlimit');
+
 	my $basecfg_fn = PVE::LXC::Config->config_file($vmid);
 
 	my $same_container_exists = -f $basecfg_fn;
@@ -247,6 +255,7 @@ __PACKAGE__->register_method({
 	    $archive = PVE::Storage::abs_filesystem_path($storage_cfg, $ostemplate);
 	}
 
+	my %used_storages;
 	my $check_and_activate_storage = sub {
 	    my ($sid) = @_;
 
@@ -258,6 +267,8 @@ __PACKAGE__->register_method({
 	    $rpcenv->check($authuser, "/storage/$sid", ['Datastore.AllocateSpace']);
 
 	    PVE::Storage::activate_storage($storage_cfg, $sid);
+
+	    $used_storages{$sid} = 1;
 	};
 
 	my $conf = {};
@@ -387,7 +398,8 @@ __PACKAGE__->register_method({
 
 		eval {
 		    my $rootdir = PVE::LXC::mount_all($vmid, $storage_cfg, $conf, 1);
-		    PVE::LXC::Create::restore_archive($archive, $rootdir, $conf, $ignore_unpack_errors);
+		    $bwlimit = PVE::Storage::get_bandwidth_limit('restore', [keys %used_storages], $bwlimit);
+		    PVE::LXC::Create::restore_archive($archive, $rootdir, $conf, $ignore_unpack_errors, $bwlimit);
 
 		    if ($restore) {
 			PVE::LXC::Create::restore_configuration($vmid, $rootdir, $conf, $authuser ne 'root at pam');
diff --git a/src/PVE/LXC/Create.pm b/src/PVE/LXC/Create.pm
index d8f8f04..6f09989 100644
--- a/src/PVE/LXC/Create.pm
+++ b/src/PVE/LXC/Create.pm
@@ -59,7 +59,7 @@ sub detect_architecture {
 }
 
 sub restore_archive {
-    my ($archive, $rootdir, $conf, $no_unpack_error) = @_;
+    my ($archive, $rootdir, $conf, $no_unpack_error, $bwlimit) = @_;
 
     my ($id_map, $rootuid, $rootgid) = PVE::LXC::parse_id_maps($conf);
     my $userns_cmd = PVE::LXC::userns_command($id_map);
@@ -101,6 +101,10 @@ sub restore_archive {
     push @$cmd, '--anchored';
     push @$cmd, '--exclude' , './dev/*';
 
+    if (defined($bwlimit)) {
+	$cmd = [ ['cstream', '-t', $bwlimit*1024], $cmd ];
+    }
+
     if ($archive eq '-') {
 	print "extracting archive from STDIN\n";
     } else {
-- 
2.11.0





More information about the pve-devel mailing list