Subject: bin/20305: mount(8) mounts based on existing mount points
To: None <gnats-bugs@gnats.netbsd.org>
From: None <cgd@netbsd.org>
List: netbsd-bugs
Date: 02/12/2003 00:55:00
>Number:         20305
>Category:       bin
>Synopsis:       feature request: mount(8) mounts based on existing mount points
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Tue Feb 11 16:56:01 PST 2003
>Closed-Date:
>Last-Modified:
>Originator:     Chris G. Demetriou
>Release:        NetBSD-current 2003-02-11 00:00 UTC
>Organization:
>Environment:
See release.  8-)
>Description:
This is a request for a new feature, implemented by the patch below.

It allows fstab entries to be specified like:

from_mount      /               nfs ro 0 0

i.e., take the fs to mount for / from the existing mount point.
(this can be useful for diskless clients.)

In the example given above, it arranges for root to be re-mounted
read-only, which is important to help provide a generic "here's an NFS
file system" tarball which:

* can be untarred into any location to provide a working NFS root FS
  (i.e., no hard-coded paths in the FS, just pop them into your DHCP config
  or whatever.)

* which can be used read-only and shared by multiple clients *** with
  a completely generic kernel capable of root on NFS *** i.e., needing
  no special options to enable read-only root.

I use this type of thing to provide a pre-packaged hacking environment
for people (i.e., "you want to boot your machines?  point them at this
NFS root." or "you want an NFS root?  here's a tarball, point your
DHCP config at it, and use it for as many of your boxes as you'd like!")

>How-To-Repeat:

>Fix:

Index: mount.8
===================================================================
RCS file: /projects/bbp/cvsroot/systemsw/netbsd/src/sbin/mount/mount.8,v
retrieving revision 1.1.1.7
retrieving revision 1.8
diff -u -p -r1.1.1.7 -r1.8
--- mount.8	6 Feb 2003 00:30:37 -0000	1.1.1.7
+++ mount.8	12 Feb 2003 00:34:51 -0000	1.8
@@ -58,6 +58,7 @@ command invokes a filesystem-specific pr
 .Ar special
 device or remote node (rhost:path) on to the file system tree at the point
 .Ar node .
+.Pp
 If either
 .Ar special
 or
@@ -70,6 +71,17 @@ The provided argument is looked up first
 then in the
 .Dq fs_spec
 column.
+If the matching entry in
+.Xr fstab 5
+has the string
+.Dq Li from_mount
+as its
+.Dq fs_spec
+field, the device or remote file system already mounted at
+the location specified by
+.Dq fs_spec
+will be used.
+.Pp
 If both
 .Ar special
 and
Index: mount.c
===================================================================
RCS file: /projects/bbp/cvsroot/systemsw/netbsd/src/sbin/mount/mount.c,v
retrieving revision 1.1.1.5
retrieving revision 1.6
diff -u -p -r1.1.1.5 -r1.6
--- mount.c	6 Feb 2003 00:30:37 -0000	1.1.1.5
+++ mount.c	6 Feb 2003 23:15:21 -0000	1.6
@@ -175,7 +175,15 @@ main(argc, argv)
 					continue;
 				if (hasopt(fs->fs_mntops, "noauto"))
 					continue;
-				if (mountfs(fs->fs_vfstype, fs->fs_spec,
+				if (strcmp(fs->fs_spec, "from_mount") == 0) {
+					if ((mntbuf = getmntpt(fs->fs_file)) == NULL)
+						errx(1,
+						    "unknown file system %s.",
+						    fs->fs_file);
+					mntfromname = mntbuf->f_mntfromname;
+				} else
+					mntfromname = fs->fs_spec;
+				if (mountfs(fs->fs_vfstype, mntfromname,
 				    fs->fs_file, init_flags, options,
 				    fs->fs_mntops, !forceall, NULL, 0))
 					rval = 1;
@@ -203,12 +211,13 @@ main(argc, argv)
 				errx(1,
 				    "unknown special file or file system %s.",
 				    *argv);
+			mntfromname = mntbuf->f_mntfromname;
 			if ((fs = getfsfile(mntbuf->f_mntonname)) != NULL) {
-				mntfromname = fs->fs_spec;
+				if (strcmp(fs->fs_spec, "from_mount") != 0)
+					mntfromname = fs->fs_spec;
 				/* ignore the fstab file options.  */
 				fs->fs_mntops = NULL;
-			} else
-				mntfromname = mntbuf->f_mntfromname;
+			}
 			mntonname  = mntbuf->f_mntonname;
 			fstypename = mntbuf->f_fstypename;
 			mountopts  = NULL;
@@ -221,7 +230,14 @@ main(argc, argv)
 			if (BADTYPE(fs->fs_type))
 				errx(1, "%s has unknown file system type.",
 				    *argv);
-			mntfromname = fs->fs_spec;
+			if (strcmp(fs->fs_spec, "from_mount") == 0) {
+				if ((mntbuf = getmntpt(*argv)) == NULL)
+					errx(1,
+					    "unknown special file or file system %s.",
+					    *argv);
+				mntfromname = mntbuf->f_mntfromname;
+			} else
+				mntfromname = fs->fs_spec;
 			mntonname   = fs->fs_file;
 			fstypename  = fs->fs_vfstype;
 			mountopts   = fs->fs_mntops;
>Release-Note:
>Audit-Trail:
>Unformatted: