-
Couldn't load subscription status.
- Fork 5.2k
Description
While working on some cgroups related changes, I've found that the Interop.cgroups.FindCGroupsVersion was unable to detect cgroups v1. I've investigated the issue and the problem is caused by the fact that the textual result of new DriveInfo(SysFsCgroupFileSystemPath).DriveFormat returns udev instead of tmpfs. The reason is that we get the format string from the UnixFileSystemTypes enum based on the filesystem "magic" constant and the udev and tmpfs (and few others) share the same value.
The DriveInfo calls Interop.Sys.GetFormatInfoForMountPoint that converts the filesystem numeric type (the magic constant) using this:
runtime/src/libraries/Common/src/Interop/Unix/System.Native/Interop.MountPoints.FormatInfo.cs
Lines 62 to 63 in ccc475e
| Enum.GetName(typeof(UnixFileSystemTypes), numericFormat) ?? string.Empty : | |
| Marshal.PtrToStringUTF8((IntPtr)formatBuffer)!; |
The Interop.cgroups.FindCGroupsVersion uses this switch to detect cgroups version:
runtime/src/libraries/Common/src/Interop/Linux/cgroups/Interop.cgroups.cs
Lines 115 to 120 in ccc475e
| return new DriveInfo(SysFsCgroupFileSystemPath).DriveFormat switch | |
| { | |
| "cgroup2fs" => CGroupVersion.CGroup2, | |
| "tmpfs" => CGroupVersion.CGroup1, | |
| _ => CGroupVersion.None, | |
| }; |
Since the name returned by the Enum.ToString is "udev", it fails to detect the cgroups 1.