Documentation
¶
Index ¶
- Constants
- Variables
- func FormatVFAssignedAt(claimedAt time.Time) string
- func InitVFHealth(path string, threshold int) error
- func QuarantinedVFAddresses() (map[string]struct{}, error)
- func RepairVFHealthStore() error
- func TotalQuarantinedVFs() int
- func VFHealthStoreUnavailable() bool
- func ValidateDeviceName(name string) bool
- type AvailableDevice
- type CreateDeviceRequest
- type Device
- type DeviceType
- type GPUMode
- type GPUProfile
- type HostCapabilities
- type InstanceLivenessChecker
- type Manager
- type MdevDevice
- type MdevReconcileInfo
- type PassthroughDevice
- type VFInitFailureReport
- type VFInitSuccessReport
- type VFReportOutcome
- type VFReportResult
- type VFSuccessResult
- type VGPUAssignment
- type VGPUAvailability
- type VGPUDevice
- type VGPUFramework
- type VGPUProfileType
- type VirtualFunction
Constants ¶
const ( VGPUFrameworkNone VGPUFramework = "" VGPUFrameworkMdev VGPUFramework = "mdev" VGPUFrameworkVendorVFIO VGPUFramework = "vendor-vfio" // GPUModePassthrough indicates whole GPU VFIO passthrough GPUModePassthrough GPUMode = "passthrough" // GPUModeVGPU indicates vGPU mode GPUModeVGPU GPUMode = "vgpu" // GPUModeNone indicates no GPU available GPUModeNone GPUMode = "none" )
Variables ¶
var ( // ErrNotFound is returned when a device is not found ErrNotFound = errors.New("device not found") // ErrInUse is returned when a device is currently attached to an instance ErrInUse = errors.New("device is in use") // ErrNotBound is returned when a VFIO operation requires the device to be bound ErrNotBound = errors.New("device is not bound to VFIO") // ErrAlreadyBound is returned when trying to bind a device that's already bound to VFIO ErrAlreadyBound = errors.New("device is already bound to VFIO") // ErrAlreadyExists is returned when trying to register a device that already exists ErrAlreadyExists = errors.New("device already exists") // ErrInvalidName is returned when the device name doesn't match the required pattern ErrInvalidName = errors.New("device name must match pattern ^[a-zA-Z0-9][a-zA-Z0-9_.-]+$") // ErrNameExists is returned when a device with the same name already exists ErrNameExists = errors.New("device name already exists") // ErrInvalidPCIAddress is returned when the PCI address format is invalid ErrInvalidPCIAddress = errors.New("invalid PCI address format") // ErrDeviceNotFound is returned when the PCI device doesn't exist on the host ErrDeviceNotFound = errors.New("PCI device not found on host") // ErrVFIONotAvailable is returned when VFIO modules are not loaded ErrVFIONotAvailable = errors.New("VFIO is not available (modules not loaded)") // ErrIOMMUGroupConflict is returned when not all devices in IOMMU group can be passed through ErrIOMMUGroupConflict = errors.New("IOMMU group contains other devices that must also be passed through") // ErrVGPUNotSupportedOnMacOS is returned for vGPU operations on macOS ErrVGPUNotSupportedOnMacOS = errors.New("vGPU (mdev) is not supported on macOS") )
var DeviceNamePattern = regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9_.-]+$`)
DeviceNamePattern is the regex pattern for valid device names Must start with alphanumeric, followed by alphanumeric, underscore, dot, or dash
Functions ¶
func FormatVFAssignedAt ¶ added in v0.4.0
FormatVFAssignedAt renders a claim time as the AssignedAt key used in VF health reports.
func InitVFHealth ¶ added in v0.4.0
InitVFHealth loads persisted VF health state from path and evaluates the loaded tallies against threshold, the number of failed assignments that quarantine a VF. A lowered threshold therefore applies to failures persisted before the change. An error leaves the store unavailable, which fails vGPU placement closed until a later load or write succeeds. An empty path keeps state in memory only.
func QuarantinedVFAddresses ¶ added in v0.4.0
QuarantinedVFAddresses returns the PCI addresses of quarantined VFs. It fails while the health store is unavailable so placement fails closed.
func RepairVFHealthStore ¶ added in v0.4.0
func RepairVFHealthStore() error
RepairVFHealthStore retries a failed load or persist so the store recovers without waiting for a placement or /resources read to do it. It takes vendorVFIOMu like the report paths, so a reload that changes the quarantine set cannot interleave with a vendor-VFIO configure. The same retry also runs from checkedAddresses under only s.mu; there, configure's own re-check under vendorVFIOMu covers the selection-to-configure window instead. It returns without taking either lock while the store is healthy.
func TotalQuarantinedVFs ¶ added in v0.4.0
func TotalQuarantinedVFs() int
TotalQuarantinedVFs returns the number of quarantined VFs in persisted state.
func VFHealthStoreUnavailable ¶ added in v0.4.0
func VFHealthStoreUnavailable() bool
VFHealthStoreUnavailable reports whether persisted state failed to load or the last write failed.
func ValidateDeviceName ¶
ValidateDeviceName validates that a device name matches the required pattern
Types ¶
type AvailableDevice ¶
type AvailableDevice struct {
PCIAddress string `json:"pci_address"`
VendorID string `json:"vendor_id"`
DeviceID string `json:"device_id"`
VendorName string `json:"vendor_name"`
DeviceName string `json:"device_name"`
IOMMUGroup int `json:"iommu_group"`
CurrentDriver *string `json:"current_driver"` // nil if no driver bound
}
AvailableDevice represents a PCI device discovered on the host
type CreateDeviceRequest ¶
type CreateDeviceRequest struct {
Name string `json:"name,omitempty"` // optional: globally unique name (auto-generated if not provided)
PCIAddress string `json:"pci_address"` // required: PCI address (e.g., "0000:a2:00.0")
Tags tags.Tags `json:"tags,omitempty"`
}
CreateDeviceRequest is the request to register a new device
type Device ¶
type Device struct {
Id string `json:"id"` // cuid2 identifier
Name string `json:"name"` // user-provided globally unique name
Type DeviceType `json:"type"` // gpu or pci
Tags tags.Tags `json:"tags,omitempty"` // user-defined key-value tags
PCIAddress string `json:"pci_address"` // e.g., "0000:a2:00.0"
VendorID string `json:"vendor_id"` // e.g., "10de"
DeviceID string `json:"device_id"` // e.g., "27b8"
IOMMUGroup int `json:"iommu_group"` // IOMMU group number
BoundToVFIO bool `json:"bound_to_vfio"` // whether device is bound to vfio-pci
AttachedTo *string `json:"attached_to"` // instance ID if attached, nil otherwise
CreatedAt time.Time `json:"created_at"`
}
Device represents a registered PCI device for passthrough
type DeviceType ¶
type DeviceType string
DeviceType represents the type of PCI device
const ( DeviceTypeGPU DeviceType = "gpu" DeviceTypeGeneric DeviceType = "pci" )
type GPUMode ¶ added in v0.0.5
type GPUMode string
GPUMode represents the host's GPU configuration mode
type GPUProfile ¶ added in v0.0.5
type GPUProfile struct {
Name string `json:"name"` // user-facing name, e.g., "L40S-1Q"
FramebufferMB int `json:"framebuffer_mb"` // frame buffer size in MB
Available int `json:"available"` // more instances that fit if only this profile is added
}
GPUProfile describes an available vGPU profile type
type HostCapabilities ¶ added in v0.4.0
type HostCapabilities struct {
// SupportsVGPU indicates whether the platform supports mediated vGPU operations.
SupportsVGPU bool
}
HostCapabilities describes optional device features supported by the host platform.
type InstanceLivenessChecker ¶
type InstanceLivenessChecker interface {
// IsInstanceRunning returns true if the instance exists and is in a running state
// (i.e., has an active VMM process). Returns false if the instance doesn't exist
// or is stopped/standby/unknown.
IsInstanceRunning(ctx context.Context, instanceID string) bool
// GetInstanceDevices returns the list of device IDs attached to an instance.
// Returns nil if the instance doesn't exist.
GetInstanceDevices(ctx context.Context, instanceID string) []string
// ListAllInstanceDevices returns a map of instanceID -> []deviceIDs for all instances.
ListAllInstanceDevices(ctx context.Context) map[string][]string
// DetectSuspiciousVMMProcesses finds cloud-hypervisor processes that don't match
// known instances and logs warnings. Returns the count of suspicious processes found.
DetectSuspiciousVMMProcesses(ctx context.Context) int
}
InstanceLivenessChecker provides a way to check if an instance is running. This interface allows devices to query instance state without a circular dependency.
type Manager ¶
type Manager interface {
// ListDevices returns all registered devices
ListDevices(ctx context.Context) ([]Device, error)
// ListAvailableDevices discovers passthrough-capable devices on the host
ListAvailableDevices(ctx context.Context) ([]AvailableDevice, error)
// CreateDevice registers a new device for passthrough
CreateDevice(ctx context.Context, req CreateDeviceRequest) (*Device, error)
// GetDevice returns a device by ID or name
GetDevice(ctx context.Context, idOrName string) (*Device, error)
// DeleteDevice unregisters a device
DeleteDevice(ctx context.Context, id string) error
// BindToVFIO binds a device to vfio-pci driver
BindToVFIO(ctx context.Context, id string) error
// UnbindFromVFIO unbinds a device from vfio-pci driver
UnbindFromVFIO(ctx context.Context, id string) error
// MarkAttached marks a device as attached to an instance
MarkAttached(ctx context.Context, deviceID, instanceID string) error
// MarkDetached marks a device as detached from an instance
MarkDetached(ctx context.Context, deviceID string) error
// ReconcileDevices cleans up stale device state on startup.
// It detects devices with AttachedTo referencing non-existent instances
// and clears the orphaned attachment state.
ReconcileDevices(ctx context.Context) error
// SetLivenessChecker sets the instance liveness checker after construction.
// This allows breaking the circular dependency between device and instance managers.
SetLivenessChecker(checker InstanceLivenessChecker)
}
Manager provides device management operations
func NewManager ¶
NewManager creates a new device manager. Use SetLivenessChecker after construction to enable accurate orphan detection.
type MdevDevice ¶ added in v0.0.5
type MdevDevice struct {
UUID string `json:"uuid"` // e.g., "aa618089-8b16-4d01-a136-25a0f3c73123"
VFAddress string `json:"vf_address"` // VF this mdev resides on
ProfileType string `json:"profile_type"` // internal type name, e.g., "nvidia-556"
ProfileName string `json:"profile_name"` // user-facing name, e.g., "L40S-1Q"
SysfsPath string `json:"sysfs_path"` // path for VMM device attachment
InstanceID string `json:"instance_id"` // instance this mdev is attached to
}
MdevDevice represents an active mediated device (vGPU instance)
type MdevReconcileInfo ¶ added in v0.0.5
type MdevReconcileInfo struct {
InstanceID string
MdevUUID string
IsRunning bool // true if instance's VMM is running or state is unknown
}
MdevReconcileInfo contains information needed to reconcile mdevs for an instance
type PassthroughDevice ¶ added in v0.0.5
type PassthroughDevice struct {
Name string `json:"name"` // GPU name, e.g., "NVIDIA L40S"
Available bool `json:"available"` // true if not attached to an instance
}
PassthroughDevice describes a physical GPU available for passthrough
type VFInitFailureReport ¶ added in v0.4.0
VFInitFailureReport describes one guest-reported driver init failure.
InstanceID and AssignedAt together identify the assignment. AssignedAt is the instance's stored GPUClaimedAt rendered with FormatVFAssignedAt; a success report only clears a failure whose AssignedAt string matches exactly, so every reporter must use that formatting.
type VFInitSuccessReport ¶ added in v0.4.0
VFInitSuccessReport identifies the assignment that successfully initialized. AssignedAt follows the same format as VFInitFailureReport.AssignedAt.
A success clears the matched failure and every older tally. It rescinds a quarantine only when the matched failure is the most recent one recorded: the report that crossed the threshold, or the newest tally when a lowered threshold quarantined the VF at load.
type VFReportOutcome ¶ added in v0.4.0
type VFReportOutcome int
VFReportOutcome describes how a failure report changed a VF's health state.
const ( // VFReportUnchanged means the VF was already quarantined or this // assignment was already recorded. VFReportUnchanged VFReportOutcome = iota // VFReportRecorded means the failure was tallied below the quarantine threshold. VFReportRecorded // VFReportQuarantined means this report crossed the threshold and quarantined the VF. VFReportQuarantined )
type VFReportResult ¶ added in v0.4.0
type VFReportResult struct {
Outcome VFReportOutcome
Failures int
Threshold int
}
VFReportResult is the outcome of recording a driver init failure.
func ReportVFInitFailure ¶ added in v0.4.0
func ReportVFInitFailure(report VFInitFailureReport) (VFReportResult, error)
ReportVFInitFailure records a guest-reported driver init failure and quarantines the VF once failures from enough distinct assignments accumulate.
type VFSuccessResult ¶ added in v0.4.0
VFSuccessResult describes how a successful init changed a VF's health state.
func ReportVFInitSuccess ¶ added in v0.4.0
func ReportVFInitSuccess(report VFInitSuccessReport) (VFSuccessResult, error)
ReportVFInitSuccess clears failures through an exactly matched successful assignment. A quarantine is rescinded only when that assignment triggered it.
type VGPUAssignment ¶ added in v0.4.0
type VGPUAssignment struct {
Framework VGPUFramework
DevicePath string
MdevUUID string
InstanceID string
}
VGPUAssignment identifies an existing vGPU assignment to release.
type VGPUAvailability ¶ added in v0.4.0
type VGPUAvailability struct {
AllocatableSlots int // free VFs eligible for placement
QuarantinedSlots int
Quarantined map[string]struct{} // PCI addresses of quarantined VFs
}
VGPUAvailability is one VF health snapshot applied to discovered VFs. Pass Quarantined to ListGPUProfilesWithVFs so profile availability is computed from the same snapshot without reading the store again.
func GetVGPUAvailability ¶ added in v0.4.0
func GetVGPUAvailability(framework VGPUFramework, vfs []VirtualFunction) (VGPUAvailability, error)
GetVGPUAvailability counts free allocatable and quarantined VFs. It fails while the health store is unavailable so callers fail closed.
type VGPUDevice ¶ added in v0.4.0
type VGPUFramework ¶ added in v0.4.0
type VGPUFramework string
type VGPUProfileType ¶ added in v0.4.0
VGPUProfileType describes a driver profile that can be configured on a VF.
type VirtualFunction ¶ added in v0.0.5
type VirtualFunction struct {
PCIAddress string `json:"pci_address"` // e.g., "0000:82:00.4"
ParentGPU string `json:"parent_gpu"` // e.g., "0000:82:00.0"
Allocated bool `json:"allocated"` // true if a vGPU is assigned to this VF
ProfileType string `json:"profile_type,omitempty"`
}
VirtualFunction represents an SR-IOV Virtual Function for vGPU