Skip to content

Commit ad8781b

Browse files
committed
libcontainer/specconv/spec_linux: Support empty 'type' for bind mounts
From the "Creating a bind mount" section of mount(2) [1]: > If mountflags includes MS_BIND (available since Linux 2.4), then > perform a bind mount... > > The filesystemtype and data arguments are ignored. This commit adds support for configurations that leave the OPTIONAL type [2] unset for bind mounts. There's a related spec-example change in flight with [3], although my personal preference would be a more explicit spec for the whole mount structure [4]. [1]: http://man7.org/linux/man-pages/man2/mount.2.html [2]: https://github.com/opencontainers/runtime-spec/blame/v1.0.1/config.md#L102 [3]: opencontainers/runtime-spec#954 [4]: opencontainers/runtime-spec#771 Signed-off-by: W. Trevor King <[email protected]>
1 parent ce80fa0 commit ad8781b

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

libcontainer/specconv/spec_linux.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,13 +269,17 @@ func CreateLibcontainerConfig(opts *CreateOpts) (*configs.Config, error) {
269269
func createLibcontainerMount(cwd string, m specs.Mount) *configs.Mount {
270270
flags, pgflags, data, ext := parseMountOptions(m.Options)
271271
source := m.Source
272-
if m.Type == "bind" {
272+
device := m.Type
273+
if flags|unix.MS_BIND != 0 {
274+
if device == "" {
275+
device = "bind"
276+
}
273277
if !filepath.IsAbs(source) {
274278
source = filepath.Join(cwd, m.Source)
275279
}
276280
}
277281
return &configs.Mount{
278-
Device: m.Type,
282+
Device: device,
279283
Source: source,
280284
Destination: m.Destination,
281285
Data: data,

notify_socket.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func (ns *notifySocket) Close() error {
4444
// If systemd is supporting sd_notify protocol, this function will add support
4545
// for sd_notify protocol from within the container.
4646
func (s *notifySocket) setupSpec(context *cli.Context, spec *specs.Spec) {
47-
mount := specs.Mount{Destination: s.host, Type: "bind", Source: s.socketPath, Options: []string{"bind"}}
47+
mount := specs.Mount{Destination: s.host, Source: s.socketPath, Options: []string{"bind"}}
4848
spec.Mounts = append(spec.Mounts, mount)
4949
spec.Process.Env = append(spec.Process.Env, fmt.Sprintf("NOTIFY_SOCKET=%s", s.host))
5050
}

tests/integration/mounts.bats

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bats
2+
3+
load helpers
4+
5+
function setup() {
6+
teardown_busybox
7+
setup_busybox
8+
}
9+
10+
function teardown() {
11+
teardown_busybox
12+
}
13+
14+
@test "runc run [bind mount]" {
15+
CONFIG=$(jq '.mounts |= . + [{"source": ".", "destination": "/tmp/bind", "options": ["bind"]}] | .process.args = ["ls", "/tmp/bind/config.json"]' config.json)
16+
echo "${CONFIG}" >config.json
17+
18+
runc run test_bind_mount
19+
[ "$status" -eq 0 ]
20+
[ "x${lines[0]}" = 'x/tmp/bind/config.json' ]
21+
}

0 commit comments

Comments
 (0)