diff --git a/cmd/runtimetest/main.go b/cmd/runtimetest/main.go index 4138fe078..614725b68 100644 --- a/cmd/runtimetest/main.go +++ b/cmd/runtimetest/main.go @@ -204,6 +204,39 @@ func validateSysctls(spec *specs.LinuxSpec, rspec *specs.LinuxRuntimeSpec) error return nil } +func validateMount(spec *specs.LinuxSpec, rspec *specs.LinuxRuntimeSpec) error { + fmt.Println("validating mount") + //read the /proc/mount file and covert to map[path]spec.mount + mntori, _ := ioutil.ReadFile("/proc/mounts") + mnt := bytes.Split(mntori, []byte{'\n'}) + containermnts := make(map[string]specs.Mount) + for _, row := range mnt { + col := bytes.Split(row, []byte{' '}) + if len(col) != 6 { + break + } + ops := strings.Split(string(col[3]), ",") + containermnts[string(col[1])] = specs.Mount{string(col[2]), "", ops} + } + //read config.json and runtime.json and compare the mount + mntpts := spec.Mounts + mnts := rspec.Mounts + for _, mntpt := range mntpts { + mnt := mnts[mntpt.Name] + mntcotainer, exsist := containermnts[mntpt.Path] + if !exsist { + return fmt.Errorf("mountpoint name:%v, path: %v doesn't exsist", mntpt.Name, mntpt.Path) + } + if strings.EqualFold(mnt.Type, "cgroup") && !strings.EqualFold(mntcotainer.Type, "tmpfs") { + return fmt.Errorf("cgroup filesystem error") + } + if !strings.EqualFold(mnt.Type, "cgroup") && !strings.EqualFold(mnt.Type, mntcotainer.Type) { + return fmt.Errorf("mount.Type expected: %v, actual: %v", mnt.Type, mntcotainer.Type) + } + } + return nil +} + func main() { spec, rspec, err := loadSpecConfig() if err != nil { @@ -212,6 +245,7 @@ func main() { validations := []validation{ validateProcess, + validateMount, validateCapabilities, validateHostname, validateRlimits,