From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id 6IwgJLc+n2YO0gAA62LTzQ:P1 (envelope-from ) for ; Tue, 23 Jul 2024 05:25:11 +0000 Received: from aspmx1.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1.migadu.com with LMTPS id 6IwgJLc+n2YO0gAA62LTzQ (envelope-from ) for ; Tue, 23 Jul 2024 07:25:11 +0200 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=hallsby.com header.s=google header.b=NNfbn1RK; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1721712311; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=jR1nSIMmVIJR319gRbMxBKPwlndlI2/8ek5lZC85UqQ=; b=oiOxB4cycpvtqDfGkX6uw5ez3HIyPfvv0EnRKmXcAanxhkra1+BJWki1WgKaBbRynz2+sY ECaJJk01eOiS8XFjUt13frmTdbYnRCAB+4EO0TmfGXpMWhQVLjQPBbrvVMOS97EKJ9eneC 5v/KVOdPA/Et99PWTU95I73XNoooF6aCRMbGU82+W1kwKgkMTPYFPuX8YcdmzwFn5vzcwN nqqYEhp7CFhFgY2zSlbu3mG69WGlWxX3rbttzXjdysXz156+XJvo+rRb+PSWIE8huBzCCU jXKJWFbWcyJNosyEkxZAH3Sx2qMR17BMeEK13KgrmR8j0XWZkA3TWcgjd/DmMg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1721712311; a=rsa-sha256; cv=none; b=b2sQnYmAr3tLLW0iJPGlo8d5e3bKatAlfO+lKm3IciLZbByxjBHPnL9FIqr6LM2Uv30yOS RxCjVDijhbaIz3DV3h/6wdhRCh9u0JfPlt05H32qG07R6jN20nOAL4f9Xzrtdm+UhEK66w ZBp90rK5U8T4yzNs/wBEiUxXhnhQZNWBNqtM+6P+6p9bay85x4FKFZJn61ABkFkhow1sJ0 6FJHKvKr6b7KDdwe2szbLjnFeB2N98sthos7LdYD+8hT6K9tf5drV4zJ3PJ/jbX+mZxwL1 OTmhkifTasMH0wJSOdtI+ilrzp1UgcVRqEtw5dxt2fNnATx6LSCi4WOQYyngOQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=hallsby.com header.s=google header.b=NNfbn1RK; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" 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 576F37504E for ; Tue, 23 Jul 2024 07:25:11 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sW81H-0003cN-7L; Tue, 23 Jul 2024 01:25:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sW81D-0003bF-Ug for guix-patches@gnu.org; Tue, 23 Jul 2024 01:24:59 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sW81C-0007Ei-Sw; Tue, 23 Jul 2024 01:24:58 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sW81F-0002qU-Kr; Tue, 23 Jul 2024 01:25:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#72249] [PATCH 2/2] services: Add xe-guest-utilities-service-type. Resent-From: Karl Hallsby Original-Sender: "Debbugs-submit" Resent-CC: pelzflorian@pelzflorian.de, ludo@gnu.org, matt@excalamus.com, maxim.cournoyer@gmail.com, guix-patches@gnu.org Resent-Date: Tue, 23 Jul 2024 05:25:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 72249 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 72249@debbugs.gnu.org Cc: Karl Hallsby , Florian Pelz , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Matthew Trzcinski , Maxim Cournoyer X-Debbugs-Original-Xcc: Florian Pelz , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Matthew Trzcinski , Maxim Cournoyer Received: via spool by 72249-submit@debbugs.gnu.org id=B72249.172171224210849 (code B ref 72249); Tue, 23 Jul 2024 05:25:01 +0000 Received: (at 72249) by debbugs.gnu.org; 23 Jul 2024 05:24:02 +0000 Received: from localhost ([127.0.0.1]:58974 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sW80H-0002oj-H5 for submit@debbugs.gnu.org; Tue, 23 Jul 2024 01:24:02 -0400 Received: from mail-io1-f48.google.com ([209.85.166.48]:44508) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sW80E-0002o9-RL for 72249@debbugs.gnu.org; Tue, 23 Jul 2024 01:23:59 -0400 Received: by mail-io1-f48.google.com with SMTP id ca18e2360f4ac-7fb93b2e2a3so214539939f.1 for <72249@debbugs.gnu.org>; Mon, 22 Jul 2024 22:23:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hallsby.com; s=google; t=1721712169; x=1722316969; darn=debbugs.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wDO4umrRiFPybL1CvELsnkMjputpRAygZI7aJJFfw6o=; b=NNfbn1RKMNDCbzdlNTw1yp9xiWEglNGrJKD7t+VFk3Q1HvRoHSUVpTq/pk7VrmGeZN uOq40zjcT/XcqVKUDwKDKKy7EVE9Wi755q6uvLicZxEfEHts63TwLnfSl8ugQFm7ZDZt aIpbFSkY/4JoSm7tHSfooD2URISUTTLoBST6UXa+qDDbXTKX7oqj68AigoyndiRnJVbM 848uAXb468c4vhrnsAAPsMyHbblJ0HRR05uhhiXFVCSIXC2WVb2fYAXAXRzEfxy3y3Up AGQPD1wMsBVy1OCdW6VdBcw66wnEDQZcBKmPmWKncHzAhgpjgLyv9+vFojfawRh7iSX6 VlOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721712169; x=1722316969; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wDO4umrRiFPybL1CvELsnkMjputpRAygZI7aJJFfw6o=; b=QvdbNn479/1aet3Nd58QK46mYCaJN3GcbQIqaRfmopfd7tALhf4G+885ZmenF8tgdJ 2kQ6X3TisCYKn7a1mFUHWLA6rTTZ47On1oX+QjWequiDXGsziprzeZTzi4erKG8OGgTe Wug4tHJt9BvpT+7xfe5EcbuxnpIcT5ofvp1sKsg/4o1JEdBxVxsev1zKZyS6LKqBNZdX 5YIZw7VZosWuzzJkUkwK/mD20BwSsKEZ+ws3TjTxNcCXAMib2zS0fuAuJVBRNE+8ip/A h/K/yF+C/6LWTjS/tHRvObsRZtqD3WFp8vqGXxP4+bnmyYG44yNfnItsSn/Iey9NNohO u/zw== X-Gm-Message-State: AOJu0YwsI0B9Zb7Y5aDov4ICqpMFmZa6JJ0jqpgB+7/0tHTZGUVE+4Rr BFxgbEqhuqW1NqEFluauB6Gcs5QUyzd33IqgDTFh2XmUEg7j+jLN8zxb2THs7zwpjYonFaV28d4 = X-Google-Smtp-Source: AGHT+IFOsjjyPEPvBnoFbnEPhgbsPIKqYfXoJZpuj5bd4gwhrHHGFaUipw6S+wnC+VaEj6+RLOoI5g== X-Received: by 2002:a05:6602:1601:b0:7f9:bef6:2068 with SMTP id ca18e2360f4ac-81b34880de9mr1154226839f.10.1721712168875; Mon, 22 Jul 2024 22:22:48 -0700 (PDT) Received: from Karl-Desktop.raven (168-91-194-13.s3595.c3-0.frg-cbr1.chi-frg.il.cable.rcncustomer.com. [168.91.194.13]) by smtp.gmail.com with ESMTPSA id ca18e2360f4ac-819aba11fd4sm285786539f.4.2024.07.22.22.22.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jul 2024 22:22:48 -0700 (PDT) Date: Tue, 23 Jul 2024 00:22:38 -0500 Message-ID: <1c2bcecabee79ce42af6d0d3d653f9fdf3ad5458.1721711392.git.karl@hallsby.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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: , Reply-to: Karl Hallsby X-ACL-Warn: , Karl Hallsby via Guix-patches From: Karl Hallsby via Guix-patches via Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Spam-Score: -1.91 X-Spam-Score: -1.91 X-Migadu-Queue-Id: 576F37504E X-Migadu-Scanner: mx11.migadu.com X-TUID: JZZGuoDx+WXj * gnu/services/virtualization.scm (xe-guest-utilities-configuration, xe-guest-utilities-service-type): New variables. Change-Id: Ife4e79fa6d1a9d5a21bf7479488884f2a5cf8d56 --- doc/guix.texi | 30 ++++++ gnu/services/virtualization.scm | 178 +++++++++++++++++++++++++++++++- 2 files changed, 207 insertions(+), 1 deletion(-) diff --git a/doc/guix.texi b/doc/guix.texi index 9ba96af459..6a29731b95 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -36873,6 +36873,36 @@ Virtualization Services @end table @end deftp +@subsubheading Xen Guest Agent + +@cindex xen +@cindex xen guest agent + +The Xen guest agent allows a Xen host to control the emulated system. +The @code{xe-guest-agent} service runs the agent on Guix guests. + +@quotation Note +The default Linux-libre kernel that Guix ships already enables the +necessary features for a guest. There is nothing you need to enable for +the guest to fully support paravirtualization features. +@end quotation + +@defvar xe-guest-agent-service-type +Service type for the QEMU guest agent service. +@end defvar + +@deftp {Data Type} xe-guest-agent-configuration +Configuration for the @code{xen-guest-agent} service. + +@table @asis +@item @code{package} (default: @code{xen-guest-utilities}) +The Xen guest utilities package to use. + +@item @code{pid-file} (default: @code{"/var/run/xe-daemon.pid"}) +Path to the file holding the PID of xe-deamon. +@end table +@end deftp + @anchor{build-vm} @subsubheading Virtual Build Machines diff --git a/gnu/services/virtualization.scm b/gnu/services/virtualization.scm index c9f8225570..29d5de6cc7 100644 --- a/gnu/services/virtualization.scm +++ b/gnu/services/virtualization.scm @@ -33,6 +33,9 @@ (define-module (gnu services virtualization) #:autoload (gnu packages gnupg) (guile-gcrypt) #:use-module (gnu packages package-management) #:use-module (gnu packages ssh) + #:use-module (gnu packages base) + #:use-module (gnu packages gawk) + #:use-module (gnu packages linux) #:use-module (gnu packages virtualization) #:use-module (gnu services base) #:use-module (gnu services configuration) @@ -107,7 +110,10 @@ (define-module (gnu services virtualization) qemu-guest-agent-configuration qemu-guest-agent-configuration? - qemu-guest-agent-service-type)) + qemu-guest-agent-service-type + + xe-guest-agent-configuration + xe-guest-agent-service-type)) (define (uglify-field-name field-name) (let ((str (symbol->string field-name))) @@ -1004,6 +1010,77 @@ (define qemu-guest-agent-service-type (default-value (qemu-guest-agent-configuration)) (description "Run the QEMU guest agent."))) + +;;; +;;; Guest agent for VMs running under Xen +;;; +(define-configuration/no-serialization xe-guest-agent-configuration + (package + (package xe-guest-utilities) + "Xen guest management utilities package.") + (pid-file + (string "/var/run/xe-daemon.pid") + "Path to the file holding the PID of xe-deamon.")) + +(define (generate-xe-guest-agent-documentation) + "Generate documentation for xe-guest-agent fields" + (generate-documentation + `((xe-guest-agent-configuration ,xe-guest-agent-configuration-fields)) + 'xe-guest-agent-configuration)) + +(define (xe-guest-agent-shepherd-service config) + (let ((xe-guest-utils (xe-guest-agent-configuration-package config)) + (pid-file (xe-guest-agent-configuration-pid-file config))) + (list + (shepherd-service + (provision '(xe-guest-agent)) + (requirement '(networking user-processes udev)) + (documentation "Run the Xen guest management agent.") + (start + #~(lambda _ + (let ((pid (make-forkexec-constructor + (list + #$(file-append xe-guest-utils + "/sbin/xe-daemon") + "-p" #$pid-file) + #:log-file "/var/log/xe-daemon.log" + #:pid-file #$pid-file + #:environment-variables + (list (string-append + "PATH=" + #$(file-append xe-guest-utils "/bin") ":" + ;; logger + #$(file-append inetutils "/bin")))))) + ;; Run xe-linux-distribution script before starting the actual + ;; daemon. The script collects some basic system information that + ;; is shared back to the Xen host. + (system* #$(file-append xe-guest-utils "/sbin/xe-linux-distribution") + "/var/cache/xe-linux-distribution") + ;; Finally, start and return the PID made by + ;; make-forkexec-constructor. + pid))) + (stop #~(make-kill-destructor)))))) + +(define (xe-guest-agent-udev-rules-service config) + (let ((guest-utils (xe-guest-agent-configuration-package config))) + (list + (file->udev-rule "z10_xen-vcpu-hotplug.rules" + (file-append + guest-utils + ;; I hate this z10_ prefix too + "/lib/udev/rules.d/z10_xen-vcpu-hotplug.rules"))))) + +(define xe-guest-agent-service-type + (service-type + (name 'xe-guest-agent) + (extensions + (list (service-extension shepherd-root-service-type + xe-guest-agent-shepherd-service) + (service-extension udev-service-type + xe-guest-agent-udev-rules-service))) + (default-value (xe-guest-agent-configuration)) + (description "Run the Xen guest management utilities."))) + ;;; ;;; Secrets for guest VMs. @@ -1860,3 +1937,102 @@ (define hurd-vm-service-type (description "Provide a virtual machine (VM) running GNU/Hurd, also known as a @dfn{childhurd}."))) + +(define-configuration/no-serialization xe-guest-utilities-configuration + (xe-guest-utilities + (file-like xe-guest-utilities) + "XenServer guest utilities package.") + (pid-file + (string "/var/run/xe-daemon.pid") + "File holding the PID of xe-deamon.")) + +(define (generate-xe-guest-utilities-documentation) + "Generate documentation for xe-guest-utilities fields" + (generate-documentation + `((xe-guest-utilities-configuration ,xe-guest-utilities-configuration-fields)) + 'xe-guest-utilities-configuration)) + +(define (xe-guest-utils-service config) + (let ((pid-file (xe-guest-utilities-configuration-pid-file config))) + (list + ;; Generate s that run the xe-daemon forever. + (shepherd-service + (documentation "Run the xe-guest-utilities daemon.") + (provision '(xe-guest-utilities-daemon)) + (requirement '(xe-guest-utilities-procfs + xe-guest-utilities-distro)) + (start #~(make-forkexec-constructor + (list #$(file-append xe-guest-utilities "/bin/xe-daemon") + "-p" #$pid-file) + #:pid-file #$pid-file + #:environment-variables + (list (string-append + "PATH=/run/current-system/profile/bin:" + "/run/current-system/profile/sbin:" + #$(file-append coreutils "/bin") ":" + #$(file-append iproute "/bin"))))) + (stop #~(make-kill-destructor))) + + ;; Generate one-shot s that informs the host hypervisor about + ;; the distribution of the guest (Guix in this case) + (shepherd-service + (documentation "Inform host hypervisor of guest's distribution.") + (provision '(xe-guest-utilities-distro)) + (requirement '(;;xe-guest-utilities-xend + )) + (one-shot? #t) + (start #~(make-forkexec-constructor + (list #$(file-append xe-guest-utilities "/bin/xe-linux-distribution") + "/var/run/xe-linux-distribution") + #:environment-variables + (list (string-append + "PATH=" + #$(file-append xe-guest-utilities "/bin") ":" + #$(file-append coreutils "/bin") ":" ;uname & co + #$(file-append gawk "/bin") ":" + #$(file-append sed "/bin"))))) + (stop #~(make-kill-destructor))) + + ;; Generate s to mount the xen directory in /proc. + (shepherd-service + (documentation "Mount /proc/xen files.") + (provision '(xe-guest-utilities-procfs)) + (requirement '(file-systems)) + (start #~(lambda () + (mount "xenfs" "/proc/xen" "/proc/xen") + (member "/proc/xen" (mount-points)))) + (stop #~(lambda () + (umount "/proc/xen" MNT_DETACH) + (not (member "/proc/xen" (mount-points)))))) + + ;; Generate s to create the necessary temporary directories for XenStore. + (shepherd-service + (documentation "Provide a temporary directory for XenStore.") + (provision '(xe-guest-utilities-tmp-dir)) + (one-shot? #t) + (requirement '(file-systems)) + (start #~(lambda () + (mkdir "/var/run/xenstored") + (chmod o755 "/var/run/xenstored"))) + (stop #~(lambda () + (delete-file-recursively "/var/run/xenstored"))))))) + +(define (xe-guest-utils-udev-rules-service config) + (let ((guest-utils (xe-guest-utilities-configuration-xe-guest-utilities config))) + (list + (file->udev-rule "z10_xen-vcpu-hotplug.rules" + (file-append + guest-utils + ;; I hate this z10_ prefix too + "/etc/udev/rules.d/z10_xen-vcpu-hotplug.rules"))))) + +(define xe-guest-utilities-service-type + (service-type + (name 'xe-guest-utilities) + (extensions (list (service-extension shepherd-root-service-type + xe-guest-utils-service) + (service-extension udev-service-type + xe-guest-utils-udev-rules-service))) + (default-value (xe-guest-utilities-configuration)) + (description + "Enable a Guix System VM to communicate with a Xen-based hypervisor host."))) -- 2.45.2