Subject: Re: multiple mounts on same directory
To: Alan Barrett <>
From: Bill Studenmund <>
List: tech-userlevel
Date: 07/18/2003 09:27:12
On Fri, 18 Jul 2003, Alan Barrett wrote:

> I want to have several union mounts on the same destination directory.
> When I perform the mounts one by one, it all works fine.  For example,
> 	mount -t null -o union /source1 /target
> 	mount -t null -o union /source2 /target
> However, when I put the following lines in /etc/fstab:
> 	/source1	/target		null	rw,union	0 0
> 	/source2	/target		null	rw,union	0 0
> and run "mount -av", then only the first mount works.  The second mount
> falls foul of a duplicate detection test in the mountfs() function
> near line 352 of src/sbin/mount/mount.c.  The test in question looks
> something like this:
> 		/*
> 		 * XXX can't check f_mntfromname,
> 		 * thanks to mfs, union, etc.
> 		 */
> 		if (strncmp(name, sfp[i].f_mntonname, MNAMELEN) == 0 &&
> 		    strncmp(vfstype, sfp[i].f_fstypename,
> 			MFSNAMELEN) == 0) {
> 			/* ignore duplicate ... */
> 		}
> I can see why we would sometimes want to avoid checking the f_mntfromname
> field (for example, with mfs mounts, it shows "mfs:<pid>" instead of just
> "mfs".  But sometimes (as in the multiple-union-mount case) we really
> do need to check f_mntfromname.
> I have the following ideas for fixing this:
>   1. Add a MNT_foo flag to mean "Do not use the f_mntfromname field
>      as part of duplicate detection"; let the flag be set by procfs,
>      kernfs, mfs, and any others that need it; and let it be tested by
>      the relevant part of mountfs().

Please don't. This case only matters to mount -a, and we've got a lot of
mount flags as it is. Please don't add a new one. We can just tweak the
mount -a code.

>   2. Add some special rules to the relevant part of mountfs() to help it
>      guess whether or not to use f_mntfromname for duplicate detection.
>      For example, it could assume that f_mntfromname is important for
>      all mounts with fstype="union" or with the MNT_UNION flag set.
>   3. Add fuzzy matching of f_mntfromname to the relevant part of
>      mountfs().  For example, it could decide that "mfs" and "mfs:123"
>      are close enough to count as duplicates.

I think it's perfectly fine to just have the code in mount know that for
mfs mount (and mfs mounts _only_), f_mntfromname doesn't matter for

The reason that "union" is special is that if you mount with the -b
option, then the f_mntfromname will get changed. As I recall, it'll become
"<below>:" in front of the name. So the matching code would also need to
synthesize a new union f_mntfromname. But once it's done that, it will
match perfectly well.

Note: this suggestion is a modification of #2. :-)

>   4. Keep both the original name (e.g."mfs") and the modified name (e.g.
>      "mfs:<pid>") around in the kernel, and make them both available in
>      struct statfs.  Let the relevant part of mountfs() use the original
>      name for duplicate detection.
> I like option 1 best.  I have written code for option 2 and it seems to
> work.

As above, I like a modified #2. There's no need for the kernel to get
involved in this, and I'd rather it didn't.

Take care,