mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-31 15:25:26 +00:00
Merge pull request #4550 from liubin/fix/4548-overwrite-mount-type-for-bind-mount
runtime: overwrite mount type to bind for bind mounts
This commit is contained in:
commit
a1de394e51
@ -186,16 +186,27 @@ func cmdEnvs(spec specs.Spec, envs []types.EnvVar) []types.EnvVar {
|
|||||||
|
|
||||||
func newMount(m specs.Mount) vc.Mount {
|
func newMount(m specs.Mount) vc.Mount {
|
||||||
readonly := false
|
readonly := false
|
||||||
|
bind := false
|
||||||
for _, flag := range m.Options {
|
for _, flag := range m.Options {
|
||||||
if flag == "ro" {
|
switch flag {
|
||||||
|
case "rbind", "bind":
|
||||||
|
bind = true
|
||||||
|
case "ro":
|
||||||
readonly = true
|
readonly = true
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// normal bind mounts, set type to bind.
|
||||||
|
// https://github.com/opencontainers/runc/blob/v1.1.3/libcontainer/specconv/spec_linux.go#L512-L520
|
||||||
|
mountType := m.Type
|
||||||
|
if mountType != vc.KataEphemeralDevType && mountType != vc.KataLocalDevType && bind {
|
||||||
|
mountType = "bind"
|
||||||
|
}
|
||||||
|
|
||||||
return vc.Mount{
|
return vc.Mount{
|
||||||
Source: m.Source,
|
Source: m.Source,
|
||||||
Destination: m.Destination,
|
Destination: m.Destination,
|
||||||
Type: m.Type,
|
Type: mountType,
|
||||||
Options: m.Options,
|
Options: m.Options,
|
||||||
ReadOnly: readonly,
|
ReadOnly: readonly,
|
||||||
}
|
}
|
||||||
@ -912,9 +923,6 @@ func SandboxConfig(ocispec specs.Spec, runtime RuntimeConfig, bundlePath, cid st
|
|||||||
|
|
||||||
DisableGuestSeccomp: runtime.DisableGuestSeccomp,
|
DisableGuestSeccomp: runtime.DisableGuestSeccomp,
|
||||||
|
|
||||||
// Q: Is this really necessary? @weizhang555
|
|
||||||
// Spec: &ocispec,
|
|
||||||
|
|
||||||
Experimental: runtime.Experimental,
|
Experimental: runtime.Experimental,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1200,3 +1200,79 @@ func TestCalculateSandboxSizing(t *testing.T) {
|
|||||||
assert.Equal(tt.expectedMem, mem, "unexpected memory")
|
assert.Equal(tt.expectedMem, mem, "unexpected memory")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestNewMount(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
testCases := []struct {
|
||||||
|
out vc.Mount
|
||||||
|
in specs.Mount
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
in: specs.Mount{
|
||||||
|
Source: "proc",
|
||||||
|
Destination: "/proc",
|
||||||
|
Type: "proc",
|
||||||
|
Options: nil,
|
||||||
|
},
|
||||||
|
out: vc.Mount{
|
||||||
|
Source: "proc",
|
||||||
|
Destination: "/proc",
|
||||||
|
Type: "proc",
|
||||||
|
Options: nil,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
in: specs.Mount{
|
||||||
|
Source: "proc",
|
||||||
|
Destination: "/proc",
|
||||||
|
Type: "proc",
|
||||||
|
Options: []string{"ro"},
|
||||||
|
},
|
||||||
|
out: vc.Mount{
|
||||||
|
Source: "proc",
|
||||||
|
Destination: "/proc",
|
||||||
|
Type: "proc",
|
||||||
|
Options: []string{"ro"},
|
||||||
|
ReadOnly: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
in: specs.Mount{
|
||||||
|
Source: "/abc",
|
||||||
|
Destination: "/def",
|
||||||
|
Type: "none",
|
||||||
|
Options: []string{"bind"},
|
||||||
|
},
|
||||||
|
out: vc.Mount{
|
||||||
|
Source: "/abc",
|
||||||
|
Destination: "/def",
|
||||||
|
Type: "bind",
|
||||||
|
Options: []string{"bind"},
|
||||||
|
},
|
||||||
|
}, {
|
||||||
|
in: specs.Mount{
|
||||||
|
Source: "/abc",
|
||||||
|
Destination: "/def",
|
||||||
|
Type: "none",
|
||||||
|
Options: []string{"rbind"},
|
||||||
|
},
|
||||||
|
out: vc.Mount{
|
||||||
|
Source: "/abc",
|
||||||
|
Destination: "/def",
|
||||||
|
Type: "bind",
|
||||||
|
Options: []string{"rbind"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range testCases {
|
||||||
|
actualMount := newMount(tt.in)
|
||||||
|
|
||||||
|
assert.Equal(tt.out.Source, actualMount.Source, "unexpected mount source")
|
||||||
|
assert.Equal(tt.out.Destination, actualMount.Destination, "unexpected mount destination")
|
||||||
|
assert.Equal(tt.out.Type, actualMount.Type, "unexpected mount type")
|
||||||
|
assert.Equal(tt.out.Options, actualMount.Options, "unexpected mount options")
|
||||||
|
assert.Equal(tt.out.ReadOnly, actualMount.ReadOnly, "unexpected mount ReadOnly")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user