libct: devices: drop deprecated cgroup types

These were all marked deprecated in commit a75076b4a4 ("Switch to
opencontainers/cgroups") when we switched maintenance of our cgroup code
to opencontainers/cgroups.

Users have had ample time to switch to opencontainers/cgroups
themselves, so we can finally remove this.

Note that the whole libcontainer/devices package will be moved to
moby/sys in the near future, so this whole package will be marked
deprecated soon.

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
This commit is contained in:
Aleksa Sarai
2026-03-04 22:13:05 +11:00
parent 6a77ee7864
commit 625ef531b7
4 changed files with 27 additions and 34 deletions
+11
View File
@@ -29,6 +29,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `libcontainer/configs.NewThrottleDevice` - `libcontainer/configs.NewThrottleDevice`
- `libcontainer/configs.HookList.RunHooks`. (#5141) - `libcontainer/configs.HookList.RunHooks`. (#5141)
- `libcontainer/configs.MPOL_*` (#5414) - `libcontainer/configs.MPOL_*` (#5414)
- All of the types in `libcontainer/devices` which are now maintained in
`github.com/opencontainers/cgroups/devices/config` (#5141):
- `libcontainer/devices.Wildcard`
- `libcontainer/devices.WildcardDevice`
- `libcontainer/devices.BlockDevice`
- `libcontainer/devices.CharDevice`
- `libcontainer/devices.FifoDevice`
- `libcontainer/devices.Device`
- `libcontainer/devices.Permissions`
- `libcontainer/devices.Type`
- `libcontainer/devices.Rule`
## [1.4.0] - 2025-11-27 ## [1.4.0] - 2025-11-27
-20
View File
@@ -1,20 +0,0 @@
package devices
import "github.com/opencontainers/cgroups/devices/config"
// Deprecated: use [github.com/opencontainers/cgroups/devices/config].
const (
Wildcard = config.Wildcard
WildcardDevice = config.WildcardDevice
BlockDevice = config.BlockDevice
CharDevice = config.CharDevice
FifoDevice = config.FifoDevice
)
// Deprecated: use [github.com/opencontainers/cgroups/devices/config].
type (
Device = config.Device
Permissions = config.Permissions
Type = config.Type
Rule = config.Rule
)
+13 -12
View File
@@ -7,6 +7,7 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"github.com/opencontainers/cgroups/devices/config"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
) )
@@ -22,7 +23,7 @@ var (
// DeviceFromPath takes the path to a device and its cgroup_permissions (which // DeviceFromPath takes the path to a device and its cgroup_permissions (which
// cannot be easily queried) to look up the information about a linux device // cannot be easily queried) to look up the information about a linux device
// and returns that information as a Device struct. // and returns that information as a Device struct.
func DeviceFromPath(path, permissions string) (*Device, error) { func DeviceFromPath(path, permissions string) (*config.Device, error) {
var stat unix.Stat_t var stat unix.Stat_t
err := unixLstat(path, &stat) err := unixLstat(path, &stat)
if err != nil { if err != nil {
@@ -30,7 +31,7 @@ func DeviceFromPath(path, permissions string) (*Device, error) {
} }
var ( var (
devType Type devType config.Type
mode = stat.Mode mode = stat.Mode
devNumber = uint64(stat.Rdev) //nolint:unconvert // Rdev is uint32 on e.g. MIPS. devNumber = uint64(stat.Rdev) //nolint:unconvert // Rdev is uint32 on e.g. MIPS.
major = unix.Major(devNumber) major = unix.Major(devNumber)
@@ -38,20 +39,20 @@ func DeviceFromPath(path, permissions string) (*Device, error) {
) )
switch mode & unix.S_IFMT { switch mode & unix.S_IFMT {
case unix.S_IFBLK: case unix.S_IFBLK:
devType = BlockDevice devType = config.BlockDevice
case unix.S_IFCHR: case unix.S_IFCHR:
devType = CharDevice devType = config.CharDevice
case unix.S_IFIFO: case unix.S_IFIFO:
devType = FifoDevice devType = config.FifoDevice
default: default:
return nil, ErrNotADevice return nil, ErrNotADevice
} }
return &Device{ return &config.Device{
Rule: Rule{ Rule: config.Rule{
Type: devType, Type: devType,
Major: int64(major), Major: int64(major),
Minor: int64(minor), Minor: int64(minor),
Permissions: Permissions(permissions), Permissions: config.Permissions(permissions),
}, },
Path: path, Path: path,
FileMode: os.FileMode(mode &^ unix.S_IFMT), FileMode: os.FileMode(mode &^ unix.S_IFMT),
@@ -61,18 +62,18 @@ func DeviceFromPath(path, permissions string) (*Device, error) {
} }
// HostDevices returns all devices that can be found under /dev directory. // HostDevices returns all devices that can be found under /dev directory.
func HostDevices() ([]*Device, error) { func HostDevices() ([]*config.Device, error) {
return GetDevices("/dev") return GetDevices("/dev")
} }
// GetDevices recursively traverses a directory specified by path // GetDevices recursively traverses a directory specified by path
// and returns all devices found there. // and returns all devices found there.
func GetDevices(path string) ([]*Device, error) { func GetDevices(path string) ([]*config.Device, error) {
files, err := osReadDir(path) files, err := osReadDir(path)
if err != nil { if err != nil {
return nil, err return nil, err
} }
var out []*Device var out []*config.Device
for _, f := range files { for _, f := range files {
switch { switch {
case f.IsDir(): case f.IsDir():
@@ -103,7 +104,7 @@ func GetDevices(path string) ([]*Device, error) {
} }
return nil, err return nil, err
} }
if device.Type == FifoDevice { if device.Type == config.FifoDevice {
continue continue
} }
out = append(out, device) out = append(out, device)
+3 -2
View File
@@ -8,6 +8,7 @@ import (
"os" "os"
"testing" "testing"
"github.com/opencontainers/cgroups/devices/config"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
) )
@@ -85,8 +86,8 @@ func TestHostDevicesAllValid(t *testing.T) {
t.Errorf("device entry %+v has zero major number", device) t.Errorf("device entry %+v has zero major number", device)
} }
switch device.Type { switch device.Type {
case BlockDevice, CharDevice: case config.BlockDevice, config.CharDevice:
case FifoDevice: case config.FifoDevice:
t.Logf("fifo devices shouldn't show up from HostDevices") t.Logf("fifo devices shouldn't show up from HostDevices")
fallthrough fallthrough
default: default: