Skip to content

Commit

Permalink
Add device passthrough support for libvirt platform
Browse files Browse the repository at this point in the history
Implement device passthrough for libvirt platform
Use device pool and extend the functionality for libvirt platform
Schema change to configure device pool from runbook
Set each node context based on requirement for device pass-through

Signed-off-by: Smit Gardhariya <[email protected]>
  • Loading branch information
smit-gardhariya committed Aug 30, 2024
1 parent d49ded8 commit 1b2176b
Show file tree
Hide file tree
Showing 5 changed files with 440 additions and 1 deletion.
13 changes: 13 additions & 0 deletions lisa/sut_orchestrator/libvirt/ch_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ def _create_node_domain_xml(
os_kernel.text = node_context.firmware_path

devices = ET.SubElement(domain, "devices")
if len(node_context.passthrough_devices) > 0:
devices = self.device_pool._add_device_passthrough_xml(
devices,
node_context,
)

console = ET.SubElement(devices, "console")
console.attrib["type"] = "pty"
Expand Down Expand Up @@ -171,6 +176,14 @@ def _create_domain_and_attach_logger(
node_context.domain, node_context.console_log_file_path
)

if len(node_context.passthrough_devices) > 0:
# Once libvirt domain is created, check if driver attached to device
# on the host is vfio-pci for PCI device passthrough to make sure if
# pass-through for PCI device is happened properly or not
self.device_pool._verify_device_passthrough_post_boot(
node_context=node_context,
)

# Create the OS disk.
def _create_node_os_disk(
self, environment: Environment, log: Logger, node: Node
Expand Down
17 changes: 16 additions & 1 deletion lisa/sut_orchestrator/libvirt/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@

from lisa.environment import Environment
from lisa.node import Node
from lisa.sut_orchestrator.util.schema import HostDevicePoolType

from .console_logger import QemuConsoleLogger
from .schema import DiskImageFormat
from .schema import DeviceAddressSchema, DiskImageFormat


@dataclass
Expand All @@ -33,6 +34,15 @@ class InitSystem:
IGNITION: str = "ignition"


@dataclass
class DevicePassthroughContext:
pool_type: HostDevicePoolType = HostDevicePoolType.PCI_NIC
device_list: List[DeviceAddressSchema] = field(
default_factory=list,
)
managed: str = ""


@dataclass
class NodeContext:
vm_name: str = ""
Expand All @@ -57,6 +67,11 @@ class NodeContext:
console_logger: Optional[QemuConsoleLogger] = None
domain: Optional[libvirt.virDomain] = None

# Device pass through configuration
passthrough_devices: List[DevicePassthroughContext] = field(
default_factory=list,
)


def get_environment_context(environment: Environment) -> EnvironmentContext:
return environment.get_context(EnvironmentContext)
Expand Down
Loading

0 comments on commit 1b2176b

Please sign in to comment.