devicemanager

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2019 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Device

type Device struct {
	Instance          *ec2.Instance
	Path              string
	VolumeID          string
	IsAlreadyAssigned bool
	// contains filtered or unexported fields
}

func (*Device) Release

func (d *Device) Release(force bool)

func (*Device) Taint

func (d *Device) Taint()

Taint marks the device as no longer reusable

type DeviceManager

type DeviceManager interface {
	// NewDevice retrieves the device if the device is already assigned.
	// Otherwise it creates a new device with next available device name
	// and mark it as unassigned device.
	NewDevice(instance *ec2.Instance, volumeID string) (device *Device, err error)

	// GetDevice returns the device already assigned to the volume.
	GetDevice(instance *ec2.Instance, volumeID string) (device *Device, err error)
}

func NewDeviceManager

func NewDeviceManager() DeviceManager

type ExistingNames

type ExistingNames map[string]string

ExistingNames is a map of assigned device names. Presence of a key with a device name in the map means that the device is allocated. Value is irrelevant and can be used for anything that NameAllocator user wants. Only the relevant part of device name should be in the map, e.g. "ba" for "/dev/xvdba".

type NameAllocator

type NameAllocator interface {
	// GetNext returns a free device name or error when there is no free device
	// name. Only the device name is returned, e.g. "ba" for "/dev/xvdba".
	// It's up to the called to add appropriate "/dev/sd" or "/dev/xvd" prefix.
	GetNext(existingNames ExistingNames) (name string, err error)

	// Deprioritize the device name so as it can't be used immediately again
	Deprioritize(chosen string)
}

On AWS, we should assign new (not yet used) device names to attached volumes. If we reuse a previously used name, we may get the volume "attaching" forever, see https://aws.amazon.com/premiumsupport/knowledge-center/ebs-stuck-attaching/. NameAllocator finds available device name, taking into account already assigned device names from ExistingNames map. It tries to find the next device name to the previously assigned one (from previous NameAllocator call), so all available device names are used eventually and it minimizes device name reuse. All these allocations are in-memory, nothing is written to / read from /dev directory.

func NewNameAllocator

func NewNameAllocator() NameAllocator

Allocates device names according to scheme ba..bz, ca..cz it moves along the ring and always picks next device until device list is exhausted.

Jump to

Keyboard shortcuts

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