]> git.proxmox.com Git - pve-container.git/commitdiff
restore: support i/o rate limiting
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Wed, 21 Mar 2018 08:57:48 +0000 (09:57 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 21 Mar 2018 11:29:33 +0000 (12:29 +0100)
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
src/PVE/API2/LXC.pm
src/PVE/LXC/Create.pm

index 0c834d41fbb3262a87be78bca7105ae267bd25ef..bce5fa3865dec6d72a2ec6c12d7d6e0e1c7788ac 100644 (file)
@@ -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@pam');
index d8f8f04969db3710ab6ad794ec720ba8be976eab..6f099894a7d572ca03d00aab7fd23d2ec14cd682 100644 (file)
@@ -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 {