From 2142cdd612a9d8c918c9efd561582b4a87a95926 Mon Sep 17 00:00:00 2001 From: Debarshi Ray Date: Thu, 24 Oct 2019 15:27:35 +0200 Subject: [PATCH] Log the cgroups version into the debug output The migration to cgroups v2 in Fedora 31 [1] has proved a bit stormy. This is meant to help users self-diagnose whether their problems might be originating from the use of cgroups v2. [1] https://fedoraproject.org/wiki/Changes/CGroupsV2 https://github.com/containers/toolbox/pull/309 --- toolbox | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/toolbox b/toolbox index 0cfab8e..ce7861e 100755 --- a/toolbox +++ b/toolbox @@ -22,6 +22,7 @@ arguments="" assume_yes=false base_toolbox_command=$(basename "$0" 2>&3) base_toolbox_image="" +cgroups_version="" # Based on the nameRegex value in: # https://github.com/containers/libpod/blob/master/libpod/options.go @@ -442,6 +443,24 @@ enter_print_container_not_found() ) +get_cgroups_version() +( + version=1 + + if ! mounts=$(mount 2>&3); then + echo "$base_toolbox_command: failed to detect cgroups version: couldn't list mount points" >&2 + return 1 + fi + + if ! (echo "$mounts" | grep "^cgroup " >/dev/null 2>&3) && (echo "$mounts" | grep "^cgroup2 " >/dev/null 2>&3); then + version=2 + fi + + echo "$version" + return 0 +) + + get_group_for_sudo() ( group="" @@ -2164,6 +2183,12 @@ if [ -f /run/.containerenv ] 2>&3; then esac fi +if ! cgroups_version=$(get_cgroups_version); then + exit 1 +fi + +echo "$base_toolbox_command: running on a cgroups v$cgroups_version host" >&3 + if [ "$op" != "reset" ] 2>&3; then if ! migrate; then exit 1