abstract migrate: code-style cleanup get_bwlimit

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2025-02-10 16:48:36 +01:00
parent 8d62b1e563
commit ea022f01c3

View File

@ -345,22 +345,19 @@ sub get_bwlimit {
my $bwlimit = PVE::Storage::get_bandwidth_limit('migration', $local_sids, $self->{opts}->{bwlimit}); my $bwlimit = PVE::Storage::get_bandwidth_limit('migration', $local_sids, $self->{opts}->{bwlimit});
if ($self->{opts}->{remote}) { if ($self->{opts}->{remote}) {
my $bwlimit_opts = { my $bwlimit_reply = PVE::Tunnel::write_tunnel($self->{tunnel}, 10, 'bwlimit', {
operation => 'migration', operation => 'migration',
storages => [$target], storages => [$target],
bwlimit => $self->{opts}->{bwlimit}, bwlimit => $self->{opts}->{bwlimit},
}; });
my $bwlimit_reply = PVE::Tunnel::write_tunnel( if ($bwlimit_reply && (my $remote_bwlimit_raw = $bwlimit_reply->{bwlimit})) {
$self->{tunnel}, 10, 'bwlimit', $bwlimit_opts);
if ($bwlimit_reply && $bwlimit_reply->{bwlimit}) {
# untaint # untaint
my ($remote_bwlimit) = ($bwlimit_reply->{bwlimit} =~ m/^(\d+(.\d+)?)$/) my ($remote_bwlimit) = ($remote_bwlimit_raw =~ m/^(\d+(?:.\d+)?)$/)
or die "invalid remote bandwidth limit: '$bwlimit_reply->{bwlimit}'\n"; or die "invalid remote bandwidth limit: '$bwlimit_reply->{bwlimit}'\n";
$bwlimit = $remote_bwlimit # only allow lowering the effecting bandwidth limit.
if (!$bwlimit || $bwlimit > $remote_bwlimit); $bwlimit = $remote_bwlimit if (!$bwlimit || $bwlimit > $remote_bwlimit);
} }
} }