From mboxrd@z Thu Jan 1 00:00:00 1970 From: ludo@gnu.org (Ludovic =?UTF-8?Q?Court=C3=A8s?=) Subject: bug#22050: [PATCH v3 1/2] linux-boot: Add make-static-device-nodes. Date: Thu, 14 Dec 2017 09:52:07 +0100 Message-ID: <87mv2lu1xk.fsf@gnu.org> References: <20171213220445.1056-1-dannym@scratchpost.org> <20171213223240.605-1-dannym@scratchpost.org> <20171213223240.605-2-dannym@scratchpost.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:35173) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ePPGM-00018u-7i for bug-guix@gnu.org; Thu, 14 Dec 2017 03:53:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ePPGI-0007Hl-4a for bug-guix@gnu.org; Thu, 14 Dec 2017 03:53:06 -0500 Received: from debbugs.gnu.org ([208.118.235.43]:52533) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ePPGI-0007HX-0E for bug-guix@gnu.org; Thu, 14 Dec 2017 03:53:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ePPGH-0003HZ-Ns for bug-guix@gnu.org; Thu, 14 Dec 2017 03:53:01 -0500 Sender: "Debbugs-submit" Resent-Message-ID: In-Reply-To: <20171213223240.605-2-dannym@scratchpost.org> (Danny Milosavljevic's message of "Wed, 13 Dec 2017 23:32:39 +0100") List-Id: Bug reports for GNU Guix List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guix-bounces+gcggb-bug-guix=m.gmane.org@gnu.org Sender: "bug-Guix" To: Danny Milosavljevic Cc: 22050@debbugs.gnu.org Hello! AIUI this will solve lack of /dev/fuse at startup (among other things), right? I always wondered why it wasn=E2=80=99t showing up automatically. Danny Milosavljevic skribis: > * gnu/build/linux-boot.scm (make-static-device-nodes): New variable. > --- > gnu/build/linux-boot.scm | 63 ++++++++++++++++++++++++++++++++++++++++++= ++++++ > 1 file changed, 63 insertions(+) > > diff --git a/gnu/build/linux-boot.scm b/gnu/build/linux-boot.scm > index 2547f1e0a..f6eea96e3 100644 > --- a/gnu/build/linux-boot.scm > +++ b/gnu/build/linux-boot.scm > @@ -24,6 +24,8 @@ > #:use-module (srfi srfi-1) > #:use-module (srfi srfi-26) > #:use-module (ice-9 match) > + #:use-module (ice-9 rdelim) > + #:use-module (ice-9 popen) > #:use-module (ice-9 ftw) > #:use-module (guix build utils) > #:use-module ((guix build syscalls) > @@ -35,6 +37,7 @@ > linux-command-line > find-long-option > make-essential-device-nodes > + make-static-device-nodes > configure-qemu-networking >=20=20 > bind-mount > @@ -105,6 +108,66 @@ with the given MAJOR number, starting with MINOR." > 'block-special #o644 (device-number major (+ minor i))) > (loop (+ i 1))))) >=20=20 > +(define (tmpfiles-mknod name type mode-string device-number-string) > + "Given a NAME, TYPE, MODE-STRING, DEVICE-NUMBER-STRING, > + call mknod with the respective numbers." > + (let* ((mode (string->number mode-string 8)) > + (device-number-parts (string-split device-number-string #\:))) > + (match device-number-parts > + ((major-device-number-string minor-device-number-string) > + (let ((major-device-number (string->number major-device-number-str= ing)) > + (minor-device-number (string->number minor-device-number-str= ing))) > + (mknod name type #o660 (device-number major-device-number > + minor-device-number)))) > + (_ #f)))) That=E2=80=99s a surprising name ;-), and I would suggest separating parsing from node creation (see below). > +(define (log-static-device-system-error name callback) > + "Call CALLBACK. If it fails, print an error message." > + (catch 'system-error > + (lambda () > + (callback)) > + (lambda args > + (format #t "could not create node '~a'~%" name)))) Rather: (define (report-system-error . args) (let ((errno (system-error-errno args))) (format (current-error-port) "could not create=E2=80=A6: ~a~%" (strer= ror errno)))) (define-syntax-rule (catch-system-error exp) (catch 'system-error (lambda () exp) report-system-error)) (The term =E2=80=98callback=E2=80=99 is never used in Scheme; we just write= =E2=80=98proc=E2=80=99 or =E2=80=98thunk=E2=80=99.) > +(define* (make-static-device-nodes kmod-executable-name) > + "Invoke and handle 'kmod static-nodes' output." > + ;; "kmod static-nodes --format=3Dtmpfiles" output format: > + ;; c! /dev/fuse 0600 - - - 10:229 > + ;; d /dev/vfio 0755 - - - I checked what kmod does and in fact it just reads $LINUX_MODULE_DIRECTORY/*/modules.devname, which has a format similar to what you=E2=80=99re parsing here: --8<---------------cut here---------------start------------->8--- $ cat $LINUX_MODULE_DIRECTORY/*/modules.devname # Device nodes to trigger on-demand module loading. autofs4 autofs c10:235 fuse fuse c10:229 cuse cuse c10:203 btrfs btrfs-control c10:234 userio userio c10:240 vfio vfio/vfio c10:196 hci_vhci vhci c10:137 uhid uhid c10:239 vhost_net vhost-net c10:238 vhost_vsock vhost-vsock c10:241 snd_timer snd/timer c116:33 snd_seq snd/seq c116:1 --8<---------------cut here---------------end--------------->8--- Could we read that directly instead of invoking =E2=80=98kmod=E2=80=99? What about having a =E2=80=98static-device-nodes=E2=80=99 procedure that wo= uld parse that and return a list of , where: ;; TYPE is 'char or 'block, MAJOR and MINOR are integers. (define-record-type (device-node name type major minor module) device-node? =E2=80=A6) and then: (define create-device-node (match-lambda (($ name type major minor) (mknod =E2=80=A6)))) finally: (for-each create-device-node (static-device-nodes)) ? Thanks for fixing this! Ludo=E2=80=99.