diff mbox series

[bug#70542,2/4] services: base: Use requirements to delay some file-systems

Message ID 91efec381997bd89208d9f4a47141ae6481fb963.1713904784.git.richard@freakingpenguin.com
State New
Headers show
Series Improve Shepherd service support for networked file systems | expand

Commit Message

Richard Sent April 23, 2024, 8:47 p.m. UTC
Add a mechanism to only require a subset of file-system entries during early
Shepherd initialization. Any file-system with additional Shepherd service
requirements (e.g. networking) will be brought up after 'file-systems is
provisioned.

* gnu/services/base.scm (file-system-shepherd-service): Splice
file-system-requirements into the Shepherd service requirement list.
* gnu/services/base.scm (file-system-shepherd-services): Provision
'file-system when file-systems that satisfy initial-file-system?  are started.

Change-Id: I7b1336ee970f4320f7431bef187e66f34f0d718c
---
 gnu/services/base.scm | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

Comments

Liliana Marie Prikler April 24, 2024, 5:30 p.m. UTC | #1
Am Dienstag, dem 23.04.2024 um 16:47 -0400 schrieb Richard Sent:
> Add a mechanism to only require a subset of file-system entries
> during early
> Shepherd initialization. Any file-system with additional Shepherd
> service
> requirements (e.g. networking) will be brought up after 'file-systems
> is
> provisioned.
> 
> * gnu/services/base.scm (file-system-shepherd-service): Splice
> file-system-requirements into the Shepherd service requirement list.
> * gnu/services/base.scm (file-system-shepherd-services): Provision
> 'file-system when file-systems that satisfy initial-file-system?  are
> started.
> 
> Change-Id: I7b1336ee970f4320f7431bef187e66f34f0d718c
> ---
>  gnu/services/base.scm | 16 ++++++++++++++--
>  1 file changed, 14 insertions(+), 2 deletions(-)
> 
> diff --git a/gnu/services/base.scm b/gnu/services/base.scm
> index 3f912225a0..af92b700b4 100644
> --- a/gnu/services/base.scm
> +++ b/gnu/services/base.scm
> @@ -403,6 +403,7 @@ (define (file-system-shepherd-service file-
> system)
>          (create? (file-system-create-mount-point? file-system))
>          (mount?  (file-system-mount? file-system))
>          (dependencies (file-system-dependencies file-system))
> +        (requirements (file-system-requirements file-system))
>          (packages (file-system-packages (list file-system))))
>      (and (or mount? create?)
>           (with-imported-modules (source-module-closure
> @@ -411,7 +412,8 @@ (define (file-system-shepherd-service file-
> system)
>              (provision (list (file-system->shepherd-service-name
> file-system)))
>              (requirement `(root-file-system
>                             udev
> -                           ,@(map dependency->shepherd-service-name
> dependencies)))
> +                           ,@(map dependency->shepherd-service-name
> dependencies)
> +                           ,@requirements))
>              (documentation "Check, mount, and unmount the given file
> system.")
>              (start #~(lambda args
>                         #$(if create?
> @@ -460,12 +462,22 @@ (define (file-system-shepherd-services file-
> systems)
>                                   (or (file-system-mount? x)
>                                       (file-system-create-mount-
> point? x)))
>                                 file-systems)))
> +
> +    (define (initial-file-system? file-system)
> +      "Return #t if the file system should be mounted initially or
> #f."
> +      ;; File systems with additional Shepherd requirements (e.g.
> networking)
> +      ;; should not be considered initial. Those requirements likely
> rely on
> +      ;; 'file-systems being provisioned.
> +      (null? (file-system-requirements file-system)))
> +
>      (define sink
>        (shepherd-service
>         (provision '(file-systems))
>         (requirement (cons* 'root-file-system 'user-file-systems
>                             (map file-system->shepherd-service-name
> -                                file-systems)))
> +                                ;; Only file systems considered
> initial should
> +                                ;; be required to provision 'file-
> systems.
> +                                (filter initial-file-system? file-
> systems))))
I'd compose null? and file-system-requirements directly in the filter –
that's easier to wrap my head around.
You then also have a little more space to explain why this composition
is done in the first place.

Cheers
diff mbox series

Patch

diff --git a/gnu/services/base.scm b/gnu/services/base.scm
index 3f912225a0..af92b700b4 100644
--- a/gnu/services/base.scm
+++ b/gnu/services/base.scm
@@ -403,6 +403,7 @@  (define (file-system-shepherd-service file-system)
         (create? (file-system-create-mount-point? file-system))
         (mount?  (file-system-mount? file-system))
         (dependencies (file-system-dependencies file-system))
+        (requirements (file-system-requirements file-system))
         (packages (file-system-packages (list file-system))))
     (and (or mount? create?)
          (with-imported-modules (source-module-closure
@@ -411,7 +412,8 @@  (define (file-system-shepherd-service file-system)
             (provision (list (file-system->shepherd-service-name file-system)))
             (requirement `(root-file-system
                            udev
-                           ,@(map dependency->shepherd-service-name dependencies)))
+                           ,@(map dependency->shepherd-service-name dependencies)
+                           ,@requirements))
             (documentation "Check, mount, and unmount the given file system.")
             (start #~(lambda args
                        #$(if create?
@@ -460,12 +462,22 @@  (define (file-system-shepherd-services file-systems)
                                  (or (file-system-mount? x)
                                      (file-system-create-mount-point? x)))
                                file-systems)))
+
+    (define (initial-file-system? file-system)
+      "Return #t if the file system should be mounted initially or #f."
+      ;; File systems with additional Shepherd requirements (e.g. networking)
+      ;; should not be considered initial. Those requirements likely rely on
+      ;; 'file-systems being provisioned.
+      (null? (file-system-requirements file-system)))
+
     (define sink
       (shepherd-service
        (provision '(file-systems))
        (requirement (cons* 'root-file-system 'user-file-systems
                            (map file-system->shepherd-service-name
-                                file-systems)))
+                                ;; Only file systems considered initial should
+                                ;; be required to provision 'file-systems.
+                                (filter initial-file-system? file-systems))))
        (documentation "Target for all the initially-mounted file systems")
        (start #~(const #t))
        (stop #~(const #f))))