* [RFC] mount: overwrite options from /etc/fstab when given on the commandline
@ 2012-08-01 9:11 Niels de Vos
2012-08-01 9:48 ` Karel Zak
0 siblings, 1 reply; 9+ messages in thread
From: Niels de Vos @ 2012-08-01 9:11 UTC (permalink / raw)
To: util-linux; +Cc: Niels de Vos
Hi all,
it seems that some of the options given in /etc/fstab are not overloaded by
options given on the mount-commandline. Some options are not allowed to be
passed multiple times (like the SElinux context options) and mounting will fail
if options are present in both /etc/fstab and on the commandline.
Is there a reason for not overloading the options from /etc/fstab by the
options given on the commandline?
The patch below changes the behaviour of mount so that options on the
commandline replace options given in /etc/fstab. This example is based on the
now deprecated code of mount in util-linux-2.17.2. I'd like to receive some
responses if this change would be acceptible, or if this was done by design.
If this can be accepted, I'll happily look into the libmount code and provide
a patch for the current util-linux version.
Many thanks,
Niels
---
mount/mount.c | 44 +++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 43 insertions(+), 1 deletions(-)
diff --git a/mount/mount.c b/mount/mount.c
index 45f9699..e594f5e 100644
--- a/mount/mount.c
+++ b/mount/mount.c
@@ -294,6 +294,48 @@ print_all (char *types) {
exit (0);
}
+/* reallocates its first arg
+ * opt is the single option, val is the opt=val pair */
+static char *
+merge_one_opt(char *s, const char *opt, const char *val)
+{
+ char *old_opt, *next_opt;
+
+ if (!opt)
+ return s;
+ if (!s)
+ return xstrdup(val); /* opt & opt=val */
+ if (!val)
+ return s; /* s,opt */
+
+ old_opt = strstr(s, opt);
+ if (old_opt) {
+ next_opt = strchr(old_opt, ',');
+ if (!next_opt)
+ memset(old_opt, '\0', 1);
+ else
+ memmove(old_opt, next_opt + 1, strlen(next_opt) + 1);
+ }
+ return xstrconcat3(s, ",", val); /* s,opt=val */
+}
+
+/* reallocates its first arg */
+static char *
+merge_opts(char *s, const char *extra_opts)
+{
+ char *new_opts = xstrdup(extra_opts);
+ char *opt, *opt_pos, *o;
+
+ opt = strtok_r(new_opts, ",", &opt_pos);
+ while (opt != NULL) {
+ o = xstrndup(opt, strchrnul(opt, '=') - opt);
+ s = merge_one_opt(s, o, opt);
+ opt = strtok_r(NULL, ",", &opt_pos);
+ }
+
+ return s;
+}
+
/* reallocates its first arg */
static char *
append_opt(char *s, const char *opt, const char *val)
@@ -1701,7 +1743,7 @@ mount_one (const char *spec, const char *node, const char *types,
opts = usersubst(fstabopts);
/* Merge the fstab and command line options. */
- opts = append_opt(opts, cmdlineopts, NULL);
+ opts = merge_opts(opts, cmdlineopts);
if (types == NULL && !mounttype && !is_existing_file(spec)) {
if (strchr (spec, ':') != NULL) {
--
1.7.7.6
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [RFC] mount: overwrite options from /etc/fstab when given on the commandline
2012-08-01 9:11 [RFC] mount: overwrite options from /etc/fstab when given on the commandline Niels de Vos
@ 2012-08-01 9:48 ` Karel Zak
2012-08-01 10:03 ` Karel Zak
2012-08-01 10:11 ` Niels de Vos
0 siblings, 2 replies; 9+ messages in thread
From: Karel Zak @ 2012-08-01 9:48 UTC (permalink / raw)
To: Niels de Vos; +Cc: util-linux
On Wed, Aug 01, 2012 at 11:11:41AM +0200, Niels de Vos wrote:
> it seems that some of the options given in /etc/fstab are not overloaded by
> options given on the mount-commandline.
Well, all depends on kernel (and FS driver) how mount options are
evaluated. We have no any strict rules for 'source' and 'mount
options' in the mount(2) syscall.
The generic convention (!= rule) is that the option overwrites an
option previously specified in the mount options string:
aaa=x,bbb,aaa=y -> aaa should be 'y'
This is reason why mount(8) only appends the options from command line
to the options string from fstab.
Anyway, depends on FS driver how the options string will be
interpreted -- for example btrfs supports duplicate device= mount
option.
> Some options are not allowed to be
> passed multiple times (like the SElinux context options) and mounting will fail
> if options are present in both /etc/fstab and on the commandline.
This is stupid SELinux disadvantage and SELinux should be fixed.
> Is there a reason for not overloading the options from /etc/fstab by the
> options given on the commandline?
>
> The patch below changes the behaviour of mount so that options on the
> commandline replace options given in /etc/fstab.
I'd like to avoid that mount(8) tries to understand filesystem specific
options. The command mount(8) has no clue about the options (non-VFS
options). For example:
fstab:
/dev/sda /mnt btrfs device=/dev/sdb 0 0
command line:
mount /mnt -o device=/dev/sdc,device=/dev/sdd
so the final mount options string:
device=/dev/sdb,device=/dev/sdc,device=/dev/sdd
.. and this all is pretty valid for btrfs.
I'd like to implement for the next release 2.23 a new command line
options to specify a way how compose the final options string in the
mount(8). It's already in our Documentation/TODO file, see
--options-mode, probably something like:
--options-mode={ignore,append,prepend,replace,dedup}
or so.
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [RFC] mount: overwrite options from /etc/fstab when given on the commandline
2012-08-01 9:48 ` Karel Zak
@ 2012-08-01 10:03 ` Karel Zak
2012-08-01 10:14 ` Niels de Vos
2012-08-01 10:11 ` Niels de Vos
1 sibling, 1 reply; 9+ messages in thread
From: Karel Zak @ 2012-08-01 10:03 UTC (permalink / raw)
To: Niels de Vos; +Cc: util-linux
On Wed, Aug 01, 2012 at 11:48:33AM +0200, Karel Zak wrote:
> > Some options are not allowed to be
> > passed multiple times (like the SElinux context options) and mounting will fail
> > if options are present in both /etc/fstab and on the commandline.
>
> This is stupid SELinux disadvantage and SELinux should be fixed.
Note that mount(8) and libmount removes all selinux context options on
remount for kernels < 2.6.39 because SELinux context remount was
unsupported, so this SELinux disadvantage should be hidden for usual
use case.
Maybe we can also add another exception for SELinux to de-duplicate
the SELinux context options in the options string. It's not perfect,
but probably acceptable for SELinux -- I can do this for 2.22-rc2.
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [RFC] mount: overwrite options from /etc/fstab when given on the commandline
2012-08-01 9:48 ` Karel Zak
2012-08-01 10:03 ` Karel Zak
@ 2012-08-01 10:11 ` Niels de Vos
1 sibling, 0 replies; 9+ messages in thread
From: Niels de Vos @ 2012-08-01 10:11 UTC (permalink / raw)
To: Karel Zak; +Cc: util-linux
On 08/01/2012 11:48 AM, Karel Zak wrote:
> On Wed, Aug 01, 2012 at 11:11:41AM +0200, Niels de Vos wrote:
>> it seems that some of the options given in /etc/fstab are not overloaded by
>> options given on the mount-commandline.
>
> Well, all depends on kernel (and FS driver) how mount options are
> evaluated. We have no any strict rules for 'source' and 'mount
> options' in the mount(2) syscall.
>
> The generic convention (!= rule) is that the option overwrites an
> option previously specified in the mount options string:
>
> aaa=x,bbb,aaa=y -> aaa should be 'y'
>
> This is reason why mount(8) only appends the options from command line
> to the options string from fstab.
>
> Anyway, depends on FS driver how the options string will be
> interpreted -- for example btrfs supports duplicate device= mount
> option.
Ah, okay, if there are valid use-cases for options to be listed multiple
times, it won't be possible to overload the options from /etc/fstab by the
options from the commandline.
>> Some options are not allowed to be
>> passed multiple times (like the SElinux context options) and mounting will fail
>> if options are present in both /etc/fstab and on the commandline.
>
> This is stupid SELinux disadvantage and SELinux should be fixed.
Yeah, sounds like it. I may have a look on how the kernel can handle the
SElinux options better.
>> Is there a reason for not overloading the options from /etc/fstab by the
>> options given on the commandline?
>>
>> The patch below changes the behaviour of mount so that options on the
>> commandline replace options given in /etc/fstab.
>
> I'd like to avoid that mount(8) tries to understand filesystem specific
> options. The command mount(8) has no clue about the options (non-VFS
> options). For example:
>
> fstab:
> /dev/sda /mnt btrfs device=/dev/sdb 0 0
>
> command line:
>
> mount /mnt -o device=/dev/sdc,device=/dev/sdd
>
>
> so the final mount options string:
>
> device=/dev/sdb,device=/dev/sdc,device=/dev/sdd
>
> .. and this all is pretty valid for btrfs.
Nice example!
> I'd like to implement for the next release 2.23 a new command line
> options to specify a way how compose the final options string in the
> mount(8). It's already in our Documentation/TODO file, see
> --options-mode, probably something like:
>
> --options-mode={ignore,append,prepend,replace,dedup}
>
> or so.
Hmm, that sounds like it'll solve the problem, unless you'r combining
SElinux contexts and btrsf...
Thanks for your detailed response,
Niels
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [RFC] mount: overwrite options from /etc/fstab when given on the commandline
2012-08-01 10:03 ` Karel Zak
@ 2012-08-01 10:14 ` Niels de Vos
2012-08-01 10:32 ` Karel Zak
0 siblings, 1 reply; 9+ messages in thread
From: Niels de Vos @ 2012-08-01 10:14 UTC (permalink / raw)
To: Karel Zak; +Cc: util-linux
On 08/01/2012 12:03 PM, Karel Zak wrote:
> On Wed, Aug 01, 2012 at 11:48:33AM +0200, Karel Zak wrote:
>>> Some options are not allowed to be
>>> passed multiple times (like the SElinux context options) and mounting will fail
>>> if options are present in both /etc/fstab and on the commandline.
>>
>> This is stupid SELinux disadvantage and SELinux should be fixed.
>
> Note that mount(8) and libmount removes all selinux context options on
> remount for kernels< 2.6.39 because SELinux context remount was
> unsupported, so this SELinux disadvantage should be hidden for usual
> use case.
>
> Maybe we can also add another exception for SELinux to de-duplicate
> the SELinux context options in the options string. It's not perfect,
> but probably acceptable for SELinux -- I can do this for 2.22-rc2.
That would be great. What is your opinion on getting the SElinux options
handled differently in the kernel instead or in addition? If the kernel
would allow multiple SElinux options (and only the last gets applied) would
you still be interested in adding this SElinux exception?
Thanks again,
Niels
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [RFC] mount: overwrite options from /etc/fstab when given on the commandline
2012-08-01 10:14 ` Niels de Vos
@ 2012-08-01 10:32 ` Karel Zak
2012-08-01 11:58 ` Niels de Vos
0 siblings, 1 reply; 9+ messages in thread
From: Karel Zak @ 2012-08-01 10:32 UTC (permalink / raw)
To: Niels de Vos; +Cc: util-linux
On Wed, Aug 01, 2012 at 12:14:22PM +0200, Niels de Vos wrote:
> On 08/01/2012 12:03 PM, Karel Zak wrote:
> > On Wed, Aug 01, 2012 at 11:48:33AM +0200, Karel Zak wrote:
> >>> Some options are not allowed to be
> >>> passed multiple times (like the SElinux context options) and mounting will fail
> >>> if options are present in both /etc/fstab and on the commandline.
> >>
> >> This is stupid SELinux disadvantage and SELinux should be fixed.
> >
> > Note that mount(8) and libmount removes all selinux context options on
> > remount for kernels< 2.6.39 because SELinux context remount was
> > unsupported, so this SELinux disadvantage should be hidden for usual
> > use case.
> >
> > Maybe we can also add another exception for SELinux to de-duplicate
> > the SELinux context options in the options string. It's not perfect,
> > but probably acceptable for SELinux -- I can do this for 2.22-rc2.
>
> That would be great. What is your opinion on getting the SElinux options
> handled differently in the kernel instead or in addition?
SELinux is no filesystem and we already have (must have) SELinux
specific code in mount(8) (and many others utils;-).
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [RFC] mount: overwrite options from /etc/fstab when given on the commandline
2012-08-01 10:32 ` Karel Zak
@ 2012-08-01 11:58 ` Niels de Vos
2012-08-01 17:08 ` Karel Zak
0 siblings, 1 reply; 9+ messages in thread
From: Niels de Vos @ 2012-08-01 11:58 UTC (permalink / raw)
To: Karel Zak; +Cc: util-linux
On 08/01/2012 12:32 PM, Karel Zak wrote:
> On Wed, Aug 01, 2012 at 12:14:22PM +0200, Niels de Vos wrote:
>> On 08/01/2012 12:03 PM, Karel Zak wrote:
>>> On Wed, Aug 01, 2012 at 11:48:33AM +0200, Karel Zak wrote:
>>>>> Some options are not allowed to be
>>>>> passed multiple times (like the SElinux context options) and mounting will fail
>>>>> if options are present in both /etc/fstab and on the commandline.
>>>>
>>>> This is stupid SELinux disadvantage and SELinux should be fixed.
>>>
>>> Note that mount(8) and libmount removes all selinux context options on
>>> remount for kernels< 2.6.39 because SELinux context remount was
>>> unsupported, so this SELinux disadvantage should be hidden for usual
>>> use case.
>>>
>>> Maybe we can also add another exception for SELinux to de-duplicate
>>> the SELinux context options in the options string. It's not perfect,
>>> but probably acceptable for SELinux -- I can do this for 2.22-rc2.
>>
>> That would be great. What is your opinion on getting the SElinux options
>> handled differently in the kernel instead or in addition?
>
> SELinux is no filesystem and we already have (must have) SELinux
> specific code in mount(8) (and many others utils;-).
Okay, so as it's not a filesystem, it warrants the de-dup handling. I'd
appreciate it if this makes it in 2.22-rc2. Please let me know if you want me to
provide patches and/or test the results.
Many thanks,
Niels
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [RFC] mount: overwrite options from /etc/fstab when given on the commandline
2012-08-01 11:58 ` Niels de Vos
@ 2012-08-01 17:08 ` Karel Zak
2012-08-02 9:46 ` Niels de Vos
0 siblings, 1 reply; 9+ messages in thread
From: Karel Zak @ 2012-08-01 17:08 UTC (permalink / raw)
To: Niels de Vos; +Cc: util-linux
> >>On 08/01/2012 12:03 PM, Karel Zak wrote:
> >>>Maybe we can also add another exception for SELinux to de-duplicate
> >>>the SELinux context options in the options string. It's not perfect,
> >>>but probably acceptable for SELinux -- I can do this for 2.22-rc2.
Implemented (for libmount) in the master branch. You can try it:
./autogen.sh
./configure
make mount
./mount -o ...
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [RFC] mount: overwrite options from /etc/fstab when given on the commandline
2012-08-01 17:08 ` Karel Zak
@ 2012-08-02 9:46 ` Niels de Vos
0 siblings, 0 replies; 9+ messages in thread
From: Niels de Vos @ 2012-08-02 9:46 UTC (permalink / raw)
To: Karel Zak; +Cc: util-linux
On 08/01/2012 07:08 PM, Karel Zak wrote:
>>>> On 08/01/2012 12:03 PM, Karel Zak wrote:
>>>>> Maybe we can also add another exception for SELinux to de-duplicate
>>>>> the SELinux context options in the options string. It's not perfect,
>>>>> but probably acceptable for SELinux -- I can do this for 2.22-rc2.
>
> Implemented (for libmount) in the master branch. You can try it:
>
> ./autogen.sh
> ./configure
> make mount
>
> ./mount -o ...
Great! It works for me on Fedora Rawhide when I add --with-selinux to ./configure.
Thanks for your fast responses and implementation,
Niels
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2012-08-02 9:46 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-01 9:11 [RFC] mount: overwrite options from /etc/fstab when given on the commandline Niels de Vos
2012-08-01 9:48 ` Karel Zak
2012-08-01 10:03 ` Karel Zak
2012-08-01 10:14 ` Niels de Vos
2012-08-01 10:32 ` Karel Zak
2012-08-01 11:58 ` Niels de Vos
2012-08-01 17:08 ` Karel Zak
2012-08-02 9:46 ` Niels de Vos
2012-08-01 10:11 ` Niels de Vos
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).