Skip to content

Commit 038b0c9

Browse files
committed
generate: make AddBindMount() options a slice
This allows for the set of options to be more useful than just "rw" or "ro". It also makes it match the AddTmpfsMount far more. Signed-off-by: Aleksa Sarai <[email protected]>
1 parent bb04048 commit 038b0c9

File tree

3 files changed

+28
-17
lines changed

3 files changed

+28
-17
lines changed

cmd/oci-runtime-tool/generate.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ var generateFlags = []cli.Flag{
1717
cli.StringFlag{Name: "apparmor", Usage: "specifies the the apparmor profile for the container"},
1818
cli.StringFlag{Name: "arch", Value: runtime.GOARCH, Usage: "architecture the container is created for"},
1919
cli.StringSliceFlag{Name: "args", Usage: "command to run in the container"},
20-
cli.StringSliceFlag{Name: "bind", Usage: "bind mount directories src:dest:(rw,ro)"},
20+
cli.StringSliceFlag{Name: "bind", Usage: "bind mount directories src:dest[:options...]"},
2121
cli.StringSliceFlag{Name: "cap-add", Usage: "add Linux capabilities"},
2222
cli.StringSliceFlag{Name: "cap-drop", Usage: "drop Linux capabilities"},
2323
cli.StringFlag{Name: "cgroup", Usage: "cgroup namespace"},
@@ -491,18 +491,18 @@ func parseTmpfsMount(s string) (string, []string, error) {
491491
return dest, options, err
492492
}
493493

494-
func parseBindMount(s string) (string, string, string, error) {
494+
func parseBindMount(s string) (string, string, []string, error) {
495495
var source, dest string
496-
options := "ro"
496+
options := []string{}
497497

498498
bparts := strings.SplitN(s, ":", 3)
499499
switch len(bparts) {
500500
case 2:
501501
source, dest = bparts[0], bparts[1]
502502
case 3:
503-
source, dest, options = bparts[0], bparts[1], bparts[2]
503+
source, dest, options = bparts[0], bparts[1], strings.Split(bparts[2], ":")
504504
default:
505-
return source, dest, options, fmt.Errorf("--bind should have format src:dest:[options]")
505+
return source, dest, options, fmt.Errorf("--bind should have format src:dest[:options...]")
506506
}
507507

508508
return source, dest, options, nil

generate/generate.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -633,18 +633,29 @@ func (g *Generator) AddCgroupsMount(mountCgroupOption string) error {
633633
}
634634

635635
// AddBindMount adds a bind mount into g.spec.Mounts.
636-
func (g *Generator) AddBindMount(source, dest, options string) {
637-
if options == "" {
638-
options = "ro"
636+
func (g *Generator) AddBindMount(source, dest string, options []string) {
637+
if len(options) == 0 {
638+
options = []string{"rw"}
639639
}
640640

641-
defaultOptions := []string{"bind"}
641+
// We have to make sure that there is a bind option set, otherwise it won't
642+
// be an actual bindmount.
643+
foundBindOption := false
644+
for _, opt := range options {
645+
if opt == "bind" || opt == "rbind" {
646+
foundBindOption = true
647+
break
648+
}
649+
}
650+
if !foundBindOption {
651+
options = append(options, "bind")
652+
}
642653

643654
mnt := rspec.Mount{
644655
Destination: dest,
645656
Type: "bind",
646657
Source: source,
647-
Options: append(defaultOptions, options),
658+
Options: options,
648659
}
649660
g.initSpec()
650661
g.spec.Mounts = append(g.spec.Mounts, mnt)

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ read the configuration from `config.json`.
2929

3030
--args "/usr/bin/httpd" --args "-D" --args "FOREGROUND"
3131

32-
**--bind**=*[[HOST-DIR:CONTAINER-DIR][:OPTIONS]]*
32+
**--bind**=*[[HOST-DIR:CONTAINER-DIR][:OPTIONS...]]*
3333
Bind mount directories src:dest:(rw,ro) If you specify, ` --bind
3434
/HOST-DIR:/CONTAINER-DIR`, runc bind mounts `/HOST-DIR` in the host
35-
to `/CONTAINER-DIR` in the OCI container. The `OPTIONS` are a comma
36-
delimited list and can be: [rw|ro] The `HOST_DIR` and
37-
`CONTAINER-DIR` must be absolute paths such as `/src/docs`. You
38-
can add `:ro` or `:rw` suffix to a volume to mount it read-only or
39-
read-write mode, respectively. By default, the volumes are mounted
40-
read-write.
35+
to `/CONTAINER-DIR` in the OCI container. The `OPTIONS` are a colon
36+
delimited list and can be any mount option support by the runtime such
37+
as [rw|ro|rbind|bind|...]. The `HOST_DIR` and `CONTAINER-DIR` must be
38+
absolute paths such as `/src/docs`. You can set the `ro` or `rw`
39+
options to a bind-mount to mount it read-only or read-write mode,
40+
respectively. By default, bind-mounts are mounted read-write.
4141

4242
**--cap-add**=[]
4343
Add Linux capabilities

0 commit comments

Comments
 (0)