From patchwork Tue Nov 2 19:06:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Timotej Lazar X-Patchwork-Id: 34215 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id B3C9927BBE3; Tue, 2 Nov 2021 19:09:14 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,T_DKIM_INVALID, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 3596E27BBE1 for ; Tue, 2 Nov 2021 19:09:14 +0000 (GMT) Received: from localhost ([::1]:34320 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mhz9l-0004mp-7k for patchwork@mira.cbaines.net; Tue, 02 Nov 2021 15:09:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51340) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mhz9a-0004dh-Hz for guix-patches@gnu.org; Tue, 02 Nov 2021 15:09:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:54795) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mhz9a-0004G2-84 for guix-patches@gnu.org; Tue, 02 Nov 2021 15:09:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mhz9a-0006iW-30 for guix-patches@gnu.org; Tue, 02 Nov 2021 15:09:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#51573] [PATCH] gnu: virtualization: Add qemu-guest-agent service. Resent-From: Timotej Lazar Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 02 Nov 2021 19:09:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 51573 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 51573@debbugs.gnu.org Cc: Timotej Lazar X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.163588008525750 (code B ref -1); Tue, 02 Nov 2021 19:09:01 +0000 Received: (at submit) by debbugs.gnu.org; 2 Nov 2021 19:08:05 +0000 Received: from localhost ([127.0.0.1]:38108 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mhz8f-0006hG-Fm for submit@debbugs.gnu.org; Tue, 02 Nov 2021 15:08:05 -0400 Received: from lists.gnu.org ([209.51.188.17]:33814) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mhz8c-0006h7-3T for submit@debbugs.gnu.org; Tue, 02 Nov 2021 15:08:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50954) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mhz8c-0003I9-0Y for guix-patches@gnu.org; Tue, 02 Nov 2021 15:08:02 -0400 Received: from araneo.si ([2001:15c0:2110:3400::2]:34010) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mhz8X-00043t-6D for guix-patches@gnu.org; Tue, 02 Nov 2021 15:08:01 -0400 Received: from araneo.si (localhost.lan [127.0.0.1]) by araneo.si (OpenSMTPD) with ESMTP id 5195dcda for ; Tue, 2 Nov 2021 19:07:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=araneo.si; h=from:to:cc :subject:date:message-id:mime-version:content-type :content-transfer-encoding; s=20180623; bh=IcfyZU+1DkYBNqIuF9H/f yztzNU=; b=QN0kcAer94kvOACsoNtDmYvHNQzDKNfhwcsIZABIYDODjBQpRckYv fZAT1XqQvgkayNlOWQCXHp3oc7clZFZh47TmXLSQI+KQDUEa4L22sLEfoy137BH7 1952b9Re0xkxNGVSKTYKdAR6jatoUndDfEHlc0Mrd3d2MsOCGgcdVMh2Jjx7X7Yd LnrVgK0eMI00M7y7nECtGrISZ/Q+b35bYMTRkcxBClORnGYD9BMTHeMAdGC8Fm4I 62D8VbpX1WNFOWHaB3l7b6OnTuADiblpCwHCRTMSboOmqQHDW39anhIYLSnDHXZ3 w/QIVEsuFr2xCpxkcl7jLM9GuRuTB00tw== Received: by araneo.si (OpenSMTPD) with ESMTPSA id d9e6bd80 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 2 Nov 2021 19:07:51 +0000 (UTC) From: Timotej Lazar Date: Tue, 2 Nov 2021 20:06:32 +0100 Message-Id: <20211102190629.14471-1-timotej.lazar@araneo.si> X-Mailer: git-send-email 2.33.1 MIME-Version: 1.0 Received-SPF: pass client-ip=2001:15c0:2110:3400::2; envelope-from=timotej.lazar@araneo.si; helo=araneo.si X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * gnu/services/virtualization.scm (): 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 ;;; Copyright © 2018, 2020, 2021 Ludovic Courtès ;;; Copyright © 2020,2021 Jan (janneke) Nieuwenhuizen +;;; Copyright © 2021 Timotej Lazar ;;; ;;; 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 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.