]> git.proxmox.com Git - pve-common.git/blobdiff - src/PVE/CpuSet.pm
fix #1819: fork_worker: ensure sync'ed workers control terminal
[pve-common.git] / src / PVE / CpuSet.pm
index 753b3cdec4cac5edc64a251ef9f464593cb034bb..92fd18fe73a86c6120f5f0f70547aa1eb8275fd5 100644 (file)
@@ -5,28 +5,13 @@ use warnings;
 use PVE::Tools;
 use PVE::ProcFSTools;
 
-my $MAX_CPUID;
-
-sub max_cpuid {
-
-    return $MAX_CPUID if defined($MAX_CPUID);
-
-    my $cpuinfo = PVE::ProcFSTools::read_cpuinfo();
-
-    $MAX_CPUID = $cpuinfo->{cpus} || 1;
-
-    return $MAX_CPUID;
-}
-
 sub new {
     my ($this) = @_;
 
     my $class = ref($this) || $this;
 
     my $self = bless { members => {} }, $class;
-    
-    max_cpuid() if !defined($MAX_CPUID); # initialize $MAX_CPUID
-    
+
     return $self;
 }
 
@@ -48,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;
@@ -82,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 {
@@ -91,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++;
@@ -106,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++;
@@ -125,7 +106,7 @@ sub has {
 sub members {
     my ($self) = @_;
 
-    return sort keys %{$self->{members}};
+    return sort { $a <=> $b } keys %{$self->{members}};
 }    
 
 sub size {
@@ -164,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;
        }
     }