Skip to content

Commit 4fad62b

Browse files
author
zhouhao
committed
add device-remove-all potion
Signed-off-by: zhouhao <[email protected]>
1 parent e001bd6 commit 4fad62b

File tree

4 files changed

+19
-0
lines changed

4 files changed

+19
-0
lines changed

cmd/oci-runtime-tool/generate.go

Lines changed: 6 additions & 0 deletions
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.StringSliceFlag{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"},
@@ -529,6 +530,11 @@ func setupSpec(g *generate.Generator, context *cli.Context) error {
529530
}
530531
}
531532

533+
534+
if context.Bool("device-remove-all") {
535+
g.ClearLinuxDevices()
536+
}
537+
532538
err := addSeccomp(context, g)
533539
return err
534540
}

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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,15 @@ func (g *Generator) RemoveDevice(dev rspec.Device) error {
936936
return nil
937937
}
938938

939+
// ClearLinuxDevices clear g.spec.Linux.Devices.
940+
func (g *Generator) ClearLinuxDevices() {
941+
if g.spec == nil || g.spec.Linux == nil || g.spec.Linux.Devices == nil {
942+
return
943+
}
944+
945+
g.spec.Linux.Devices = []rspec.Device{}
946+
}
947+
939948
// strPtr returns the pointer pointing to the string s.
940949
func strPtr(s string) *string { return &s }
941950

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)