Skip to content

Commit 261a736

Browse files
author
zhouhao
committed
add device-remove option
Signed-off-by: zhouhao <zhouhao@cn.fujitsu.com>
1 parent 71bccea commit 261a736

4 files changed

Lines changed: 32 additions & 0 deletions

File tree

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
@@ -310,6 +310,7 @@ _oci-runtime-tool_generate() {
310310
--cgroups-path
311311
--cwd
312312
--device-add
313+
--device-remove
313314
--env
314315
--env-file
315316
--gid

generate/generate.go

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

1034+
//RemoveDevice remove a device from g.spec.Linux.Devices
1035+
func(g *Generator) RemoveDevice(path string) error {
1036+
if g.spec == nil || g.spec.Linux == nil || g.spec.Linux.Devices == nil {
1037+
return nil
1038+
}
1039+
1040+
for i, device := range g.spec.Linux.Devices {
1041+
if device.Path == path {
1042+
g.spec.Linux.Devices = append(g.spec.Linux.Devices[:i], g.spec.Linux.Devices[i+1:]...)
1043+
return nil
1044+
}
1045+
}
1046+
return nil
1047+
}
1048+
1049+
10341050
// strPtr returns the pointer pointing to the string s.
10351051
func strPtr(s string) *string { return &s }
10361052

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)