X-Git-Url: https://git.proxmox.com/?p=pve-common.git;a=blobdiff_plain;f=src%2FPVE%2FCpuSet.pm;h=12bda2ce07a912d2a82ad208b507727bd7783a48;hp=aab2c9a7f454197f47ab59f79a064241a0d17e48;hb=d37a71867233a09803e825f0249a1c7df8be25a0;hpb=591be969580e7b7ceee9051e4e83390f522ffe7c diff --git a/src/PVE/CpuSet.pm b/src/PVE/CpuSet.pm index aab2c9a..12bda2c 100644 --- a/src/PVE/CpuSet.pm +++ b/src/PVE/CpuSet.pm @@ -14,19 +14,33 @@ sub new { return $self; } +# Create a new set with the contents of a cgroup-v1 subdirectory. +# Deprecated: sub new_from_cgroup { - my ($class, $cgroup, $kind) = @_; + my ($class, $cgroup, $effective) = @_; - $kind //= 'cpus'; + return $class->new_from_path("/sys/fs/cgroup/cpuset/$cgroup", $effective); +} + +# Create a new set from the contents of a complete path to a cgroup directory. +sub new_from_path { + my ($class, $path, $effective) = @_; + + 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 = "/sys/fs/cgroup/cpuset/$cgroup/cpuset.$kind"; my $set_text = PVE::Tools::file_read_firstline($filename) // ''; my ($count, $members) = parse_cpuset($set_text); - die "got empty cpuset for cgroup '$cgroup'\n" - if !$count; - return $class->new($members); } @@ -53,10 +67,19 @@ sub parse_cpuset { 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(); @@ -65,8 +88,6 @@ sub write_to_cgroup { $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";