mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
Change getDeviceMajorMinor to use unix.Stat
This commit is contained in:
parent
aee875a855
commit
8a09460c2f
@ -13,7 +13,15 @@ go_library(
|
|||||||
"//pkg/util/mount:go_default_library",
|
"//pkg/util/mount:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/types:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/types:go_default_library",
|
||||||
"//vendor/k8s.io/klog:go_default_library",
|
"//vendor/k8s.io/klog:go_default_library",
|
||||||
|
] + select({
|
||||||
|
"@io_bazel_rules_go//go/platform:android": [
|
||||||
|
"//vendor/golang.org/x/sys/unix:go_default_library",
|
||||||
],
|
],
|
||||||
|
"@io_bazel_rules_go//go/platform:linux": [
|
||||||
|
"//vendor/golang.org/x/sys/unix:go_default_library",
|
||||||
|
],
|
||||||
|
"//conditions:default": [],
|
||||||
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
filegroup(
|
filegroup(
|
||||||
|
@ -27,6 +27,8 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"golang.org/x/sys/unix"
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
"k8s.io/klog"
|
"k8s.io/klog"
|
||||||
)
|
)
|
||||||
@ -220,24 +222,20 @@ func compareBindMountAndSymlinks(global, pod string) (bool, error) {
|
|||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// getDeviceMajorMinor returns major/minor number for the path with belwo format:
|
// getDeviceMajorMinor returns major/minor number for the path with below format:
|
||||||
// major:minor (in hex)
|
// major:minor (in hex)
|
||||||
// ex)
|
// ex)
|
||||||
// fc:10
|
// fc:10
|
||||||
func getDeviceMajorMinor(path string) (string, error) {
|
func getDeviceMajorMinor(path string) (string, error) {
|
||||||
args := []string{"-c", "%t:%T", path}
|
var stat unix.Stat_t
|
||||||
cmd := exec.Command(statPath, args...)
|
|
||||||
out, err := cmd.CombinedOutput()
|
if err := unix.Stat(path, &stat); err != nil {
|
||||||
if err != nil {
|
return "", fmt.Errorf("failed to stat path %s: %v", path, err)
|
||||||
klog.V(2).Infof("Failed to stat path: %s %v %s ", path, err, out)
|
|
||||||
return "", fmt.Errorf("stat -c %%t:%%T %s failed: %v", path, err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// stat -c "%t:%T" {path} outputs following format(major:minor in hex):
|
devNumber := uint64(stat.Rdev)
|
||||||
// fc:10
|
major := unix.Major(devNumber)
|
||||||
if len(out) == 0 {
|
minor := unix.Minor(devNumber)
|
||||||
return "", errors.New(ErrDeviceNotFound)
|
|
||||||
}
|
|
||||||
|
|
||||||
return strings.TrimSpace(string(out)), nil
|
return fmt.Sprintf("%x:%x", major, minor), nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user