X-Git-Url: https://git.proxmox.com/?p=pve-common.git;a=blobdiff_plain;f=src%2FPVE%2FCpuSet.pm;h=92fd18fe73a86c6120f5f0f70547aa1eb8275fd5;hp=4004bb3bab1a620f137068f279e03982447bf77e;hb=e97f807c388c10250f442b1f16c5315df2ffc2af;hpb=284dca701b3461cd41efe52c1c395a9a7a42095b diff --git a/src/PVE/CpuSet.pm b/src/PVE/CpuSet.pm index 4004bb3..92fd18f 100644 --- a/src/PVE/CpuSet.pm +++ b/src/PVE/CpuSet.pm @@ -3,8 +3,7 @@ package PVE::CpuSet; use strict; use warnings; use PVE::Tools; - -our $MAX_CPUID = 256; # should be enough for the next years +use PVE::ProcFSTools; sub new { my ($this) = @_; @@ -34,8 +33,6 @@ sub new_from_cgroup { if ($part =~ /^\s*(\d+)(?:-(\d+))?\s*$/) { my ($from, $to) = ($1, $2); $to //= $1; - die "cpu id '$from' is out of range\n" if $from >= $MAX_CPUID; - die "cpu id '$to' is out of range\n" if $to >= $MAX_CPUID; die "invalid range: $part ($to < $from)\n" if $to < $from; for (my $i = $from; $i <= $to; $i++) { $members->{$i} = 1; @@ -68,7 +65,7 @@ sub write_to_cgroup { open(my $fh, '>', $filename) || die "failed to open '$filename' - $!\n"; PVE::Tools::safe_print($filename, $fh, "$value\n"); - close($fh); + close($fh) || die "failed to close '$filename' - $!\n"; } sub insert { @@ -77,7 +74,6 @@ sub insert { my $count = 0; foreach my $cpu (@members) { - die "cpu id '$cpu' is out of range\n" if $cpu >= $MAX_CPUID; next if $self->{members}->{$cpu}; $self->{members}->{$cpu} = 1; $count++; @@ -92,7 +88,6 @@ sub delete { my $count = 0; foreach my $cpu (@members) { - die "cpu id '$cpu' is out of range\n" if $cpu >= $MAX_CPUID; next if !$self->{members}->{$cpu}; delete $self->{members}->{$cpu}; $count++; @@ -111,7 +106,7 @@ sub has { sub members { my ($self) = @_; - return sort keys %{$self->{members}}; + return sort { $a <=> $b } keys %{$self->{members}}; } sub size { @@ -150,8 +145,12 @@ sub short_string { $next = $cpu; } else { $res .= ',' if length($res); - $res .= "$last-$next"; - $last = $next = undef; + if ($last != $next) { + $res .= "$last-$next"; + } else { + $res .= "$last"; + } + $last = $next = $cpu; } }