Skip to content

Commit

Permalink
Add guest_agent config option for QEMU driver (#12800)
Browse files Browse the repository at this point in the history
Add boolean 'guest_agent' config option for QEMU driver, which will
create the socket file for the QEMU Guest Agent in the task dir when
enabled.
  • Loading branch information
phreakocious committed Jun 9, 2022
1 parent e78a590 commit f877436
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
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 @@ -450,6 +455,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")
}

// 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

0 comments on commit f877436

Please sign in to comment.