From f1643decb22c589e5c62f5bb720b8ff68804d623 Mon Sep 17 00:00:00 2001 From: phreakocious Date: Wed, 27 Apr 2022 09:55:19 -0500 Subject: [PATCH 1/5] 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 --- drivers/qemu/driver.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/qemu/driver.go b/drivers/qemu/driver.go index 4a3db808220a..97b6f8042203 100644 --- a/drivers/qemu/driver.go +++ b/drivers/qemu/driver.go @@ -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 @@ -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), }) @@ -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. @@ -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 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. From d74a1bcaa00199b81d1dc060593749ab652356a6 Mon Sep 17 00:00:00 2001 From: phreakocious Date: Wed, 27 Apr 2022 10:10:56 -0500 Subject: [PATCH 2/5] add documentation for guest_agent option --- website/content/docs/drivers/qemu.mdx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/website/content/docs/drivers/qemu.mdx b/website/content/docs/drivers/qemu.mdx index 7ba7630c36b2..8fed8710631c 100644 --- a/website/content/docs/drivers/qemu.mdx +++ b/website/content/docs/drivers/qemu.mdx @@ -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 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, which + must be running in the VM to work. This feature is currently not supported + on Windows. + - `port_map` - (Optional) A key-value map of port labels. ```hcl From a7f3feed725a4459ac5d3d0bcc28fb42d4e43ed5 Mon Sep 17 00:00:00 2001 From: phreakocious Date: Thu, 28 Apr 2022 09:11:40 -0500 Subject: [PATCH 3/5] Update website/content/docs/drivers/qemu.mdx Co-authored-by: Tim Gross --- website/content/docs/drivers/qemu.mdx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/website/content/docs/drivers/qemu.mdx b/website/content/docs/drivers/qemu.mdx index 8fed8710631c..30cb1bf0ee98 100644 --- a/website/content/docs/drivers/qemu.mdx +++ b/website/content/docs/drivers/qemu.mdx @@ -61,11 +61,11 @@ 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 the [QEMU Guest - Agent](https://wiki.qemu.org/Features/GuestAgent) for this virtual machine. This +- `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, which - must be running in the VM to work. This feature is currently not supported + 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. From 6d808467b83efb7f0e03fe57fc93e4d9810d50ae Mon Sep 17 00:00:00 2001 From: phreakocious Date: Thu, 28 Apr 2022 13:04:25 -0500 Subject: [PATCH 4/5] tweak wording for Windows error --- drivers/qemu/driver.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/qemu/driver.go b/drivers/qemu/driver.go index 97b6f8042203..821500771441 100644 --- a/drivers/qemu/driver.go +++ b/drivers/qemu/driver.go @@ -462,7 +462,7 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *drive if driverConfig.GuestAgent { if runtime.GOOS == "windows" { - return nil, nil, errors.New("QEMU Guest Agent is unsupported on the Windows platform") + 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) From 242f9b2f99c1741ef5f273380e4aaa4e12158308 Mon Sep 17 00:00:00 2001 From: Tim Gross Date: Mon, 6 Jun 2022 16:42:24 -0400 Subject: [PATCH 5/5] changelog entry --- .changelog/12800.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/12800.txt diff --git a/.changelog/12800.txt b/.changelog/12800.txt new file mode 100644 index 000000000000..b58a322a3348 --- /dev/null +++ b/.changelog/12800.txt @@ -0,0 +1,3 @@ +```release-note:improvement +qemu: add support for guest agent socket +```