Skip to content

Commit fa9842c

Browse files
Zhai Zhaoxuanzhouhao
Zhai Zhaoxuan
authored and
zhouhao
committed
Add manpages and bash-completion for --device-access-add and --device-access-remove
Signed-off-by: Zhai Zhaoxuan <[email protected]> Signed-off-by: zhouhao <[email protected]>
1 parent 7f09e1b commit fa9842c

File tree

4 files changed

+32
-20
lines changed

4 files changed

+32
-20
lines changed

Diff for: cmd/oci-runtime-tool/generate.go

+16-17
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ var generateFlags = []cli.Flag{
4040
cli.StringSliceFlag{Name: "linux-device-add", Usage: "add a device which must be made available in the container"},
4141
cli.StringSliceFlag{Name: "linux-device-remove", Usage: "remove a device which must be made available in the container"},
4242
cli.BoolFlag{Name: "linux-device-remove-all", Usage: "remove all devices which must be made available in the container"},
43+
cli.StringSliceFlag{Name: "linux-device-cgroup-add", Usage: "add a device access rule"},
44+
cli.StringSliceFlag{Name: "linux-device-cgroup-remove", Usage: "remove a device access rule"},
4345
cli.BoolFlag{Name: "linux-disable-oom-kill", Usage: "disable OOM Killer"},
4446
cli.StringSliceFlag{Name: "linux-gidmappings", Usage: "add GIDMappings e.g HostID:ContainerID:Size"},
4547
cli.StringSliceFlag{Name: "linux-hugepage-limits-add", Usage: "add hugepage resource limits"},
@@ -63,8 +65,6 @@ var generateFlags = []cli.Flag{
6365
cli.StringSliceFlag{Name: "linux-readonly-paths", Usage: "specifies paths readonly inside container"},
6466
cli.Int64Flag{Name: "linux-realtime-period", Usage: "CPU period to be used for realtime scheduling (in usecs)"},
6567
cli.Int64Flag{Name: "linux-realtime-runtime", Usage: "the time realtime scheduling may use (in usecs)"},
66-
cli.StringSliceFlag{Name: "linux-resources-device-add", Usage: "add a device access rule"},
67-
cli.StringSliceFlag{Name: "linux-resources-device-remove", Usage: "remove a device access rule"},
6868
cli.StringFlag{Name: "linux-rootfs-propagation", Usage: "mount propagation for rootfs"},
6969
cli.StringFlag{Name: "linux-seccomp-allow", Usage: "specifies syscalls to respond with allow"},
7070
cli.StringFlag{Name: "linux-seccomp-arch", Usage: "specifies additional architectures permitted to be used for system calls"},
@@ -243,8 +243,8 @@ func setupSpec(g *generate.Generator, context *cli.Context) error {
243243
}
244244
}
245245

246-
if context.IsSet("linux-resources-device-add") {
247-
devices := context.StringSlice("linux-resources-device-add")
246+
if context.IsSet("linux-device-cgroup-add") {
247+
devices := context.StringSlice("linux-device-cgroup-add")
248248
for _, device := range devices {
249249
dev, err := parseLinuxResourcesDeviceAccess(device, g)
250250
if err != nil {
@@ -254,8 +254,8 @@ func setupSpec(g *generate.Generator, context *cli.Context) error {
254254
}
255255
}
256256

257-
if context.IsSet("linux-resources-device-remove") {
258-
devices := context.StringSlice("linux-resources-device-remove")
257+
if context.IsSet("linux-device-cgroup-remove") {
258+
devices := context.StringSlice("linux-device-cgroup-remove")
259259
for _, device := range devices {
260260
dev, err := parseLinuxResourcesDeviceAccess(device, g)
261261
if err != nil {
@@ -835,7 +835,6 @@ func parseRlimit(rlimit string) (string, uint64, uint64, error) {
835835
return parts[0], uint64(hard), uint64(soft), nil
836836
}
837837

838-
<<<<<<< 9e0e42dbf918070406a2a4a2e1476e7350ba9129
839838
func parseNamespace(ns string) (string, string, error) {
840839
parts := strings.SplitN(ns, ":", 2)
841840
if len(parts) == 0 || parts[0] == "" {
@@ -943,7 +942,7 @@ var cgroupDeviceAccess = map[string]bool{
943942
}
944943

945944
// parseLinuxResourcesDeviceAccess parses the raw string passed with the --device-access-add flag
946-
func parseLinuxResourcesDeviceAccess(device string, g *generate.Generator) (rspec.DeviceCgroup, error) {
945+
func parseLinuxResourcesDeviceAccess(device string, g *generate.Generator) (rspec.LinuxDeviceCgroup, error) {
947946
var allow bool
948947
var devType, access string
949948
var major, minor *int64
@@ -956,7 +955,7 @@ func parseLinuxResourcesDeviceAccess(device string, g *generate.Generator) (rspe
956955
case "deny":
957956
allow = false
958957
default:
959-
return rspec.DeviceCgroup{},
958+
return rspec.LinuxDeviceCgroup{},
960959
fmt.Errorf("Only 'allow' and 'deny' are allowed in the first field of device-access-add: %s", device)
961960
}
962961

@@ -967,38 +966,38 @@ func parseLinuxResourcesDeviceAccess(device string, g *generate.Generator) (rspe
967966
}
968967
parts := strings.SplitN(s, "=", 2)
969968
if len(parts) != 2 {
970-
return rspec.DeviceCgroup{}, fmt.Errorf("Incomplete device-access-add arguments: %s", s)
969+
return rspec.LinuxDeviceCgroup{}, fmt.Errorf("Incomplete device-access-add arguments: %s", s)
971970
}
972971
name, value := parts[0], parts[1]
973972

974973
switch name {
975974
case "type":
976975
if !cgroupDeviceType[value] {
977-
return rspec.DeviceCgroup{}, fmt.Errorf("Invalid device type in device-access-add: %s", value)
976+
return rspec.LinuxDeviceCgroup{}, fmt.Errorf("Invalid device type in device-access-add: %s", value)
978977
}
979-
devType = &value
978+
devType = value
980979
case "major":
981980
i, err := strconv.ParseInt(value, 10, 64)
982981
if err != nil {
983-
return rspec.DeviceCgroup{}, err
982+
return rspec.LinuxDeviceCgroup{}, err
984983
}
985984
major = &i
986985
case "minor":
987986
i, err := strconv.ParseInt(value, 10, 64)
988987
if err != nil {
989-
return rspec.DeviceCgroup{}, err
988+
return rspec.LinuxDeviceCgroup{}, err
990989
}
991990
minor = &i
992991
case "access":
993992
for _, c := range strings.Split(value, "") {
994993
if !cgroupDeviceAccess[c] {
995-
return rspec.DeviceCgroup{}, fmt.Errorf("Invalid device access in device-access-add: %s", c)
994+
return rspec.LinuxDeviceCgroup{}, fmt.Errorf("Invalid device access in device-access-add: %s", c)
996995
}
997996
}
998-
access = &value
997+
access = value
999998
}
1000999
}
1001-
return rspec.DeviceCgroup{
1000+
return rspec.LinuxDeviceCgroup{
10021001
Allow: allow,
10031002
Type: devType,
10041003
Major: major,

Diff for: completions/bash/oci-runtime-tool

+2
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,8 @@ _oci-runtime-tool_generate() {
326326
--linux-cpu-shares
327327
--linux-device-add
328328
--linux-device-remove
329+
--linux-device-cgroup-add
330+
--linux-device-cgroup-remove
329331
--linux-gidmappings
330332
--linux-hugepage-limits-add
331333
--linux-hugepage-limits-drop

Diff for: generate/generate.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -1177,10 +1177,10 @@ func (g *Generator) ClearLinuxDevices() {
11771177
}
11781178

11791179
// AddLinuxResourcesDevice - add a device into g.spec.Linux.Resources.Devices
1180-
func (g *Generator) AddLinuxResourcesDevice(allow bool, devType string, major, minor *int64, access *string) {
1180+
func (g *Generator) AddLinuxResourcesDevice(allow bool, devType string, major, minor *int64, access string) {
11811181
g.initSpecLinuxResources()
11821182

1183-
device := rspec.DeviceCgroup{
1183+
device := rspec.LinuxDeviceCgroup{
11841184
Allow: allow,
11851185
Type: devType,
11861186
Access: access,
@@ -1191,7 +1191,7 @@ func (g *Generator) AddLinuxResourcesDevice(allow bool, devType string, major, m
11911191
}
11921192

11931193
// RemoveLinuxResourcesDevice - remove a device from g.spec.Linux.Resources.Devices
1194-
func (g *Generator) RemoveLinuxResourcesDevice(allow bool, devType string, major, minor *int64, access *string) {
1194+
func (g *Generator) RemoveLinuxResourcesDevice(allow bool, devType string, major, minor *int64, access string) {
11951195
if g.spec == nil || g.spec.Linux == nil || g.spec.Linux.Resources == nil {
11961196
return
11971197
}

Diff for: man/oci-runtime-tool-generate.1.md

+11
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,17 @@ read the configuration from `config.json`.
121121
**--linux-device-remove-all**=true|false
122122
Remove all devices for linux inside the container. The default is *false*.
123123

124+
**--linux-device-cgroup-add**=allow|deny[,type=TYPE][,major=MAJOR][,minor=MINOR][,access=ACCESS]
125+
Add a device control rule.
126+
allow|deny: whether the entry is allowed or denied.
127+
TYPE: the device type. The value could be one of 'a' (all), 'b' (block), 'c' (character).
128+
MAJOR/MINOR: the major/minor id of device.
129+
ACCESS: cgroup permissions for device. A composition of r (read), w (write), and m (mknod).
130+
131+
**--linux-device-cgroup-remove**=allow|deny[,type=TYPE][,major=MAJOR][,minor=MINOR][,access=ACCESS]
132+
Remove a device control rule.
133+
The arguments is same as *--linux-device-cgroup-add*.
134+
124135
**--linux-disable-oom-kill**=true|false
125136
Whether to disable OOM Killer for the container or not.
126137

0 commit comments

Comments
 (0)