unofficial mirror of bug-guix@gnu.org 
 help / color / mirror / code / Atom feed
* bug#39770: mount-file-system fails to mount NFS file system
@ 2020-02-24 19:39 maxim.cournoyer
  2020-02-24 21:21 ` Maxim Cournoyer
  0 siblings, 1 reply; 2+ messages in thread
From: maxim.cournoyer @ 2020-02-24 19:39 UTC (permalink / raw)
  To: 39770

The mount-file-system call used in our init RAM disk (see: (gnu build
file-systems)) doesn't produce the correct system call as can be
demontstrated by the following C program:

--8<---------------cut here---------------start------------->8---
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <sys/mount.h>

/* int mount(const char *source, const char *target, */
/* 	  const char *filesystemtype, unsigned long mountflags, */
/* 	  const void *data); */

int main() {
  //char *src = "192.168.51.34:/mnt/scratch/yocto-sstate";
  char *src = "192.168.51.34:/mnt/scratch/yocto-sstate";
  char *target = "/mnt/scratch/yocto-sstate";
  char *type = "nfs";
  unsigned long mountflags = 0;
  char *data = "addr=192.168.51.34";  //file system specific options

  int ret = 0;
  ret = mount(src, target, type, mountflags, data);

  if (ret == -1); {
    int errsv = errno;
    printf("mount() failed with error: %s\n", strerror(errsv));
  }
}

--8<---------------cut here---------------end--------------->8---

Running the program with strace, we can see that it failed with a
connection refused error:

--8<---------------cut here---------------start------------->8---
/* mount("192.168.51.34:/mnt/scratch/yocto-sstate", "/mnt/scratch/yocto-sstate", "nfs", 0, "addr=192.168.51.34") = -1 ECONNREFUSED (Connection refused) */
--8<---------------cut here---------------end--------------->8---


When having nfs-utils installed and tracing mount.nfs with:

--8<---------------cut here---------------start------------->8---
strace -f -s320 mount j1-slave1.sfl.team:/mnt/scratch/yocto-dldir /mnt/scratch/yocto-dldir -t nfs
--8<---------------cut here---------------end--------------->8---

We can see that the working invocation reads as:

--8<---------------cut here---------------start------------->8---
mount("j1-slave1.sfl.team:/mnt/scratch/yocto-dldir", "/mnt/scratch/yocto-dldir", "nfs", 0, "vers=4.2,addr=192.168.51.34,clientaddr=192.168.49.249")
--8<---------------cut here---------------end--------------->8---

It seems we're missing either a "vers" (doubtful) or more likely the
"clientaddr" option.

Maxim

^ permalink raw reply	[flat|nested] 2+ messages in thread

* bug#39770: mount-file-system fails to mount NFS file system
  2020-02-24 19:39 bug#39770: mount-file-system fails to mount NFS file system maxim.cournoyer
@ 2020-02-24 21:21 ` Maxim Cournoyer
  0 siblings, 0 replies; 2+ messages in thread
From: Maxim Cournoyer @ 2020-02-24 21:21 UTC (permalink / raw)
  To: 39770

[-- Attachment #1: Type: text/plain, Size: 727 bytes --]

Hi,

maxim.cournoyer@gmail.com writes:

[...]

> It seems we're missing either a "vers" (doubtful) or more likely the
> "clientaddr" option.

It turns out that the "vers" (or more specifically, "nfsvers") option
was mandatory to resolve this error.  What "mount.nfs" from
nfs-utils seems to do is start with "4.2", then retry upon errors lesser
versions.

The attached patch adds the required "nfsvers=4.2" option by default, or
honors a user specified one.  No retry is done.  Note that it currently
uses file system options represented as an alist, but this is likely to
change as the code review on "allow booting from a Btrfs subvolume"
progresses (the current patch is based atop of
<https://bugs.gnu.org/37305>).

Maxim


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-build-file-systems-Specify-a-nfsvers-option-by-defau.patch --]
[-- Type: text/x-patch, Size: 4614 bytes --]

From 6cbae0746dbeb736dc8c037183038eca2f7867fd Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
Date: Mon, 24 Feb 2020 16:09:10 -0500
Subject: [PATCH] build: file-systems: Specify a "nfsvers" option by default
 for NFS.

Without it, the mount system call fails with an ECONNREFUSED (Connection
refused) error.

* gnu/build/file-systems.scm (nfs-source->ip-address): Add procedure, with
code moved from...
(mount-file-system): ...the inner `mount-nfs' procedure, now removed.  The NFS
specific required options default values are now computed and added to the
regular options.  Honor any user given "addr", "nfsvers" or "vers" option."
Remove the call to `mount-nfs', no longer needed.
---
 gnu/build/file-systems.scm | 59 +++++++++++++++++++++-----------------
 1 file changed, 33 insertions(+), 26 deletions(-)

diff --git a/gnu/build/file-systems.scm b/gnu/build/file-systems.scm
index 76c143654d..fdeb12e825 100644
--- a/gnu/build/file-systems.scm
+++ b/gnu/build/file-systems.scm
@@ -640,36 +640,45 @@ corresponds to the symbols listed in FLAGS."
       (()
        0))))
 
+(define (nfs-source->ip-address source)
+  "Return the IP address from the source component of a network file-system."
+  (let* ((idx (string-rindex source #\:))
+         (host-part (string-take source idx))
+         ;; Strip [] from around host if present
+         (host (match (string-split host-part (string->char-set "[]"))
+                 (("" h "") h)
+                 ((h) h)))
+         (aa (match (getaddrinfo host "nfs") ((x . _) x)))
+         (sa (addrinfo:addr aa)))
+    (inet-ntop (sockaddr:fam sa)
+               (sockaddr:addr sa))))
+
 (define* (mount-file-system fs #:key (root "/root"))
   "Mount the file system described by FS, a <file-system> object, under ROOT."
 
-  (define (mount-nfs source mount-point type flags options)
-    (let* ((idx (string-rindex source #\:))
-           (host-part (string-take source idx))
-           ;; Strip [] from around host if present
-           (host (match (string-split host-part (string->char-set "[]"))
-                 (("" h "") h)
-                 ((h) h)))
-           (aa (match (getaddrinfo host "nfs") ((x . _) x)))
-           (sa (addrinfo:addr aa))
-           (inet-addr (inet-ntop (sockaddr:fam sa)
-                                 (sockaddr:addr sa))))
-
-      ;; Mounting an NFS file system requires passing the address
-      ;; of the server in the addr= option
-      (mount source mount-point type flags
-             (string-append "addr="
-                            inet-addr
-                            (if options
-                                (string-append "," options)
-                                "")))))
   (let* ((type        (file-system-type fs))
          (nfs? (string-prefix? "nfs" type))
+         (source      (canonicalize-device-spec (file-system-device fs)))
          (fs-options (file-system-options fs))
-         (options (if (null? fs-options)
+         (fs-options*
+          (if nfs?
+              ;; Do not override user specified "addr", "nfsvers" or "vers",
+              ;; but provide default values as otherwise mount fails to
+              ;; connect.
+              `(,@fs-options
+                ,@(if (member "addr" fs-options)
+                      '()
+                      (list (format #f "addr=~a"
+                                    (nfs-source->ip-address source))))
+                ,@(if (or (assoc-ref fs-options "nfsvers")
+                          (assoc-ref fs-options "vers"))
+                      '()
+                      (list "nfsvers=4.2")))
+              fs-options))
+         (options (if (null? fs-options*)
                       #f
-                      (file-system-options->string fs-options)))
-         (source      (canonicalize-device-spec (file-system-device fs)))
+                      (file-system-options->string fs-options*)))
+
          (mount-point (string-append root "/"
                                      (file-system-mount-point fs)))
          (flags       (mount-flags->bit-mask (file-system-flags fs))))
@@ -685,9 +694,7 @@ corresponds to the symbols listed in FLAGS."
           (call-with-output-file mount-point (const #t)))
         (mkdir-p mount-point))
 
-    (if nfs?
-        (mount-nfs source mount-point type flags options)
-        (mount source mount-point type flags options))
+    (mount source mount-point type flags options)
 
     ;; For read-only bind mounts, an extra remount is needed, as per
     ;; <http://lwn.net/Articles/281157/>, which still applies to Linux 4.0.
-- 
2.25.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-02-24 21:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-24 19:39 bug#39770: mount-file-system fails to mount NFS file system maxim.cournoyer
2020-02-24 21:21 ` Maxim Cournoyer

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).