osutils

package
v2.7.3 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2023 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package osutils provides methods to perform os specific operations

Index

Constants

View Source
const (
	UUIDPrefix = "VMware-"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Device

type Device struct {
	FullPath string // full path where device is mounted
	Name     string // name of device
	RealDev  string // in windows it represents volumeID and in linux it represents device path
}

Device is a struct for holding details about a block device.

type NodePublishParams

type NodePublishParams struct {
	// volID is the identifier for the underlying volume.
	VolID string
	// Target path is used to bind-mount a staged volume to the pod.
	Target string
	// Staging Target path is used to mount the volume to the node.
	StagingTarget string
	// diskID is the identifier for the disk.
	DiskID string
	// volumePath represents the sym-linked block volume full path.
	VolumePath string
	// device represents the actual path of the block volume.
	Device string
	// Read-only flag.
	Ro bool
}

struct to hold params required for NodePublish operation

type NodeStageParams

type NodeStageParams struct {
	// volID is the identifier for the underlying volume.
	VolID string
	// fsType is the file system type - ext3, ext4, nfs, nfs4.
	FsType string
	// Staging Target path is used to mount the volume to the node.
	StagingTarget string
	// Mount flags/options intended to be used while running the mount command.
	MntFlags []string
	// Read-only flag.
	Ro bool
}

struct to hold params required for NodeStage operation

type OsUtils

type OsUtils struct {
	Mounter *mount.SafeFormatAndMount
}

func NewOsUtils

func NewOsUtils(ctx context.Context) (*OsUtils, error)

NewOsUtils creates OsUtils with a linux specific mounter

func (*OsUtils) CleanupPublishPath

func (osUtils *OsUtils) CleanupPublishPath(ctx context.Context, target string, volID string) error

CleanupPublishPath will unmount and remove publish path

func (*OsUtils) CleanupStagePath

func (osUtils *OsUtils) CleanupStagePath(ctx context.Context, stagingTarget string, volID string) error

CleanupStagePath will unmount the volume from node and remove the stage directory

func (*OsUtils) ConvertUUID

func (osUtils *OsUtils) ConvertUUID(uuid string) (string, error)

convertUUID helps convert UUID to vSphere format, for example, Input uuid: 6B8C2042-0DD1-D037-156F-435F999D94C1 Returned uuid: 42208c6b-d10d-37d0-156f-435f999d94c1

func (*OsUtils) EnsureMountVol

func (osUtils *OsUtils) EnsureMountVol(ctx context.Context, log *zap.SugaredLogger,
	volCap *csi.VolumeCapability) (string, []string, error)

EnsureMountVol ensures that VolumeCapability has mount option and returns fstype, mount flags

func (*OsUtils) GetBlockSizeBytes

func (osUtils *OsUtils) GetBlockSizeBytes(ctx context.Context, devicePath string) (int64, error)

GetBlockSizeBytes returns the Block size in bytes

func (*OsUtils) GetDevFromMount

func (osUtils *OsUtils) GetDevFromMount(ctx context.Context, target string) (*Device, error)

GetDevFromMount returns device info mounted on the target dir

func (*OsUtils) GetDevMounts

func (osUtils *OsUtils) GetDevMounts(ctx context.Context,
	sysDevice *Device) ([]gofsutil.Info, error)

A wrapper around gofsutil.GetMounts that handles bind mounts.

func (*OsUtils) GetDevice

func (osUtils *OsUtils) GetDevice(ctx context.Context, path string) (*Device, error)

GetDevice returns a Device struct with info about the given device, or an error if it doesn't exist or is not a block device.

func (*OsUtils) GetDeviceRescanPath

func (osUtils *OsUtils) GetDeviceRescanPath(dev *Device) (string, error)

GetDeviceRescanPath is used to rescan the device

func (*OsUtils) GetDiskID

func (osUtils *OsUtils) GetDiskID(pubCtx map[string]string, log *zap.SugaredLogger) (string, error)

GetDiskID returns the diskID of the disk attached

func (*OsUtils) GetDiskPath

func (osUtils *OsUtils) GetDiskPath(id string) (string, error)

GetDiskPath return the full DiskPath for diskID

func (*OsUtils) GetMetrics

func (osUtils *OsUtils) GetMetrics(ctx context.Context, path string) (*k8svol.Metrics, error)

GetMetrics helps get volume metrics using k8s fsInfo strategy.

func (*OsUtils) GetSystemUUID

func (osUtils *OsUtils) GetSystemUUID(ctx context.Context) (string, error)

GetSystemUUID returns the UUID used to identify node vm

func (*OsUtils) GetVolumeCapabilityFsType

func (osUtils *OsUtils) GetVolumeCapabilityFsType(ctx context.Context, capability *csi.VolumeCapability) string

GetVolumeCapabilityFsType retrieves fstype from VolumeCapability. Defaults to nfs4 for file volume and ext4 for block volume when empty string is observed. This function also ignores default ext4 fstype supplied by external-provisioner when none is specified in the StorageClass

func (*OsUtils) IsBlockVolumeMounted

func (osUtils *OsUtils) IsBlockVolumeMounted(
	ctx context.Context,
	volID string,
	stagingTargetPath string) (
	bool, error)

IsBlockVolumeMounted checks if the block volume is properly mounted or not. If yes, then the calling function proceeds to unmount the volume.

func (*OsUtils) IsBlockVolumePublished

func (osUtils *OsUtils) IsBlockVolumePublished(ctx context.Context, volID string, target string) (bool, error)

IsBlockVolumePublished checks if the device backing block volume exists.

func (*OsUtils) IsTargetInMounts

func (osUtils *OsUtils) IsTargetInMounts(ctx context.Context, path string) (bool, error)

IsTargetInMounts checks if a path exists in the mounts

func (*OsUtils) Mkdir

func (osUtils *OsUtils) Mkdir(ctx context.Context, path string) (bool, error)

Mkdir creates the directory specified by path if needed. Return pair is a bool flag of whether dir was created, and an error.

func (*OsUtils) Mkfile

func (osUtils *OsUtils) Mkfile(ctx context.Context, path string) (bool, error)

Mkfile creates a file specified by the path if needed. Return pair is a bool flag of whether file was created, and an error.

func (*OsUtils) NodeStageBlockVolume

func (osUtils *OsUtils) NodeStageBlockVolume(
	ctx context.Context,
	req *csi.NodeStageVolumeRequest,
	params NodeStageParams) (
	*csi.NodeStageVolumeResponse, error)

NodeStageBlockVolume mounts mount volume or file volume to staging target

func (*OsUtils) PublishBlockVol

func (osUtils *OsUtils) PublishBlockVol(
	ctx context.Context,
	req *csi.NodePublishVolumeRequest,
	dev *Device,
	params NodePublishParams) (
	*csi.NodePublishVolumeResponse, error)

PublishBlockVol mounts raw block device to publish target

func (*OsUtils) PublishFileVol

func (osUtils *OsUtils) PublishFileVol(
	ctx context.Context,
	req *csi.NodePublishVolumeRequest,
	params NodePublishParams) (
	*csi.NodePublishVolumeResponse, error)

PublishBlockVol mounts file volume to publish target

func (*OsUtils) PublishMountVol

func (osUtils *OsUtils) PublishMountVol(
	ctx context.Context,
	req *csi.NodePublishVolumeRequest,
	dev *Device,
	params NodePublishParams) (
	*csi.NodePublishVolumeResponse, error)

PublishBlockVol mounts block volume to publish target

func (*OsUtils) RescanDevice

func (osUtils *OsUtils) RescanDevice(ctx context.Context, dev *Device) error

RescanDevice rescans the device

func (*OsUtils) ResizeVolume

func (osUtils *OsUtils) ResizeVolume(ctx context.Context, devicePath, volumePath string, reqVolSizeBytes int64) error

ResizeVolume resizes the volume

func (*OsUtils) Rmpath

func (osUtils *OsUtils) Rmpath(ctx context.Context, target string) error

Rmpath removes the given target path, whether it is a file or a directory. For directories, an error is returned if the dir is not empty.

func (*OsUtils) ShouldContinue

func (osUtils *OsUtils) ShouldContinue(ctx context.Context)

decides if node should continue

func (*OsUtils) VerifyTargetDir

func (osUtils *OsUtils) VerifyTargetDir(ctx context.Context, target string, targetShouldExist bool) (bool, error)

VerifyTargetDir checks if the target path is not empty, exists and is a directory. If targetShouldExist is set to false, then verifyTargetDir returns (false, nil) if the path does not exist. If targetShouldExist is set to true, then verifyTargetDir returns (false, err) if the path does not exist.

func (*OsUtils) VerifyVolumeAttached

func (osUtils *OsUtils) VerifyVolumeAttached(ctx context.Context, diskID string) (string, error)

VerifyVolumeAttached verifies if the volume path exist for diskID

func (*OsUtils) VerifyVolumeAttachedAndFillParams

func (osUtils *OsUtils) VerifyVolumeAttachedAndFillParams(ctx context.Context,
	pubCtx map[string]string, params *NodePublishParams, dev **Device) error

Jump to

Keyboard shortcuts

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