public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH common 1/2] cgroup: make get_v1_controllers private
@ 2022-09-21  7:53 Wolfgang Bumiller
  2022-09-21  7:53 ` [pve-devel] [PATCH common 2/2] cgroup: get mode by checking /sys/fs/cgroup mount point Wolfgang Bumiller
  2022-09-21  8:03 ` [pve-devel] applied: [PATCH common 1/2] cgroup: make get_v1_controllers private Thomas Lamprecht
  0 siblings, 2 replies; 4+ messages in thread
From: Wolfgang Bumiller @ 2022-09-21  7:53 UTC (permalink / raw)
  To: pve-devel

we have no external users left

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
---
 src/PVE/CGroup.pm | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/src/PVE/CGroup.pm b/src/PVE/CGroup.pm
index 44b3297..92a0654 100644
--- a/src/PVE/CGroup.pm
+++ b/src/PVE/CGroup.pm
@@ -40,9 +40,7 @@ sub new {
 #
 # Returns a set (hash mapping names to `1`) of cgroupv1 controllers, and an
 # optional boolean whether a unified (cgroupv2) hierarchy exists.
-#
-# Deprecated: Use `get_cgroup_controllers()` instead.
-sub get_v1_controllers {
+my sub get_v1_controllers {
     my $v1 = {};
     my $v2 = 0;
     my $data = PVE::Tools::file_get_contents('/proc/self/cgroup');
-- 
2.30.2





^ permalink raw reply	[flat|nested] 4+ messages in thread

* [pve-devel] [PATCH common 2/2] cgroup: get mode by checking /sys/fs/cgroup mount point
  2022-09-21  7:53 [pve-devel] [PATCH common 1/2] cgroup: make get_v1_controllers private Wolfgang Bumiller
@ 2022-09-21  7:53 ` Wolfgang Bumiller
  2022-09-21  8:05   ` [pve-devel] applied: " Thomas Lamprecht
  2022-09-21  8:03 ` [pve-devel] applied: [PATCH common 1/2] cgroup: make get_v1_controllers private Thomas Lamprecht
  1 sibling, 1 reply; 4+ messages in thread
From: Wolfgang Bumiller @ 2022-09-21  7:53 UTC (permalink / raw)
  To: pve-devel

Since even in pure unified layouts there may be a
`name=systemd` v1 cgroup mounted additionally (manually or
potentially via systemd-nspawn apparently), we should check
what's actually mounted at `/sys/fs/cgroup` rather than
whether v1 cgroups exist.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
---
 src/PVE/CGroup.pm | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)

diff --git a/src/PVE/CGroup.pm b/src/PVE/CGroup.pm
index 92a0654..45c0788 100644
--- a/src/PVE/CGroup.pm
+++ b/src/PVE/CGroup.pm
@@ -86,21 +86,30 @@ sub get_cgroup_controllers() {
 my $CGROUP_MODE = undef;
 # Figure out which cgroup mode we're operating under:
 #
-# Returns 1 if cgroupv1 controllers exist (hybrid or legacy mode), and 2 in a
-# cgroupv2-only environment.
+# For this we check the file system type of `/sys/fs/cgroup` as it may well be possible that some
+# additional cgroupv1 mount points have been created by tools such as `systemd-nspawn`, or
+# manually.
+#
+# Returns 1 for what we consider the hybrid layout, 2 for what we consider the unified layout.
 #
 # NOTE: To fully support a hybrid layout it is better to use functions like
-# `cpuset_controller_path`.
+# `cpuset_controller_path` and not rely on this value for anything involving paths.
 #
 # This is a function, not a method!
 sub cgroup_mode() {
     if (!defined($CGROUP_MODE)) {
-	my ($v1, $v2) = get_cgroup_controllers();
-	if (keys %$v1) {
-	    # hybrid or legacy mode
-	    $CGROUP_MODE = 1;
-	} elsif ($v2) {
-	    $CGROUP_MODE = 2;
+	my $mounts = PVE::ProcFSTools::parse_proc_mounts();
+	for my $entry (@$mounts) {
+	    my ($what, $dir, $fstype, $opts) = @$entry;
+	    if ($dir eq '/sys/fs/cgroup') {
+		if ($fstype eq 'cgroup2') {
+		    $CGROUP_MODE = 2;
+		    last;
+		} else {
+		    $CGROUP_MODE = 1;
+		    last;
+		}
+	    }
 	}
     }
 
-- 
2.30.2





^ permalink raw reply	[flat|nested] 4+ messages in thread

* [pve-devel] applied: [PATCH common 1/2] cgroup: make get_v1_controllers private
  2022-09-21  7:53 [pve-devel] [PATCH common 1/2] cgroup: make get_v1_controllers private Wolfgang Bumiller
  2022-09-21  7:53 ` [pve-devel] [PATCH common 2/2] cgroup: get mode by checking /sys/fs/cgroup mount point Wolfgang Bumiller
@ 2022-09-21  8:03 ` Thomas Lamprecht
  1 sibling, 0 replies; 4+ messages in thread
From: Thomas Lamprecht @ 2022-09-21  8:03 UTC (permalink / raw)
  To: Proxmox VE development discussion, Wolfgang Bumiller

Am 21/09/2022 um 09:53 schrieb Wolfgang Bumiller:
> we have no external users left
> 
> Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
> ---
>  src/PVE/CGroup.pm | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
>

applied, thanks!




^ permalink raw reply	[flat|nested] 4+ messages in thread

* [pve-devel] applied: [PATCH common 2/2] cgroup: get mode by checking /sys/fs/cgroup mount point
  2022-09-21  7:53 ` [pve-devel] [PATCH common 2/2] cgroup: get mode by checking /sys/fs/cgroup mount point Wolfgang Bumiller
@ 2022-09-21  8:05   ` Thomas Lamprecht
  0 siblings, 0 replies; 4+ messages in thread
From: Thomas Lamprecht @ 2022-09-21  8:05 UTC (permalink / raw)
  To: Proxmox VE development discussion, Wolfgang Bumiller

Am 21/09/2022 um 09:53 schrieb Wolfgang Bumiller:
> Since even in pure unified layouts there may be a
> `name=systemd` v1 cgroup mounted additionally (manually or
> potentially via systemd-nspawn apparently), we should check
> what's actually mounted at `/sys/fs/cgroup` rather than
> whether v1 cgroups exist.
> 
> Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
> ---
>  src/PVE/CGroup.pm | 27 ++++++++++++++++++---------
>  1 file changed, 18 insertions(+), 9 deletions(-)
> 
>

applied, thanks!

> +	my $mounts = PVE::ProcFSTools::parse_proc_mounts();
> +	for my $entry (@$mounts) {
> +	    my ($what, $dir, $fstype, $opts) = @$entry;

style nit: we nowadays try to use $foo->@* for new additions, but really no hard
feelings so I kept it as is.




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-09-21  8:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-21  7:53 [pve-devel] [PATCH common 1/2] cgroup: make get_v1_controllers private Wolfgang Bumiller
2022-09-21  7:53 ` [pve-devel] [PATCH common 2/2] cgroup: get mode by checking /sys/fs/cgroup mount point Wolfgang Bumiller
2022-09-21  8:05   ` [pve-devel] applied: " Thomas Lamprecht
2022-09-21  8:03 ` [pve-devel] applied: [PATCH common 1/2] cgroup: make get_v1_controllers private Thomas Lamprecht

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal