GNU bug report logs - #51573
[PATCH] gnu: virtualization: Add qemu-guest-agent service.

Previous Next

Package: guix-patches;

Reported by: Timotej Lazar <timotej.lazar <at> araneo.si>

Date: Tue, 2 Nov 2021 19:09:01 UTC

Severity: normal

Tags: patch

Done: Ludovic Courtès <ludo <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 51573 in the body.
You can then email your comments to 51573 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to guix-patches <at> gnu.org:
bug#51573; Package guix-patches. (Tue, 02 Nov 2021 19:09:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Timotej Lazar <timotej.lazar <at> araneo.si>:
New bug report received and forwarded. Copy sent to guix-patches <at> gnu.org. (Tue, 02 Nov 2021 19:09:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Timotej Lazar <timotej.lazar <at> araneo.si>
To: guix-patches <at> gnu.org
Cc: Timotej Lazar <timotej.lazar <at> araneo.si>
Subject: [PATCH] gnu: virtualization: Add qemu-guest-agent service.
Date: Tue,  2 Nov 2021 20:06:32 +0100
* gnu/services/virtualization.scm (<qemu-guest-agent-configuration>): New
record.
(qemu-guest-agent-shepherd-service): New procedure.
(qemu-guest-agent-service-type): New variable.
* doc/guix.texi (Virtualization Services): Document it.
---
 doc/guix.texi                   | 47 ++++++++++++++++++++++++++++++++
 gnu/services/virtualization.scm | 48 ++++++++++++++++++++++++++++++++-
 2 files changed, 94 insertions(+), 1 deletion(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index ea1973f02c..5e6a6dea0e 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -30042,6 +30042,53 @@ Return the name of @var{platform}---a string such as @code{"arm"}.
 @end deffn
 
 
+@subsubheading QEMU guest agent
+
+@cindex emulation
+
+The QEMU guest agent provides control over the emulated system to the
+host.  The @code{qemu-guest-agent} service runs the agent on Guix
+guests.  To control the agent from the host, open a socket by invoking
+@code{qemu} with the following arguments:
+
+@example
+qemu-system-x86_64 \
+	-chardev socket,path=/tmp/qga.sock,server=on,wait=off,id=qga0 \
+	-device virtio-serial \
+	-device virtserialport,chardev=qga0,name=org.qemu.guest_agent.0 \
+	...
+@end example
+
+This creates a socket at @file{/tmp/qga.sock} on the host.  Once the
+guest agent is running, you can issue commands with @code{socat}:
+
+@example
+$ guix shell socat -- socat unix-connect:/tmp/qga.sock stdio
+@{"execute": "guest-get-host-name"@}
+@{"return": @{"host-name": "guix"@}@}
+@end example
+
+See @url{https://wiki.qemu.org/Features/GuestAgent,QEMU guest agent
+documentation} for more options and commands.
+
+@defvr {Scheme Variable} qemu-guest-agent-service-type
+Service type for the QEMU guest agent service.
+@end defvr
+
+@deftp {Data Type} qemu-guest-agent-configuration
+Configuration for the @code{qemu-guest-agent} service.
+
+@table @asis
+@item @code{qemu} (default: @code{qemu-minimal})
+The qemu package to use.
+
+@item @code{device} (default: @code{""})
+Path to device or socket the agent uses to communicate with the host.
+If empty, QEMU uses a default path.
+@end table
+@end deftp
+
+
 @subsubheading The Hurd in a Virtual Machine
 
 @cindex @code{hurd}
diff --git a/gnu/services/virtualization.scm b/gnu/services/virtualization.scm
index bca5f56b87..1a5744ffbf 100644
--- a/gnu/services/virtualization.scm
+++ b/gnu/services/virtualization.scm
@@ -2,6 +2,7 @@
 ;;; Copyright © 2017 Ryan Moe <ryan.moe <at> gmail.com>
 ;;; Copyright © 2018, 2020, 2021 Ludovic Courtès <ludo <at> gnu.org>
 ;;; Copyright © 2020,2021 Jan (janneke) Nieuwenhuizen <janneke <at> gnu.org>
+;;; Copyright © 2021 Timotej Lazar <timotej.lazar <at> araneo.si>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -82,7 +83,11 @@ (define-module (gnu services virtualization)
 
             qemu-binfmt-configuration
             qemu-binfmt-configuration?
-            qemu-binfmt-service-type))
+            qemu-binfmt-service-type
+
+            qemu-guest-agent-configuration
+            qemu-guest-agent-configuration?
+            qemu-guest-agent-service-type))
 
 (define (uglify-field-name field-name)
   (let ((str (symbol->string field-name)))
@@ -847,6 +852,47 @@ (define qemu-binfmt-service-type
 compiled for other architectures using QEMU and the @code{binfmt_misc}
 functionality of the kernel Linux.")))
 
+
+;;;
+;;; QEMU guest agent service.
+;;;
+
+(define-configuration qemu-guest-agent-configuration
+  (qemu
+   (package qemu-minimal)
+   "QEMU package.")
+  (device
+   (string "")
+   "Path to device or socket used to communicate with the host.  If not
+specified, the QEMU default path is used."))
+
+(define qemu-guest-agent-shepherd-service
+  (match-lambda
+    (($ <qemu-guest-agent-configuration> qemu device)
+     (list
+      (shepherd-service
+       (provision '(qemu-guest-agent))
+       (documentation "Run the QEMU guest agent.")
+       (start #~(make-forkexec-constructor
+                 `(,(string-append #$qemu "/bin/qemu-ga") "--daemon"
+                   "--pidfile=/var/run/qemu-ga.pid"
+                   "--statedir=/var/run"
+                   ,@(if #$device
+                         (list (string-append "--path=" #$device))
+                         '()))
+                 #:pid-file "/var/run/qemu-ga.pid"
+                 #:log-file "/var/log/qemu-ga.log"))
+       (stop #~(make-kill-destructor)))))))
+
+(define qemu-guest-agent-service-type
+  (service-type
+   (name 'qemu-guest-agent)
+   (extensions
+    (list (service-extension shepherd-root-service-type
+                             qemu-guest-agent-shepherd-service)))
+   (default-value (qemu-guest-agent-configuration))
+   (description "Run the QEMU guest agent.")))
+
 
 ;;;
 ;;; Secrets for guest VMs.
-- 
2.33.1





Reply sent to Ludovic Courtès <ludo <at> gnu.org>:
You have taken responsibility. (Fri, 12 Nov 2021 22:42:02 GMT) Full text and rfc822 format available.

Notification sent to Timotej Lazar <timotej.lazar <at> araneo.si>:
bug acknowledged by developer. (Fri, 12 Nov 2021 22:42:02 GMT) Full text and rfc822 format available.

Message #10 received at 51573-done <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: Timotej Lazar <timotej.lazar <at> araneo.si>
Cc: 51573-done <at> debbugs.gnu.org
Subject: Re: bug#51573: [PATCH] gnu: virtualization: Add qemu-guest-agent
 service.
Date: Fri, 12 Nov 2021 23:41:29 +0100
[Message part 1 (text/plain, inline)]
Hi,

Timotej Lazar <timotej.lazar <at> araneo.si> skribis:

> * gnu/services/virtualization.scm (<qemu-guest-agent-configuration>): New
> record.
> (qemu-guest-agent-shepherd-service): New procedure.
> (qemu-guest-agent-service-type): New variable.
> * doc/guix.texi (Virtualization Services): Document it.

Nice.  Do you think we could have a simple test under (gnu tests
virtualization) for this?

Applied with the cosmetic changes below.

Thanks!

Ludo’.

[Message part 2 (text/x-patch, inline)]
diff --git a/doc/guix.texi b/doc/guix.texi
index c0dfb2e5e2..7e54b5f75e 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -30060,14 +30060,14 @@ Return the name of @var{platform}---a string such as @code{"arm"}.
 @end deffn
 
 
-@subsubheading QEMU guest agent
+@subsubheading QEMU Guest Agent
 
 @cindex emulation
 
 The QEMU guest agent provides control over the emulated system to the
 host.  The @code{qemu-guest-agent} service runs the agent on Guix
 guests.  To control the agent from the host, open a socket by invoking
-@code{qemu} with the following arguments:
+QEMU with the following arguments:
 
 @example
 qemu-system-x86_64 \
@@ -30098,11 +30098,11 @@ Configuration for the @code{qemu-guest-agent} service.
 
 @table @asis
 @item @code{qemu} (default: @code{qemu-minimal})
-The qemu package to use.
+The QEMU package to use.
 
 @item @code{device} (default: @code{""})
-Path to device or socket the agent uses to communicate with the host.
-If empty, QEMU uses a default path.
+File name of the device or socket the agent uses to communicate with the
+host.  If empty, QEMU uses a default file name.
 @end table
 @end deftp
 

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sat, 11 Dec 2021 12:24:06 GMT) Full text and rfc822 format available.

This bug report was last modified 2 years and 98 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.