* mount: "nofail" and already mounted devices?
@ 2014-01-08 17:55 Stanislav Brabec
2014-01-09 10:02 ` Karel Zak
0 siblings, 1 reply; 4+ messages in thread
From: Stanislav Brabec @ 2014-01-08 17:55 UTC (permalink / raw)
To: util-linux
Attempting to mount of already mounted devices is a common situation in
many scripts. There is no easy way to detect it in the current mount
implementation.
One of our users complains that this situation is not covered by
"nofail" mount option. ("nofail" does exactly what the documentation
describes and nothing more.)
Would be acceptable a patch that adds "already mounted" to "nofail"?
If not, what would be the best way of enabling this feature for mounting
a single device? (It already exists in mount, but it is usable only with
"mount -a".)
- Add another mount option, e. g. mountednofail or mountedok
- Make possible to use "-a" with further arguments.
- Add new option, e. g. "-A".
and/or
- New result code, e. g. 33 instead of 32. (As it can not suppress the
error message, it is well usable only as an addition to above.)
--
Best Regards / S pozdravem,
Stanislav Brabec
software developer
---------------------------------------------------------------------
SUSE LINUX, s. r. o. e-mail: sbrabec@suse.cz
Lihovarská 1060/12 tel: +49 911 7405384547
190 00 Praha 9 fax: +420 284 084 001
Czech Republic http://www.suse.cz/
PGP: 830B 40D5 9E05 35D8 5E27 6FA3 717C 209F A04F CD76
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: mount: "nofail" and already mounted devices?
2014-01-08 17:55 mount: "nofail" and already mounted devices? Stanislav Brabec
@ 2014-01-09 10:02 ` Karel Zak
2014-01-09 15:51 ` Stanislav Brabec
0 siblings, 1 reply; 4+ messages in thread
From: Karel Zak @ 2014-01-09 10:02 UTC (permalink / raw)
To: Stanislav Brabec; +Cc: util-linux
On Wed, Jan 08, 2014 at 06:55:41PM +0100, Stanislav Brabec wrote:
> Attempting to mount of already mounted devices is a common situation in
> many scripts.
What about to fix the scripts? :-)
All you need is to call
findmnt --source <dev> --target <mountpoint>
and another possibility is compose /tmp/fstab by the script and then
call "mount --all --fstab /tmp/fstab"
> There is no easy way to detect it in the current mount
> implementation.
>
> Would be acceptable a patch that adds "already mounted" to "nofail"?
Maybe.
> If not, what would be the best way of enabling this feature for mounting
> a single device? (It already exists in mount, but it is usable only with
> "mount -a".)
It's not the same situation. The mount --all checks for the problem in
userspace (don't call mount(2) if the device is already mounted), but
for a single device we always call mount(2) and "already mounted or
busy" is based on EBUSY from kernel and you have to check mtab to
verify that the device is really already mounted (sys-utils/mount.c:481).
> - Add another mount option, e. g. mountednofail or mountedok
I'd like to avoid new mount options.
> - Make possible to use "-a" with further arguments.
mount -a /foo /bar [...]
Right?
It seems also attractive feature when you want to manually mount more
filesystems and it's without any side effects to the current mount(8)
semantic. (And we already ave "umount /foo /bar [...]".)
If you want to implement it then you have to filter out fstab entries
in the sys-utils/mount.c:mount_all() because "mount-all" logic is
hidden in libmount and I'm not sure if I want to extend the API for
this functionality :-)
So something like, sys-utils/mount.c:mount_all():
if (nwanted) {
struct libmnt_table *fstab;
mnt_context_get_fstab(cxt, &fstab);
while (mnt_table_next_fs(fstab, itr, &fs) == 0) {
int yes = 0;
for (i = 0; yes == 0 && i < nwanted; i++)
yes = mnt_fs_match_target(fs, wanted[i], cache);
if (!yes)
mnt_table_remove_fs(fstab, fs);
}
}
while (mnt_context_next_mount ....
... where wanted[] is array composed from argv[].
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: mount: "nofail" and already mounted devices?
2014-01-09 10:02 ` Karel Zak
@ 2014-01-09 15:51 ` Stanislav Brabec
2014-01-09 16:21 ` Karel Zak
0 siblings, 1 reply; 4+ messages in thread
From: Stanislav Brabec @ 2014-01-09 15:51 UTC (permalink / raw)
To: Karel Zak; +Cc: util-linux
Karel Zak wrote:
> On Wed, Jan 08, 2014 at 06:55:41PM +0100, Stanislav Brabec wrote:
> > Attempting to mount of already mounted devices is a common situation in
> > many scripts.
>
> What about to fix the scripts? :-)
>
> All you need is to call
>
> findmnt --source <dev> --target <mountpoint>
Yes, it is an option.
The new behavior could simplify common situation and also prevent a
race:
if the device is not yet mounted
mount it
do the work
> > Would be acceptable a patch that adds "already mounted" to "nofail"?
>
> Maybe.
Well, It could be a straightforward solution (~2 lines change). But it
could break following script (theoretical, a bit dumb and fragile, but
still depending only on documented behavior):
... do some actions that will initiate delayed $DEVICE creation ...
while mount -o nofail $DEVICE /opt ; do
if test -d /opt/myvendor ; then
break
fi
sleep 1
done
Now imagine, that somebody previously called:
mount $DEVICE /opt
What will happen with the current mount?
The script will fail as expected.
What will happen after such patch?
The script will enter to a dead loop.
> > - Make possible to use "-a" with further arguments.
>
> mount -a /foo /bar [...]
>
> Right?
Well, it sounds interesting as well, but I was thinking about
(conflicting):
mount -a /dev/device /mountpoint
It can be done both:
mount -a /foo /bar [...]
mount -A /dev/device /mountpoint
-A Do not report errors if the mount point is already used or device is
already mounted.
--
Best Regards / S pozdravem,
Stanislav Brabec
software developer
---------------------------------------------------------------------
SUSE LINUX, s. r. o. e-mail: sbrabec@suse.cz
Lihovarská 1060/12 tel: +49 911 7405384547
190 00 Praha 9 fax: +420 284 084 001
Czech Republic http://www.suse.cz/
PGP: 830B 40D5 9E05 35D8 5E27 6FA3 717C 209F A04F CD76
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: mount: "nofail" and already mounted devices?
2014-01-09 15:51 ` Stanislav Brabec
@ 2014-01-09 16:21 ` Karel Zak
0 siblings, 0 replies; 4+ messages in thread
From: Karel Zak @ 2014-01-09 16:21 UTC (permalink / raw)
To: Stanislav Brabec; +Cc: util-linux
On Thu, Jan 09, 2014 at 04:51:54PM +0100, Stanislav Brabec wrote:
> Karel Zak wrote:
> The new behavior could simplify common situation and also prevent a
> race:
> if the device is not yet mounted
> mount it
> do the work
It would be enough to add extra return code for EBUSY (which is
probably a good idea for all scenarios).
> > > - Make possible to use "-a" with further arguments.
> >
> > mount -a /foo /bar [...]
> >
> > Right?
>
> Well, it sounds interesting as well, but I was thinking about
> (conflicting):
> mount -a /dev/device /mountpoint
It's new feature, so we can be pretty strict about it
mount -a [<mountpoint> ..]
and do not support "mount -a <source> <target>". If you need
something more advanced then you have to compose a script.
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-01-09 16:21 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-01-08 17:55 mount: "nofail" and already mounted devices? Stanislav Brabec
2014-01-09 10:02 ` Karel Zak
2014-01-09 15:51 ` Stanislav Brabec
2014-01-09 16:21 ` Karel Zak
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox