Documentation ¶
Index ¶
- Constants
- Variables
- func GetDeviceFSMap(devices []string) (map[string]string, error)
- func GetMatchingSymlinksInDirs(path string, dirs ...string) ([]string, error)
- func GetOrphanedSymlinks(symlinkDir string, validDevices []BlockDevice) ([]string, error)
- func PathEvalsToDiskLabel(path, devName string) (bool, error)
- type BlockDevice
- func (b BlockDevice) GetDevPath() (path string, err error)
- func (b *BlockDevice) GetPathByID() (string, error)
- func (b BlockDevice) GetReadOnly() (bool, error)
- func (b BlockDevice) GetRemovable() (bool, error)
- func (b BlockDevice) GetRotational() (bool, error)
- func (b BlockDevice) GetSize() (int64, error)
- func (b *BlockDevice) HasBindMounts() (bool, string, error)
- func (b BlockDevice) HasChildren() (bool, error)
- type ExclusiveFileLock
- type IDPathNotFoundError
Constants ¶
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 ¶
var ( ExecCommand = exec.Command FilePathGlob = filepath.Glob FilePathEvalSymLinks = filepath.EvalSymlinks )
Functions ¶
func GetDeviceFSMap ¶
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 ¶
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 ¶
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 ¶
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) 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