Skip to content

Interop.cgroups.FindCGroupsVersion broken for cgroups v1 #93581

@janvorli

Description

@janvorli

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:

Enum.GetName(typeof(UnixFileSystemTypes), numericFormat) ?? string.Empty :
Marshal.PtrToStringUTF8((IntPtr)formatBuffer)!;

The Interop.cgroups.FindCGroupsVersion uses this switch to detect cgroups version:

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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions