When I run "mount -a" (and possibly in other circumstances) mount attempts to determine if the requested filesystem is already mounted. It seems to have some handling for various special cases, but doesn't handle all cases properly. For example, if I have server:/export /import nfs .... 192.168.1.1:/private private nfs .... in /etc/fstab and the IP address of 'server' is 192.168.1.1, then both entries will appear in /proc/mounts with the same host name (depending on which order there were mounted). When I run "mount -a" a second time it will detect that one of these is already correctly mounted, and will ignore it. The other will not be detected as already being mounted (as the hostname appears different) and "mount -a" will try to mount it again. This will fail with "EBUSY" and mount will report an error .... is busy or already mounted. So while both filesystems are already mounted, we only get an error for one of them. The irony here is that while it is hard for user-space to determine if the mounted filesystem matches the requested filesystem it is trivial for the kernel. For NFS we could try canonicalizing the server name, but undoubtedly other issues would arrive. I believe there are similar issues with btrfs and submount, though I have looked closely. For the kernel, it is as simple as /* Refuse the same filesystem on the same mount point */ err = -EBUSY; if (path->mnt->mnt_sb == newmnt->mnt.mnt_sb && path->mnt->mnt_root == path->dentry) goto unlock; This is the *only* time that the kernel returns EBUSY for a "mount a new filesystem" request (remount can return EBUSY for other reasons I think). So in the case where "mount" thinks it should check if the filesystem is already mounted and ignore the request if it is, the best thing it can do is to just try the mount and ignore any "EBUSY" error status - treat that the same as success. So all that code for "is this the same mountpoint" can probably be discarded. Did I miss any important consideration there? Unfortunately this change could be awkward to implement as /sbin/mount decides whether to try the mount and (for NFS), /sbin/mount.nfs gives an error message if EBUSY is returned. Would we need to pass a "noebusy" flag, but only if mount.nfs were willing to accept it.... Any suggestions? NeilBrown
Attachment:
signature.asc
Description: PGP signature