Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add guest_agent config option for QEMU driver #12800

Merged
merged 5 commits into from
Jun 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/12800.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
qemu: add support for guest agent socket
```
16 changes: 16 additions & 0 deletions drivers/qemu/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ const (
qemuGracefulShutdownMsg = "system_powerdown\n"
qemuMonitorSocketName = "qemu-monitor.sock"

// Socket file enabling communication with the Qemu Guest Agent (if enabled and running)
qemuGuestAgentSocketName = "qemu-guest-agent.sock"

// Maximum socket path length prior to qemu 2.10.1
qemuLegacyMaxMonitorPathLen = 108

Expand Down Expand Up @@ -94,6 +97,7 @@ var (
"image_path": hclspec.NewAttr("image_path", "string", true),
"accelerator": hclspec.NewAttr("accelerator", "string", false),
"graceful_shutdown": hclspec.NewAttr("graceful_shutdown", "bool", false),
"guest_agent": hclspec.NewAttr("guest_agent", "bool", false),
"args": hclspec.NewAttr("args", "list(string)", false),
"port_map": hclspec.NewAttr("port_map", "list(map(number))", false),
})
Expand Down Expand Up @@ -121,6 +125,7 @@ type TaskConfig struct {
Args []string `codec:"args"` // extra arguments to qemu executable
PortMap hclutils.MapStrInt `codec:"port_map"` // A map of host port and the port name defined in the image manifest file
GracefulShutdown bool `codec:"graceful_shutdown"`
GuestAgent bool `codec:"guest_agent"`
}

// TaskState is the state which is encoded in the handle returned in StartTask.
Expand Down Expand Up @@ -455,6 +460,17 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *drive
args = append(args, "-monitor", fmt.Sprintf("unix:%s,server,nowait", monitorPath))
}

if driverConfig.GuestAgent {
if runtime.GOOS == "windows" {
return nil, nil, errors.New("QEMU Guest Agent socket is unsupported on the Windows platform")
}
// This socket will be used to communicate with the Guest Agent (if it's running)
taskDir := filepath.Join(cfg.AllocDir, cfg.Name)
args = append(args, "-chardev", fmt.Sprintf("socket,path=%s/%s,server,nowait,id=qga0", taskDir, qemuGuestAgentSocketName))
args = append(args, "-device", "virtio-serial")
args = append(args, "-device", "virtserialport,chardev=qga0,name=org.qemu.guest_agent.0")
tgross marked this conversation as resolved.
Show resolved Hide resolved
}

// Add pass through arguments to qemu executable. A user can specify
// these arguments in driver task configuration. These arguments are
// passed directly to the qemu driver as command line options.
Expand Down
7 changes: 7 additions & 0 deletions website/content/docs/drivers/qemu.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ The `qemu` driver supports the following configuration in the job spec:
[alloc_dir](/docs/configuration/client#alloc_dir)
paths.) This feature is currently not supported on Windows.

- `guest_agent` `(bool: false)` - Enable support for the [QEMU Guest
Agent](https://wiki.qemu.org/Features/GuestAgent) for this virtual machine. This
will add the necessary virtual hardware and create a `qemu-guest-agent.sock`
file in the task's working directory for interacting with the agent. The QEMU Guest
Agent must be running in the guest VM. This feature is currently not supported
on Windows.

- `port_map` - (Optional) A key-value map of port labels.

```hcl
Expand Down