fix: Check Statfs_t type using unix package only

This commit is contained in:
lucming
2025-09-24 18:05:32 +08:00
committed by liuming54
parent 11ade2f7dd
commit 9c3167d3cc
2 changed files with 3 additions and 16 deletions

View File

@@ -31,12 +31,6 @@ import (
"k8s.io/api/core/v1"
)
// Defined by Linux - the type number for tmpfs mounts.
const (
linuxTmpfsMagic = 0x01021994
linuxHugetlbfsMagic = 0x958458f6
)
// realMountDetector implements mountDetector in terms of syscalls.
type realMountDetector struct {
mounter mount.Interface
@@ -98,9 +92,9 @@ func (m *realMountDetector) GetMountMedium(path string, requestedMedium v1.Stora
klog.V(3).Infof("Statfs_t of %v: %+v", path, buf)
if buf.Type == linuxTmpfsMagic {
if buf.Type == unix.TMPFS_MAGIC {
return v1.StorageMediumMemory, !notMnt, nil, nil
} else if int64(buf.Type) == linuxHugetlbfsMagic {
} else if int64(buf.Type) == unix.HUGETLBFS_MAGIC {
// Skip page size detection if requested medium doesn't have size specified
if requestedMedium == v1.StorageMediumHugePages {
return v1.StorageMediumHugePages, !notMnt, nil, nil

View File

@@ -29,9 +29,6 @@ func umask(mask int) int {
return syscall.Umask(mask)
}
// Defined by Linux (sys/statfs.h) - the type number for tmpfs mounts.
const linuxTmpfsMagic = 0x01021994
func fsType(path string) error {
if path == "" {
return nil
@@ -43,11 +40,7 @@ func fsType(path string) error {
return err
}
if buf.Type == linuxTmpfsMagic {
fmt.Printf("mount type of %q: tmpfs\n", path)
} else {
fmt.Printf("mount type of %q: %v\n", path, buf.Type)
}
fmt.Printf("mount type of %q: %v\n", path, buf.Type)
return nil
}