From patchwork Sat Jun 20 09:19:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janneke Nieuwenhuizen X-Patchwork-Id: 22791 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 5947B27BBE3; Sat, 20 Jun 2020 10:20:11 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,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 ESMTP id 93E0427BBE1 for ; Sat, 20 Jun 2020 10:20:10 +0100 (BST) Received: from localhost ([::1]:47286 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jmZfW-0002rG-5V for patchwork@mira.cbaines.net; Sat, 20 Jun 2020 05:20:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59694) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jmZfO-0002r6-UY for guix-patches@gnu.org; Sat, 20 Jun 2020 05:20:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:45782) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jmZfO-0007LO-Lb for guix-patches@gnu.org; Sat, 20 Jun 2020 05:20:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jmZfO-0007zx-Hg for guix-patches@gnu.org; Sat, 20 Jun 2020 05:20:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#41961] [PATCH 1/1] services: childhurd: Support more than one instance. References: <20200620091656.6804-1-janneke@gnu.org> In-Reply-To: <20200620091656.6804-1-janneke@gnu.org> Resent-From: "Jan (janneke) Nieuwenhuizen" Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sat, 20 Jun 2020 09:20:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 41961 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 41961@debbugs.gnu.org Cc: rekado@elephly.net Received: via spool by 41961-submit@debbugs.gnu.org id=B41961.159264476730690 (code B ref 41961); Sat, 20 Jun 2020 09:20:02 +0000 Received: (at 41961) by debbugs.gnu.org; 20 Jun 2020 09:19:27 +0000 Received: from localhost ([127.0.0.1]:57323 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jmZep-0007yw-0h for submit@debbugs.gnu.org; Sat, 20 Jun 2020 05:19:27 -0400 Received: from eggs.gnu.org ([209.51.188.92]:45198) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jmZen-0007yj-Dd for 41961@debbugs.gnu.org; Sat, 20 Jun 2020 05:19:25 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:37067) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jmZei-0007JC-6q; Sat, 20 Jun 2020 05:19:20 -0400 Received: from [2001:980:1b4f:1:42d2:832d:bb59:862] (port=34770 helo=dundal.fritz.box) by fencepost.gnu.org with esmtpa (Exim 4.82) (envelope-from ) id 1jmZeh-0005E5-6o; Sat, 20 Jun 2020 05:19:19 -0400 From: "Jan (janneke) Nieuwenhuizen" Date: Sat, 20 Jun 2020 11:19:18 +0200 Message-Id: <20200620091918.6868-1-janneke@gnu.org> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 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 ()[id,net-options]: New fields. (hurd-vm-net-options): New prodecure. Parameterize port forwarding with ID. * gnu/services/virtualization.scm (hurd-vm-shepherd-service): Use them. Parameterize provision with ID, if set. * doc/guix.texi (Virtualization Services): Document new fields. --- doc/guix.texi | 35 ++++++++++++++++++++-------- gnu/services/virtualization.scm | 41 +++++++++++++++++++++++++-------- 2 files changed, 58 insertions(+), 18 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 2268e159a2..59f8a89387 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -24728,12 +24728,31 @@ The size of the disk image. @item @code{memory-size} (default: @code{512}) The memory size of the Virtual Machine in mebibytes. -@item @code{options} (default: @code{'("--device"} @code{"rtl8139,netdev=net0"} @ - @code{"--netdev"} @ - @code{"user,id=net0,hostfwd=tcp:127.0.0.1:20022-:2222,hostfwd=tcp:127.0.0.1:25900-:5900"} @ - @code{"--snapshot"} @ - @code{"--hda")}) +@item @code{options} (default: @code{'("--snapshot" "--hda")}) The extra options for running QEMU. + +@item @code{id} (default: @code{#f}) +If set, a non-zero positive integer used to parameterize Childhurd +instances. It is appended to the service's name, +e.g. @code{childhurd1}. + +@item @code{net-options} (default: @var{hurd-vm-net-options}) +The procedure used to produce the list of QEMU networking options. + +By default, it produces + +@lisp +'("--device" "rtl8139,netdev=net0" + "--netdev" "user,id=net0\ + ,hostfwd=tcp:127.0.0.1:-:2222\ + ,hostfwd=tcp:127.0.0.1:-:5900") +@end lisp +with forwarded ports +@example +: @code{(+ 10022 (* 1000 @var{ID}))} +: @code{(+ 15900 (* 1000 @var{ID}))} +@end example + @end table @end deftp @@ -24745,10 +24764,8 @@ the @code{--snapshot} flag using something along these lines: @lisp (service hurd-vm-service-type (hurd-vm-configuration - (image (const "/out/of/store/writable/hurd.img")) - (options '("--device" "rtl8139,netdev=net0" - "--netdev" - "user,id=net0,hostfwd=tcp:127.0.0.1:20022-:2222")))) + (image (const "/out/of/store/writable/hurd.img")) + (options '("--hda")))) @end lisp @node Version Control Services diff --git a/gnu/services/virtualization.scm b/gnu/services/virtualization.scm index 4e96607680..e60d169791 100644 --- a/gnu/services/virtualization.scm +++ b/gnu/services/virtualization.scm @@ -51,6 +51,10 @@ #:export (%hurd-vm-operating-system hurd-vm-configuration + hurd-vm-disk-image + hurd-vm-id + hurd-vm-net-options + hurd-vm-options hurd-vm-service-type libvirt-configuration @@ -833,13 +837,13 @@ functionality of the kernel Linux."))) (default 512)) (options hurd-vm-configuration-options ;list of string (default - `("--device" "rtl8139,netdev=net0" - "--netdev" ,(string-append - "user,id=net0" - ",hostfwd=tcp:127.0.0.1:20022-:2222" - ",hostfwd=tcp:127.0.0.1:25900-:5900") - "--snapshot" - "--hda")))) + `("--snapshot" + "--hda"))) + (id hurd-vm-configuration-id ;#f or integer [1..] + (default #f)) + (net-options hurd-vm-configuration-net-options ;list of string + (thunked) + (default (hurd-vm-net-options this-record)))) (define (hurd-vm-disk-image config) "Return a disk-image for the Hurd according to CONFIG." @@ -851,26 +855,45 @@ functionality of the kernel Linux."))) (size disk-size) (operating-system os))))) +(define (hurd-vm-net-options config) + (let ((id (or (hurd-vm-configuration-id config) 0))) + (define (qemu-vm-port base) + (number->string (+ base (* 1000 id)))) + `("--device" "rtl8139,netdev=net0" + "--netdev" ,(string-append + "user,id=net0" + ",hostfwd=tcp:127.0.0.1:" (qemu-vm-port 10022) "-:2222" + ",hostfwd=tcp:127.0.0.1:" (qemu-vm-port 15900) "-:5900")))) + (define (hurd-vm-shepherd-service config) "Return a for a Hurd in a Virtual Machine with CONFIG." (let ((image (hurd-vm-configuration-image config)) (qemu (hurd-vm-configuration-qemu config)) (memory-size (hurd-vm-configuration-memory-size config)) - (options (hurd-vm-configuration-options config))) + (options (hurd-vm-configuration-options config)) + (id (hurd-vm-configuration-id config)) + (net-options (hurd-vm-configuration-net-options config)) + (provisions '(hurd-vm childhurd))) (define vm-command #~(list (string-append #$qemu "/bin/qemu-system-i386") #$@(if (file-exists? "/dev/kvm") '("--enable-kvm") '()) "-m" (number->string #$memory-size) + #$@net-options #$@options #+image)) (list (shepherd-service (documentation "Run the Hurd in a Virtual Machine: a Childhurd.") - (provision '(hurd-vm childhurd)) + (provision (if id + (map + (cute symbol-append <> + (string->symbol (number->string id))) + provisions) + provisions)) (requirement '(networking)) (start #~(make-forkexec-constructor #$vm-command)) (stop #~(make-kill-destructor))))))