From mboxrd@z Thu Jan 1 00:00:00 1970 From: John Darrington Subject: Re: [PATCH] gnu: Allow nfs filesystems to be automatically mounted. Date: Thu, 24 Nov 2016 00:32:58 +0100 Message-ID: <20161123233258.GA17068@jocasta.intra> References: <87a8cy780c.fsf@gnu.org> <1479842100-13226-1-git-send-email-jmd@gnu.org> <87mvgp4zq8.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="5mCyUwZo2JvN/JJP" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:45292) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c9h2M-0007gB-4l for guix-devel@gnu.org; Wed, 23 Nov 2016 18:33:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c9h2L-0001QC-1X for guix-devel@gnu.org; Wed, 23 Nov 2016 18:33:10 -0500 Content-Disposition: inline In-Reply-To: <87mvgp4zq8.fsf@gnu.org> List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: "Guix-devel" To: Ludovic Court??s Cc: guix-devel@gnu.org, John Darrington --5mCyUwZo2JvN/JJP Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Nov 23, 2016 at 11:07:27PM +0100, Ludovic Court??s wrote: John Darrington skribis: =20 > * gnu/build/file-systems.scm (mount-file-system): Append target addr= =3D when > mounting nfs filesystems. > --- > gnu/build/file-systems.scm | 16 +++++++++++++++- > 1 file changed, 15 insertions(+), 1 deletion(-) > > diff --git a/gnu/build/file-systems.scm b/gnu/build/file-systems.scm > index 0d55e91..c6fc784 100644 > --- a/gnu/build/file-systems.scm > +++ b/gnu/build/file-systems.scm > @@ -481,7 +481,21 @@ run a file system check." > (call-with-output-file mount-point (const #t))) > (mkdir-p mount-point)) > =20 > - (mount source mount-point type flags options) > + (mount source mount-point type flags > + (cond > + ((string-match "^nfs.*" type) > + (let* ((host (car (string-split source #\:))) > + (aa (car (getaddrinfo host #f))) > + (sa (addrinfo:addr aa)) > + (inet-addr (inet-ntop (sockaddr:fam sa) > + (sockaddr:addr sa)))) > + (string-append "addr=3D" > + inet-addr > + (if options > + (string-append "," options) > + "")))) > + (else > + options))) =20 Looking at mount(8), it seems that the normal way is for ???source??? = to be something like ???knuth.cwi.nl:/dir???. The kernel then takes care of parsing that and doing name resolution somehow. =20 In that case, we don???t have anything to do, good for us. Unforunately that is not the case. :( Attempting to mount a NFS system by a direct system call will fail unless y= ou pass addr=3D as an option (try it if you don't believe me). The mount.nfs command when used with -v shows what actually goes on: $ sudo mount.nfs -v 192.168.0.125:/export/junk /mnt mount.nfs: timeout set for Wed Nov 23 23:50:43 2016 mount.nfs: trying text-based options 'vers=3D4.2,addr=3D192.168.0.125,clie= ntaddr=3D192.168.0.22' mount.nfs: mount(2): Protocol not supported mount.nfs: trying text-based options 'vers=3D4.1,addr=3D192.168.0.125,clie= ntaddr=3D192.168.0.22' mount.nfs: mount(2): No such file or directory mount.nfs: trying text-based options 'addr=3D192.168.0.125' mount.nfs: prog 100003, trying vers=3D3, prot=3D6 mount.nfs: trying 192.168.0.125 prog 100003 vers 3 prot TCP port 2049 mount.nfs: prog 100005, trying vers=3D3, prot=3D17 mount.nfs: trying 192.168.0.125 prog 100005 vers 3 prot UDP port 45585 192.168.0.125:/export/junk on /mnt type nfs As you can see, it does a kind of crude protocol negotiation with the serve= r. It's also instructive to experiment a bit by running a command like: sudo strace mount -v :/export/junk -o addr=3D192.168.0.125 /mnt in which one can see the system call:=20 mount(":/export/junk", "/mnt", "nfs", MS_MGC_VAL, "addr=3D192.168.0.125") = =3D 0 However running the same command but dropping the option will result in: sudo strace mount -v :/export/junk /mnt mount(":/export/junk", "/mnt", "nfs", MS_MGC_VAL, NULL) =3D -1 EINVAL (Inva= lid argument) So I think we really do need this patch or something similar to it. mount(8) doesn???t mention ???addr???. Do you have documentation abou= t it? This aspect of NFS is poorly documented. The best I found is a discussion = at http://stackoverflow.com/questions/28350912/nfs-mount-system-call-in-linux =20 J' =20 --=20 Avoid eavesdropping. Send strong encrypted email. PGP Public key ID: 1024D/2DE827B3=20 fingerprint =3D 8797 A26D 0854 2EAB 0285 A290 8A67 719C 2DE8 27B3 See http://sks-keyservers.net or any PGP keyserver for public key. --5mCyUwZo2JvN/JJP Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iEYEARECAAYFAlg2JyoACgkQimdxnC3oJ7P8owCeMeEmLHII/AQvXQkyDzCE1rfJ p6UAn3eL0ZxrWzU6piqWAqtS9ubXEDu6 =BdJH -----END PGP SIGNATURE----- --5mCyUwZo2JvN/JJP--