Subject: patch to fix mount_nfs(8) problem with relative mount point
To: None <netbsd-users@netbsd.org>
From: George Abdelmalik <gabdelmalik@avdat.com.au>
List: netbsd-users
Date: 01/29/2005 04:57:24
--Boundary-00=_E0n+Bk2O9jNcVig
Content-Type: text/plain;
  charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline


=46rom those who are interested, I've produced a patch for a problem in=20
mount_nfs(8) which arises when specify a relative path for the mount point.

I'm running 2-0-RELEASE, and have also verified this with a recent -current=
,=20
but have only tested the patch on 2-0.

See attached file mount_nfs.c.diff, this patch was created against HEAD.

If somebody what to bring the patch into the source tree that fine with me.

An example that illustrates the problem is presented as follows.


=3D> contents of /etc/exports:

/mnt/shared -mapall=3Dgabdelmalik:users tb10


=3D> display currtenly mount directories

bash-3.00# mount

/dev/wd0a on / type ffs (NFS exported, local)

=3D> change to /tmp =A0and list

bash-3.00# cd /tmp
bash-3.00# ls -l
drwxr-xr-x =A02 root =A0 =A0 =A0 =A0 wheel =A0512 Jan 29 03:26 mnt

=3D> nfs mount /mnt/shared onto mnt

bash-3.00# mount_nfs tb10:/mnt/shared mnt

=3D> display currently mounted directories

bash-3.00# mount
/dev/wd0a on / type ffs (NFS exported, local)
tb10:/mnt/shared on mnt type nfs
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ^^^ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0|
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0|-Note that mount point is liste=
d with relative path

=3D> the contents of the mount fs can be listed successfully

bash-3.00# ls mnt
total 82
=2Drw-r--r-- =A01 root =A0wheel =A043779 Jan 29 03:26 NetBSD.png
=2Drw-r--r-- =A01 root =A0wheel =A0 =A0 =A01 Jan 29 03:26 SEE.altq.conf.man=
page
=2Drw-r--r-- =A01 root =A0wheel =A0 =A0 =A01 Jan 29 03:26 SEE.chflags.manpa=
ge
=2Drw-r--r-- =A01 root =A0wheel =A0 =A0 =A01 Jan 29 03:26 SEE.dumpfs.manpage
=2Drwxr-xr-x =A01 root =A0wheel =A0 9050 Jan 29 03:26 cpuflags.NetBSD
=2Drwxr-xr-x =A01 root =A0wheel =A0 =A0645 Jan 29 03:26 dos2unix.sh
=2Drwxr-xr-x =A01 root =A0wheel =A0 =A0 21 Jan 29 03:26 dos2unix.vi
=2Drwx------ =A01 root =A0wheel =A0 =A0598 Jan 29 03:26 retouch.sh
=2Drwxr-xr-x =A01 root =A0wheel =A011736 Jan 29 03:26 slocc.sh
=2Drwxr-xr-x =A01 root =A0wheel =A0 =A0243 Jan 29 03:26 spawn
=2Drw-r--r-- =A01 root =A0wheel =A0 =A0419 Jan 29 03:26 trix


=3D> attempting to umount the fs using the mount point results in an error

bash-3.00# umount mnt
umount: /tmp/mnt: not currently mounted


=3D> unmounting is only possible using rhost:path

bash-3.00# umount tb10:/mnt/shared
bash-3.00# mount
/dev/wd0a on / type ffs (NFS exported, local)


=3D> moding src/sbin/mount_nfs/mount_nfs.c =A0to use realpath(3) [see diff=
=20
attached], allows a relative mount point to be specified with the mount_nfs=
=20
command, and be able to umount that fs in the normal may.

=3D> using the newly built mount_nfs yields


bash-3.00# mount_nfs tb10:/mnt/shared mnt
bash-3.00# mount
/dev/wd0a on / type ffs (NFS exported, local)
tb10:/mnt/shared on /tmp/mnt type nfs
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ^^^^^^^^
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0|
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0|-Note that mount point is n=
ow shown with absolute path
bash-3.00# umount mnt
bash-3.00# mount
/dev/wd0a on / type ffs (NFS exported, local)



--Boundary-00=_E0n+Bk2O9jNcVig
Content-Type: text/x-diff;
  charset="iso-8859-1";
  name="mount_nfs.c.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename="mount_nfs.c.diff"

Index: mount_nfs.c
===================================================================
RCS file: /cvsroot/src/sbin/mount_nfs/mount_nfs.c,v
retrieving revision 1.45
diff -r1.45 mount_nfs.c
238c238,239
< 	char *name, *p, *spec, *ospec;
---
> 	char *p, *spec, *ospec;
>         char name[MAXPATHLEN];
516c517,520
< 	name = *argv;
---
> 
> 	/* represent the mount point as absolute path */
>         realpath(*argv, name);
> 

--Boundary-00=_E0n+Bk2O9jNcVig--