On Fri, Oct 30 2015, Karel Zak wrote: > On Mon, Oct 19, 2015 at 12:08:41PM +1100, Neil Brown wrote: >> /* 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. > > Well, we have many situations (another than mount -a) when you want to > know if the FS is mounted, but you have not permissions for mount(2) > or you don't want to try it (because mount(2) may trigger many another > things in userspace). > >> Did I miss any important consideration there? > > The problem is that the way between fstab entry and mount(2) is > sometimes pretty complex (mount.<type> helpers, loop devices, > UUID/LABEL translation, etc). > > So, compare fstab with /proc/mounts is usually good compromise... > > Your suggestion seems usable for mount -a, but it's one small use-case > (and for example systemd don't use "mount -a" during boot). > >> 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? > > We have kill(PID, 0) to detect if the PID is valid, you don't have to > parse all /proc. It would be nice to have the same for filesystems, > something like > > mount("/dev/sda1, "/mnt", "ext4", MS_NOMOUNT, NULL) I like that! I really do. It returns the same error as mount would if run by a privileged uses, or returns success without actually changing anything. MS_NOMOUNT is incompatible with MS_REMOUNT, MS_MOVE and several others. I won't be providing a kernel patch straight away, but I would like to see this happen. Thanks, NeilBrown
Attachment:
signature.asc
Description: PGP signature