hostutil

package
v1.17.12-rc.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 13, 2020 License: Apache-2.0 Imports: 11 Imported by: 46

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DoMakeRShared

func DoMakeRShared(path string, mountInfoFilename string) error

DoMakeRShared is common implementation of MakeRShared on Linux. It checks if path is shared and bind-mounts it as rshared if needed. mountCmd and mountArgs are expected to contain mount-like command, DoMakeRShared will add '--bind <path> <path>' and '--make-rshared <path>' to mountArgs.

func ExclusiveOpenFailsOnDevice

func ExclusiveOpenFailsOnDevice(pathname string) (bool, error)

ExclusiveOpenFailsOnDevice is shared with NsEnterMounter

func GetModeLinux

func GetModeLinux(pathname string) (os.FileMode, error)

GetModeLinux is shared between Linux and NsEnterMounter

func GetOwnerLinux

func GetOwnerLinux(pathname string) (int64, int64, error)

GetOwnerLinux is shared between Linux and NsEnterMounter pathname must already be evaluated for symlinks

func GetSELinux

func GetSELinux(path string, mountInfoFilename string) (bool, error)

GetSELinux is common implementation of GetSELinuxSupport on Linux.

Types

type FakeHostUtil

type FakeHostUtil struct {
	MountPoints []mount.MountPoint
	Filesystem  map[string]FileType
	// contains filtered or unexported fields
}

FakeHostUtil is a fake HostUtils implementation for testing

func NewFakeHostUtil

func NewFakeHostUtil(fs map[string]FileType) *FakeHostUtil

NewFakeHostUtil returns a struct that implements the HostUtils interface for testing TODO: no callers were initializing the struct with any MountPoints. Check if those are still being used by any callers and if MountPoints still need to be a part of the struct.

func (*FakeHostUtil) DeviceOpened

func (hu *FakeHostUtil) DeviceOpened(pathname string) (bool, error)

DeviceOpened checks if block device referenced by pathname is in use by checking if is listed as a device in the in-memory mountpoint table.

func (hu *FakeHostUtil) EvalHostSymlinks(pathname string) (string, error)

EvalHostSymlinks returns the path name after evaluating symlinks. No-op for testing

func (*FakeHostUtil) GetDeviceNameFromMount

func (hu *FakeHostUtil) GetDeviceNameFromMount(mounter mount.Interface, mountPath, pluginMountDir string) (string, error)

GetDeviceNameFromMount given a mount point, find the volume id

func (*FakeHostUtil) GetFileType

func (hu *FakeHostUtil) GetFileType(pathname string) (FileType, error)

GetFileType checks for file/directory/socket/block/character devices. Defaults to Directory if otherwise unspecified.

func (*FakeHostUtil) GetMode

func (hu *FakeHostUtil) GetMode(pathname string) (os.FileMode, error)

GetMode returns permissions of pathname. Not implemented for testing

func (*FakeHostUtil) GetOwner

func (hu *FakeHostUtil) GetOwner(pathname string) (int64, int64, error)

GetOwner returns the integer ID for the user and group of the given path Not implemented for testing

func (*FakeHostUtil) GetSELinuxSupport

func (hu *FakeHostUtil) GetSELinuxSupport(pathname string) (bool, error)

GetSELinuxSupport tests if pathname is on a mount that supports SELinux. Not implemented for testing

func (*FakeHostUtil) MakeRShared

func (hu *FakeHostUtil) MakeRShared(path string) error

MakeRShared checks if path is shared and bind-mounts it as rshared if needed. No-op for testing

func (*FakeHostUtil) PathExists

func (hu *FakeHostUtil) PathExists(pathname string) (bool, error)

PathExists checks if pathname exists.

func (*FakeHostUtil) PathIsDevice

func (hu *FakeHostUtil) PathIsDevice(pathname string) (bool, error)

PathIsDevice always returns true

type FileType

type FileType string

FileType enumerates the known set of possible file types.

const (
	// FileTypeBlockDev defines a constant for the block device FileType.
	FileTypeBlockDev FileType = "BlockDevice"
	// FileTypeCharDev defines a constant for the character device FileType.
	FileTypeCharDev FileType = "CharDevice"
	// FileTypeDirectory defines a constant for the directory FileType.
	FileTypeDirectory FileType = "Directory"
	// FileTypeFile defines a constant for the file FileType.
	FileTypeFile FileType = "File"
	// FileTypeSocket defines a constant for the socket FileType.
	FileTypeSocket FileType = "Socket"
	// FileTypeUnknown defines a constant for an unknown FileType.
	FileTypeUnknown FileType = ""
)

type HostUtil

type HostUtil struct {
}

HostUtil implements HostUtils for Linux platforms.

func NewHostUtil

func NewHostUtil() *HostUtil

NewHostUtil returns a struct that implements the HostUtils interface on linux platforms

func (*HostUtil) DeviceOpened

func (hu *HostUtil) DeviceOpened(pathname string) (bool, error)

DeviceOpened checks if block device in use by calling Open with O_EXCL flag. If pathname is not a device, log and return false with nil error. If open returns errno EBUSY, return true with nil error. If open returns nil, return false with nil error. Otherwise, return false with error

func (hu *HostUtil) EvalHostSymlinks(pathname string) (string, error)

EvalHostSymlinks returns the path name after evaluating symlinks. TODO once the nsenter implementation is removed, this method can be removed from the interface and filepath.EvalSymlinks used directly

func (*HostUtil) GetDeviceNameFromMount

func (hu *HostUtil) GetDeviceNameFromMount(mounter mount.Interface, mountPath, pluginMountDir string) (string, error)

GetDeviceNameFromMount given a mount point, find the device name from its global mount point

func (*HostUtil) GetFileType

func (hu *HostUtil) GetFileType(pathname string) (FileType, error)

GetFileType checks for file/directory/socket/block/character devices.

func (*HostUtil) GetMode

func (hu *HostUtil) GetMode(pathname string) (os.FileMode, error)

GetMode returns permissions of the path.

func (*HostUtil) GetOwner

func (hu *HostUtil) GetOwner(pathname string) (int64, int64, error)

GetOwner returns the integer ID for the user and group of the given path

func (*HostUtil) GetSELinuxSupport

func (hu *HostUtil) GetSELinuxSupport(pathname string) (bool, error)

GetSELinuxSupport returns true if given path is on a mount that supports SELinux.

func (*HostUtil) MakeRShared

func (hu *HostUtil) MakeRShared(path string) error

MakeRShared checks that given path is on a mount with 'rshared' mount propagation. If not, it bind-mounts the path as rshared.

func (*HostUtil) PathExists

func (hu *HostUtil) PathExists(pathname string) (bool, error)

PathExists tests if the given path already exists Error is returned on any other error than "file not found".

func (*HostUtil) PathIsDevice

func (hu *HostUtil) PathIsDevice(pathname string) (bool, error)

PathIsDevice uses FileInfo returned from os.Stat to check if path refers to a device.

type HostUtils

type HostUtils interface {
	// DeviceOpened determines if the device (e.g. /dev/sdc) is in use elsewhere
	// on the system, i.e. still mounted.
	DeviceOpened(pathname string) (bool, error)
	// PathIsDevice determines if a path is a device.
	PathIsDevice(pathname string) (bool, error)
	// GetDeviceNameFromMount finds the device name by checking the mount path
	// to get the global mount path within its plugin directory.
	GetDeviceNameFromMount(mounter mount.Interface, mountPath, pluginMountDir string) (string, error)
	// MakeRShared checks that given path is on a mount with 'rshared' mount
	// propagation. If not, it bind-mounts the path as rshared.
	MakeRShared(path string) error
	// GetFileType checks for file/directory/socket/block/character devices.
	GetFileType(pathname string) (FileType, error)
	// PathExists tests if the given path already exists
	// Error is returned on any other error than "file not found".
	PathExists(pathname string) (bool, error)
	// EvalHostSymlinks returns the path name after evaluating symlinks.
	EvalHostSymlinks(pathname string) (string, error)
	// GetOwner returns the integer ID for the user and group of the given path
	GetOwner(pathname string) (int64, int64, error)
	// GetSELinuxSupport returns true if given path is on a mount that supports
	// SELinux.
	GetSELinuxSupport(pathname string) (bool, error)
	// GetMode returns permissions of the path.
	GetMode(pathname string) (os.FileMode, error)
}

HostUtils defines the set of methods for interacting with paths on a host.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL