Util-Linux package development
 help / color / mirror / Atom feed
From: NeilBrown <neilb@suse.com>
To: Karel Zak <kzak@redhat.com>
Cc: util-linux@vger.kernel.org
Subject: Re: "mount -o remount,rw" sometimes doesn't work as expected.
Date: Wed, 31 May 2017 13:05:26 +1000	[thread overview]
Message-ID: <87zidtenex.fsf@notabene.neil.brown.name> (raw)
In-Reply-To: <20170522112635.bcnfvxuqi7xbifb5@ws.net.home>

[-- Attachment #1: Type: text/plain, Size: 3710 bytes --]

On Mon, May 22 2017, Karel Zak wrote:

> On Mon, May 22, 2017 at 08:16:36AM +1000, NeilBrown wrote:
>> oooh... it just occurred to me that for a mount, I can make it
>> read/write by:
>> 
>>    mount -o remount,rw none /mount/point
>> 
>> providing I know that no other flags are needed.  I don't need to give
>> the correct device path, do I?
>
> Yes, "none" is an usable placeholder there.
>
>> > After this call, mount reads fstab and merges these options with the
>> > options from the command line (-o).  If no mountpoint is found in
>> > fstab, then a remount with  unspecified source is allowed.
>> 
>> BTW, if fstab contains just
>> 
>>    /bar /foo none bind 0 0
>> 
>> 
>> Then both
>>   mount -o remount,rw /bar
>> and
>>   mount -o remount,rw /foo
>> 
>> will try to remount /foo.  This is also surprising....
>
> Yes, mount(8) goal is to accept "whatever" to keep users happy :-)
>
> This your example is well known disadvantage, the solution is to use
> --source and --target options (it's strongly recommended for scripts):
>
>    mount -o remount,rw --source /bar
>    mount -o remount,rw --target /foo
>
> in this case mount(8) will not try to be smart...
>
> ...
>
>> >> You could possibly argue that the current behaviour is correct
>> >> as /foo is listed as bind mount.  That doesn't stop is being surprising.
>> >> Also
>> >>    mount /bar /foo -o remount,rw
>> >> 
>> >> doesn't pick up the "bind" flag, so the filesystem gets remounted.
>> >> So I think there is definitely something wrong.
>> >
>> > That's question... "remount,bind" is really special and maybe "bind"
>> > from fstab should be really ignored in this case.
>> 
>> I think that is probably the best way forward, at least in the short
>> term.
>> I might try to dig into the code and see how easy this would be.
>
> It's trivial patch, see below. Seems to work as expected (I use
> "findmnt -o TARGET,VFS-OPTIONS,FS-OPTION" to see ro/rw).
>
>     Karel
>

Sorry for the delay.

Yes, this does look easy, makes sense, and does work as expected for me
too.

Reported-and-tested-by: NeilBrown <neilb@suse.com>

will you be queuing this for the next release?

Thanks,
NeilBrown


>
> diff --git a/libmount/src/context.c b/libmount/src/context.c
> index 38e0363..a574758 100644
> --- a/libmount/src/context.c
> +++ b/libmount/src/context.c
> @@ -2038,7 +2038,7 @@ static int apply_table(struct libmnt_context *cxt, struct libmnt_table *tb,
>   */
>  int mnt_context_apply_fstab(struct libmnt_context *cxt)
>  {
> -	int rc = -1, isremount = 0;
> +	int rc = -1, isremount = 0, iscmdbind = 0;
>  	struct libmnt_table *tab = NULL;
>  	const char *src = NULL, *tgt = NULL;
>  	unsigned long mflags = 0;
> @@ -2063,8 +2063,10 @@ int mnt_context_apply_fstab(struct libmnt_context *cxt)
>  		cxt->optsmode &= ~MNT_OMODE_FORCE;
>  	}
>  
> -	if (mnt_context_get_mflags(cxt, &mflags) == 0 && mflags & MS_REMOUNT)
> -		isremount = 1;
> +	if (mnt_context_get_mflags(cxt, &mflags) == 0) {
> +		isremount = !!(mflags & MS_REMOUNT);
> +		iscmdbind = !!(mflags & MS_BIND);
> +	}
>  
>  	if (cxt->fs) {
>  		src = mnt_fs_get_source(cxt->fs);
> @@ -2131,6 +2133,12 @@ int mnt_context_apply_fstab(struct libmnt_context *cxt)
>  		 * not found are not so important and may be misinterpreted by
>  		 * applications... */
>  		rc = -MNT_ERR_NOFSTAB;
> +
> +
> +	} else if (isremount && !iscmdbind) {
> +
> +		/* remove "bind" from fstab (or no-op if not present) */
> +		mnt_optstr_remove_option(&cxt->fs->optstr, "bind");
>  	}
>  	return rc;
>  }
>
>
>
> -- 
>  Karel Zak  <kzak@redhat.com>
>  http://karelzak.blogspot.com

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

  reply	other threads:[~2017-05-31  3:05 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-19  7:14 "mount -o remount,rw" sometimes doesn't work as expected NeilBrown
2017-05-19  9:11 ` Karel Zak
2017-05-21 22:16   ` NeilBrown
2017-05-22 11:26     ` Karel Zak
2017-05-31  3:05       ` NeilBrown [this message]
2017-05-31  9:18         ` Karel Zak
2017-05-31 22:55           ` NeilBrown

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=87zidtenex.fsf@notabene.neil.brown.name \
    --to=neilb@suse.com \
    --cc=kzak@redhat.com \
    --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