Skip to content

Commit 158fd56

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 158fd56

File tree

4 files changed

+26
-14
lines changed

4 files changed

+26
-14
lines changed

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

+10-11
Original file line numberDiff line numberDiff line change
@@ -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
@@ -347,6 +347,8 @@ _oci-runtime-tool_generate() {
347347
--linux-readonly-paths
348348
--linux-realtime-period
349349
--linux-realtime-runtime
350+
--linux-resources-device-add
351+
--linux-resources-device-remove
350352
--linux-rootfs-propagation
351353
--linux-seccomp-allow
352354
--linux-seccomp-arch

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
@@ -211,6 +211,17 @@ read the configuration from `config.json`.
211211
**--linux-realtime-runtime**=REALTIMERUNTIME
212212
Specifies a period of time in microseconds for the longest continuous period in which the tasks in a cgroup have access to CPU resources.
213213

214+
**--linux-resources-device-add**=allow|deny[,type=TYPE][,major=MAJOR][,minor=MINOR][,access=ACCESS]
215+
Add a device control rule.
216+
allow|deny: whether the entry is allowed or denied.
217+
TYPE: the device type. The value could be one of 'a' (all), 'b' (block), 'c' (character).
218+
MAJOR/MINOR: the major/minor id of device.
219+
ACCESS: cgroup permissions for device. A composition of r (read), w (write), and m (mknod).
220+
221+
**--linux-resources-device-remove**=allow|deny[,type=TYPE][,major=MAJOR][,minor=MINOR][,access=ACCESS]
222+
Remove a device control rule.
223+
The arguments is same as *--linux-resources-device-add*.
224+
214225
**--linux-rootfs-propagation**=PROPOGATIONMODE
215226
Mount propagation for root filesystem.
216227
Values are "shared, rshared, private, rprivate, slave, rslave"

0 commit comments

Comments
 (0)