public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Wolfgang Bumiller <w.bumiller@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH common 2/2] cgroup: get mode by checking /sys/fs/cgroup mount point
Date: Wed, 21 Sep 2022 09:53:13 +0200	[thread overview]
Message-ID: <20220921075313.65674-2-w.bumiller@proxmox.com> (raw)
In-Reply-To: <20220921075313.65674-1-w.bumiller@proxmox.com>

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





  reply	other threads:[~2022-09-21  7:53 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2022-09-21  8:05   ` [pve-devel] applied: [PATCH common 2/2] cgroup: get mode by checking /sys/fs/cgroup mount point Thomas Lamprecht
2022-09-21  8:03 ` [pve-devel] applied: [PATCH common 1/2] cgroup: make get_v1_controllers private Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220921075313.65674-2-w.bumiller@proxmox.com \
    --to=w.bumiller@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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