Skip to content

devices: move libcontainer/devices to moby/sys#212

Merged
thaJeztah merged 54 commits intomoby:mainfrom
cyphar:devices
Apr 1, 2026
Merged

devices: move libcontainer/devices to moby/sys#212
thaJeztah merged 54 commits intomoby:mainfrom
cyphar:devices

Conversation

@cyphar
Copy link
Copy Markdown
Contributor

@cyphar cyphar commented Mar 4, 2026

This is migrated from runc's libcontainer/devices, as this package has
only ever really been used outside of runc to generate device
configurations, so it makes more sense for it to live in
github.com/moby/sys.

With regards to the go.mod used, github.com/opencontainers/cgroups
requires Go 1.24, but aside from that all of these requirements are as
minimal as possible.

This merge was generated with git filter-repo --path-glob="libcontainer/devices/*" --path-rename=libcontainer/devices:devices. This does lose some of the pre-2015 history (opencontainers/runc@8f97d39 moved libcontainer into a subdirectory which means that the libcontainer/devices glob is missing commits before then) but this should be sufficient...

Fixes #181

crosbymichael and others added 30 commits June 21, 2015 19:29
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
Signed-off-by: John Howard <jhoward@microsoft.com>
Signed-off-by: Yuanhong Peng <pengyuanhong@huawei.com>
Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
getDevices() has been updated to skip `/dev/.lxc` and `/dev/.lxd-mounts`, which was breaking privileged Docker containers running on runC, inside of LXD managed Linux Containers

Signed-off-by: Carlton-Semple <carlton.semple@ibm.com>
Signed-off-by: Carlton-Semple <carlton.semple@ibm.com>
FreeBSD does not support cgroups or namespaces, which the code suggested, and is not supported
in runc anyway right now. So clean up the file naming to use `_linux` where appropriate.

Signed-off-by: Justin Cormack <justin.cormack@docker.com>
Since syscall is outdated and broken for some architectures,
use x/sys/unix instead.

There are still some dependencies on the syscall package that will
remain in syscall for the forseeable future:

Errno
Signal
SysProcAttr

Additionally:
- os still uses syscall, so it needs to be kept for anything
returning *os.ProcessState, such as process.Wait.

Signed-off-by: Christy Perez <christy@linux.vnet.ibm.com>
Refactor DeviceFromPath in order to get rid of package syscall and
directly use the functions from x/sys/unix. This also allows to get rid
of the conversion from the OS-independent file mode values (from the os
package) to Linux specific values and instead let's us use the raw
file mode value directly.

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
libcontainer: one more switch from syscall to x/sys/unix
Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>
Before this change, some file type would be treated as char devices
(e.g. symlinks).

Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>
The Major and Minor functions were added for Linux in golang/sys@85d1495
which is already vendored in. Use these functions instead of the local
re-implementation.

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
libcontainer: use Major/Minor from x/sys/unix
runc is not supported on FreeBSD, so remove all FreeBSD specific bits.

As suggested by @crosbymichael in #1653

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
runc currently only support Linux platform, and since we dont intend to expose
the support to other platform, removing all other platforms placeholder code.

`libcontainer/configs` still being used in
https://github.com/moby/moby/blob/master/daemon/daemon_windows.go so
keeping it for now.

After this, we probably should also rename files to drop linux suffices
if possible.

Signed-off-by: Daniel Dao <dqminh89@gmail.com>
It turns out that MIPS uses uint32 in the device number returned by
stat(2), so explicitly wrap everything to make the compiler happy. I
really wish that Go had C-like numeric type promotion.

Signed-off-by: Aleksa Sarai <asarai@suse.de>
Closes: #2093

Signed-off-by: Erik Sipsma <sipsma@amazon.com>
Signed-off-by: sashayakovtseva <sasha@sylabs.io>
Making them the same type is simply confusing, but also means that you
could accidentally use one in the wrong context. This eliminates that
problem. This also includes a whole bunch of cleanups for the types
within DeviceRule, so that they can be used more ergonomically.

Signed-off-by: Aleksa Sarai <asarai@suse.de>
(mode&S_IFCHR == S_IFCHR) is the wrong way of checking the type of an
inode because the S_IF* bits are actually not a bitmask and instead must
be checked using S_IF*. This bug was neatly hidden behind a (major == 0)
sanity-check but that was removed by [1].

In addition, add a test that makes sure that HostDevices() doesn't give
rubbish results -- because we broke this and fixed this before[2].

[1]: e0224a6 ("configs: use different types for .Devices and .Resources.Devices")
[2]: 058bfbb ("Handle non-devices correctly in DeviceFromPath")

Fixes: 38d4b67 ("libcontainer: one more switch from syscall to x/sys/unix")
Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
Aleksa Sarai (1):
  devices: correctly check device types

LGTMs: @AkihiroSuda @mrunalp
Closes #2529
Move the Device-related types to libcontainer/devices, so that
the package can be used in isolation. Aliases have been created
in libcontainer/configs for backward compatibility.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Iceber Gu <wei.cai-nat@daocloud.io>
libcontainer: fix the file mode of the device
Allows importing this package on Windows (for the types)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This was initially added by commit d78ee47154eee7 but later
moved from libcontainer/configs to libcontainer/devices by
commit ee96d80.

Looks like since commit ee96d80 and also [1]
there is no use for this, thus removing.

[1] containers/buildah#2652

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
cyphar and others added 5 commits March 1, 2025 21:37
Kir Kolyshkin (1):
  Switch to opencontainers/cgroups

LGTMs: lifubang cyphar
This silences all of the "should have a package comment" lint warnings
from golangci-lint.

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
Aleksa Sarai (1):
  lint/revive: add package doc comments

LGTMs: lifubang kolyshkin
Aleksa Sarai (5):
  lint/revive: add package doc comments
  Revert "libct/devices: change devices.Type to be a string"
  devices: correctly check device types
  configs: use different types for .Devices and .Resources.Devices
  libcontainer: devices: fix mips builds

Carlton-Semple (2):
  Added comment linking to LXD issue 2825
  Update devices_unix.go for LXD

Christy Perez (1):
  Move libcontainer to x/sys/unix

Curd Becker (1):
  Replace os.Is* error checking functions with their errors.Is counterpart

Daniel Dao (1):
  remove placeholder for non-linux platforms

Erik Sipsma (1):
  Skip searching /dev/.udev for device nodes.

Kir Kolyshkin (9):
  Switch to opencontainers/cgroups
  libct/devices: move config to libct/cg/devices/config
  Drop go 1.16
  Remove io/ioutil use
   *: add go-1.17+ go:build tags
  ci: enable unconvert linter, fix its warnings
  *: use errors.As and errors.Is
  Use gofumpt to format code
  libcontainer/devices/device_windows.go: rm

Iceber Gu (1):
  libcontainer: fix the file mode of the device

John Howard (1):
  Windows: Tidy libcontainer\devices

Justin Cormack (1):
  Clean up unix vs linux usage

Kenfe-Mickael Laventure (2):
  Handle non-devices correctly in DeviceFromPath
  Fix condition to detect device type in DeviceFromPath

Michael Crosby (2):
  Update import paths for new repository
  Move libcontainer into subdirectory

Mrunal Patel (1):
  Don't add device to list if it doesn't exist anymore

Sasha Yakovtseva (1):
  Make get devices function public

Sebastiaan van Stijn (6):
  remove pre-go1.17 build-tags
  libct/devices: change devices.Type to be a string
  libcontainer/devices: fix godoc (golint)
  Fix build-tags in libcontainer/devices
  libcontainer/devices: remove "Device" prefix from types
  libcontainer: isolate libcontainer/devices

Tobias Klauser (3):
  libcontainer: drop FreeBSD support
  libcontainer: use Major/Minor from x/sys/unix
  libcontainer: one more switch from syscall to x/sys/unix

Yuanhong Peng (1):
  Fix typo.

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
@cyphar cyphar requested a review from kolyshkin March 5, 2026 05:54
@cyphar cyphar force-pushed the devices branch 3 times, most recently from 788f7a8 to 83e8cc9 Compare March 5, 2026 10:15
cyphar added 4 commits March 5, 2026 22:28
The original file did not have a license header, but given that the code
comes from a different project it seems prudent to at least mention
which contributors the code came from. The detailed commit history (and
thus authorship) is maintained in the subtree-merge.

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
These are old APIs from runc that we should not export at all.

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
macOS appears to have major-0 devices in /dev, so we should only error
this test out on Linux (where that is not the case).

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
This is migrated from runc's libcontainer/devices, as this package has
only ever really been used outside of runc to generate device
configurations, so it makes more sense for it to live in
github.com/moby/sys.

With regards to the go.mod used, github.com/opencontainers/cgroups
requires Go 1.24, but aside from that all of these requirements are as
minimal as possible.

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
Copy link
Copy Markdown
Collaborator

@kolyshkin kolyshkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@thaJeztah PTAL

@kolyshkin
Copy link
Copy Markdown
Collaborator

@thaJeztah PTAL 🙏🏻

1 similar comment
@kolyshkin
Copy link
Copy Markdown
Collaborator

@thaJeztah PTAL 🙏🏻

@thaJeztah
Copy link
Copy Markdown
Member

WELP #toomanynotifications sorry! Let me have a peek 🤗

Copy link
Copy Markdown
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like a clean move

LGTM, thanks!

@thaJeztah thaJeztah merged commit bdb4ad6 into moby:main Apr 1, 2026
20 checks passed
@thaJeztah
Copy link
Copy Markdown
Member

@kolyshkin want to do the honours of tagging ? Not sure what version to start with but v0.1.0 probably would do the trick?

@cyphar cyphar deleted the devices branch April 2, 2026 00:18
@kolyshkin
Copy link
Copy Markdown
Collaborator

@kolyshkin want to do the honours of tagging ? Not sure what version to start with but v0.1.0 probably would do the trick?

Done:
https://github.com/moby/sys/releases/tag/devices%2Fv0.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

proposal: add moby/sys/devices