Documentation
¶
Index ¶
- Constants
- func ApplyHooksToContainer(hooksFilePath string, c instance.Container) error
- func GenerateFromCDI(isCore bool, inst instance.Instance, cdiID ID) (*ConfigDevices, *Hooks, error)
- type CDILogger
- func (l *CDILogger) Debugf(format string, args ...any)
- func (l *CDILogger) Errorf(format string, args ...any)
- func (l *CDILogger) Info(args ...any)
- func (l *CDILogger) Infof(format string, args ...any)
- func (l *CDILogger) Tracef(format string, args ...any)
- func (l *CDILogger) Warning(args ...any)
- func (l *CDILogger) Warningf(format string, args ...any)
- type Class
- type ConfigDevices
- type Hooks
- type ID
- type SymlinkEntry
- type Vendor
Constants ¶
const ( // CDIHooksFileSuffix is the suffix for the file that contains the CDI hooks. CDIHooksFileSuffix = "_cdi_hooks.json" // CDIConfigDevicesFileSuffix is the suffix for the file that contains the CDI config devices. CDIConfigDevicesFileSuffix = "_cdi_config_devices.json" // CDIUnixPrefix is the prefix used for creating unix char devices // (e.g. cdi.unix.<device_name>.<encoded_dest_path>). CDIUnixPrefix = "cdi.unix" // CDIDiskPrefix is the prefix used for creating bind mounts (or 'disk' devices) // representing user space files required for a CDI passthrough // (e.g. cdi.disk.<device_name>.<encoded_dest_path>). CDIDiskPrefix = "cdi.disk" )
Variables ¶
This section is empty.
Functions ¶
func ApplyHooksToContainer ¶
ApplyHooksToContainer applies CDI hooks to a container by creating symlinks and updating the linker configuration using SFTP.
func GenerateFromCDI ¶
GenerateFromCDI does several things: 1. Generate a CDI specification from a CDI ID and an instance. According the the specified 'vendor', 'class' and 'name' (this assembled triplet is called a fully-qualified CDI ID. We'll just call it ID in the context of this package), the CDI specification is generated. The CDI specification is a JSON-like format that describes a per-device configuration and general container edits. - Per-device configuration represents a single device identified by the CDI ID (e.g. /dev/nvidia0) It contains device-specific 'container edits' (device nodes, hooks and mounts). We only select those that matches the provided CDI ID (which can be a device index, uuid or 'all'). The hooks will be centralized in a single resource file that will be read and executed as a LXC `lxc.hook.mount` hook, through LXD's `callhook` command. - General container edits are instructions on how to modify the container when a CDI device is used. These edits are not specific to a single device, rather they apply to all devices of a given class/vendor. These edits must be applied if one or multiple devices are getting passed through (e.g. /dev/nvidia-uvm) 2. Process per-device configuration(s): we convert this information into a map of devices (keyed by their path given in the spec, it mapped to a map of device properties). We also collect mounts (but we do not process them yet) and hooks. 3. Process general container edits in the same fashion. 4. Process all the mounts collected from the spec in order to turn them into disk devices. This operations generate a side effect: it generates a list of indirect symlinks (see `specMountToLXDDev`) 5. Merge all the hooks (direct + indirect) into a single list of hooks.
Types ¶
type CDILogger ¶
type CDILogger struct {
// contains filtered or unexported fields
}
CDILogger reuses LXD's shared logger to log the internal operations of the CDI spec generator.
func NewCDILogger ¶
NewCDILogger creates a new CDI logger from a LXD logger instance.
func (*CDILogger) Debugf ¶
Debugf logs at the DEBUG log level using a standard printf format string.
func (*CDILogger) Errorf ¶
Errorf logs at the ERROR log level using a standard printf format string.
func (*CDILogger) Tracef ¶
Tracef logs at the TRACE log level using a standard printf format string.
type ConfigDevices ¶
type ConfigDevices struct {
// UnixCharDevs is a slice of unix-char device configuration.
UnixCharDevs []map[string]string `json:"unix_char_devs" yaml:"unix_char_devs"`
// BindMounts is a slice of mount configuration.
BindMounts []map[string]string `json:"bind_mounts" yaml:"bind_mounts"`
}
ConfigDevices represents devices and mounts that need to be configured from a CDI specification.
func ReloadConfigDevicesFromDisk ¶
func ReloadConfigDevicesFromDisk(pathsToConfigDevicesFilePath string) (ConfigDevices, error)
ReloadConfigDevicesFromDisk reads the paths to the CDI configuration devices file from the disk. This is useful in order to cache the CDI configuration devices file so that wee don't have to re-generate a CDI spec whhen stopping the container.
type Hooks ¶
type Hooks struct {
// ContainerRootFS is the path to the container's root filesystem.
ContainerRootFS string `json:"container_rootfs" yaml:"container_rootfs"`
// LdCacheUpdates is a list of entries to update the ld cache.
LDCacheUpdates []string `json:"ld_cache_updates" yaml:"ld_cache_updates"`
// SymLinks is a list of entries to create a symlink.
Symlinks []SymlinkEntry `json:"symlinks" yaml:"symlinks"`
}
Hooks represents all the hook instructions that can be executed by `lxd-cdi-hook`.
type ID ¶
ID represents a Container Device Interface (CDI) identifier.
+------------+-------+------------------------------------------+ | Vendor | Class | Name | +---------------------------------------------------------------+ | nvidia.com | gpu | [dev_idx], [dev_uuid] or `all` | | | mig | [dev_idx]:[mig_idx], [dev_uuid] or `all` | | | igpu | [dev_idx], [dev_uuid] or `all` | +------------+-------+------------------------------------------+
Examples:
- nvidia.com/gpu=0
- nvidia.com/gpu=d1f1c76e-7a72-487e-b121-e6d2e5555dc8
- nvidia.com/gpu=all
- nvidia.com/mig=0:1
- nvidia.com/igpu=0
type SymlinkEntry ¶
type SymlinkEntry struct {
Target string `json:"target" yaml:"target"`
Link string `json:"link" yaml:"link"`
}
SymlinkEntry represents a symlink entry.