Subject: bug#39770: mount-file-system fails to mount NFS file system

From: [email-masked]
Date: Mon, 24 Feb 2020 14:39:13 -0500

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