From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id EHaQDCZUuF7OWwAA0tVLHw (envelope-from ) for ; Sun, 10 May 2020 19:21:10 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id WMzgMjNUuF5QRAAA1q6Kng (envelope-from ) for ; Sun, 10 May 2020 19:21:23 +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 6764C940C73 for ; Sun, 10 May 2020 19:21:21 +0000 (UTC) Received: from localhost ([::1]:54058 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jXrVp-00044M-NE for larch@yhetil.org; Sun, 10 May 2020 15:21:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49724) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jXrVW-000445-CC for guix-patches@gnu.org; Sun, 10 May 2020 15:21:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:38880) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jXrVW-0003a1-3J for guix-patches@gnu.org; Sun, 10 May 2020 15:21:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jXrVV-0004JB-VQ for guix-patches@gnu.org; Sun, 10 May 2020 15:21:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#41180] [PATCH] Add cachefilesd service. Resent-From: Jean-Baptiste Note Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 10 May 2020 19:21:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 41180 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 41180@debbugs.gnu.org Cc: Mathieu Othacehe X-Debbugs-Original-To: guixpatch Received: via spool by submit@debbugs.gnu.org id=B.158913840416456 (code B ref -1); Sun, 10 May 2020 19:21:01 +0000 Received: (at submit) by debbugs.gnu.org; 10 May 2020 19:20:04 +0000 Received: from localhost ([127.0.0.1]:50425 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jXrUL-0004Gh-MK for submit@debbugs.gnu.org; Sun, 10 May 2020 15:20:04 -0400 Received: from lists.gnu.org ([209.51.188.17]:59318) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jXrUK-0004Ga-4Q for submit@debbugs.gnu.org; Sun, 10 May 2020 15:19:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49634) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jXrUJ-0003tu-Tq for guix-patches@gnu.org; Sun, 10 May 2020 15:19:47 -0400 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]:46094) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jXrUI-00089q-9a for guix-patches@gnu.org; Sun, 10 May 2020 15:19:47 -0400 Received: by mail-wr1-x42d.google.com with SMTP id w7so8247989wre.13 for ; Sun, 10 May 2020 12:19:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:user-agent:mime-version; bh=bp1Ant0B3dOd4OqziYdhUbhCmJA01A4VvXrJIaAVckw=; b=fjdb4Y3qKP6zkuzkoBXSXXnHwtfeyCB6Vp6j9OKOGFpYlEOHIXohUbmDI5u0K22T7O jSrewT7aBS2C/+YYhtcVqQo/88GsU1A0jZJLbFCA0Wd9jQiGyLVoz/Ph+chzqdpWWUYE wgmXyieweFd6ddQEz7eJrgUoDwLuRBMLOTyn+uBvOJbqA9yyE6/mSFQSP4V2gM7skHqO ldvn6UkWtNZM00fwP2UAqlSVklSHUO30EaZglXQEHyD3Oe/vRc+fj60BoGkUyRz4hFOR QIyXxtNradiA/yu592YR35XUQ++uhzcaU+CQhwQjsRvxF6tBqWZG4lpyTp5YD4dwXUOt Mbiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :user-agent:mime-version; bh=bp1Ant0B3dOd4OqziYdhUbhCmJA01A4VvXrJIaAVckw=; b=OYD6Xlb3VDk+eHTSTK7os3XB/n0Ou2Ekjq62D6QhAo35g8+CloI1wF0w5O0rrJi1BH 4A2SE7SM4wsC2qCQmnSURKuOAlnjGctNroKRYNIMuE/rAXAuEx/0pSxtBQylgTvuZpVe SUrChkTHtwuRdGIwO6oJnF6HpFBdkn3mgWUMNi4pfSzx/cyHrg3sg4sG7MNuBHwoUOMp f12pLjkmWJHpmlKYsR39wjklLU+pHFm84Vs4eB5iicMpQIrBBRGjwJo3+hDlMMvAdXq+ qeV9HPYn5Jo1vP80XKN5GL5EwDMwtRG/Bb4XrFAQtgGhjpAPAoAaxN7sVCYJc4rQm7Oa sMtw== X-Gm-Message-State: AGi0Pub5ez2yGxTHcFv0oVxYv6EsfvDdDvNeKmMD0aR6k2ipoMWZ8ciw 9lZLBq++BKnT0eWIl7CxV2c= X-Google-Smtp-Source: APiQypJPNY7espjIHSpKOlgud47x9Ulo8GGj9PxrvByXrrCevmGYkmlFr+pOoYs1IYkUYChXtRyqEQ== X-Received: by 2002:adf:cc81:: with SMTP id p1mr14119991wrj.192.1589138384181; Sun, 10 May 2020 12:19:44 -0700 (PDT) Received: from guixrules ([2a01:e35:2e0b:a6b0:e2ce:c3ff:fe74:cec8]) by smtp.gmail.com with ESMTPSA id u16sm14201275wrq.17.2020.05.10.12.19.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 May 2020 12:19:42 -0700 (PDT) From: Jean-Baptiste Note Date: Sun, 10 May 2020 19:19:36 +0000 Message-ID: <87v9l3zjg7.fsf@m4x.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Received-SPF: pass client-ip=2a00:1450:4864:20::42d; envelope-from=jbnote@gmail.com; helo=mail-wr1-x42d.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-Spam-Score: 1.1 (+) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-Spam-Score: -0.5 (/) 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-Scanner: scn0 X-Spam-Score: -2.11 Authentication-Results: aspmx1.migadu.com; dkim=fail (body hash did not verify) header.d=gmail.com header.s=20161025 header.b=fjdb4Y3q; dmarc=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-Scan-Result: default: False [-2.11 / 13.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; GENERIC_REPUTATION(0.00)[-0.53905880578355]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(-0.20)[+ip4:209.51.188.0/24:c]; R_DKIM_REJECT(1.00)[gmail.com:s=20161025]; HAS_ATTACHMENT(0.00)[]; IP_REPUTATION_HAM(0.00)[asn: 22989(0.08), country: US(-0.00), ip: 209.51.188.17(-0.54)]; DWL_DNSWL_FAIL(0.00)[209.51.188.17:server fail]; DKIM_TRACE(0.00)[gmail.com:-]; RCPT_COUNT_TWO(0.00)[2]; MX_GOOD(-0.50)[cached: eggs.gnu.org]; MAILLIST(-0.20)[mailman]; SIGNED_PGP(-2.00)[]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; MIME_TRACE(0.00)[0:+,1:+,2:+,3:+,4:~]; RCVD_TLS_LAST(0.00)[]; ASN(0.00)[asn:22989, ipnet:209.51.188.0/24, country:US]; TAGGED_FROM(0.00)[larch=yhetil.org]; FROM_NEQ_ENVFROM(0.00)[jean-baptiste.note@m4x.org,guix-patches-bounces@gnu.org]; ARC_NA(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; FROM_HAS_DN(0.00)[]; URIBL_BLOCKED(0.00)[gnu.org:url,m4x.org:email]; TAGGED_RCPT(0.00)[]; MIME_GOOD(-0.20)[multipart/signed,multipart/mixed,text/plain,text/x-patch]; DMARC_NA(0.00)[m4x.org]; HAS_LIST_UNSUB(-0.01)[]; DNSWL_BLOCKED(0.00)[209.51.188.17:from]; RWL_MAILSPIKE_POSSIBLE(0.00)[209.51.188.17:from]; FREEMAIL_CC(0.00)[gmail.com]; RCVD_COUNT_SEVEN(0.00)[11]; FORGED_SENDER_MAILLIST(0.00)[] X-TUID: QMLdV1Dx+4qE --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain Dear guix developers, Mathieu, Please find attached a first version of the cachefilesd service patch. The second patch for documentation will be sent right after. I have a few general newbie scheme questions: - I gathered that #~ / #$ kinds of suspends evaluation / forces it -- is there documentation about this somewhere ? - There's something that looks like a splat operator (only seen in conjuction with forcing evaluation in #$@) -- again i'd be interested in more documentation about this feature -- is this a guix-specific operator? - I don't understand why there are ^L separating services in the scheme files -- is this necessary? A convention? What purpose does it serve? Regarding the patch itself: - i'm not entirely sure the service belongs to services/linux.scm - documentation is hastily written. I have found no way to indent automatically the lisp code in the texi file, which is very painfull -- would there be an emacs solution for this? - there are no automated tests (beyond what I have done by hand locally!), and there's no lint, so I don't really feel confident about it :) Are there tests for services to alleviate my fears? - I've copied some other service for modprobing the required kernel modules before launching the daemon with a one-shot shepherd service. Frankly i'm not happy about this solution, it seems to me that it unnecessarily pollutes the shepherd configuration; maybe some other mechanism (graft?) adjusting the modprobe configuration could be better (better still, autoload the file). Any guidance would be nice (including, that this solution is sufficient for now :)) I had great fun writing this, it reminded me of writing cookbooks during my 'Chef' days. I must confess that the Chef DSL embedded in ruby seemed more concise, and that it provided a way to write a cookbook 'out-of-tree' which was kind of less daunting for newcomers; however it's already amazing that you have this kind of functionality! Kind regards, Jean-Baptiste --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-gnu-Add-cachefilesd-service.patch Content-Transfer-Encoding: quoted-printable From=20729d43d541e8dcb41b36a7522ec291b0c3f8dd14 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Note Date: Sat, 9 May 2020 15:14:26 +0000 Subject: [PATCH 1/2] gnu: Add cachefilesd-service. * doc/guix.texi (Linux Services): Add a new subsection and document the new service and its configuration. * gnu/services/linux.scm (cachefilesd-service-type): New type. (cachefilesd-configuration): New type. =2D-- gnu/services/linux.scm | 210 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 209 insertions(+), 1 deletion(-) diff --git a/gnu/services/linux.scm b/gnu/services/linux.scm index 12934c2084..810901e0ca 100644 =2D-- a/gnu/services/linux.scm +++ b/gnu/services/linux.scm @@ -42,7 +42,11 @@ earlyoom-configuration-send-notification-command earlyoom-service-type =20 =2D kernel-module-loader-service-type)) + kernel-module-loader-service-type + + cachefilesd-configuration + cachefilesd-configuration? + cachefilesd-service-type)) =20 ;;; @@ -177,3 +181,207 @@ representation." (compose concatenate) (extend append) (default-value '()))) + + +;;; +;;; cachefilesd. +;;; + +(define-record-type* + cachefilesd-configuration make-cachefilesd-configuration + cachefilesd-configuration? + + ;; + (cachefilesd cachefilesd-configuration-cachefilesd + (default cachefilesd)) + + ;; cmdline flags + ;; Boolean + (daemonic? cachefilesd-configuration-daemonic? + (default #t)) + + ;; string + (pid-file cachefilesd-configuration-pid-file + (default "/var/run/cachefilesd.pid")) + + ;; Boolean + (debug? cachefilesd-configuration-debug? + (default #f)) + ;; Boolean + (syslog? cachefilesd-configuration-syslog? + (default #t)) + ;; Boolean + (culling-and-scanning? cachefilesd-configuration-culling-and-scanning? + (default #t)) + + ;; configuration file contents + ;; String + (dir cachefilesd-configuration-dir + (default "/var/cache/fscache")) + + ;; String + (tag cachefilesd-configuration-tag + (default "CacheFiles")) + + ;; String + (secctx cachefilesd-configuration-secctx + (default #f)) + + ;; integers + (brun cachefilesd-configuration-brun + (default 7)) + (frun cachefilesd-configuration-frun + (default 7)) + (bcull cachefilesd-configuration-bcull + (default 5)) + (fcull cachefilesd-configuration-fcull + (default 5)) + (bstop cachefilesd-configuration-bstop + (default 1)) + (fstop cachefilesd-configuration-fstop + (default 1)) + + ;; integer + (culltable cachefilesd-configuration-culltable + (default 12)) + + ;; integer / debug mask + (kernel-debug cachefilesd-configuration-kernel-debug + (default 0)) + + ;; boolean + (nocull? cachefilesd-configuration-nocull? + (default #f)) + ;; Boolean + ;; XXX: This should really be handled in an orthogonal way, for instance= as + ;; proposed in . Keep it internal/undocumen= ted + ;; for now. + (%auto-start? cachefilesd-auto-start? + (default #t))) + +(define (cachefilesd-configuration-file config) + "Return the cachefilesd configuration file corresponding to CONFIG." + (define secctx + (cachefilesd-configuration-dir config)) + + (computed-file + "cachefilesd.conf" + #~(begin + (use-modules (ice-9 match)) + (call-with-output-file #$output + (lambda (port) + (display "# Generated by 'cachefilesd-service'.\n" port) + (format port "dir ~a\n" #$(cachefilesd-configuration-dir config= )) + + (let ((secctx #$(cachefilesd-configuration-secctx config))) + (if secctx (format port "secctx ~a" secctx))) + + ;; XXX factor this + (format port "brun ~a%\n" + #$(number->string + (cachefilesd-configuration-brun config))) + (format port "frun ~a%\n" + #$(number->string + (cachefilesd-configuration-frun config))) + (format port "bcull ~a%\n" + #$(number->string + (cachefilesd-configuration-bcull config))) + (format port "fcull ~a%\n" + #$(number->string + (cachefilesd-configuration-fcull config))) + (format port "bstop ~a%\n" + #$(number->string + (cachefilesd-configuration-bstop config))) + (format port "fstop ~a%\n" + #$(number->string + (cachefilesd-configuration-fstop config))) + + (format port "tag ~a\n" #$(cachefilesd-configuration-tag config= )) + + (format port "culltable ~a\n" + #$(number->string + (cachefilesd-configuration-culltable config))) + + (if #$(cachefilesd-configuration-nocull? config) + (display "nocull\n" port)) + + (format port "debug ~a\n" + #$(number->string + (cachefilesd-configuration-kernel-debug config))) + + #t))))) + +(define (cachefilesd-activation config) + "Return cachefilesd's activation GEXP for CONFIG." + (with-imported-modules '((guix build utils)) + #~(begin + (use-modules (guix build utils)) + ;; Make sure the cache directory and pid dir exists + (mkdir-p #$(cachefilesd-configuration-dir config)) + (mkdir-p (dirname #$(cachefilesd-configuration-pid-file config))))= )) + +(define (cachefilesd-shepherd-service config) + "Return a for cachefilesd with CONFIG." + + (define cachefilesdpath + (cachefilesd-configuration-cachefilesd config)) + (define pid-file + (cachefilesd-configuration-pid-file config)) + (define syslog? + (cachefilesd-configuration-syslog? config)) + (define culling-and-scanning? + (cachefilesd-configuration-culling-and-scanning? config)) + (define debug? + (cachefilesd-configuration-debug? config)) + + (define cachefilesd-command + #~(list #$(file-append cachefilesdpath "/sbin/cachefilesd") + #$@(if (cachefilesd-configuration-daemonic? config) '() '("-n"= )) + ;; XXX shepherd pid file handling: no idea how shepherd does it + ;; and if it's going to conflict with cachefilesd's + #$@(if debug? '("-d") '()) + #$@(if syslog? '() '("-s")) + #$@(if culling-and-scanning? '() '("-N")) + "-p" #$pid-file + "-f" #$(cachefilesd-configuration-file config))) + + (list (shepherd-service + (documentation "Start cachefilesd daemon.") + (requirement (append '(file-systems cachefiles-module) + (if syslog? '(syslogd) '()))) + (provision '(cachefilesd)) + (start #~(make-forkexec-constructor #$cachefilesd-command + #:pid-file #$pid-file)) + (stop #~(make-kill-destructor)) + (auto-start? (cachefilesd-auto-start? config))) + + (shepherd-service + (provision '(cachefiles-module)) + (requirement '(file-systems)) + (modules '((guix build utils))) + (documentation + "Load the cachefiles Linux kernel module.") + (start (with-imported-modules '((guix build utils)) + #~(lambda _ + ;; XXX: duplicated from networking + ;; -- factor this into a modprobe command + ;; XXX: We can't use 'load-linux-module*' here becau= se it + ;; expects a flat module directory. + (setenv "LINUX_MODULE_DIRECTORY" + "/run/booted-system/kernel/lib/modules") + (invoke #$(file-append kmod "/bin/modprobe") + "cachefiles")))) + (one-shot? #t)))) + +(define cachefilesd-service-type + (service-type (name 'cachefilesd) + (description + "Run the CacheFile backend daemon, @command{cachefilesd}.= ") + (extensions + (list + (service-extension shepherd-root-service-type + cachefilesd-shepherd-service) + (service-extension activation-service-type + cachefilesd-activation))) + (compose concatenate) + (default-value (cachefilesd-configuration)))) =2D-=20 2.26.2 --=-=-=-- --==-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEPxcq3dp4FVY5UpckkC0pVsuz75YFAl64U8gACgkQkC0pVsuz 75bJ4RAAoUmmXPdAGW3uD5W/YO8U8A1FhUr/qoq+1qkClSDv0Jt/qyKRca7hYrdZ C0JAgfYGmdk/Qy0ltnRACR96pcZP4YUf5NWjTKNPQykOjucJISXsSUTSojljZHbT c4ei7KjNMU0jRrrKZFqR4IlsVLYy1K4wFQfU4yLH9sU2ZgUd4R+Mb6eM1F7zWYog qSHTp3+ZgAVB5BaZ9pDlDdsOAKU8WO5oy8in/GEFREoL5vjeBiueqLMSYI/epPWn N94j96cM3I/sL/FaBs6Ib5cGvXox8TW54BoOx2HBTZMoo4iZkhDnSnFro8cZYa66 IeDta1xzfusDMmQibvMiw2w3D3w/mgLz+X5HO7kPTQrbg5XlK2kMdeiO6oUH5cw7 GA7ooB4MTIivZZeyqynXieUvcS2lIQ/1TS8TU6wgGNymUsrmym08+Y06Qtc9lyZh nsIeFCmNEMqIXb/wIIjRgWtIX6movMmRNTCq7fBCXeTu50IvING1PNZsrToHN1qA V9g49CBByBhVbEa661bldRwfVJgINoigI23BBzTZe0omabNym9RKdayAHdP099yY zwC1e9KUUAK8UXU1X272lRjCElJy0+h5q++KVMdhiC8502nE2IJeLH1V2hZZOXkC cywDxV5BhxISME24RFAXCrJxFUqdViZ3cU3dL1lmKDg+NPk7pzQ= =sR04 -----END PGP SIGNATURE----- --==-=-=--