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

Fabian Grünbichler f.gruenbichler at proxmox.com
Fri Feb 9 09:41:04 CET 2018


small nit(s) inside

On Tue, Feb 06, 2018 at 02:00:46PM +0100, Wolfgang Bumiller wrote:
> Signed-off-by: Wolfgang Bumiller <w.bumiller at proxmox.com>
> ---
>  src/PVE/API2/LXC.pm   | 16 +++++++++++++++-
>  src/PVE/LXC/Create.pm | 12 +++++++++++-
>  2 files changed, 26 insertions(+), 2 deletions(-)
> 
> diff --git a/src/PVE/API2/LXC.pm b/src/PVE/API2/LXC.pm
> index 733826e..c49cf4f 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).",

this does not mention that it's for restore only?

> +		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');

sets the override if passed in for both create and restore

> +
>  	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,10 @@ __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);
> +		    if ($restore) {
> +			$bwlimit = PVE::Storage::get_bandwidth_limit('restore', [keys %used_storages], $bwlimit);

applies storage/default limit only when restoring

> +		    }
> +		    PVE::LXC::Create::restore_archive($archive, $rootdir, $conf, $ignore_unpack_errors, $bwlimit);

applies the limit (override for create, override+storage/global limit
for restore).

maybe it would make sense to use the same logic for create/restore?
templates are usually small so you won't feel a bwlimit anyway, and if
they are user-created templates which are huge, the bwlimit is probably
desired ;)

>  
>  		    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 2a37d93..0851b08 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);
> @@ -74,6 +74,12 @@ sub restore_archive {
>  	$archive_fh->fcntl(Fcntl::F_SETFD(), $flags & ~(Fcntl::FD_CLOEXEC()));
>      }
>  
> +    my $bwlimit_cmd;
> +    if (defined($bwlimit)) {
> +	$bwlimit_cmd = ['cstream', '-t', $bwlimit*1024, '--', $tar_input_file];
> +	$tar_input_file = '-';
> +    }
> +
>      my $cmd = [@$userns_cmd, 'tar', 'xpf', $tar_input_file, '--totals',
>                 @PVE::Storage::Plugin::COMMON_TAR_FLAGS,
>                 '-C', $rootdir];
> @@ -86,6 +92,10 @@ sub restore_archive {
>      push @$cmd, '--anchored';
>      push @$cmd, '--exclude' , './dev/*';
>  
> +    if ($bwlimit_cmd) {
> +	$cmd = [$bwlimit_cmd, $cmd];
> +    }
> +
>      if ($archive eq '-') {
>  	print "extracting archive from STDIN\n";
>  	eval { PVE::Tools::run_command($cmd, input => "<&STDIN"); };
> -- 
> 2.11.0
> 
> 
> _______________________________________________
> pve-devel mailing list
> pve-devel at pve.proxmox.com
> https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel




More information about the pve-devel mailing list