Skip to content

Commit 200f563

Browse files
committed
libct/devices: move config to libct/cg/devices/config
Currently, libcontainer/devices contains two things: 1. Device-related configuration data structures and accompanying methods. Those are used by runc itself, mostly by libct/cgroups. 2. A few functions (HostDevices, DeviceFromPath, GetDevices). Those are not used by runc directly, but have some external users (cri-o, microsoft/hcsshim), and they also have a few forks (containerd/pkg/oci, podman/pkg/util). This commit moves (1) to a new separate package, config (under libcontainer/cgroups/devices), adding a backward-compatible aliases (marked as deprecated so we will be able to remove those later). Alas it's not possible to move this to libcontainer/cgroups directly because some IDs (Type, Rule, Permissions) are too generic, and renaming them (to DeviceType, DeviceRule, DevicePermissions) will break backward compatibility (mostly due to Rule being embedded into Device). Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent f1c0e63 commit 200f563

File tree

4 files changed

+35
-8
lines changed

4 files changed

+35
-8
lines changed

libcontainer/devices/device.go renamed to libcontainer/cgroups/devices/config/device.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package devices
1+
package config
22

33
import (
44
"fmt"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package config
2+
3+
import (
4+
"errors"
5+
6+
"golang.org/x/sys/unix"
7+
)
8+
9+
func mkDev(d *Rule) (uint64, error) {
10+
if d.Major == Wildcard || d.Minor == Wildcard {
11+
return 0, errors.New("cannot mkdev() device with wildcards")
12+
}
13+
return unix.Mkdev(uint32(d.Major), uint32(d.Minor)), nil
14+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package devices
2+
3+
import "github.com/opencontainers/runc/libcontainer/cgroups/devices/config"
4+
5+
// Deprecated: use [github.com/opencontainers/runc/libcontainer/cgroups/devices/config].
6+
const (
7+
Wildcard = config.Wildcard
8+
WildcardDevice = config.WildcardDevice
9+
BlockDevice = config.BlockDevice
10+
CharDevice = config.CharDevice
11+
FifoDevice = config.FifoDevice
12+
)
13+
14+
// Deprecated: use [github.com/opencontainers/runc/libcontainer/cgroups/devices/config].
15+
type (
16+
Device = config.Device
17+
Permissions = config.Permissions
18+
Type = config.Type
19+
Rule = config.Rule
20+
)

libcontainer/devices/device_unix.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,6 @@ var (
1919
osReadDir = os.ReadDir
2020
)
2121

22-
func mkDev(d *Rule) (uint64, error) {
23-
if d.Major == Wildcard || d.Minor == Wildcard {
24-
return 0, errors.New("cannot mkdev() device with wildcards")
25-
}
26-
return unix.Mkdev(uint32(d.Major), uint32(d.Minor)), nil
27-
}
28-
2922
// DeviceFromPath takes the path to a device and its cgroup_permissions (which
3023
// cannot be easily queried) to look up the information about a linux device
3124
// and returns that information as a Device struct.

0 commit comments

Comments
 (0)