mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 10:33:35 +00:00
rebase: update kubernetes to v1.25.0
update kubernetes to latest v1.25.0 release. Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
committed by
mergify[bot]
parent
f47839d73d
commit
e3bf375035
296
vendor/k8s.io/kubernetes/pkg/volume/util/volumepathhandler/volume_path_handler.go
generated
vendored
Normal file
296
vendor/k8s.io/kubernetes/pkg/volume/util/volumepathhandler/volume_path_handler.go
generated
vendored
Normal file
@ -0,0 +1,296 @@
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
|
||||
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 volumepathhandler
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"k8s.io/klog/v2"
|
||||
"k8s.io/mount-utils"
|
||||
utilexec "k8s.io/utils/exec"
|
||||
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
)
|
||||
|
||||
const (
|
||||
losetupPath = "losetup"
|
||||
ErrDeviceNotFound = "device not found"
|
||||
)
|
||||
|
||||
// BlockVolumePathHandler defines a set of operations for handling block volume-related operations
|
||||
type BlockVolumePathHandler interface {
|
||||
// MapDevice creates a symbolic link to block device under specified map path
|
||||
MapDevice(devicePath string, mapPath string, linkName string, bindMount bool) error
|
||||
// UnmapDevice removes a symbolic link to block device under specified map path
|
||||
UnmapDevice(mapPath string, linkName string, bindMount bool) error
|
||||
// RemovePath removes a file or directory on specified map path
|
||||
RemoveMapPath(mapPath string) error
|
||||
// IsSymlinkExist retruns true if specified symbolic link exists
|
||||
IsSymlinkExist(mapPath string) (bool, error)
|
||||
// IsDeviceBindMountExist retruns true if specified bind mount exists
|
||||
IsDeviceBindMountExist(mapPath string) (bool, error)
|
||||
// GetDeviceBindMountRefs searches bind mounts under global map path
|
||||
GetDeviceBindMountRefs(devPath string, mapPath string) ([]string, error)
|
||||
// FindGlobalMapPathUUIDFromPod finds {pod uuid} symbolic link under globalMapPath
|
||||
// corresponding to map path symlink, and then return global map path with pod uuid.
|
||||
FindGlobalMapPathUUIDFromPod(pluginDir, mapPath string, podUID types.UID) (string, error)
|
||||
// AttachFileDevice takes a path to a regular file and makes it available as an
|
||||
// attached block device.
|
||||
AttachFileDevice(path string) (string, error)
|
||||
// DetachFileDevice takes a path to the attached block device and
|
||||
// detach it from block device.
|
||||
DetachFileDevice(path string) error
|
||||
// GetLoopDevice returns the full path to the loop device associated with the given path.
|
||||
GetLoopDevice(path string) (string, error)
|
||||
}
|
||||
|
||||
// NewBlockVolumePathHandler returns a new instance of BlockVolumeHandler.
|
||||
func NewBlockVolumePathHandler() BlockVolumePathHandler {
|
||||
var volumePathHandler VolumePathHandler
|
||||
return volumePathHandler
|
||||
}
|
||||
|
||||
// VolumePathHandler is path related operation handlers for block volume
|
||||
type VolumePathHandler struct {
|
||||
}
|
||||
|
||||
// MapDevice creates a symbolic link to block device under specified map path
|
||||
func (v VolumePathHandler) MapDevice(devicePath string, mapPath string, linkName string, bindMount bool) error {
|
||||
// Example of global map path:
|
||||
// globalMapPath/linkName: plugins/kubernetes.io/{PluginName}/{DefaultKubeletVolumeDevicesDirName}/{volumePluginDependentPath}/{podUid}
|
||||
// linkName: {podUid}
|
||||
//
|
||||
// Example of pod device map path:
|
||||
// podDeviceMapPath/linkName: pods/{podUid}/{DefaultKubeletVolumeDevicesDirName}/{escapeQualifiedPluginName}/{volumeName}
|
||||
// linkName: {volumeName}
|
||||
if len(devicePath) == 0 {
|
||||
return fmt.Errorf("failed to map device to map path. devicePath is empty")
|
||||
}
|
||||
if len(mapPath) == 0 {
|
||||
return fmt.Errorf("failed to map device to map path. mapPath is empty")
|
||||
}
|
||||
if !filepath.IsAbs(mapPath) {
|
||||
return fmt.Errorf("the map path should be absolute: map path: %s", mapPath)
|
||||
}
|
||||
klog.V(5).Infof("MapDevice: devicePath %s", devicePath)
|
||||
klog.V(5).Infof("MapDevice: mapPath %s", mapPath)
|
||||
klog.V(5).Infof("MapDevice: linkName %s", linkName)
|
||||
|
||||
// Check and create mapPath
|
||||
_, err := os.Stat(mapPath)
|
||||
if err != nil && !os.IsNotExist(err) {
|
||||
return fmt.Errorf("cannot validate map path: %s: %v", mapPath, err)
|
||||
}
|
||||
if err = os.MkdirAll(mapPath, 0750); err != nil {
|
||||
return fmt.Errorf("failed to mkdir %s: %v", mapPath, err)
|
||||
}
|
||||
|
||||
if bindMount {
|
||||
return mapBindMountDevice(v, devicePath, mapPath, linkName)
|
||||
}
|
||||
return mapSymlinkDevice(v, devicePath, mapPath, linkName)
|
||||
}
|
||||
|
||||
func mapBindMountDevice(v VolumePathHandler, devicePath string, mapPath string, linkName string) error {
|
||||
// Check bind mount exists
|
||||
linkPath := filepath.Join(mapPath, string(linkName))
|
||||
|
||||
file, err := os.Stat(linkPath)
|
||||
if err != nil {
|
||||
if !os.IsNotExist(err) {
|
||||
return fmt.Errorf("failed to stat file %s: %v", linkPath, err)
|
||||
}
|
||||
|
||||
// Create file
|
||||
newFile, err := os.OpenFile(linkPath, os.O_CREATE|os.O_RDWR, 0750)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to open file %s: %v", linkPath, err)
|
||||
}
|
||||
if err := newFile.Close(); err != nil {
|
||||
return fmt.Errorf("failed to close file %s: %v", linkPath, err)
|
||||
}
|
||||
} else {
|
||||
// Check if device file
|
||||
// TODO: Need to check if this device file is actually the expected bind mount
|
||||
if file.Mode()&os.ModeDevice == os.ModeDevice {
|
||||
klog.Warningf("Warning: Map skipped because bind mount already exist on the path: %v", linkPath)
|
||||
return nil
|
||||
}
|
||||
|
||||
klog.Warningf("Warning: file %s is already exist but not mounted, skip creating file", linkPath)
|
||||
}
|
||||
|
||||
// Bind mount file
|
||||
mounter := &mount.SafeFormatAndMount{Interface: mount.New(""), Exec: utilexec.New()}
|
||||
if err := mounter.MountSensitiveWithoutSystemd(devicePath, linkPath, "" /* fsType */, []string{"bind"}, nil); err != nil {
|
||||
return fmt.Errorf("failed to bind mount devicePath: %s to linkPath %s: %v", devicePath, linkPath, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func mapSymlinkDevice(v VolumePathHandler, devicePath string, mapPath string, linkName string) error {
|
||||
// Remove old symbolic link(or file) then create new one.
|
||||
// This should be done because current symbolic link is
|
||||
// stale across node reboot.
|
||||
linkPath := filepath.Join(mapPath, string(linkName))
|
||||
if err := os.Remove(linkPath); err != nil && !os.IsNotExist(err) {
|
||||
return fmt.Errorf("failed to remove file %s: %v", linkPath, err)
|
||||
}
|
||||
return os.Symlink(devicePath, linkPath)
|
||||
}
|
||||
|
||||
// UnmapDevice removes a symbolic link associated to block device under specified map path
|
||||
func (v VolumePathHandler) UnmapDevice(mapPath string, linkName string, bindMount bool) error {
|
||||
if len(mapPath) == 0 {
|
||||
return fmt.Errorf("failed to unmap device from map path. mapPath is empty")
|
||||
}
|
||||
klog.V(5).Infof("UnmapDevice: mapPath %s", mapPath)
|
||||
klog.V(5).Infof("UnmapDevice: linkName %s", linkName)
|
||||
|
||||
if bindMount {
|
||||
return unmapBindMountDevice(v, mapPath, linkName)
|
||||
}
|
||||
return unmapSymlinkDevice(v, mapPath, linkName)
|
||||
}
|
||||
|
||||
func unmapBindMountDevice(v VolumePathHandler, mapPath string, linkName string) error {
|
||||
// Check bind mount exists
|
||||
linkPath := filepath.Join(mapPath, string(linkName))
|
||||
if isMountExist, checkErr := v.IsDeviceBindMountExist(linkPath); checkErr != nil {
|
||||
return checkErr
|
||||
} else if !isMountExist {
|
||||
klog.Warningf("Warning: Unmap skipped because bind mount does not exist on the path: %v", linkPath)
|
||||
|
||||
// Check if linkPath still exists
|
||||
if _, err := os.Stat(linkPath); err != nil {
|
||||
if !os.IsNotExist(err) {
|
||||
return fmt.Errorf("failed to check if path %s exists: %v", linkPath, err)
|
||||
}
|
||||
// linkPath has already been removed
|
||||
return nil
|
||||
}
|
||||
// Remove file
|
||||
if err := os.Remove(linkPath); err != nil && !os.IsNotExist(err) {
|
||||
return fmt.Errorf("failed to remove file %s: %v", linkPath, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Unmount file
|
||||
mounter := &mount.SafeFormatAndMount{Interface: mount.New(""), Exec: utilexec.New()}
|
||||
if err := mounter.Unmount(linkPath); err != nil {
|
||||
return fmt.Errorf("failed to unmount linkPath %s: %v", linkPath, err)
|
||||
}
|
||||
|
||||
// Remove file
|
||||
if err := os.Remove(linkPath); err != nil && !os.IsNotExist(err) {
|
||||
return fmt.Errorf("failed to remove file %s: %v", linkPath, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func unmapSymlinkDevice(v VolumePathHandler, mapPath string, linkName string) error {
|
||||
// Check symbolic link exists
|
||||
linkPath := filepath.Join(mapPath, string(linkName))
|
||||
if islinkExist, checkErr := v.IsSymlinkExist(linkPath); checkErr != nil {
|
||||
return checkErr
|
||||
} else if !islinkExist {
|
||||
klog.Warningf("Warning: Unmap skipped because symlink does not exist on the path: %v", linkPath)
|
||||
return nil
|
||||
}
|
||||
return os.Remove(linkPath)
|
||||
}
|
||||
|
||||
// RemoveMapPath removes a file or directory on specified map path
|
||||
func (v VolumePathHandler) RemoveMapPath(mapPath string) error {
|
||||
if len(mapPath) == 0 {
|
||||
return fmt.Errorf("failed to remove map path. mapPath is empty")
|
||||
}
|
||||
klog.V(5).Infof("RemoveMapPath: mapPath %s", mapPath)
|
||||
err := os.RemoveAll(mapPath)
|
||||
if err != nil && !os.IsNotExist(err) {
|
||||
return fmt.Errorf("failed to remove directory %s: %v", mapPath, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// IsSymlinkExist returns true if specified file exists and the type is symbolik link.
|
||||
// If file doesn't exist, or file exists but not symbolic link, return false with no error.
|
||||
// On other cases, return false with error from Lstat().
|
||||
func (v VolumePathHandler) IsSymlinkExist(mapPath string) (bool, error) {
|
||||
fi, err := os.Lstat(mapPath)
|
||||
if err != nil {
|
||||
// If file doesn't exist, return false and no error
|
||||
if os.IsNotExist(err) {
|
||||
return false, nil
|
||||
}
|
||||
// Return error from Lstat()
|
||||
return false, fmt.Errorf("failed to Lstat file %s: %v", mapPath, err)
|
||||
}
|
||||
// If file exits and it's symbolic link, return true and no error
|
||||
if fi.Mode()&os.ModeSymlink == os.ModeSymlink {
|
||||
return true, nil
|
||||
}
|
||||
// If file exits but it's not symbolic link, return false and no error
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// IsDeviceBindMountExist returns true if specified file exists and the type is device.
|
||||
// If file doesn't exist, or file exists but not device, return false with no error.
|
||||
// On other cases, return false with error from Lstat().
|
||||
func (v VolumePathHandler) IsDeviceBindMountExist(mapPath string) (bool, error) {
|
||||
fi, err := os.Lstat(mapPath)
|
||||
if err != nil {
|
||||
// If file doesn't exist, return false and no error
|
||||
if os.IsNotExist(err) {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// Return error from Lstat()
|
||||
return false, fmt.Errorf("failed to Lstat file %s: %v", mapPath, err)
|
||||
}
|
||||
// If file exits and it's device, return true and no error
|
||||
if fi.Mode()&os.ModeDevice == os.ModeDevice {
|
||||
return true, nil
|
||||
}
|
||||
// If file exits but it's not device, return false and no error
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// GetDeviceBindMountRefs searches bind mounts under global map path
|
||||
func (v VolumePathHandler) GetDeviceBindMountRefs(devPath string, mapPath string) ([]string, error) {
|
||||
var refs []string
|
||||
files, err := ioutil.ReadDir(mapPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, file := range files {
|
||||
if file.Mode()&os.ModeDevice != os.ModeDevice {
|
||||
continue
|
||||
}
|
||||
filename := file.Name()
|
||||
// TODO: Might need to check if the file is actually linked to devPath
|
||||
refs = append(refs, filepath.Join(mapPath, filename))
|
||||
}
|
||||
klog.V(5).Infof("GetDeviceBindMountRefs: refs %v", refs)
|
||||
return refs, nil
|
||||
}
|
229
vendor/k8s.io/kubernetes/pkg/volume/util/volumepathhandler/volume_path_handler_linux.go
generated
vendored
Normal file
229
vendor/k8s.io/kubernetes/pkg/volume/util/volumepathhandler/volume_path_handler_linux.go
generated
vendored
Normal file
@ -0,0 +1,229 @@
|
||||
//go:build linux
|
||||
// +build linux
|
||||
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
|
||||
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 volumepathhandler
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/klog/v2"
|
||||
)
|
||||
|
||||
// AttachFileDevice takes a path to a regular file and makes it available as an
|
||||
// attached block device.
|
||||
func (v VolumePathHandler) AttachFileDevice(path string) (string, error) {
|
||||
blockDevicePath, err := v.GetLoopDevice(path)
|
||||
if err != nil && err.Error() != ErrDeviceNotFound {
|
||||
return "", fmt.Errorf("GetLoopDevice failed for path %s: %v", path, err)
|
||||
}
|
||||
|
||||
// If no existing loop device for the path, create one
|
||||
if blockDevicePath == "" {
|
||||
klog.V(4).Infof("Creating device for path: %s", path)
|
||||
blockDevicePath, err = makeLoopDevice(path)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("makeLoopDevice failed for path %s: %v", path, err)
|
||||
}
|
||||
}
|
||||
return blockDevicePath, nil
|
||||
}
|
||||
|
||||
// DetachFileDevice takes a path to the attached block device and
|
||||
// detach it from block device.
|
||||
func (v VolumePathHandler) DetachFileDevice(path string) error {
|
||||
loopPath, err := v.GetLoopDevice(path)
|
||||
if err != nil {
|
||||
if err.Error() == ErrDeviceNotFound {
|
||||
klog.Warningf("couldn't find loopback device which takes file descriptor lock. Skip detaching device. device path: %q", path)
|
||||
} else {
|
||||
return fmt.Errorf("GetLoopDevice failed for path %s: %v", path, err)
|
||||
}
|
||||
} else {
|
||||
if len(loopPath) != 0 {
|
||||
err = removeLoopDevice(loopPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("removeLoopDevice failed for path %s: %v", path, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetLoopDevice returns the full path to the loop device associated with the given path.
|
||||
func (v VolumePathHandler) GetLoopDevice(path string) (string, error) {
|
||||
_, err := os.Stat(path)
|
||||
if os.IsNotExist(err) {
|
||||
return "", errors.New(ErrDeviceNotFound)
|
||||
}
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("not attachable: %v", err)
|
||||
}
|
||||
|
||||
return getLoopDeviceFromSysfs(path)
|
||||
}
|
||||
|
||||
func makeLoopDevice(path string) (string, error) {
|
||||
args := []string{"-f", path}
|
||||
cmd := exec.Command(losetupPath, args...)
|
||||
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
klog.V(2).Infof("Failed device create command for path: %s %v %s", path, err, out)
|
||||
return "", fmt.Errorf("losetup %s failed: %v", strings.Join(args, " "), err)
|
||||
}
|
||||
|
||||
return getLoopDeviceFromSysfs(path)
|
||||
}
|
||||
|
||||
// removeLoopDevice removes specified loopback device
|
||||
func removeLoopDevice(device string) error {
|
||||
args := []string{"-d", device}
|
||||
cmd := exec.Command(losetupPath, args...)
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
if _, err := os.Stat(device); os.IsNotExist(err) {
|
||||
return nil
|
||||
}
|
||||
klog.V(2).Infof("Failed to remove loopback device: %s: %v %s", device, err, out)
|
||||
return fmt.Errorf("losetup -d %s failed: %v", device, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// getLoopDeviceFromSysfs finds the backing file for a loop
|
||||
// device from sysfs via "/sys/block/loop*/loop/backing_file".
|
||||
func getLoopDeviceFromSysfs(path string) (string, error) {
|
||||
// If the file is a symlink.
|
||||
realPath, err := filepath.EvalSymlinks(path)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to evaluate path %s: %s", path, err)
|
||||
}
|
||||
|
||||
devices, err := filepath.Glob("/sys/block/loop*")
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to list loop devices in sysfs: %s", err)
|
||||
}
|
||||
|
||||
for _, device := range devices {
|
||||
backingFile := fmt.Sprintf("%s/loop/backing_file", device)
|
||||
|
||||
// The contents of this file is the absolute path of "path".
|
||||
data, err := ioutil.ReadFile(backingFile)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
// Return the first match.
|
||||
backingFilePath := strings.TrimSpace(string(data))
|
||||
if backingFilePath == path || backingFilePath == realPath {
|
||||
return fmt.Sprintf("/dev/%s", filepath.Base(device)), nil
|
||||
}
|
||||
}
|
||||
|
||||
return "", errors.New(ErrDeviceNotFound)
|
||||
}
|
||||
|
||||
// FindGlobalMapPathUUIDFromPod finds {pod uuid} bind mount under globalMapPath
|
||||
// corresponding to map path symlink, and then return global map path with pod uuid.
|
||||
// (See pkg/volume/volume.go for details on a global map path and a pod device map path.)
|
||||
// ex. mapPath symlink: pods/{podUid}}/{DefaultKubeletVolumeDevicesDirName}/{escapeQualifiedPluginName}/{volumeName} -> /dev/sdX
|
||||
//
|
||||
// globalMapPath/{pod uuid} bind mount: plugins/kubernetes.io/{PluginName}/{DefaultKubeletVolumeDevicesDirName}/{volumePluginDependentPath}/{pod uuid} -> /dev/sdX
|
||||
func (v VolumePathHandler) FindGlobalMapPathUUIDFromPod(pluginDir, mapPath string, podUID types.UID) (string, error) {
|
||||
var globalMapPathUUID string
|
||||
// Find symbolic link named pod uuid under plugin dir
|
||||
err := filepath.Walk(pluginDir, func(path string, fi os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if (fi.Mode()&os.ModeDevice == os.ModeDevice) && (fi.Name() == string(podUID)) {
|
||||
klog.V(5).Infof("FindGlobalMapPathFromPod: path %s, mapPath %s", path, mapPath)
|
||||
if res, err := compareBindMountAndSymlinks(path, mapPath); err == nil && res {
|
||||
globalMapPathUUID = path
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("FindGlobalMapPathUUIDFromPod failed: %v", err)
|
||||
}
|
||||
klog.V(5).Infof("FindGlobalMapPathFromPod: globalMapPathUUID %s", globalMapPathUUID)
|
||||
// Return path contains global map path + {pod uuid}
|
||||
return globalMapPathUUID, nil
|
||||
}
|
||||
|
||||
// compareBindMountAndSymlinks returns if global path (bind mount) and
|
||||
// pod path (symlink) are pointing to the same device.
|
||||
// If there is an error in checking it returns error.
|
||||
func compareBindMountAndSymlinks(global, pod string) (bool, error) {
|
||||
// To check if bind mount and symlink are pointing to the same device,
|
||||
// we need to check if they are pointing to the devices that have same major/minor number.
|
||||
|
||||
// Get the major/minor number for global path
|
||||
devNumGlobal, err := getDeviceMajorMinor(global)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("getDeviceMajorMinor failed for path %s: %v", global, err)
|
||||
}
|
||||
|
||||
// Get the symlinked device from the pod path
|
||||
devPod, err := os.Readlink(pod)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("failed to readlink path %s: %v", pod, err)
|
||||
}
|
||||
// Get the major/minor number for the symlinked device from the pod path
|
||||
devNumPod, err := getDeviceMajorMinor(devPod)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("getDeviceMajorMinor failed for path %s: %v", devPod, err)
|
||||
}
|
||||
klog.V(5).Infof("CompareBindMountAndSymlinks: devNumGlobal %s, devNumPod %s", devNumGlobal, devNumPod)
|
||||
|
||||
// Check if the major/minor number are the same
|
||||
if devNumGlobal == devNumPod {
|
||||
return true, nil
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// getDeviceMajorMinor returns major/minor number for the path with below format:
|
||||
// major:minor (in hex)
|
||||
// ex)
|
||||
//
|
||||
// fc:10
|
||||
func getDeviceMajorMinor(path string) (string, error) {
|
||||
var stat unix.Stat_t
|
||||
|
||||
if err := unix.Stat(path, &stat); err != nil {
|
||||
return "", fmt.Errorf("failed to stat path %s: %v", path, err)
|
||||
}
|
||||
|
||||
devNumber := uint64(stat.Rdev)
|
||||
major := unix.Major(devNumber)
|
||||
minor := unix.Minor(devNumber)
|
||||
|
||||
return fmt.Sprintf("%x:%x", major, minor), nil
|
||||
}
|
49
vendor/k8s.io/kubernetes/pkg/volume/util/volumepathhandler/volume_path_handler_unsupported.go
generated
vendored
Normal file
49
vendor/k8s.io/kubernetes/pkg/volume/util/volumepathhandler/volume_path_handler_unsupported.go
generated
vendored
Normal file
@ -0,0 +1,49 @@
|
||||
//go:build !linux
|
||||
// +build !linux
|
||||
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
|
||||
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 volumepathhandler
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
)
|
||||
|
||||
// AttachFileDevice takes a path to a regular file and makes it available as an
|
||||
// attached block device.
|
||||
func (v VolumePathHandler) AttachFileDevice(path string) (string, error) {
|
||||
return "", fmt.Errorf("AttachFileDevice not supported for this build.")
|
||||
}
|
||||
|
||||
// DetachFileDevice takes a path to the attached block device and
|
||||
// detach it from block device.
|
||||
func (v VolumePathHandler) DetachFileDevice(path string) error {
|
||||
return fmt.Errorf("DetachFileDevice not supported for this build.")
|
||||
}
|
||||
|
||||
// GetLoopDevice returns the full path to the loop device associated with the given path.
|
||||
func (v VolumePathHandler) GetLoopDevice(path string) (string, error) {
|
||||
return "", fmt.Errorf("GetLoopDevice not supported for this build.")
|
||||
}
|
||||
|
||||
// FindGlobalMapPathUUIDFromPod finds {pod uuid} bind mount under globalMapPath
|
||||
// corresponding to map path symlink, and then return global map path with pod uuid.
|
||||
func (v VolumePathHandler) FindGlobalMapPathUUIDFromPod(pluginDir, mapPath string, podUID types.UID) (string, error) {
|
||||
return "", fmt.Errorf("FindGlobalMapPathUUIDFromPod not supported for this build.")
|
||||
}
|
Reference in New Issue
Block a user