Documentation
¶
Index ¶
- Variables
- func DestroyMdev(ctx context.Context, mdevUUID string) error
- func GetDeviceSysfsPath(pciAddress string) string
- func GetIOMMUGroupDevices(iommuGroup int) ([]string, error)
- func IsMdevInUse(mdevUUID string) bool
- func ReconcileMdevs(ctx context.Context, instanceInfos []MdevReconcileInfo) error
- func SetGPUProfileCacheTTL(ttl string)
- func ValidateDeviceName(name string) bool
- func ValidatePCIAddress(addr string) bool
- type AvailableDevice
- type CreateDeviceRequest
- type Device
- type DeviceType
- type GPUMode
- type GPUProfile
- type InstanceLivenessChecker
- type Manager
- type MdevDevice
- type MdevReconcileInfo
- type PassthroughDevice
- type VFIOBinder
- func (v *VFIOBinder) BindToVFIO(pciAddress string) error
- func (v *VFIOBinder) CheckIOMMUGroupSafe(pciAddress string, allowedDevices []string) error
- func (v *VFIOBinder) GetVFIOGroupPath(pciAddress string) (string, error)
- func (v *VFIOBinder) IsDeviceBoundToVFIO(pciAddress string) bool
- func (v *VFIOBinder) IsVFIOAvailable() bool
- func (v *VFIOBinder) UnbindFromVFIO(pciAddress string) error
- type VirtualFunction
Constants ¶
This section is empty.
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") )
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
var ErrNotSupportedOnMacOS = fmt.Errorf("PCI device passthrough is not supported on macOS")
ErrNotSupportedOnMacOS is returned for operations not supported on macOS
var ErrVFIONotSupportedOnMacOS = fmt.Errorf("VFIO device passthrough is not supported on macOS")
ErrVFIONotSupportedOnMacOS is returned for VFIO operations on macOS
var ErrVGPUNotSupportedOnMacOS = fmt.Errorf("vGPU (mdev) is not supported on macOS")
ErrVGPUNotSupportedOnMacOS is returned for vGPU operations on macOS
Functions ¶
func DestroyMdev ¶ added in v0.0.5
DestroyMdev is a no-op on macOS.
func GetDeviceSysfsPath ¶
GetDeviceSysfsPath returns an empty string on macOS.
func GetIOMMUGroupDevices ¶
GetIOMMUGroupDevices returns an error on macOS as IOMMU is not available.
func IsMdevInUse ¶ added in v0.0.5
IsMdevInUse returns false on macOS.
func ReconcileMdevs ¶ added in v0.0.5
func ReconcileMdevs(ctx context.Context, instanceInfos []MdevReconcileInfo) error
ReconcileMdevs is a no-op on macOS.
func SetGPUProfileCacheTTL ¶ added in v0.0.6
func SetGPUProfileCacheTTL(ttl string)
SetGPUProfileCacheTTL is a no-op on macOS.
func ValidateDeviceName ¶
ValidateDeviceName validates that a device name matches the required pattern
func ValidatePCIAddress ¶
ValidatePCIAddress validates that a string is a valid PCI address format. On macOS, this always returns false as PCI passthrough is not supported.
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
func DiscoverAvailableDevices ¶
func DiscoverAvailableDevices() ([]AvailableDevice, error)
DiscoverAvailableDevices returns an empty list on macOS. PCI device passthrough is not supported on macOS.
func GetDeviceInfo ¶
func GetDeviceInfo(pciAddress string) (*AvailableDevice, error)
GetDeviceInfo returns an error on macOS as PCI passthrough is not supported.
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")
}
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
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" )
func DetermineDeviceType ¶
func DetermineDeviceType(device *AvailableDevice) DeviceType
DetermineDeviceType returns DeviceTypeGeneric on macOS.
type GPUMode ¶ added in v0.0.5
type GPUMode string
GPUMode represents the host's GPU configuration mode
func DetectHostGPUMode ¶ added in v0.0.5
func DetectHostGPUMode() GPUMode
DetectHostGPUMode determines the host's GPU configuration mode.
Returns:
- GPUModeVGPU if /sys/class/mdev_bus has entries (SR-IOV VFs present)
- GPUModePassthrough if NVIDIA GPUs are available for VFIO passthrough
- GPUModeNone if no GPUs are available
Note: A host is configured for either vGPU or passthrough, not both, because the host driver determines which mode is available.
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"` // number of VFs that can create this profile
}
GPUProfile describes an available vGPU profile type
func ListGPUProfiles ¶ added in v0.0.5
func ListGPUProfiles() ([]GPUProfile, error)
ListGPUProfiles returns an empty list on macOS.
func ListGPUProfilesWithVFs ¶ added in v0.0.5
func ListGPUProfilesWithVFs(vfs []VirtualFunction) ([]GPUProfile, error)
ListGPUProfilesWithVFs returns an empty list on macOS.
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)
func CreateMdev ¶ added in v0.0.5
func CreateMdev(ctx context.Context, profileName, instanceID string) (*MdevDevice, error)
CreateMdev returns an error on macOS as mdev is not supported.
func ListMdevDevices ¶ added in v0.0.5
func ListMdevDevices() ([]MdevDevice, error)
ListMdevDevices returns an empty list on macOS.
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 VFIOBinder ¶
type VFIOBinder struct{}
VFIOBinder handles binding and unbinding devices to/from VFIO. On macOS, this is a stub that returns errors for all operations.
func (*VFIOBinder) BindToVFIO ¶
func (v *VFIOBinder) BindToVFIO(pciAddress string) error
BindToVFIO returns an error on macOS as VFIO is not supported.
func (*VFIOBinder) CheckIOMMUGroupSafe ¶
func (v *VFIOBinder) CheckIOMMUGroupSafe(pciAddress string, allowedDevices []string) error
CheckIOMMUGroupSafe returns an error on macOS as IOMMU is not available.
func (*VFIOBinder) GetVFIOGroupPath ¶
func (v *VFIOBinder) GetVFIOGroupPath(pciAddress string) (string, error)
GetVFIOGroupPath returns an error on macOS as VFIO is not supported.
func (*VFIOBinder) IsDeviceBoundToVFIO ¶
func (v *VFIOBinder) IsDeviceBoundToVFIO(pciAddress string) bool
IsDeviceBoundToVFIO returns false on macOS.
func (*VFIOBinder) IsVFIOAvailable ¶
func (v *VFIOBinder) IsVFIOAvailable() bool
IsVFIOAvailable returns false on macOS as VFIO is not available.
func (*VFIOBinder) UnbindFromVFIO ¶
func (v *VFIOBinder) UnbindFromVFIO(pciAddress string) error
UnbindFromVFIO returns an error on macOS as VFIO is not supported.
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"
HasMdev bool `json:"has_mdev"` // true if an mdev is created on this VF
}
VirtualFunction represents an SR-IOV Virtual Function for vGPU
func DiscoverVFs ¶ added in v0.0.5
func DiscoverVFs() ([]VirtualFunction, error)
DiscoverVFs returns an empty list on macOS. SR-IOV Virtual Functions are not available on macOS.