[pve-devel] [PATCH v2 manager 4/5] cluster resources: add cgroup-mode to node properties

Fiona Ebner f.ebner at proxmox.com
Fri Oct 7 14:41:55 CEST 2022


so the frontend has the information readily available.

It's enough for pvestatd to broadcast the value whenever it's outdated
or not set in the node's local kv store, because pmxcfs will
re-broadcast the local kv store whenever the quorate partition
changes. This is already relied upon for the 'ceph-versions' kv pair.

Suggested-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
Signed-off-by: Fiona Ebner <f.ebner at proxmox.com>
---

Changes from v1:
    * Only broadcast if necessary rather than periodically.

 PVE/API2/Cluster.pm     | 12 ++++++++++++
 PVE/Service/pvestatd.pm | 16 ++++++++++++++++
 2 files changed, 28 insertions(+)

diff --git a/PVE/API2/Cluster.pm b/PVE/API2/Cluster.pm
index d6b405e2..cb96abd7 100644
--- a/PVE/API2/Cluster.pm
+++ b/PVE/API2/Cluster.pm
@@ -312,6 +312,11 @@ __PACKAGE__->register_method({
 		    type => 'string',
 		    optional => 1,
 		},
+		'cgroup-mode' => {
+		    description => "The cgroup mode the node operates under (when type == node).",
+		    type => 'integer',
+		    optional => 1,
+		},
 	    },
 	},
     },
@@ -416,10 +421,17 @@ __PACKAGE__->register_method({
 	    }
 	}
 
+	my $cgroup_modes = PVE::Cluster::get_node_kv("cgroup-mode");
+
 	if (!$param->{type} || $param->{type} eq 'node') {
 	    foreach my $node (@$nodelist) {
 		my $can_audit = $rpcenv->check($authuser, "/nodes/$node", [ 'Sys.Audit' ], 1);
 		my $entry = PVE::API2Tools::extract_node_stats($node, $members, $rrd, !$can_audit);
+
+		if (defined(my $mode = $cgroup_modes->{$node})) {
+		    $entry->{'cgroup-mode'} = int($mode);
+		}
+
 		push @$res, $entry;
 	    }
 	}
diff --git a/PVE/Service/pvestatd.pm b/PVE/Service/pvestatd.pm
index eac953df..61de8b36 100755
--- a/PVE/Service/pvestatd.pm
+++ b/PVE/Service/pvestatd.pm
@@ -123,9 +123,25 @@ my $generate_rrd_string = sub {
     return join(':', map { $_ // 'U' } @$data);
 };
 
+my sub broadcast_cgroup_mode {
+    my $cgroup_mode = eval { PVE::CGroup::cgroup_mode(); };
+    if (my $err = $@) {
+	syslog('err', "cgroup mode error: $err");
+	return;
+    }
+
+    my $old = PVE::Cluster::get_node_kv("cgroup-mode", $cgroup_mode, $nodename);
+    $old = eval { decode_json($old->{$nodename}) } if defined($old->{$nodename});
+
+    PVE::Cluster::broadcast_node_kv("cgroup-mode", $cgroup_mode)
+	if !$old || $old != $cgroup_mode;
+}
+
 sub update_node_status {
     my ($status_cfg) = @_;
 
+    broadcast_cgroup_mode();
+
     my ($uptime) = PVE::ProcFSTools::read_proc_uptime();
 
     my ($avg1, $avg5, $avg15) = PVE::ProcFSTools::read_loadavg();
-- 
2.30.2






More information about the pve-devel mailing list