
IsLikelyNotMountPoint determines if a directory is not a mountpoint. It is fast but not necessarily ALWAYS correct. If the path is in fact a bind mount from one part of a mount to another it will not be detected. mkdir /tmp/a /tmp/b; mount --bin /tmp/a /tmp/b; IsLikelyNotMountPoint("/tmp/b") will return true. When in fact /tmp/b is a mount point. So this patch renames the function and switches it from a positive to a negative (I could think of a good positive name). This should make future users of this function aware that it isn't quite perfect, but probably good enough.
60 lines
1.7 KiB
Go
60 lines
1.7 KiB
Go
// +build linux
|
|
|
|
/*
|
|
Copyright 2015 The Kubernetes Authors All rights reserved.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package empty_dir
|
|
|
|
import (
|
|
"fmt"
|
|
"syscall"
|
|
|
|
"github.com/docker/libcontainer/selinux"
|
|
"github.com/golang/glog"
|
|
"k8s.io/kubernetes/pkg/util/mount"
|
|
)
|
|
|
|
// Defined by Linux - the type number for tmpfs mounts.
|
|
const linuxTmpfsMagic = 0x01021994
|
|
|
|
// realMountDetector implements mountDetector in terms of syscalls.
|
|
type realMountDetector struct {
|
|
mounter mount.Interface
|
|
}
|
|
|
|
func (m *realMountDetector) GetMountMedium(path string) (storageMedium, bool, error) {
|
|
glog.V(5).Infof("Determining mount medium of %v", path)
|
|
notMnt, err := m.mounter.IsLikelyNotMountPoint(path)
|
|
if err != nil {
|
|
return 0, false, fmt.Errorf("IsLikelyNotMountPoint(%q): %v", path, err)
|
|
}
|
|
buf := syscall.Statfs_t{}
|
|
if err := syscall.Statfs(path, &buf); err != nil {
|
|
return 0, false, fmt.Errorf("statfs(%q): %v", path, err)
|
|
}
|
|
|
|
glog.V(5).Info("Statfs_t of %v: %+v", path, buf)
|
|
if buf.Type == linuxTmpfsMagic {
|
|
return mediumMemory, !notMnt, nil
|
|
}
|
|
return mediumUnknown, !notMnt, nil
|
|
}
|
|
|
|
// selinuxEnabled determines whether SELinux is enabled.
|
|
func selinuxEnabled() bool {
|
|
return selinux.SelinuxEnabled()
|
|
}
|