qemu

package
v0.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 16, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

Package qemu implements the hypervisor.Hypervisor interface for QEMU.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildArgs

func BuildArgs(cfg hypervisor.VMConfig) []string

BuildArgs converts hypervisor.VMConfig to QEMU command-line arguments.

func NewVsockDialer

func NewVsockDialer(vsockSocket string, vsockCID int64) hypervisor.VsockDialer

NewVsockDialer creates a new VsockDialer for QEMU. The vsockSocket parameter is unused for QEMU (it uses CID instead). The vsockCID is the guest's Context ID assigned via vhost-vsock-pci.

func Remove

func Remove(socketPath string)

Remove closes and removes a client from the pool. Called automatically on errors to allow fresh reconnection. Close is done asynchronously to avoid blocking if the connection is in a bad state.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client wraps go-qemu's Domain and raw.Monitor with convenience methods.

func NewClient

func NewClient(socketPath string) (*Client, error)

NewClient creates a new QEMU client connected to the given socket.

func (*Client) Close

func (c *Client) Close() error

Close disconnects from the QMP socket.

func (*Client) Continue

func (c *Client) Continue() error

Continue resumes VM execution (QMP 'cont' command).

func (*Client) Events

func (c *Client) Events() (chan qmp.Event, chan struct{}, error)

Events returns a channel for receiving QEMU events.

func (*Client) Migrate

func (c *Client) Migrate(uri string) error

Migrate initiates a migration to the given URI (typically "file:///path"). This is used for saving VM state to a file for snapshot/standby.

func (*Client) QueryMigration

func (c *Client) QueryMigration() (raw.MigrationInfo, error)

QueryMigration returns the current migration status.

func (*Client) Quit

func (c *Client) Quit() error

Quit shuts down QEMU (QMP 'quit' command).

func (*Client) Run

func (c *Client) Run(cmd qmp.Command) ([]byte, error)

Run executes a raw QMP command (for commands not yet wrapped).

func (*Client) Status

func (c *Client) Status() (qemu.Status, error)

Status returns the current VM status as a typed enum.

func (*Client) StatusInfo

func (c *Client) StatusInfo() (raw.StatusInfo, error)

StatusInfo returns detailed status information from the raw monitor.

func (*Client) Stop

func (c *Client) Stop() error

Stop pauses VM execution (QMP 'stop' command).

func (*Client) SystemPowerdown

func (c *Client) SystemPowerdown() error

SystemPowerdown sends ACPI power button event (graceful shutdown).

func (*Client) SystemReset

func (c *Client) SystemReset() error

SystemReset resets the VM (hard reset).

func (*Client) Version

func (c *Client) Version() (string, error)

Version returns the QEMU version string.

func (*Client) WaitMigration

func (c *Client) WaitMigration(ctx context.Context, timeout time.Duration) error

WaitMigration polls until an outgoing migration completes or times out. Used for snapshot/standby operations where we initiate the migration. Returns nil if migration completed successfully, error otherwise.

func (*Client) WaitVMReady

func (c *Client) WaitVMReady(ctx context.Context, timeout time.Duration) error

WaitVMReady polls until the VM is ready after an incoming migration. Used for restore operations where QEMU was started with -incoming. The VM transitions from "inmigrate" to "paused" when migration data is loaded. Returns nil when VM is ready for resume, error on timeout or failure.

type QEMU

type QEMU struct {
	// contains filtered or unexported fields
}

QEMU implements hypervisor.Hypervisor for QEMU VMM.

func GetOrCreate

func GetOrCreate(socketPath string) (*QEMU, error)

GetOrCreate returns an existing QEMU client for the socket path, or creates a new one if none exists.

func New

func New(socketPath string) (*QEMU, error)

New returns a QEMU client for the given socket path. Uses a connection pool to ensure only one connection per socket exists.

func (*QEMU) Capabilities

func (q *QEMU) Capabilities() hypervisor.Capabilities

Capabilities returns the features supported by QEMU.

func (*QEMU) DeleteVM

func (q *QEMU) DeleteVM(ctx context.Context) error

DeleteVM removes the VM configuration from QEMU. This sends a graceful shutdown signal to the guest.

func (*QEMU) GetVMInfo

func (q *QEMU) GetVMInfo(ctx context.Context) (*hypervisor.VMInfo, error)

GetVMInfo returns current VM state.

func (*QEMU) Pause

func (q *QEMU) Pause(ctx context.Context) error

Pause suspends VM execution.

func (*QEMU) ResizeMemory

func (q *QEMU) ResizeMemory(ctx context.Context, bytes int64) error

ResizeMemory changes the VM's memory allocation. Not implemented in first pass.

func (*QEMU) ResizeMemoryAndWait

func (q *QEMU) ResizeMemoryAndWait(ctx context.Context, bytes int64, timeout time.Duration) error

ResizeMemoryAndWait changes the VM's memory allocation and waits for it to stabilize. Not implemented in first pass.

func (*QEMU) Resume

func (q *QEMU) Resume(ctx context.Context) error

Resume continues VM execution.

func (*QEMU) Shutdown

func (q *QEMU) Shutdown(ctx context.Context) error

Shutdown stops the QEMU process.

func (*QEMU) Snapshot

func (q *QEMU) Snapshot(ctx context.Context, destPath string) error

Snapshot creates a VM snapshot using QEMU's migrate-to-file mechanism. The VM state is saved to destPath/memory file. The VM config is copied to destPath for restore (QEMU requires exact arg match).

type Starter

type Starter struct{}

Starter implements hypervisor.VMStarter for QEMU.

func NewStarter

func NewStarter() *Starter

NewStarter creates a new QEMU starter.

func (*Starter) GetBinaryPath

func (s *Starter) GetBinaryPath(p *paths.Paths, version string) (string, error)

GetBinaryPath returns the path to the QEMU binary. QEMU is expected to be installed on the system.

func (*Starter) GetVersion

func (s *Starter) GetVersion(p *paths.Paths) (string, error)

GetVersion returns the version of the installed QEMU binary. Parses the output of "qemu-system-* --version" to extract the version string.

func (*Starter) RestoreVM

func (s *Starter) RestoreVM(ctx context.Context, p *paths.Paths, version string, socketPath string, snapshotPath string) (int, hypervisor.Hypervisor, error)

RestoreVM starts QEMU and restores VM state from a snapshot. The VM is in paused state after restore; caller should call Resume() to continue execution.

func (*Starter) SocketName

func (s *Starter) SocketName() string

SocketName returns the socket filename for QEMU.

func (*Starter) StartVM

func (s *Starter) StartVM(ctx context.Context, p *paths.Paths, version string, socketPath string, config hypervisor.VMConfig) (int, hypervisor.Hypervisor, error)

StartVM launches QEMU with the VM configuration and returns a Hypervisor client. QEMU receives all configuration via command-line arguments at process start.

type VsockDialer

type VsockDialer struct {
	// contains filtered or unexported fields
}

VsockDialer implements hypervisor.VsockDialer for QEMU. QEMU with vhost-vsock-pci uses the kernel's native AF_VSOCK socket family. Connections are made using the guest's CID (Context ID) and port number.

func (*VsockDialer) DialVsock

func (d *VsockDialer) DialVsock(ctx context.Context, port int) (net.Conn, error)

DialVsock connects to the guest on the specified port using AF_VSOCK. This uses the kernel's vsock infrastructure with the guest's CID.

func (*VsockDialer) Key

func (d *VsockDialer) Key() string

Key returns a unique identifier for this dialer, used for connection pooling.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL