}
# Create a new set with the contents of a cgroup-v1 subdirectory.
+# Deprecated:
sub new_from_cgroup {
my ($class, $cgroup, $effective) = @_;
sub new_from_path {
my ($class, $path, $effective) = @_;
- my $kind = $effective ? 'effective_cpus' : 'cpus';
+ my $filename;
+ if ($effective) {
+ $filename = "$path/cpuset.effective_cpus";
+ if (!-e $filename) {
+ # cgroupv2:
+ $filename = "$path/cpuset.cpus.effective";
+ }
+ } else {
+ $filename = "$path/cpuset.cpus";
+ }
- my $filename = "$path/cpuset.$kind";
my $set_text = PVE::Tools::file_read_firstline($filename) // '';
my ($count, $members) = parse_cpuset($set_text);
- die "got empty cpuset for cgroup '$path'\n"
- if !$count;
-
return $class->new($members);
}
return ($count, $members);
}
+# Deprecated:
sub write_to_cgroup {
my ($self, $cgroup) = @_;
- my $filename = "/sys/fs/cgroup/cpuset/$cgroup/cpuset.cpus";
+ return $self->write_to_path("/sys/fs/cgroup/cpuset/$cgroup");
+}
+
+# Takes the cgroup directory containing the cpuset.cpus file (to be closer to
+# new_from_path behavior this doesn't take the complete file name).
+sub write_to_path {
+ my ($self, $path) = @_;
+
+ my $filename = "$path/cpuset.cpus";
my $value = '';
my @members = $self->members();
$value .= $cpuid;
}
- die "unable to write empty cpu set\n" if !length($value);
-
open(my $fh, '>', $filename) || die "failed to open '$filename' - $!\n";
PVE::Tools::safe_print($filename, $fh, "$value\n");
close($fh) || die "failed to close '$filename' - $!\n";
sub members {
my ($self) = @_;
- return sort { $a <=> $b } keys %{$self->{members}};
+ my @sorted_members = sort { $a <=> $b } keys %{$self->{members}};
+ return @sorted_members;
}
sub size {