internal

package
v0.0.0-...-2a80d7f Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// StateSuspended is a possible value of BlockDevice.State
	StateSuspended = "suspended"
	// DiskByIDDir is the path for symlinks to the device by id.
	DiskByIDDir = "/dev/disk/by-id/"
	// DiskDMDir is the path for symlinks of device mapper disks (e.g. mpath)
	DiskDMDir = "/dev/mapper/"
)

Variables

View Source
var (
	ExecCommand          = exec.Command
	FilePathGlob         = filepath.Glob
	FilePathEvalSymLinks = filepath.EvalSymlinks
)

Functions

func GetDeviceFSMap

func GetDeviceFSMap(devices []string) (map[string]string, error)

GetDeviceFSMap returns mapping between disks and the filesystem using blkid It parses the output of `blkid -s TYPE`. Sample ouput format before parsing `/dev/sdc: TYPE="ext4" /dev/sdd: TYPE="ext2"` If devices is empty, it scans all disks, otherwise only devices.

func GetMatchingSymlinksInDirs

func GetMatchingSymlinksInDirs(path string, dirs ...string) ([]string, error)

GetMatchingSymlinksInDirs returns all the files in dir that are the same file as path after evaluating symlinks it works using `find -L dir1 dir2 dirn -samefile path`

func GetOrphanedSymlinks(symlinkDir string, validDevices []BlockDevice) ([]string, error)

GetOrphanedSymlinks returns the devices that were symlinked previously, but didn't match the updated LocalVolumeSet deviceInclusionSpec or LocalVolume devicePaths

func PathEvalsToDiskLabel

func PathEvalsToDiskLabel(path, devName string) (bool, error)

PathEvalsToDiskLabel checks if the path is a symplink to a file devName

Types

type BlockDevice

type BlockDevice struct {
	Name   string `json:"name"`
	KName  string `json:"kname"`
	Type   string `json:"type"`
	Model  string `json:"model,omitempty"`
	Vendor string `json:"vendor,omitempty"`
	State  string `json:"state,omitempty"`
	FSType string `json:"fsType"`
	Size   string `json:"size"`
	// Children   []BlockDevice `json:"children,omitempty"`
	Rotational string `json:"rota"`
	ReadOnly   string `json:"ro,omitempty"`
	Removable  string `json:"rm,omitempty"`
	PathByID   string `json:"pathByID,omitempty"`
	Serial     string `json:"serial,omitempty"`
	PartLabel  string `json:"partLabel,omitempty"`
}

BlockDevice is the a block device as output by lsblk. All the fields are lsblk columns.

func ListBlockDevices

func ListBlockDevices(devices []string) ([]BlockDevice, []string, error)

ListBlockDevices using the lsblk command

func (BlockDevice) GetDevPath

func (b BlockDevice) GetDevPath() (path string, err error)

GetDevPath for block device (/dev/sdx)

func (*BlockDevice) GetPathByID

func (b *BlockDevice) GetPathByID() (string, error)

GetPathByID check on BlockDevice

func (BlockDevice) GetReadOnly

func (b BlockDevice) GetReadOnly() (bool, error)

GetReadOnly as bool

func (BlockDevice) GetRemovable

func (b BlockDevice) GetRemovable() (bool, error)

GetRemovable as bool

func (BlockDevice) GetRotational

func (b BlockDevice) GetRotational() (bool, error)

GetRotational as bool

func (BlockDevice) GetSize

func (b BlockDevice) GetSize() (int64, error)

GetSize as int64

func (*BlockDevice) HasBindMounts

func (b *BlockDevice) HasBindMounts() (bool, string, error)

HasBindMounts checks for bind mounts and returns mount point for a device by parsing `proc/1/mountinfo`. HostPID should be set to true inside the POD spec to get details of host's mount points inside `proc/1/mountinfo`.

func (BlockDevice) HasChildren

func (b BlockDevice) HasChildren() (bool, error)

HasChildren check on BlockDevice

type ExclusiveFileLock

type ExclusiveFileLock struct {
	Path string
	// contains filtered or unexported fields
}

func GetPVCreationLock

func GetPVCreationLock(device string, symlinkDirs ...string) (ExclusiveFileLock, bool, []string, error)

GetPVCreationLock checks whether a PV can be created based on this device and Locks the device so that no PVs can be created on it while the lock is held. the PV lock will fail if: - another process holds an exclusive file lock on the device (using the syscall flock) - a symlink to this device exists in symlinkDirs returns: ExclusiveFileLock, must be unlocked regardless of success bool determines if flock was placed on device. existingLinkPaths is a list of existing symlinks. It is not exhaustive error

func (*ExclusiveFileLock) Lock

func (e *ExclusiveFileLock) Lock() (bool, error)

Lock locks the file so other process cannot open the file

func (*ExclusiveFileLock) Unlock

func (e *ExclusiveFileLock) Unlock() error

Unlock releases the lock. It is idempotent

type IDPathNotFoundError

type IDPathNotFoundError struct {
	DeviceName string
}

IDPathNotFoundError indicates that a symlink to the device was not found in /dev/disk/by-id/

func (IDPathNotFoundError) Error

func (e IDPathNotFoundError) Error() string

Jump to

Keyboard shortcuts

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