]> git.proxmox.com Git - pve-common.git/commitdiff
cpuset: cleanup/refactor
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Mon, 30 Mar 2020 14:30:32 +0000 (16:30 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 31 Mar 2020 06:50:10 +0000 (08:50 +0200)
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
src/PVE/CpuSet.pm

index b7dc4f50f5754c2cc598054c0898529090936016..aab2c9a7f454197f47ab59f79a064241a0d17e48 100644 (file)
@@ -6,27 +6,34 @@ use PVE::Tools;
 use PVE::ProcFSTools;
 
 sub new {
 use PVE::ProcFSTools;
 
 sub new {
-    my ($this) = @_;
+    my ($class, $members) = @_;
 
 
-    my $class = ref($this) || $this;
-
-    my $self = bless { members => {} }, $class;
+    $members //= {};
+    my $self = bless { members => $members }, $class;
 
     return $self;
 }
 
 sub new_from_cgroup {
 
     return $self;
 }
 
 sub new_from_cgroup {
-    my ($this, $cgroup, $kind) = @_;
+    my ($class, $cgroup, $kind) = @_;
 
     $kind //= 'cpus';
 
     my $filename = "/sys/fs/cgroup/cpuset/$cgroup/cpuset.$kind";
     my $set_text = PVE::Tools::file_read_firstline($filename) // '';
 
 
     $kind //= 'cpus';
 
     my $filename = "/sys/fs/cgroup/cpuset/$cgroup/cpuset.$kind";
     my $set_text = PVE::Tools::file_read_firstline($filename) // '';
 
-    my $cpuset = $this->new();
+    my ($count, $members) = parse_cpuset($set_text);
 
 
-    my $members = $cpuset->{members};
+    die "got empty cpuset for cgroup '$cgroup'\n"
+       if !$count;
+
+    return $class->new($members);
+}
 
 
+sub parse_cpuset {
+    my ($set_text) = @_;
+
+    my $members = {};
     my $count = 0;
 
     foreach my $part (split(/,/, $set_text)) {
     my $count = 0;
 
     foreach my $part (split(/,/, $set_text)) {
@@ -43,10 +50,7 @@ sub new_from_cgroup {
        }
     }
 
        }
     }
 
-    die "got empty cpuset for cgroup '$cgroup'\n"
-       if !$count;
-
-    return $cpuset;
+    return ($count, $members);
 }
 
 sub write_to_cgroup {
 }
 
 sub write_to_cgroup {