devices

package
v0.0.0-...-58f6e79 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2025 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DevPrefix     = "/dev/"
	DevMapperRoot = "/dev/mapper/"
)

Variables

View Source
var (
	LuksCloseDurations = durations.TimeDuration{}
)

Functions

func PathExists

func PathExists(fs afero.Fs, path string) (bool, error)

Types

type Client

type Client struct {
	SizeGetter
	// contains filtered or unexported fields
}

func New

func New() *Client

func NewDetailed

func NewDetailed(command exec.Command, osFs afero.Fs, diskSizeGetter SizeGetter) *Client

func (*Client) CloseLUKSDevice

func (c *Client) CloseLUKSDevice(ctx context.Context, devicePath string) error

CloseLUKSDevice performs a luksClose on the device at the specified path (example: "/dev/mapper/<luks>").

func (*Client) EnsureDeviceReadable

func (c *Client) EnsureDeviceReadable(ctx context.Context, device string) error

EnsureDeviceReadable reads first 4 KiBs of the device to ensures it is readable

func (*Client) EnsureLUKSDeviceClosed

func (c *Client) EnsureLUKSDeviceClosed(ctx context.Context, devicePath string) error

EnsureLUKSDeviceClosed ensures there is no open LUKS device at the specified path (example: "/dev/mapper/<luks>").

func (*Client) EnsureLUKSDeviceClosedWithMaxWaitLimit

func (c *Client) EnsureLUKSDeviceClosedWithMaxWaitLimit(ctx context.Context, luksDevicePath string) error

func (*Client) FindDevicesForMultipathDevice

func (c *Client) FindDevicesForMultipathDevice(ctx context.Context, device string) []string

FindDevicesForMultipathDevice finds the constituent devices for a devicemapper parent device like /dev/dm-0.

func (*Client) FindMultipathDeviceForDevice

func (c *Client) FindMultipathDeviceForDevice(ctx context.Context, device string) string

FindMultipathDeviceForDevice finds the devicemapper parent of a device name like /dev/sdx.

func (*Client) FlushDevice

func (c *Client) FlushDevice(ctx context.Context, deviceInfo *models.ScsiDeviceInfo, force bool) error

flushDevice flushes any outstanding I/O to all paths to a device.

func (*Client) FlushOneDevice

func (c *Client) FlushOneDevice(ctx context.Context, devicePath string) error

FlushOneDevice flushes any outstanding I/O to a disk

func (*Client) GetDeviceFSType

func (c *Client) GetDeviceFSType(ctx context.Context, device string) (string, error)

GetDeviceFSType returns the filesystem for the supplied device.

func (*Client) GetLUKSDeviceForMultipathDevice

func (c *Client) GetLUKSDeviceForMultipathDevice(multipathDevice string) (string, error)

func (*Client) GetLunSerial

func (c *Client) GetLunSerial(ctx context.Context, path string) (string, error)

GetLunSerial get Linux's idea of what the LUN serial number is

func (*Client) GetMultipathDeviceBySerial

func (c *Client) GetMultipathDeviceBySerial(ctx context.Context, hexSerial string) (string, error)

GetMultipathDeviceBySerial find DM device whose UUID /sys/block/dmX/dm/uuid contains serial in hex format.

func (*Client) GetMultipathDeviceDisks

func (c *Client) GetMultipathDeviceDisks(
	ctx context.Context, multipathDevicePath string,
) ([]string, error)

GetMultipathDeviceDisks find the /sys/block/dmX/slaves/sdX disks.

func (*Client) GetMultipathDeviceUUID

func (c *Client) GetMultipathDeviceUUID(multipathDevicePath string) (string, error)

GetMultipathDeviceUUID find the /sys/block/dmX/dm/uuid UUID that contains DM device serial in hex format.

func (*Client) IsDeviceUnformatted

func (c *Client) IsDeviceUnformatted(ctx context.Context, device string) (bool, error)

IsDeviceUnformatted reads first 2 MiBs of the device to identify if it is unformatted and contains all zeros

func (*Client) ListAllDevices

func (c *Client) ListAllDevices(ctx context.Context)

ListAllDevices logs info about session and what devices are present

func (*Client) MultipathFlushDevice

func (c *Client) MultipathFlushDevice(ctx context.Context, deviceInfo *models.ScsiDeviceInfo) error

MultipathFlushDevice invokes the 'multipath' commands to flush paths for a single device.

func (*Client) RemoveDevice

func (c *Client) RemoveDevice(ctx context.Context, devices []string, ignoreErrors bool) error

removeDevice tells Linux that a device will be removed.

func (*Client) RemoveMultipathDeviceMapping

func (c *Client) RemoveMultipathDeviceMapping(ctx context.Context, devicePath string) error

RemoveMultipathDeviceMapping uses "multipath -f <devicePath>" to flush(remove) unused map. Unused maps can happen when Unstage is called on offline/deleted LUN.

func (*Client) RemoveMultipathDeviceMappingWithRetries

func (c *Client) RemoveMultipathDeviceMappingWithRetries(ctx context.Context, devicePath string, retries uint64,
	sleep time.Duration,
) error

RemoveMultipathDeviceMappingWithRetries calls RemoveMultipathDeviceMapping with retries.

func (*Client) ScanTargetLUN

func (c *Client) ScanTargetLUN(ctx context.Context, deviceAddresses []models.ScsiDeviceAddress) error

ScanTargetLUN scans a single LUN or all the LUNs on an iSCSI target to discover it. If all the LUNs are to be scanned please pass -1 for lunID.

func (*Client) VerifyMultipathDevice

func (c *Client) VerifyMultipathDevice(
	ctx context.Context, publishInfo *models.VolumePublishInfo,
	allPublishInfos []models.VolumePublishInfo, deviceInfo *models.ScsiDeviceInfo,
) (bool, error)

VerifyMultipathDevice verifies that device being removed is correct based on published device path, device serial number (if present) or comparing all publications (allPublishInfos) for LUN number uniqueness.

func (*Client) VerifyMultipathDeviceSize

func (c *Client) VerifyMultipathDeviceSize(
	ctx context.Context, multipathDevice, device string,
) (int64, bool, error)

VerifyMultipathDeviceSize compares the size of the DM device with the size of a device to ensure correct DM device has the correct size.

func (*Client) WaitForDevice

func (c *Client) WaitForDevice(ctx context.Context, device string) error

WaitForDevice accepts a device name and checks if it is present

func (*Client) WaitForDevicesRemoval

func (c *Client) WaitForDevicesRemoval(ctx context.Context, devicePathPrefix string, deviceNames []string,
	maxWaitTime time.Duration,
) error

WaitForDevicesRemoval waits for devices to be removed from the system.

type Devices

type Devices interface {
	FlushDevice(ctx context.Context, deviceInfo *models.ScsiDeviceInfo, force bool) error
	FlushOneDevice(ctx context.Context, devicePath string) error
	EnsureDeviceReadable(ctx context.Context, device string) error
	IsDeviceUnformatted(ctx context.Context, device string) (bool, error)
	ListAllDevices(ctx context.Context)
	WaitForDevice(ctx context.Context, device string) error
	GetDeviceFSType(ctx context.Context, device string) (string, error)
	FindMultipathDeviceForDevice(ctx context.Context, device string) string
	FindDevicesForMultipathDevice(ctx context.Context, device string) []string
	VerifyMultipathDeviceSize(ctx context.Context, multipathDevice, device string) (int64, bool, error)
	GetDiskSize(ctx context.Context, devicePath string) (int64, error)
	MultipathFlushDevice(ctx context.Context, deviceInfo *models.ScsiDeviceInfo) error
	RemoveDevice(ctx context.Context, devices []string, ignoreErrors bool) error
	VerifyMultipathDevice(
		ctx context.Context, publishInfo *models.VolumePublishInfo,
		allPublishInfos []models.VolumePublishInfo, deviceInfo *models.ScsiDeviceInfo,
	) (bool, error)
	GetLunSerial(ctx context.Context, path string) (string, error)
	GetMultipathDeviceUUID(multipathDevicePath string) (string, error)
	GetLUKSDeviceForMultipathDevice(multipathDevice string) (string, error)
	ScanTargetLUN(ctx context.Context, deviceAddresses []models.ScsiDeviceAddress) error
	CloseLUKSDevice(ctx context.Context, devicePath string) error
	EnsureLUKSDeviceClosedWithMaxWaitLimit(ctx context.Context, luksDevicePath string) error
	EnsureLUKSDeviceClosed(ctx context.Context, devicePath string) error
	RemoveMultipathDeviceMapping(ctx context.Context, devicePath string) error
	WaitForDevicesRemoval(ctx context.Context, devicePathPrefix string, deviceNames []string,
		maxWaitTime time.Duration,
	) error
	RemoveMultipathDeviceMappingWithRetries(ctx context.Context, devicePath string, retries uint64,
		sleep time.Duration) error
}

type DiskSizeGetter

type DiskSizeGetter struct{}

func NewDiskSizeGetter

func NewDiskSizeGetter() *DiskSizeGetter

func (*DiskSizeGetter) GetDiskSize

func (c *DiskSizeGetter) GetDiskSize(ctx context.Context, devicePath string) (int64, error)

GetDiskSize queries the current block size in bytes

type SizeGetter

type SizeGetter interface {
	GetDiskSize(ctx context.Context, devicePath string) (int64, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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