public inbox for util-linux@vger.kernel.org
 help / color / mirror / Atom feed
From: Karel Zak <kzak@redhat.com>
To: Stanislav Brabec <sbrabec@suse.cz>
Cc: util-linux@vger.kernel.org
Subject: Re: mount: "nofail" and already mounted devices?
Date: Thu, 9 Jan 2014 11:02:54 +0100	[thread overview]
Message-ID: <20140109100254.GD7516@x2.net.home> (raw)
In-Reply-To: <1389203741.8841.31.camel@oct.suse.cz>

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

  reply	other threads:[~2014-01-09 10:02 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-08 17:55 mount: "nofail" and already mounted devices? Stanislav Brabec
2014-01-09 10:02 ` Karel Zak [this message]
2014-01-09 15:51   ` Stanislav Brabec
2014-01-09 16:21     ` Karel Zak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140109100254.GD7516@x2.net.home \
    --to=kzak@redhat.com \
    --cc=sbrabec@suse.cz \
    --cc=util-linux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox