From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id 4DdrItuMgWGVQgEAgWs5BA (envelope-from ) for ; Tue, 02 Nov 2021 20:09:15 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id KIz2HduMgWF5VQAAbx9fmQ (envelope-from ) for ; Tue, 02 Nov 2021 19:09:15 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id AD0CB28F17 for ; Tue, 2 Nov 2021 20:09:14 +0100 (CET) Received: from localhost ([::1]:34320 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mhz9l-0004mp-RD for larch@yhetil.org; 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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1635880154; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=4GNAcqdVHKNJ9SmS172nV280mGV1POSJhyi/28BpQEY=; b=qOFetilEkf7iZKLKprLgihG3uTKM7CvTgctuHesWrnmu/6m0liyLOGRHLCxJKFlskvDsq5 sITWwmKTvFDyVP0NOAaD+innmNtOeFXZN/PESiEGy07b4NLfBqCQoynouw9Gqg9NHOEcu/ XMuTV6HY74tpB6bR0p2C2HL6hPQZa1CFGppXJfpUUarXQ09gAP/AY1sxCCVWwk4S2PbPLq vwupTSGlSJo45w5Q/Qw2Qm3X/R4cJYmOGV952t110DiIT7uJfbWIa0kVdNvnjTQRBJK5J/ WezV9GAPOk8fgg61BKhbyBRIppnN6TForrFnkCwSsgNWC6IwYTAZM8sdY5pfGA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1635880154; a=rsa-sha256; cv=none; b=KnmTrZdCxHvQbOOCXFJWYsyM3uhXMxa5hhcqYTpirNHfmXpjy8aVtZoHtbWfIoRnHNhOOP 443LrRCkRZypjMZm/R3mGfQmcIfzvEnibjg+zH4fai6jabFrijlL13YqP7HBO578YtT7PH zDxlM308eANbFGOutwdzLz3H3azSBdgjlp+XcdBusTyS2vXefqYK/hZ8e6W3I8yypmDJLn VWovHiZJLIIG+/sxVr50B4EEeeTx3m9ITnlw19N4KW/4lrNlf3ND2fMMZ65725oDCs9qJ8 auWq7adbDXSjonRglhBv+NBtXm2Ka+dVQql4uOhskdjpEQoRPJ/LVdsWgB5wmQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=araneo.si header.s=20180623 header.b=QN0kcAer; dmarc=fail reason="SPF not aligned (relaxed)" header.from=araneo.si (policy=none); spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Spam-Score: -0.32 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=araneo.si header.s=20180623 header.b=QN0kcAer; dmarc=fail reason="SPF not aligned (relaxed)" header.from=araneo.si (policy=none); spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Queue-Id: AD0CB28F17 X-Spam-Score: -0.32 X-Migadu-Scanner: scn0.migadu.com X-TUID: hibZ7vjytGYz * 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. -- 2.33.1