diff mbox

mount syscall

Message ID 20161116210601.GA409@jocasta.intra
State New
Headers show

Commit Message

John Darrington Nov. 16, 2016, 9:06 p.m. UTC
On Tue, Nov 15, 2016 at 11:46:01AM +0100, Ludovic Court??s wrote:
     John Darrington <john@darrington.wattle.id.au> skribis:
     
     > On Mon, Nov 14, 2016 at 10:48:18AM +0100, Ludovic Court??s wrote:
     >      
     >      The ???mount??? system call; see (gnu build file-systems).
     >
     > I confess, I have not really thought about this before. But supposing somebody has in their /etc/config.scm:
     >
     >   (file-systems 
     >    (cons*
     >     (file-system
     >       (device "my-root")
     >       (title 'label)
     >       (mount-point "/")
     >       (type "ext4"))
     >     (file-system
     >       (device "fileserver.example.com:/home")
     >       (title 'device)
     >       (mount-point "/home")
     >       (type "nfs4"))
     >     %base-file-systems))
     >
     > Would the /home filesystem then get mounted on boot?
     
     Maybe not.  :-)
     
     The man page for mount(2) says:
     
     --8<---------------cut here---------------start------------->8--- Values
     for the filesystemtype argument supported by the kernel are listed in
     /proc/filesystems (e.g., "btrfs", "ext4", "jfs", "xfs", "vfat", "fuse",
     "tmpfs", "cgroup", "proc", "mqueue", "nfs", "cifs", "iso9660").  Further
     types may become available when the appropriate modules are loaded.
     --8<---------------cut here---------------end--------------->8---
     
     I don???t know what happens with NFS, you???ll have to tell us.

The answer seems to be that it would fail unless we patch our mount syscall
wrapper with something like:



WDYT?

Comments

Ludovic Courtès Nov. 17, 2016, 9:47 a.m. UTC | #1
John Darrington <john@darrington.wattle.id.au> skribis:

> On Tue, Nov 15, 2016 at 11:46:01AM +0100, Ludovic Court??s wrote:
>      John Darrington <john@darrington.wattle.id.au> skribis:
>      
>      > On Mon, Nov 14, 2016 at 10:48:18AM +0100, Ludovic Court??s wrote:
>      >      
>      >      The ???mount??? system call; see (gnu build file-systems).
>      >
>      > I confess, I have not really thought about this before. But supposing somebody has in their /etc/config.scm:
>      >
>      >   (file-systems 
>      >    (cons*
>      >     (file-system
>      >       (device "my-root")
>      >       (title 'label)
>      >       (mount-point "/")
>      >       (type "ext4"))
>      >     (file-system
>      >       (device "fileserver.example.com:/home")
>      >       (title 'device)
>      >       (mount-point "/home")
>      >       (type "nfs4"))
>      >     %base-file-systems))
>      >
>      > Would the /home filesystem then get mounted on boot?
>      
>      Maybe not.  :-)
>      
>      The man page for mount(2) says:
>      
>      --8<---------------cut here---------------start------------->8--- Values
>      for the filesystemtype argument supported by the kernel are listed in
>      /proc/filesystems (e.g., "btrfs", "ext4", "jfs", "xfs", "vfat", "fuse",
>      "tmpfs", "cgroup", "proc", "mqueue", "nfs", "cifs", "iso9660").  Further
>      types may become available when the appropriate modules are loaded.
>      --8<---------------cut here---------------end--------------->8---
>      
>      I don???t know what happens with NFS, you???ll have to tell us.
>
> The answer seems to be that it would fail unless we patch our mount syscall
> wrapper with something like:

[...]

> +                    (let ((xoptions
> +                           (cond
> +                            ((string-match "^nfs.*" type)
> +                             (let* ((hosts (string-split source #\:))
> +                                    (aa (car (getaddrinfo (car hosts)  #f)))
> +                                    (sa (addrinfo:addr aa))
> +                                    (inet-addr (inet-ntop (sockaddr:fam sa)
> +                                                          (sockaddr:addr sa))))
> +                               (string-append "addr="
> +                                              inet-addr
> +                                              (if options
> +                                                  (string-append "," options)
> +                                                  ""))))
> +                            (else
> +                             options))))

The ‘mount’ binding shouldn’t try to be smart and do things like this
IMO.  However, we could have a separate helper procedure to do that, if
needed and ‘file-system-shepherd-service’ would pick the right one.

Now, we should add system tests for that, otherwise it sounds like we’re
adding code that will rarely be used and we’ll never know whether it
actually works or how it’s supposed to be used.  :-)

Thanks,
Ludo’.
diff mbox

Patch

diff --git a/guix/build/syscalls.scm b/guix/build/syscalls.scm
index 2cee654..3435617 100644
--- a/guix/build/syscalls.scm
+++ b/guix/build/syscalls.scm
@@ -415,17 +415,33 @@  string.  When FLAGS contains MS_REMOUNT, SOURCE and TYPE are ignored.  When
 UPDATE-MTAB? is true, update /etc/mtab.  Raise a 'system-error' exception on
 error."
       (let-values (((ret err)
-                    (proc (if source
-                              (string->pointer source)
-                              %null-pointer)
-                          (string->pointer target)
-                          (if type
-                              (string->pointer type)
-                              %null-pointer)
-                          flags
-                          (if options
-                              (string->pointer options)
-                              %null-pointer))))
+                    (let ((xoptions
+                           (cond
+                            ((string-match "^nfs.*" type)
+                             (let* ((hosts (string-split source #\:))
+                                    (aa (car (getaddrinfo (car hosts)  #f)))
+                                    (sa (addrinfo:addr aa))
+                                    (inet-addr (inet-ntop (sockaddr:fam sa)
+                                                          (sockaddr:addr sa))))
+                               (string-append "addr="
+                                              inet-addr
+                                              (if options
+                                                  (string-append "," options)
+                                                  ""))))
+                            (else
+                             options))))
+                      (proc
+                       (if source
+                           (string->pointer source)
+                           %null-pointer)
+                       (string->pointer target)
+                       (if type
+                           (string->pointer type)
+                           %null-pointer)
+                       flags
+                       (if xoptions
+                           (string->pointer xoptions)
+                           %null-pointer)))))
         (unless (zero? ret)
           (throw 'system-error "mount" "mount ~S on ~S: ~A"
                  (list source target (strerror err))