lxd: github.com/lxc/lxd/lxd/device Index | Files | Directories

package device

import "github.com/lxc/lxd/lxd/device"

Index

Package Files

device.go device_instance.go device_runconfig.go device_utils_disk.go device_utils_infiniband.go device_utils_inotify.go device_utils_instance.go device_utils_network.go device_utils_proxy.go device_utils_unix.go device_utils_unix_events.go device_utils_usb_events.go disk.go errors.go gpu.go infiniband.go infiniband_physical.go infiniband_sriov.go nic.go nic_bridged.go nic_ipvlan.go nic_macvlan.go nic_p2p.go nic_physical.go nic_sriov.go none.go proxy.go unix_common.go usb.go

Constants

const IBDevPrefix = "infiniband.unix"

IBDevPrefix Infiniband devices prefix.

const MountOwnerShiftDynamic = "dynamic"

MountOwnerShiftDynamic use shiftfs for dynamic owner shifting.

const MountOwnerShiftNone = ""

MountOwnerShiftNone do not use owner shifting.

const MountOwnerShiftStatic = "static"

MountOwnerShiftStatic statically modify ownership.

Variables

var ErrUnsupportedDevType = fmt.Errorf("Unsupported device type")

ErrUnsupportedDevType is the error that occurs when an unsupported device type is created.

var InstanceLoadByProjectAndName func(s *state.State, project, name string) (Instance, error)

InstanceLoadByProjectAndName returns instance config by project and name.

var InstanceLoadNodeAll func(s *state.State) ([]Instance, error)

InstanceLoadNodeAll returns all local instance configs.

var StorageRootFSApplyQuota func(instance Instance, newSize int64) (bool, error)

StorageRootFSApplyQuota applies a new quota.

var StorageVolumeMount func(s *state.State, poolName string, volumeName string, volumeTypeName string, instance Instance) error

StorageVolumeMount checks if storage volume is mounted and if not tries to mount it.

var StorageVolumeUmount func(s *state.State, poolName string, volumeName string, volumeType int) error

StorageVolumeUmount unmounts a storage volume.

func BlockFsDetect Uses

func BlockFsDetect(dev string) (string, error)

BlockFsDetect detects the type of block device.

func DiskMount Uses

func DiskMount(srcPath string, dstPath string, readonly bool, recursive bool, propagation string) error

DiskMount mounts a disk device.

func InotifyHandler Uses

func InotifyHandler(s *state.State)

InotifyHandler starts watching for inotify events.

func InotifyInit Uses

func InotifyInit(s *state.State) (int, error)

InotifyInit initialises the inotify internal structures.

func IsBlockdev Uses

func IsBlockdev(path string) bool

IsBlockdev returns boolean indicating whether device is block type.

func NetworkAttachInterface Uses

func NetworkAttachInterface(netName string, devName string) error

NetworkAttachInterface attaches an interface to a bridge.

func NetworkCreateVlanDeviceIfNeeded Uses

func NetworkCreateVlanDeviceIfNeeded(parent string, vlanDevice string, vlanID string) (bool, error)

NetworkCreateVlanDeviceIfNeeded creates a VLAN device if doesn't already exist.

func NetworkGetDevMAC Uses

func NetworkGetDevMAC(devName string) (string, error)

NetworkGetDevMAC retrieves the current MAC setting for a named network device.

func NetworkGetDevMTU Uses

func NetworkGetDevMTU(devName string) (uint64, error)

NetworkGetDevMTU retrieves the current MTU setting for a named network device.

func NetworkGetHostDevice Uses

func NetworkGetHostDevice(parent string, vlan string) string

NetworkGetHostDevice figures out whether there is an existing interface for the supplied parent device and VLAN ID and returns it. Otherwise just returns the parent device name.

func NetworkRandomDevName Uses

func NetworkRandomDevName(prefix string) string

NetworkRandomDevName returns a random device name with prefix. If the random string combined with the prefix exceeds 13 characters then empty string is returned. This is to ensure we support buggy dhclient applications: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=858580

func NetworkRemoveInterface Uses

func NetworkRemoveInterface(nic string) error

NetworkRemoveInterface removes a network interface by name.

func NetworkSetDevMAC Uses

func NetworkSetDevMAC(devName string, mac string) error

NetworkSetDevMAC sets the MAC setting for a named network device if different from current.

func NetworkSetDevMTU Uses

func NetworkSetDevMTU(devName string, mtu uint64) error

NetworkSetDevMTU sets the MTU setting for a named network device if different from current.

func NetworkSysctlGet Uses

func NetworkSysctlGet(path string) (string, error)

NetworkSysctlGet retrieves the value of a sysctl file in /proc/sys/net.

func NetworkSysctlSet Uses

func NetworkSysctlSet(path string, value string) error

NetworkSysctlSet writes a value to a sysctl file in /proc/sys/net.

func NetworkValidAddress Uses

func NetworkValidAddress(value string) error

NetworkValidAddress validates an IP address string. If string is empty, returns valid.

func NetworkValidAddressV4 Uses

func NetworkValidAddressV4(value string) error

NetworkValidAddressV4 validates an IPv4 addresss string. If string is empty, returns valid.

func NetworkValidAddressV4List Uses

func NetworkValidAddressV4List(value string) error

NetworkValidAddressV4List validates a comma delimited list of IPv4 addresses.

func NetworkValidAddressV6 Uses

func NetworkValidAddressV6(value string) error

NetworkValidAddressV6 validates an IPv6 addresss string. If string is empty, returns valid.

func NetworkValidAddressV6List Uses

func NetworkValidAddressV6List(value string) error

NetworkValidAddressV6List validates a comma delimited list of IPv6 addresses.

func NetworkValidNetworkV4 Uses

func NetworkValidNetworkV4(value string) error

NetworkValidNetworkV4 validates an IPv4 CIDR string. If string is empty, returns valid.

func NetworkValidNetworkV4List Uses

func NetworkValidNetworkV4List(value string) error

NetworkValidNetworkV4List validates a comma delimited list of IPv4 CIDR strings.

func NetworkValidNetworkV6 Uses

func NetworkValidNetworkV6(value string) error

NetworkValidNetworkV6 validates an IPv6 CIDR string. If string is empty, returns valid.

func NetworkValidNetworkV6List Uses

func NetworkValidNetworkV6List(value string) error

NetworkValidNetworkV6List validates a comma delimited list of IPv6 CIDR strings.

func USBRunHandlers Uses

func USBRunHandlers(state *state.State, event *USBEvent)

USBRunHandlers executes any handlers registered for USB events.

func UnixDeviceExists Uses

func UnixDeviceExists(devicesPath string, prefix string, path string) bool

UnixDeviceExists checks if the unix device already exists in devices path.

type Device Uses

type Device interface {
    // CanHotPlug returns true if device can be managed whilst instance is running.
    // It also returns a slice of config fields that can be live updated. If only fields in this
    // list have changed then Update() is called rather than triggering a device remove & add.
    CanHotPlug() (bool, []string)

    // Add performs any host-side setup when a device is added to an instance.
    // It is called irrespective of whether the instance is running or not.
    Add() error

    // Start peforms any host-side configuration required to start the device for the instance.
    // This can be when a device is plugged into a running instance or the instance is starting.
    // Returns run-time configuration needed for configuring the instance with the new device.
    Start() (*RunConfig, error)

    // Register provides the ability for a device to subcribe to events that LXD can generate.
    // It is called after a device is started (after Start()) or when LXD starts.
    Register() error

    // Update performs host-side modifications for a device based on the difference between the
    // current config and previous devices config supplied as an argument. This called if the
    // only config fields that have changed are supplied in the list returned from CanHotPlug().
    // The function also accepts a boolean indicating whether the instance is running or not.
    Update(oldDevices deviceConfig.Devices, running bool) error

    // Stop performs any host-side cleanup required when a device is removed from an instance,
    // either due to unplugging it from a running instance or instance is being shutdown.
    // Returns run-time configuration needed for detaching the device from the instance.
    Stop() (*RunConfig, error)

    // Remove performs any host-side cleanup when an instance is removed from an instance.
    Remove() error
}

Device represents a device that can be added to an instance.

func New Uses

func New(instance Instance, state *state.State, name string, conf deviceConfig.Device, volatileGet VolatileGetter, volatileSet VolatileSetter) (Device, error)

New instantiates a new device struct, validates the supplied config and sets it into the device. If the device type is valid, but the other config validation fails then an instantiated device is still returned with the validation error. If an unknown device is requested or the device is not compatible with the instance type then an ErrUnsupportedDevType error is returned.

type Instance Uses

type Instance interface {
    Name() string
    Type() instancetype.Type
    Project() string
    DevicesPath() string
    RootfsPath() string
    LogPath() string
    ExpandedConfig() map[string]string
    LocalDevices() deviceConfig.Devices
    ExpandedDevices() deviceConfig.Devices
    DeviceEventHandler(*RunConfig) error
}

Instance is an interface that allows us to identify an Instance and its properties. It is intended that this interface be entirely comprised of functions which cannot be blocking irrespective of when they're called in the instance lifecycle.

type MountEntryItem Uses

type MountEntryItem struct {
    DevPath    string   // Describes the block special device or remote filesystem to be mounted.
    TargetPath string   // Describes the mount point (target) for the filesystem.
    FSType     string   // Describes the type of the filesystem.
    Opts       []string // Describes the mount options associated with the filesystem.
    Freq       int      // Used by dump(8) to determine which filesystems need to be dumped. Defaults to zero (don't dump) if not present.
    PassNo     int      // Used by fsck(8) to determine the order in which filesystem checks are done at boot time. Defaults to zero (don't fsck) if not present.
    OwnerShift string   // Ownership shifting mode, use constants MountOwnerShiftNone, MountOwnerShiftStatic or MountOwnerShiftDynamic.
}

MountEntryItem represents a single mount entry item.

type ProxyAddress Uses

type ProxyAddress struct {
    ConnType string
    Addr     []string
    Abstract bool
}

ProxyAddress represents a proxy address configuration.

func ProxyParseAddr Uses

func ProxyParseAddr(addr string) (*ProxyAddress, error)

ProxyParseAddr validates a proxy address and parses it into its constituent parts.

type RootFSEntryItem Uses

type RootFSEntryItem struct {
    Path string   // Describes the root file system source.
    Opts []string // Describes the mount options associated with the filesystem.
}

RootFSEntryItem represents the root filesystem options for an Instance.

type RunConfig Uses

type RunConfig struct {
    RootFS           RootFSEntryItem  // RootFS to setup.
    NetworkInterface []RunConfigItem  // Network interface configuration settings.
    CGroups          []RunConfigItem  // Cgroup rules to setup.
    Mounts           []MountEntryItem // Mounts to setup/remove.
    Uevents          [][]string       // Uevents to inject.
    PostHooks        []func() error   // Functions to be run after device attach/detach.
}

RunConfig represents LXD defined run-time config used for device setup/cleanup.

type RunConfigItem Uses

type RunConfigItem struct {
    Key   string
    Value string
}

RunConfigItem represents a single config item.

type USBEvent Uses

type USBEvent struct {
    Action string

    Vendor  string
    Product string

    Path        string
    Major       uint32
    Minor       uint32
    UeventParts []string
    UeventLen   int
}

USBEvent represents the properties of a USB device uevent.

func USBNewEvent Uses

func USBNewEvent(action string, vendor string, product string, major string, minor string, busnum string, devnum string, devname string, ueventParts []string, ueventLen int) (USBEvent, error)

USBNewEvent instantiates a new USBEvent struct.

type UnixDevice Uses

type UnixDevice struct {
    HostPath     string      // Absolute path to the device on the host.
    RelativePath string      // Relative path where the device will be mounted inside instance.
    Type         string      // Type of device; c (for char) or b for (block).
    Major        uint32      // Major number.
    Minor        uint32      // Minor number.
    Mode         os.FileMode // File mode.
    UID          int         // Owner UID.
    GID          int         // Owner GID.
}

UnixDevice contains information about a created UNIX device.

func UnixDeviceCreate Uses

func UnixDeviceCreate(s *state.State, idmapSet *idmap.IdmapSet, devicesPath string, prefix string, m deviceConfig.Device, defaultMode bool) (*UnixDevice, error)

UnixDeviceCreate creates a UNIX device (either block or char). If the supplied device config map contains a major and minor number for the device, then a stat is avoided, otherwise this info retrieved from the origin device. Similarly, if a mode is supplied in the device config map or defaultMode is set as true, then the device is created with the supplied or default mode (0660) respectively, otherwise the origin device's mode is used. If the device config doesn't contain a type field then it defaults to created a unix-char device. The ownership of the created device defaults to root (0) but can be specified with the uid and gid fields in the device config map. It returns a UnixDevice containing information about the device created.

type UnixEvent Uses

type UnixEvent struct {
    Action string // The type of event, either add or remove.
    Path   string // The absolute source path on the host.
}

UnixEvent represents the properties of a Unix device inotify event.

type UnixSubscription Uses

type UnixSubscription struct {
    Path    string                              // The absolute source path on the host.
    Handler func(UnixEvent) (*RunConfig, error) // The function to run when an event occurs.
}

UnixSubscription used to subcribe to specific events.

type VolatileGetter Uses

type VolatileGetter func() map[string]string

VolatileGetter is a function that retrieves any key/value string that exists in the LXD database config for this instance. It should only return keys that match the volatile device name prefix, and should remove the prefix before being returned.

type VolatileSetter Uses

type VolatileSetter func(map[string]string) error

VolatileSetter is a function that accepts one or more key/value strings to save into the LXD config for this instance. It should add the volatile device name prefix to each key when saving.

Directories

PathSynopsis
config

Package device imports 43 packages (graph) and is imported by 3 packages. Updated 2019-10-22. Refresh now. Tools for package owners.