GNU bug report logs - #58086
[PATCH] gnu: Add fstrim-service-type.

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: guix-patches; Reported by: iyzsong@HIDDEN; Keywords: moreinfo patch; dated Mon, 26 Sep 2022 07:29:01 UTC; Maintainer for guix-patches is guix-patches@HIDDEN.
Added tag(s) moreinfo. Request was from Christopher Baines <mail@HIDDEN> to control <at> debbugs.gnu.org. Full text available.

Message received at 58086 <at> debbugs.gnu.org:


Received: (at 58086) by debbugs.gnu.org; 6 Oct 2022 21:00:24 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Oct 06 17:00:24 2022
Received: from localhost ([127.0.0.1]:33655 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1ogXyh-0005Lj-N2
	for submit <at> debbugs.gnu.org; Thu, 06 Oct 2022 17:00:24 -0400
Received: from eggs.gnu.org ([209.51.188.92]:38740)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <ludo@HIDDEN>) id 1ogXyb-0005LQ-Qw
 for 58086 <at> debbugs.gnu.org; Thu, 06 Oct 2022 17:00:21 -0400
Received: from fencepost.gnu.org ([2001:470:142:3::e]:48526)
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <ludo@HIDDEN>)
 id 1ogXyV-0001b8-Ns; Thu, 06 Oct 2022 17:00:11 -0400
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=MIME-Version:In-Reply-To:Date:References:Subject:To:
 From; bh=n5a+n3bvghe6R4u4WwEVb/3FK5BW+Ew4yefy5D4Siqw=; b=F5G8fWwDGnYI78LTBwDp
 7gqQjNrwkwTujNxQL6arQkVnrs6s/dHgD0IuCB4EjmbUZGjUD7UbuWIhaDD4RUXixE+azv8TPCjDZ
 cHN4o5zInd7te7WtfOsqGONXL5tYWW+0pMrdj2n455yJ1GF5Jfp/d2WKfewCRKOnjRZ/Xc5zr5YGY
 wgHLcLf79bj6FhB1iSrHiG7AYMZM6jPLufEyKw9vow9cvHT4X1hRIAQOjMbg09DYouPZWKyHrm636
 C5ruzAKnVnH3DDD28KHCS7kzc0lkWAEFKO6A4T4ES6YCFRmXcVWSFHomZHRxGyaHTx3BqzP1RXJ7B
 cn0tsCFwsg452w==;
Received: from 91-160-117-201.subs.proxad.net ([91.160.117.201]:59648
 helo=ribbon)
 by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <ludo@HIDDEN>)
 id 1ogXyV-0006Xn-4N; Thu, 06 Oct 2022 17:00:11 -0400
From: =?utf-8?Q?Ludovic_Court=C3=A8s?= <ludo@HIDDEN>
To: iyzsong@HIDDEN
Subject: Re: bug#58086: [PATCH] gnu: Add fstrim-service-type.
References: <20220926072825.4689-1-iyzsong@HIDDEN>
Date: Thu, 06 Oct 2022 23:00:08 +0200
In-Reply-To: <20220926072825.4689-1-iyzsong@HIDDEN> (iyzsong@HIDDEN's
 message of "Mon, 26 Sep 2022 15:28:25 +0800")
Message-ID: <87a668hdlz.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.1 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 58086
Cc: =?utf-8?B?5a6L5paH5q2m?= <iyzsong@HIDDEN>, 58086 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

Hi,

iyzsong@HIDDEN skribis:

> From: =E5=AE=8B=E6=96=87=E6=AD=A6 <iyzsong@HIDDEN>
>
> A timestamp file "/var/lib/mcron/fstrim.stamp" is used to ensure we will
> catch up on missed job runs when the system was powered down.
>
> * gnu/services/mcron.scm (%mcron-activation): New extension to create
> '/var/lib/mcron'.
> * gnu/services/admin.scm (fstrim-configuration): New record type.
> (fstrim-mcron-jobs): New procedure.
> (fstrim-service-type): New service type.

Please add documentation in doc/guix.texi.  :-)


[...]

> +(define fstrim-mcron-jobs
> +  (match-lambda
> +    (($ <fstrim-configuration> command interval)
> +     (list
> +      #~(job
> +         (let ((last-time
> +                (catch #t
> +                  (lambda ()
> +                    (with-input-from-file #$fstrim-mcron-stamp read))
> +                  ;; We schedule a first run immediately.
> +                  (const 0))))
> +           (lambda (current-time)
> +             (let ((next-time (max current-time (+ #$interval last-time)=
)))
> +               (set! last-time next-time)
> +               next-time)))
> +         (lambda ()
> +           (apply system* '#$command)
> +           (with-output-to-file #$fstrim-mcron-stamp
> +             (lambda () (write (current-time))))))))))

That seems a little bit complicated, no?  That=E2=80=99s because you want to
make sure it runs immediately at boot if it never ran before, right?  Is
that important?

> +(define fstrim-service-type
> +  (service-type
> +   (name 'fstrim)
> +   (extensions
> +    (list (service-extension mcron-service-type
> +                             fstrim-mcron-jobs)))
> +   (description
> +    "Periodically discard unused blocks on filesystems.")

=E2=80=9Cfile systems=E2=80=9D, two words.  Perhaps add a few more words me=
ntioning the
fstrim package?

> +++ b/gnu/services/mcron.scm
> @@ -154,6 +154,12 @@ (define mcron-shepherd-services
>                (actions
>                 (list (shepherd-schedule-action mcron files)))))))))
>=20=20
> +(define %mcron-activation
> +  (with-imported-modules '((guix build utils))
> +    #~(begin
> +        (use-modules (guix build utils))
> +        (mkdir-p "/var/lib/mcron"))))

I=E2=80=99m not sure the fstrim timestamp should leave in a directory that =
looks
as if it was =E2=80=9Cowned=E2=80=9D by mcron.

Could you send an updated patch?

Thanks,
Ludo=E2=80=99.




Information forwarded to guix-patches@HIDDEN:
bug#58086; Package guix-patches. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 26 Sep 2022 07:28:44 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Sep 26 03:28:44 2022
Received: from localhost ([127.0.0.1]:49137 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1ociXk-0008HD-Bj
	for submit <at> debbugs.gnu.org; Mon, 26 Sep 2022 03:28:44 -0400
Received: from lists.gnu.org ([209.51.188.17]:44722)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <iyzsong@HIDDEN>) id 1ociXh-0008H3-EN
 for submit <at> debbugs.gnu.org; Mon, 26 Sep 2022 03:28:43 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:51722)
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <iyzsong@HIDDEN>) id 1ociXh-00023o-8j
 for guix-patches@HIDDEN; Mon, 26 Sep 2022 03:28:41 -0400
Received: from mail.envs.net ([5.199.136.28]:36160)
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <iyzsong@HIDDEN>) id 1ociXf-00063j-9D
 for guix-patches@HIDDEN; Mon, 26 Sep 2022 03:28:40 -0400
Received: from localhost (mail.envs.net [127.0.0.1])
 by mail.envs.net (Postfix) with ESMTP id 9384938A0FAF;
 Mon, 26 Sep 2022 07:28:27 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=envs.net; s=modoboa;
 t=1664177307; bh=9/+nvn8WChAUUV+3J7HnA2dmlJjtknS7GG63KUWr3Y4=;
 h=From:To:Cc:Subject:Date:From;
 b=p0OOb0EMde0lm0sroadJDxsHWtZjD7x/xbFjEjrYCIq0oh3TZcoVftEzKWd8Hc8EV
 td3kVvUn7BUhhBdqHmDiUf61qPC5E9t8ceVZpGNX2/NElLOzT2H9bYf88C6Y+O9FbN
 n4Fh9yv/Ct8IcZZFx+NfU0Z/PfH2xMAKt0oXtZG7131nhQxYeb1LrwYPhqhwxE+X+w
 Y/1K4dSVX1GWNiaGM6TR1USWXa0OBBfXDwhHWI+HHaUN3gKANAkf492Yoi7ntK/7h9
 MAsUyAvsljp9/zIZQc8Wb72Rec8yhPR8bqzKo03XOj5hCoLRorz4ThuH89YQwsWAft
 6sgLlVo/KkdnHfr7N1BaIlM8C3d15f1e1nqdJwiwzpcE0s9Ob/Nr4L10sSyfOJh/V1
 oT+SnlY3TbUlsZCw1vYUyxdmXwvjvb/oTHWuXPfGQOKza9hrxzTLOtf8uOzeKi0Gbz
 RtRGRAu4o76CxT0y64R3ZX4VOThxvMMvTY8Q+WWJeblyJ8wHHv49KA5jZccDqFdLUz
 tI5f1X4VAkcbI0R33ClhqGlUjcmg22qX301k9eptQ3CQ6y762KzwI9Sjb60Rq8416y
 F9hFpX+5x6nNfveQ3sH4ZHiL5k4+qCuZlS0WoXlElaBmRaxiqXBSPFnHFFnL6Bkzed
 6000qHgu3rIYeYBJeGlhW4fY=
X-Virus-Scanned: Debian amavisd-new at mail.envs.net
Received: from mail.envs.net ([127.0.0.1])
 by localhost (mail.envs.net [127.0.0.1]) (amavisd-new, port 10026)
 with ESMTP id 2kjrR0VJni_Q; Mon, 26 Sep 2022 07:28:24 +0000 (UTC)
Received: from localhost (unknown [182.150.116.135])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest
 SHA256) (No client certificate requested)
 by mail.envs.net (Postfix) with ESMTPSA;
 Mon, 26 Sep 2022 07:28:24 +0000 (UTC)
Received: from localhost.localdomain (localhost [127.0.0.1])
 by localhost (OpenSMTPD) with ESMTP id efc52026;
 Mon, 26 Sep 2022 07:28:27 +0000 (UTC)
From: iyzsong@HIDDEN
To: guix-patches@HIDDEN
Subject: [PATCH] gnu: Add fstrim-service-type.
Date: Mon, 26 Sep 2022 15:28:25 +0800
Message-Id: <20220926072825.4689-1-iyzsong@HIDDEN>
X-Mailer: git-send-email 2.37.3
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Received-SPF: pass client-ip=5.199.136.28; envelope-from=iyzsong@HIDDEN;
 helo=mail.envs.net
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_NONE=0.001,
 SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no
X-Spam_action: no action
X-Spam-Score: -1.4 (-)
X-Debbugs-Envelope-To: submit
Cc: =?UTF-8?q?=E5=AE=8B=E6=96=87=E6=AD=A6?= <iyzsong@HIDDEN>
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -2.4 (--)

From: 宋文武 <iyzsong@HIDDEN>

A timestamp file "/var/lib/mcron/fstrim.stamp" is used to ensure we will
catch up on missed job runs when the system was powered down.

* gnu/services/mcron.scm (%mcron-activation): New extension to create
'/var/lib/mcron'.
* gnu/services/admin.scm (fstrim-configuration): New record type.
(fstrim-mcron-jobs): New procedure.
(fstrim-service-type): New service type.
---
 gnu/services/admin.scm | 56 +++++++++++++++++++++++++++++++++++++++++-
 gnu/services/mcron.scm |  8 ++++++
 2 files changed, 63 insertions(+), 1 deletion(-)

diff --git a/gnu/services/admin.scm b/gnu/services/admin.scm
index 252bedb0bd..2b22fc5b33 100644
--- a/gnu/services/admin.scm
+++ b/gnu/services/admin.scm
@@ -21,6 +21,7 @@
 (define-module (gnu services admin)
   #:use-module (gnu packages admin)
   #:use-module (gnu packages certs)
+  #:use-module (gnu packages linux)
   #:use-module (gnu packages package-management)
   #:use-module (gnu services)
   #:use-module (gnu services mcron)
@@ -30,6 +31,7 @@ (define-module (gnu services admin)
   #:use-module (guix packages)
   #:use-module (guix records)
   #:use-module (srfi srfi-1)
+  #:use-module (ice-9 match)
   #:use-module (ice-9 vlist)
   #:export (%default-rotations
             %rotated-files
@@ -63,7 +65,11 @@ (define-module (gnu services admin)
             unattended-upgrade-configuration-services-to-restart
             unattended-upgrade-configuration-system-expiration
             unattended-upgrade-configuration-maximum-duration
-            unattended-upgrade-configuration-log-file))
+            unattended-upgrade-configuration-log-file
+
+            fstrim-service-type
+            fstrim-configuration
+            fstrim-configuration?))
 
 ;;; Commentary:
 ;;;
@@ -376,4 +382,52 @@ (define unattended-upgrade-service-type
     "Periodically upgrade the system from the current configuration.")
    (default-value (unattended-upgrade-configuration))))
 
+
+;;;
+;;; fstrim.
+;;;
+
+(define-record-type* <fstrim-configuration>
+  fstrim-configuration make-fstrim-configuration fstrim-configuration?
+  (command  fstrim-configuration-command
+            (default
+              (list (file-append util-linux "/sbin/fstrim")
+                    "--verbose" "--quiet-unsupported"
+                    "--listed-in" "/etc/fstab")))
+  (interval fstrim-configuration-interval (default (* 60 60 24 7)))) ; weekly
+
+;;; By storing the time of job's last run in a file, we can catch up on missed
+;;; runs when the system was powered down.
+(define fstrim-mcron-stamp "/var/lib/mcron/fstrim.stamp")
+
+(define fstrim-mcron-jobs
+  (match-lambda
+    (($ <fstrim-configuration> command interval)
+     (list
+      #~(job
+         (let ((last-time
+                (catch #t
+                  (lambda ()
+                    (with-input-from-file #$fstrim-mcron-stamp read))
+                  ;; We schedule a first run immediately.
+                  (const 0))))
+           (lambda (current-time)
+             (let ((next-time (max current-time (+ #$interval last-time))))
+               (set! last-time next-time)
+               next-time)))
+         (lambda ()
+           (apply system* '#$command)
+           (with-output-to-file #$fstrim-mcron-stamp
+             (lambda () (write (current-time))))))))))
+
+(define fstrim-service-type
+  (service-type
+   (name 'fstrim)
+   (extensions
+    (list (service-extension mcron-service-type
+                             fstrim-mcron-jobs)))
+   (description
+    "Periodically discard unused blocks on filesystems.")
+   (default-value (fstrim-configuration))))
+
 ;;; admin.scm ends here
diff --git a/gnu/services/mcron.scm b/gnu/services/mcron.scm
index 23760ebda4..833d979ab4 100644
--- a/gnu/services/mcron.scm
+++ b/gnu/services/mcron.scm
@@ -154,6 +154,12 @@ (define mcron-shepherd-services
               (actions
                (list (shepherd-schedule-action mcron files)))))))))
 
+(define %mcron-activation
+  (with-imported-modules '((guix build utils))
+    #~(begin
+        (use-modules (guix build utils))
+        (mkdir-p "/var/lib/mcron"))))
+
 (define mcron-service-type
   (service-type (name 'mcron)
                 (description
@@ -161,6 +167,8 @@ (define mcron-service-type
                 (extensions
                  (list (service-extension shepherd-root-service-type
                                           mcron-shepherd-services)
+                       (service-extension activation-service-type
+                                          (const %mcron-activation))
                        (service-extension profile-service-type
                                           (compose list
                                                    mcron-configuration-mcron))))
-- 
2.37.3





Acknowledgement sent to iyzsong@HIDDEN:
New bug report received and forwarded. Copy sent to guix-patches@HIDDEN. Full text available.
Report forwarded to guix-patches@HIDDEN:
bug#58086; Package guix-patches. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Thu, 3 Nov 2022 16:00:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.