[pve-devel] [PATCH 1/4] cpuset: cleanup/refactor

w.bumiller at proxmox.com w.bumiller at proxmox.com
Mon Mar 30 16:30:32 CEST 2020


From: Wolfgang Bumiller <w.bumiller at proxmox.com>

Signed-off-by: Wolfgang Bumiller <w.bumiller at proxmox.com>
---
 src/PVE/CpuSet.pm | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/src/PVE/CpuSet.pm b/src/PVE/CpuSet.pm
index b7dc4f5..aab2c9a 100644
--- a/src/PVE/CpuSet.pm
+++ b/src/PVE/CpuSet.pm
@@ -6,27 +6,34 @@ use PVE::Tools;
 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 {
-    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) // '';
 
-    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)) {
@@ -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 {
-- 
2.20.1





More information about the pve-devel mailing list