use strict;
use warnings;
use PVE::Tools;
+use PVE::ProcFSTools;
-our $MAX_CPUID = 256; # should be enough for the next years
+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;
}
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 {
$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;
}
}