Skip to content

Commit 6b1d25d

Browse files
committed
add defaultFS and use OCIError
Signed-off-by: liangchenye <[email protected]>
1 parent 4029999 commit 6b1d25d

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

cmd/runtimetest/main.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ const PrGetNoNewPrivs = 39
3232
const specConfig = "config.json"
3333

3434
var (
35+
defaultFS = map[string]string{
36+
"/proc": "proc",
37+
"/sys": "sysfs",
38+
"/dev/pts": "devpts",
39+
"/dev/shm": "tmpfs",
40+
}
41+
3542
defaultSymlinks = map[string]string{
3643
"/dev/fd": "/proc/self/fd",
3744
"/dev/stdin": "/proc/self/fd/0",
@@ -310,6 +317,28 @@ func validateRootFS(spec *rspec.Spec) error {
310317
return nil
311318
}
312319

320+
func validateDefaultFS(spec *rspec.Spec) error {
321+
logrus.Debugf("validating linux default filesystem")
322+
323+
mountInfos, err := mount.GetMounts()
324+
if err != nil {
325+
return ociErr.NewOCIError(ociErr.DefaultFilesystems, err.Error())
326+
}
327+
328+
mountsMap := make(map[string]string)
329+
for _, mountInfo := range mountInfos {
330+
mountsMap[mountInfo.Mountpoint] = mountInfo.Fstype
331+
}
332+
333+
for fs, fstype := range defaultFS {
334+
if !(mountsMap[fs] == fstype) {
335+
return ociErr.NewOCIError(ociErr.DefaultFilesystems, fmt.Sprintf("%v must exist and expected type is %v", fs, fstype))
336+
}
337+
}
338+
339+
return nil
340+
}
341+
313342
func validateLinuxDevices(spec *rspec.Spec) error {
314343
for _, device := range spec.Linux.Devices {
315344
fi, err := os.Stat(device.Path)
@@ -617,6 +646,10 @@ func validate(context *cli.Context) error {
617646
test: validateDefaultSymlinks,
618647
description: "default symlinks",
619648
},
649+
{
650+
test: validateDefaultFS,
651+
description: "default file system",
652+
},
620653
{
621654
test: validateDefaultDevices,
622655
description: "default devices",

0 commit comments

Comments
 (0)