Skip to content

Commit 1a4edce

Browse files
author
zhouhao
committed
add device-remove-all option
Signed-off-by: zhouhao <[email protected]>
1 parent 3ebbcc2 commit 1a4edce

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

cmd/oci-runtime-tool/generate.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ var generateFlags = []cli.Flag{
2828
cli.StringFlag{Name: "cwd", Value: "/", Usage: "current working directory for the process"},
2929
cli.StringSliceFlag{Name: "device-add", Usage: "add a device which must be made available in the container"},
3030
cli.StringSliceFlag{Name: "device-remove", Usage: "remove a device which must be made available in the container"},
31+
cli.BoolFlag{Name: "device-remove-all", Usage: "remove all devices which must be made available in the container"},
3132
cli.BoolFlag{Name: "disable-oom-kill", Usage: "disable OOM Killer"},
3233
cli.StringSliceFlag{Name: "env", Usage: "add environment variable e.g. key=value"},
3334
cli.StringSliceFlag{Name: "env-file", Usage: "read in a file of environment variables"},
@@ -524,6 +525,10 @@ func setupSpec(g *generate.Generator, context *cli.Context) error {
524525
}
525526
}
526527

528+
if context.Bool("device-remove-all") {
529+
g.ClearLinuxDevices()
530+
}
531+
527532
err := addSeccomp(context, g)
528533
return err
529534
}
@@ -655,7 +660,7 @@ var deviceType = map[string]bool{
655660
"p": true, // a FIFO
656661
}
657662

658-
// parseDevice takes the raw string passed with the --device flag
663+
// parseDevice takes the raw string passed with the --device-add flag
659664
func parseDevice(device string, g *generate.Generator) (rspec.Device, error) {
660665
dev := rspec.Device{}
661666

completions/bash/oci-runtime-tool

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ _oci-runtime-tool_generate() {
364364
"
365365

366366
local boolean_options="
367+
--device-remove-all
367368
--disable-oom-kill
368369
--linux-namespace-remove-all
369370
--no-new-privileges

generate/generate.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,7 @@ func (g *Generator) AddDevice(device rspec.Device) {
932932
}
933933

934934
//RemoveDevice remove a device from g.spec.Linux.Devices
935-
func(g *Generator) RemoveDevice(path string) error {
935+
func (g *Generator) RemoveDevice(path string) error {
936936
if g.spec == nil || g.spec.Linux == nil || g.spec.Linux.Devices == nil {
937937
return nil
938938
}
@@ -946,6 +946,13 @@ func(g *Generator) RemoveDevice(path string) error {
946946
return nil
947947
}
948948

949+
func (g *Generator) ClearLinuxDevices() {
950+
if g.spec == nil || g.spec.Linux == nil || g.spec.Linux.Devices == nil {
951+
return
952+
}
953+
954+
g.spec.Linux.Devices = []rspec.Device{}
955+
}
949956

950957
// strPtr returns the pointer pointing to the string s.
951958
func strPtr(s string) *string { return &s }

man/oci-runtime-tool-generate.1.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ read the configuration from `config.json`.
6666
Remove a device file in container.
6767
This option can be specified multiple times.
6868

69+
**--device-remove-all**=true|false
70+
Remove all devices for linux inside the container. The default is *false*.
71+
6972
**--disable-oom-kill**=true|false
7073
Whether to disable OOM Killer for the container or not.
7174

0 commit comments

Comments
 (0)