Skip to content

Commit 3ebbcc2

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

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

cmd/oci-runtime-tool/generate.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ var generateFlags = []cli.Flag{
2727
cli.StringFlag{Name: "cgroups-path", Usage: "specify the path to the cgroups"},
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"},
30+
cli.StringSliceFlag{Name: "device-remove", Usage: "remove a device which must be made available in the container"},
3031
cli.BoolFlag{Name: "disable-oom-kill", Usage: "disable OOM Killer"},
3132
cli.StringSliceFlag{Name: "env", Usage: "add environment variable e.g. key=value"},
3233
cli.StringSliceFlag{Name: "env-file", Usage: "read in a file of environment variables"},
@@ -513,6 +514,16 @@ func setupSpec(g *generate.Generator, context *cli.Context) error {
513514
}
514515
}
515516

517+
if context.IsSet("device-remove") {
518+
devices := context.StringSlice("device-remove")
519+
for _, device := range devices {
520+
err := g.RemoveDevice(device)
521+
if err != nil {
522+
return err
523+
}
524+
}
525+
}
526+
516527
err := addSeccomp(context, g)
517528
return err
518529
}

completions/bash/oci-runtime-tool

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ _oci-runtime-tool_generate() {
306306
--cgroups-path
307307
--cwd
308308
--device-add
309+
--device-remove
309310
--env
310311
--env-file
311312
--gid

generate/generate.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -931,6 +931,22 @@ func (g *Generator) AddDevice(device rspec.Device) {
931931
g.spec.Linux.Devices = append(g.spec.Linux.Devices, device)
932932
}
933933

934+
//RemoveDevice remove a device from g.spec.Linux.Devices
935+
func(g *Generator) RemoveDevice(path string) error {
936+
if g.spec == nil || g.spec.Linux == nil || g.spec.Linux.Devices == nil {
937+
return nil
938+
}
939+
940+
for i, device := range g.spec.Linux.Devices {
941+
if device.Path == path {
942+
g.spec.Linux.Devices = append(g.spec.Linux.Devices[:i], g.spec.Linux.Devices[i+1:]...)
943+
return nil
944+
}
945+
}
946+
return nil
947+
}
948+
949+
934950
// strPtr returns the pointer pointing to the string s.
935951
func strPtr(s string) *string { return &s }
936952

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ read the configuration from `config.json`.
6262
*uid*/*gid* is the user/group id of the device file.
6363
This option can be specified multiple times.
6464

65+
**--device-remove**=*PATH*
66+
Remove a device file in container.
67+
This option can be specified multiple times.
68+
6569
**--disable-oom-kill**=true|false
6670
Whether to disable OOM Killer for the container or not.
6771

0 commit comments

Comments
 (0)