Commit Graph

762 Commits

Author SHA1 Message Date
Karel Zak 026f7d3020 libmount: use fmemopen() in more robust way [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-09-20 13:00:19 +02:00
Karel Zak 987ec2a696 libmount: fix typo
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-09-03 16:18:48 +02:00
Karel Zak ee551c909f libmount; fix and improve read+poll mountinfo
* fix read() buffer size (stupid bug...)

* split read() EINTR and poll() based attempts

* use 100 attempts

* wait 10000 usec between attempts, but first 10 attempts are without
  this delay. It makes the function usable for usual use-cases as well
  as on very busy systems (successfully tested with 300 concurrent
  mount/umount processes)

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-08-29 15:50:58 +02:00
Karel Zak e4925f591c libmount: improve mountinfo reliability
The standard way how we read mount table is not reliable because
during the read() syscalls the table may be modified by some another
process. The changes in the table is possible to detect by poll()
event, and in this case it seems better to lseek to the begin of the file
and read it again. It's expensive, but better than races...

This patch does not modify mountinfo parser, but it reads all file to
memory (by read()+poll()) and than it creates memory stream
from the buffer and use it rather than a regular file stream.

It means the parser is still possible to use for normal files
(e.g. fstab) as well as for mountinfo and it's also portable to
systems where for some reason is no fmemopen().

Note that re-read after poll() event is limited to 5 attempts (but
successful read() without event zeroize the counter). It's because we
do not want to wait for consistent mountinfo for ever. It seems better
to use old (less reliable) way than hang up in read()+poll()
loop.

Addresses: https://github.com/systemd/systemd/issues/10872
Reported-by: Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-08-29 14:27:11 +02:00
Patrick Steinhardt ad167a9023 libmount: fix comment referring to passno field
There's an obvious copy-paste error in `mnt_parse_table_line` when
referring to the 6th field of the fstab format, where it says "freq"
instead of "passno". This has probably been copied from the 5th field,
which is in fact correctly labelled as "freq".

Fix the mistake by changing the comment to say "passno" instead.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
2019-08-20 14:04:33 +02:00
Kevin Hao 042057d802 libmount: Keep the mnt_tab info for the existent dest in mnt_copy_fs()
The "umount -f -a -r" get stuck in a endless loop when run with a
mountinfo like below:
  15 0 179:2 / / ro,relatime - ext4 /dev/root ro
  16 15 0:6 / /dev rw,relatime - devtmpfs devtmpfs rw,size=242896k,nr_inodes=60724,mode=755
  17 15 0:4 / /proc rw,relatime - proc proc rw
  18 15 0:15 / /mnt/.psplash rw,relatime - tmpfs tmpfs rw,size=40k
  19 15 0:16 / /sys rw,relatime - sysfs sysfs rw
  20 19 0:7 / /sys/kernel/debug rw,relatime - debugfs debugfs rw
  21 15 0:17 / /run rw,nosuid,nodev - tmpfs tmpfs rw,mode=755
  22 15 0:18 / /var/volatile rw,relatime - tmpfs tmpfs rw
  23 15 179:1 / /boot rw,relatime - vfat /dev/mmcblk0p1 rw,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro
  24 16 0:19 / /dev/pts rw,relatime - devpts devpts rw,gid=5,mode=620,ptmxmode=000
  25 18 0:20 / /mnt/.psplash rw,relatime - tmpfs tmpfs rw,size=40k

The reason is that the two same mnt entry "/mnt/.psplash" will cause
the dst->tab set to NULL when umount this mnt entry the second time.
This will trigger an endless loop in mnt_reset_table() because that
mnt entry is linked on the libmnt_table but its .tab is set to NULL.

Signed-off-by: Kevin Hao <kexin.hao@windriver.com>
2019-08-19 14:36:55 +02:00
Sami Kerola 371be858d7
libmount: fix potential null pointer dereference
This is false positive warning, but lets silence it so that if and when
warnings crop up they are easy to notice and take seriously.

libmount/src/optstr.c:354:29: warning: potential null pointer dereference
[-Wnull-dereference]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-07-12 22:09:31 +01:00
Karel Zak 369e4c53a8 libmount: fix docs typo
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-06-13 13:45:39 +02:00
Karel Zak 2089538adb libmount: (docs) add reference to v2.33 and v2.34
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-06-07 12:37:28 +02:00
Karel Zak 9db442e954 libmount: add selinuxfs between pseudo filesystems
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1714826
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-29 18:04:57 +02:00
Karel Zak 0e36d7c271 libmount: add bpf between pseudo filesystems
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1714826
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-29 18:01:04 +02:00
Sami Kerola cbcedf6ba8
libmount: avoid possible null pointer dereference [cppcheck]
[libmount/src/monitor.c:797]: (warning) Possible null pointer dereference: me

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-05-18 22:17:10 +01:00
Karel Zak cb400752a4 libmount: fix memory leak on error [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-15 17:25:04 +02:00
Austin English 9d71482941 libmount: fix "maybe be" duplication
Signed-off-by: Austin English <austinenglish@gmail.com>
2019-05-15 13:48:47 +02:00
Karel Zak cb055909c3 libmount: return errno on failed fstab stat()
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-09 10:09:34 +02:00
Karel Zak 2e5ff9db30 libmount: fix compiler warning [-Wsometimes-uninitialized]
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-04-15 13:35:21 +02:00
Karel Zak 82e39473a5 libmount: fix memleak on parse errors
Addresses: https://github.com/systemd/systemd/pull/12252
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-04-15 12:55:46 +02:00
Karel Zak 6c9ab254ae libmount: don't use sscanf() for swaps parsing
Addresses: https://github.com/karelzak/util-linux/issues/780
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-04-08 15:16:23 +02:00
Karel Zak 86673b3a46 libmount: don't use sscanf() for mountinfo parsing
Addresses: https://github.com/karelzak/util-linux/issues/780
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-04-08 14:45:56 +02:00
Karel Zak 36fcefa651 libmount: don't use sscanf() for fstab parsing
Addresses: https://github.com/karelzak/util-linux/issues/780
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-04-08 13:34:47 +02:00
Tim Hildering 9d5eb4c464 libmount: improve fs referencing in tables
* Added member 'struct libmnt_table *tab' to libmnt_fs structure.
* Added 'mnt_fs_get_table()'.
* Removed overhead from 'mnt_table_{insert,move,remove}_fs().
* Added check to 'mnt_table_set_iter()' that entry is member of table.

[kzak@redhat.com: - add to libmount.sys
                  - add to docs
                  - cleanup commit message
                  - set fs->tab = NULL before mnt_unref_fs() in mnt_table_remove_fs()]

Signed-off-by: Tim Hildering <hilderingt@posteo.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-03-08 11:40:20 +01:00
Stanislav Brabec 89342e0406 libmount: Recognize more fuse filesystems as pseudofs and netfs
Add some fuse filesystems to the list of pseudofs and netfs.

There are still tens of filesystems that should be evaluated and added.

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
2019-03-04 11:38:28 +01:00
Karel Zak 911e694528 libmount: add mnt_table_{find,insert,move}_fs()
Add functions to insert FS into table to specified position and to
move FS between two tables.

Co-Author: Tim Hildering <hilderingt@posteo.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-02-21 13:49:39 +01:00
Sami Kerola 110260830d docs: fix typos [codespell]
Reference: https://github.com/codespell-project/codespell
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-02-18 13:22:43 +01:00
Karel Zak a57c9865f8 libmount: (tabdiff) use list_add_tail() in more robust way
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-02-18 12:35:51 +01:00
Tim Hildering beb60dbd6f libmount: check table membership before adding entry
Added validation to function 'mnt_table_add_fs()' to check that added @fs
is not already a member of another table.

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-02-18 11:50:52 +01:00
Karel Zak 189a1bf3b3 libmount: add support for MS_REMOUNT on --all
This patch add to support for remount-all operation to
libmount and mount(8).

For example:
	mount --all -o remount,ro -t vfat

to remount read-only all VFAT filesystems.

Addresses: https://github.com/karelzak/util-linux/issues/589
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-01-16 15:00:07 +01:00
Karel Zak 2859592ecb libmount: (umount) make mnt_stat_mountpoin() usable for relative paths
# mount -o loop devicefile /mnt/test
 # umount devicefile
 umount: devicefile: not mounted.

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1653781
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-10 16:25:08 +01:00
Karel Zak 1dae161c83 libmount: export mnt_guess_system_root() by API
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-10 11:39:08 +01:00
Karel Zak df61216c67 libmount: (fuse) follow only user_id= on umount
The option user= is already handled by evaluate_permissions() and by
classic mount and umount usermount support. It seems we do not need
to duplicate support for user= in is_fuse_usermount().

The option user_id= is fuse specific and it's maintained by
libfuse/kernel in /proc/self/mountinfo. This is feature we need to
support in umount(8).

Addresses: https://github.com/karelzak/util-linux/pull/705
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-11-30 10:25:04 +01:00
Rian Hunter 5fea669e9e libmount: Support unmount FUSE mounts
FUSE mounts don't need an fstab entry to be unmounted.
This checks if a mount is a FUSE mount before checking for
the fstab entry, and if so returns success.

[kzak@redhat.com: - use libmount tools for mount options
                  - use namespace switches
                  - cleanup code

 The requirement is user=<username> or user_id=<uid> in /proc/self/mountinfo
 for fuse filesystem. The logic is the same as for user= mount options, but in
 this case it is not maintained by libmount in userspace, but by fuse FS in kernel.]

Co-Author: Karel Zak <kzak@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-11-30 10:25:04 +01:00
Karel Zak 4f7acf32b5 libmount: keep namespaces support optional
Reported-by: Ruediger Meier <sweet_f_a@gmx.de>
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-10-05 11:35:45 +02:00
Karel Zak 71c7d37bc4 docs: fix gtkdoc warning
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-09-24 11:21:09 +02:00
Karel Zak 2c37ca7c4b libmount: cleanup licenses sections in the files
* add SPDX-License-Identifier (see https://spdx.org/licenses/)
* add "This file part of libmount from util-linux project."
* use proper text for LGPL-2.1-or-later
* use the same texts everywhere

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-08-16 15:43:53 +02:00
Karel Zak 4189907e6c docs: use SPDX license names
Let's use standardized names for licenses. The names used by SPDX
makes things more obvious at first glance. For complete list see:
https://spdx.org/licenses/

Note, this commit does not change any license or so...

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-08-16 14:47:21 +02:00
Karel Zak 51d5109782 libmount: report context paths on debug
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-08-14 21:03:42 +02:00
Karel Zak 9c566fce79 libmount: (utils) fix compiler warnings [-Wcast-qual]
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-07-23 11:58:57 +02:00
Karel Zak b00dd55ac8 libmount: fix compiler warning [-Wcast-qual]
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-07-23 11:33:13 +02:00
Karel Zak 78c66fc61d lib/mangle: const quialifier cleanup
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-07-20 15:31:42 +02:00
Karel Zak ea927bde6b libmount: cleanup const in umount code
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-07-20 14:15:42 +02:00
Karel Zak a679b0823f libmount: add missing const
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-07-20 13:51:52 +02:00
Karel Zak 0d1e744c20 libmount: use const char in swaps parser
The parser does not modify the string, so let's keep it "const char".

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-07-20 13:49:08 +02:00
Karel Zak 4e4c9629e6 libmount: use const char in mountinfo parser
The parser does not modify the string, so let's keep it "const char".

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-07-20 13:48:09 +02:00
Karel Zak 4ccc64c4ca libmount: use const char in fstab parser
The parser does not modify the string, so let's keep it "const char".

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-07-20 13:44:53 +02:00
Karel Zak fae8328928 libmount: add since tag for new functions
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-07-19 11:38:48 +02:00
Karel Zak 4f9d999a97 build-sys: add -Wno-cast-function-type for python
libmount/python/pylibmount.c:158:19: warning: cast between incompatible function types
   from ‘PyObject * (*)(PyObject *)’ {aka ‘struct _object * (*)(struct _object *)’}
     to ‘PyObject * (*)(PyObject *, PyObject *)’ {aka ‘struct _object * (*)(struct _object *, struct _object *)’}
   [-Wcast-function-type]

This is generic problem in all Python C code and gcc v8. The another
possible (and probably more correct) way is to add unused argument to
all API functions. Unfortunately, this solution is pretty invasive. The
question is if gcc is not too paranoid in this case.

For more details see https://bugs.python.org/issue33012. It seems
Python guys also prefer CFLAGS modification for now.

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-07-18 10:23:51 +02:00
Frank Schaefer 8a12ab5775 * break up large strings for PySys_WriteStdout() 2018-07-10 20:21:02 -05:00
Alban Crequy 18a52a5094 libmount: (mountinfo) parse empty strings in source
The source of a mount in /proc/self/mountinfo can unfortunately be an
empty string. Before this patch, 'mount' and 'mountpoint' fail as
following:

  $ sudo mount -t tmpfs "" /tmp/bb
  $ mount
  mount: /proc/self/mountinfo: parse error at line 64 -- ignored
  $ mountpoint /tmp/bb
  /tmp/bb is not a mountpoint

This patch fixes the parsing. It is unfortunately more complex because
sscanf() does not handle fields with empty strings easily.

Other projects have their own parser for mountinfo and have similar
issues. I know of runc and runtime-tools (I'll send a patch for those
two) but there are probably others.

Signed-off-by: Alban Crequy <alban@kinvolk.io>
2018-07-10 13:48:38 +02:00
Vaclav Dolezal cddd2eaa27 libmount: switch namespace when appropriate
Signed-off-by: Vaclav Dolezal <vdolezal@redhat.com>
2018-06-11 16:12:55 +02:00
Vaclav Dolezal 65ca7b5a9b libmount: support for namespaces for helpers
Signed-off-by: Vaclav Dolezal <vdolezal@redhat.com>
2018-06-11 16:08:44 +02:00
Karel Zak de7ccabdfd libmount: make errno usable after mnt_context_set_target_ns()
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-06-11 16:06:17 +02:00
Vaclav Dolezal 8342e5840d libmount: added error MNT_ERR_NAMESPACE
Signed-off-by: Vaclav Dolezal <vdolezal@redhat.com>
2018-06-11 15:51:17 +02:00
Vaclav Dolezal 5cbf01b75d libmount: note namespaces in mnt_reset_context() docs
Signed-off-by: Vaclav Dolezal <vdolezal@redhat.com>
2018-06-11 15:50:29 +02:00
Vaclav Dolezal 4917d842ea libmount: add support for switching namespaces
[kzak@redhat.com: - cosmetic changes, add some comments]

Signed-off-by: Vaclav Dolezal <vdolezal@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-06-11 15:49:48 +02:00
Karel Zak 6691d53797 mount: keep MS_MOVE as flag
The previous commit 4ebea84bb1 replaced
all operations by strings, but it does not work for MS_MOVE as this
operation is not supported in fstab by libmount.

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-06-01 14:07:53 +02:00
Karel Zak 8d6de22499 libmount: don't use MS_MGC_VAL magic in mount(2) syscall
Specifying MS_MGC_VAL was required in kernel versions prior to 2.4,
but since Linux 2.4 is no longer required and is ignored if specified

The minimal kernel requirement for util-linux is Linux v2.6.

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-06-01 12:29:14 +02:00
Karel Zak 816773b475 libmount: improve MS_REC usage
libmount allows to split one library (mount(8)) call to multiple mount(2)
syscalls, for example

   --rbind --make-rslave

in this case we have to be careful with MS_REC because the flag is
applied to multiple operations.

 # strace -e mount mount --rbind --make-rslave /mnt/A /mnt/B

Old version:

 mount("/mnt/A", "/mnt/B", 0x13ecac0, MS_MGC_VAL|MS_BIND, NULL) = 0
 mount("none", "/mnt/B", NULL, MS_REC|MS_SLAVE, NULL) = 0

Fixed version:

 mount("/mnt/A", "/mnt/B", 0x1f22ac0, MS_MGC_VAL|MS_BIND|MS_REC, NULL) = 0
 mount("none", "/mnt/B", NULL, MS_REC|MS_SLAVE, NULL) = 0

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1584443
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-06-01 12:16:19 +02:00
Karel Zak c0bdff9997 libmount: include sys/mount.h on Linux only
Addresses: https://bugs.debian.org/cgi-bin/bugreport.cgi?att=1;bug=891812
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-05-29 10:06:00 +02:00
Karel Zak e82b77e969 libmount: accept another flags on MS_REMOUNT|MS_BIND
The current libmount MS_REMOUNT|MS_BIND support is restricted to
MS_RDONLY (read-only bind mount). This is too restrictive as Linux
kernel supports bind-remount for arbitrary VFS flags.

After this update you can use

 # mount /dev/sdc1 /mnt/A
 # mount --bind -onosuid,noexec /mnt/A /mnt/B

 # findmnt /dev/sdc1 -oTARGET,SOURCE,FS-OPTIONS,VFS-OPTIONS
 TARGET SOURCE    FS-OPTIONS                 VFS-OPTIONS
 /mnt/A /dev/sdc1 rw,stripe=512,data=ordered rw,relatime
 /mnt/B /dev/sdc1 rw,stripe=512,data=ordered rw,nosuid,noexec,relatime

The "mount --bind" is composed from two syscalls of course (1st is
bind, 2nd is bind,remount,nosuid,noexec).

Addresses: https://github.com/karelzak/util-linux/issues/637
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-05-28 16:15:30 +02:00
Karel Zak af8ed53ee1 libmount: fix compiler warning [-Wunused-parameter]
Reported-by: L A Walsh <lkml@tlinx.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-05-03 10:35:42 +02:00
Karel Zak f4375df0fd libmount: improve docs about mnt_context_mount() return codes
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-04-26 11:04:07 +02:00
NeilBrown 7966cbba53 libmount: fix mnt_table_is_fs_mounted() for NFS bind mounts.
When you bind-mount a subdirectory of a local filesystem, the
path to that subdirectory appears as the fourth field in mountinfo.

For nfs mounts, the fourth field is always "/", and the subdirectory
part is appended to the "special" (aka "device") field.  This is
consistent with historical NFS usage which always includes a path in
the fs_spec field.

libmount needs to know about this when "mount -a" checks to see if
a filesystem is already mounted.

Without this fix, fstab lines like:

 server::/path /dir nfs defaults 0 0
 /dir/subdir /mnt/test none bind 0 0

result in a new mount at /mnt/test every time "mount -a" is run.

[kzak@redhat.com: - use strappend() rather than asprintf()]

Signed-off-by: NeilBrown <neilb@suse.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-04-18 10:17:26 +02:00
Richard Fuchs f958101d2e bugfix: fix possible segfault during umount -a
mnt_context_get_mtab() doesn't set its return **tb argument on error,
and so in mnt_context_next_umount() mtab will remain uninitialized on
error, later resulting in cxt->mtab containing garbage, possibly
resulting in segfault on exit.
2018-04-17 09:52:37 -04:00
Karel Zak 061d1a5109 libmount: include sys/mount.h only if necessary
Addresses: https://github.com/systemd/systemd/issues/8507
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-03-22 14:05:17 +01:00
Karel Zak 1b692a26f7 libmount: (docs) update year
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-03-20 18:56:06 +01:00
Karel Zak 83212eb3df libmount: fix example in docs
Addresses: https://github.com/karelzak/util-linux/issues/599
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-03-20 13:31:19 +01:00
Karel Zak b25f3c15c2 libmount: deallocate on /proc/swaps parse error
Addresses: https://github.com/karelzak/util-linux/issues/596
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-03-20 12:52:16 +01:00
Karel Zak 4c9e4ce83c libmount: make sure we deallocate on parse error
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-03-20 12:20:05 +01:00
Karel Zak b1813c59c0 libmount: make libmount.h more robust
Let's include sys/mount.h to be sure that our local libmount fallbacks
are not used by default to avoid possible conflicts with later included
sys/mount.h.

Addresses: https://github.com/systemd/systemd/pull/8452
Reported-by: Lennart Poettering <lennart@poettering.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-03-20 10:59:56 +01:00
Karel Zak 76de2157cf libmount: fix fs pattern usage in mount --all
The command "mount -a -t <pattern>" uses the -t as pattern to filter
fstab entries. And "mount -t <type>" is used to specify FS type.

Unfortunately libmount does not care about this difference when it
calls standard mount functionality. The original pattern is still in
the library control struct and mnt_do_mount() tries to use it as FS
type.

This patch is just bugfix. Maybe the long term solution would be to
differentiate between the pattern and type in the library API. Now the
library follows mount(8) command line and it's little bit messy.

Reported-by: Lukas Czerner <lczerner@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-03-06 14:44:23 +01:00
Karel Zak ebb079266d libmount: add missing macro to docs
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-02-21 11:43:21 +01:00
Ruediger Meier 73afd3f8e8 misc: fix typos using codespell
Some more funny typos, please review carefully.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2018-02-16 11:12:52 +01:00
Karel Zak 8d31f146ed libmount: fix debug message
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-02-01 16:52:14 +01:00
Karel Zak 63c9c05d35 misc: remove %p from debug messages
From libs where suid program may be executed by non-root user.

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-02-01 13:18:57 +01:00
Ruediger Meier af1bc027db build-sys: remove redundant EXTRA_DIST files
The sources of AC_CONFIG_FILES (*.in) are automatically
distributed.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2018-01-22 11:16:49 +01:00
Ruediger Meier 4beacf105e build-sys: avoid using prog_DEPENDENCIES
Use EXTRA_prog_DEPENDENCIES to have the benefit
of automake's automatic prog_DEPENDENCIES.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2018-01-22 11:16:49 +01:00
Ruediger Meier 0da03d4490 build-sys: remove unneeded dependencies on bla.h.in
We have already automakes's automatic dependencies like
  bla.h.in -> bla.h -> foo.o -> bar.la

An explicit direct dependency bla.h.in -> bar.la
is redundant and useless anyways.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2018-01-22 11:16:49 +01:00
Ruediger Meier a459f2ec33 build-sys: automake is able to find headers in builddir ...
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2018-01-22 11:16:49 +01:00
Ruediger Meier 1d667d8849 build-sys: remove generated headers from dist tar ball
Headers should only be listed in either *_HEADERS or
*_SOURCES, especially when we want nodist_*_HEADERS.

Since all the generated headers are made by configure we
don't even need to use BUILT_SOURCES or other tricks.

Also see automake docs 9.4.1 Built Sources Example:
  case "Build bindir.h from configure"

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2018-01-22 11:16:49 +01:00
Karel Zak a15dca2f6d include/debug: introduce __UL_INIT_DEBUG_FROM_STRING()
Let's make it possible to use debug.h without environment variables.

Suggested-by: J William Piggott <elseifthen@gmx.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-01-17 13:58:29 +01:00
Karel Zak 6d00cfb233 include/debug: don't print pointer address for SUID programs
* introduce new flag __UL_DEBUG_FL_NOADDR to suppress pointer address printing

* use __UL_DEBUG_FL_NOADDR when SUID

* move ul_debugobj() to debugobj.h, and require UL_DEBUG_CURRENT_MASK
  to provide access to the current mask from ul_debugobj(). It's better
  than modify all ul_debugobj() calls and use the global mask as
  argument.

* remove never used UL_DEBUG_DEFINE_FLAG

Reported-by: halfdog <me@halfdog.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-01-12 11:01:26 +01:00
Karel Zak b5cc232362 libmount: fix mnt_table_is_fs_mounted() for rbind
There is no difference between "bind" and "rbind" if we want to FS
root to search for the FS in mountinfo file.

fstab:

 /dev/sdc1       /mnt/foo        xfs     defaults        0 0
 /mnt/foo        /mnt/test       none    rw,rbind        0 0

use -a more than once:

  mount -a
  mount -a

/proc/mounts (the current result):

 /dev/sdc1 /mnt/foo xfs rw,relatime,attr2,inode64,noquota 0 0
 /dev/sdc1 /mnt/test xfs rw,relatime,attr2,inode64,noquota 0 0
 /dev/sdc1 /mnt/test xfs rw,relatime,attr2,inode64,noquota 0 0
 /dev/sdc1 /mnt/foo xfs rw,relatime,attr2,inode64,noquota 0 0

expected (fixed version) result:

 /dev/sdc1 /mnt/foo xfs rw,relatime,attr2,inode64,noquota 0 0
 /dev/sdc1 /mnt/test xfs rw,relatime,attr2,inode64,noquota 0 0

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1528959
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-01-03 14:02:27 +01:00
Karel Zak ae6fd6802c libmount: add nsfs between pseudo filesystems
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-11-21 12:11:56 +01:00
Karel Zak 42ee788268 libmount: minimize utimensat() write test usage
utimensat() is pretty expensive when mounting parallel filesystems from
the same source. It's possible to ignore all this if mtab is not
writable.

Note that this change is irrelevant for default util-linux builds
where all around mtab is already disabled since v2.30 (commit
89958178f6).

This change is relevant only for users who still use --enable-libmount-support-mtab.

Reported-by: Douglas Jacobsen <dmjacobsen@lbl.gov>
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-11-16 12:16:09 +01:00
Karel Zak 06ff935ec3 libmount: fix access() utab write test
The commit c08396c769 replaces
open(O_CREATE) with ecaccess(). Unfortunately, another code depends on
the original behavior.

* let's make utab when really necessary rather than in the try_write() test

* __mnt_new_table_from_file() returns NULL if tab-file does not
 exists. This is incorrect for tab_update.c stuff. We need empty table
 in this case.

* we can check /run/mount/ directory for write access if
  eaccess(filename) return ENOENT (because file does not exist)

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-11-08 17:03:59 +01:00
Joshua Watt 5d9c796660 libmount: Allow MNT_FORCE and MNT_DETACH at umount
MNT_FORCE and MNT_DETACH are orthogonal in the Linux kernel, so both may
be specified without any problems. Even if there were a problem with
this combination, it should be up to the kernel to take the correct
action or report an error.

Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
2017-11-08 12:31:43 +01:00
Karel Zak fb7e447486 libmount: check waitpid() return code
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-11-06 13:22:07 +01:00
Vratislav Podzimek 7440665f9b libmount: Use waitpid() when waiting for mount helper child process
Using wait() in a library may be problematic as it may reap some
totally unrelated child process instead of the just forked
one. That can result in the library call doing weird things and
returning bad return values, but also in a breakage of an
arbitrary other thing in the program using the library.

[[kzak@redhat.com: - use waitpid() for umount too
                   - keep the current codding style]

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-11-06 13:05:04 +01:00
Karel Zak c08396c769 libmount: use eacess() rather than open() to check mtab/utab
The open() syscall is probably the most strong way how to check write
accessibility in all situations, but it's overkill and on some
paranoid systems with enabled audit/selinux. It fills logs with
"Permission denied" entries. Let's use eaccess() if available.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-10-20 12:37:04 +02:00
Karel Zak 78c57214ad libmount: make sure we call stat() propely [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-10-11 14:59:16 +02:00
Karel Zak e8365fc1c6 libmount: add human compatible message for EBADMSG errno
mount: /media/sdb5: mount(2) system call failed: Bad message.

is really ugly for end users. It seems XFS, extN (etc) use EBADMSG for
bad checksums. For network or pseudo filesystems continue to use "Bad
message" error...

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1496764
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-10-02 13:44:29 +02:00
Giuseppe Scrivano f218d8d2f5 libmount: fix Python get_propagation
The current implementation would return always 0, as it is the return
code of mnt_fs_get_propagation.  Change the implementation to raise an
exception on an error and return the propagation flags otherwise.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2017-09-21 23:18:32 +02:00
Karel Zak d369dc42cb libmount: export locking errors as MNT_EX_FILEIO
The mount man page assumes locking errors mapped to MNT_EX_FILEIO (16)
return code. Unfortunately, this is internally not exported as a
special error code, so it's returned as a generic (errno based)
stuff. This patch fixes this issue.

Note that we still use locking for example for utab or when enabled
/etc/mtab (disabled by default).

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-09-15 14:30:06 +02:00
Ruediger Meier 21be08ac8c build-sys: don't use non-existing UUID_LIBS
We've added UUID_LIBS in f77a4d1087 but I don't see what it
was good for.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-07-18 11:06:53 +02:00
Ivan Delalande b9a5e23fa8 libmount: make mnt_context_is_fs_mounted work for /proc
Assume that /proc is not mounted instead of returning an error when we
are unable to open the mounts and mountinfo files in /proc. Also set
cxt->mtab back to NULL so that it gets properly parsed when we check if
the next filesystem is mounted.

The goal is to have mount -a work when /proc is not mounted, typically
with /proc on the first line of fstab.

Signed-off-by: Ivan Delalande <colona@arista.com>
2017-07-18 09:45:26 +02:00
Karel Zak 41d758f82d libmount: use _exit() in <type> handlers
The originally used exit() is bad idea for the shared library.

Reported-by: Ruediger Meier <sweet_f_a@gmx.de>
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-06-29 12:58:57 +02:00
Karel Zak 9b76b0e98b libmount: ignore "bind" from fstab on command line "remount"
The current code always apply all flags from /etc/fstab on remount.
Unfortunately remount+bind has special semantic and it's impossible
from command line to avoid interaction with the "bind" from fstab.

Example, fstab:

	/dev/sda1 /bar ext4 defaults 0 1
	/bar /foo none bind 0 0

Command line:

    # mount /foo -o remount,rw

produces:

    mount(... MS_REMOUNT|MS_BIND ) syscall

This changes the per-mountpoint (VFS) ro flag to rw, but doesn't
change the filesystem itself.

This patch forces libmount to ignore "bind" from fstab when "-o
remount" specified on command line. If you need remount+bind semantic
you have to specify the "bind" flag on command line. This allow to
differentiate between

    # mount /foo -o remount,bind,rw  --> mount(MS_REMOUNT|MS_BIND)
and

    # mount /foo -o remount,rw       --> mount(MS_REMOUNT)

Suggested-by: NeilBrown <neilb@suse.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-06-20 12:46:02 +02:00
Ruediger Meier 0b5f75e412 libmount: fix warning "set but not used"
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-15 08:56:01 +02:00
Sami Kerola f4d3783867 misc: remove stray semicolons
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-06-14 12:21:29 +02:00
Sami Kerola 1b5042636f misc: fix reassigned values before old ones has been used [cppcheck]
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-06-14 12:19:20 +02:00
Ruediger Meier b68d953e62 libmount: btrfs, remove unused setter functions
We have never used them since introduced in 2cd28fc8.
clang compiler warned about it.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-14 11:48:22 +02:00
Karel Zak 26cd36a636 Merge branch 'pylibmount-NULL-terminate-kwlist-in-Context_init' of https://github.com/zmedico/util-linux
* 'pylibmount-NULL-terminate-kwlist-in-Context_init' of https://github.com/zmedico/util-linux:
  pylibmount: NULL terminate kwlist in Context_init
2017-06-12 15:39:59 +02:00
Zac Medico 29b721bc9d pylibmount: NULL terminate kwlist in Context_init
Fixes a segfault observed with python3.6.
2017-06-07 17:25:12 -07:00
Karel Zak 11573ac0c8 libmount: (umount) use mount table filter on -c only
The path canonicalization is the worst use-case, it's better to read
all mount table than try canonicalize.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-06-07 12:40:17 +02:00
Karel Zak f8416301c1 libmount: use mount table filter on --no-canonicalize
The umount command option --no-canonicalize means that the path is
already canonical. So, we can use mount table filter in this case too.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-06-07 11:35:26 +02:00
NeilBrown ce6e269447 umount: never 'stat' the path when "-c" is given.
It is currently not possible to reliably and automatically
unmount an NFS filesystem. If the server is not available, the
umount command will hang.

The hang can be avoided by using "-l" or "-f", but neither
of these are appropriate for automatic use such as by an
automounter (e.g automountd or systemd).

"-l" will unmount even if the filesystem is in use, which
an automounter generally doesn't want.  If the filesystem
is in use, then the umount should fail.

"-f" can cause the filesystem to abort pending transactions
which might break filesystem semantics.  This can be useful
in the hands of a sysadmin, but not when used by an
automatic tool.

umount has another option, "-c" aka "--no-canonicalize"
which avoids some "stat" calls.
Currently this doesn't avoid all calls to
canonicalize_path()
as
  mnt_context_prepare_umount() ->
    lookup_umount_fs() ->
      mnt_context_find_umount_fs() ->
        mnt_context_get_mtab_for_target() ->
	  mnt_resolve_path() ->
	    canonicalize_path_and_cache() ->
	      canonicalize_path()

leads to that function being called.

The "-c" option could be taken to mean "I know what I'm
doing, this really is the path to a mount point, I just want
you to unmount it".  Given that, it seems suitable to
extend this to avoid all 'stat' calls on the mountpoint.

It is already appropriate for any automount program to pass
"-c" to "umount", so they can be changed to do so at any
time.
With the patch below, "-c" will result in the mountpoint
never being "stat"ed, so umount won't hang on an
inaccessible server.

This isn't quite sufficient, for NFS at least, as the usage
of libmount in umount.nfs still calls 'stat' on the mount
point.
"-c" isn't passed to the umount helper, but it is reasonable
for such helpers to assume "-c" because "umount" will have
canonicalized the path when that is appropriate.

So, this patch treats "-c" much like "-l" and "-f" when
deciding whether it is safe to 'stat' the path.

Signed-off-by: NeilBrown <neilb@suse.com>
2017-06-06 11:41:05 +02:00
Ruediger Meier c0d7b11a3f build-sys: fix library order when linking
We got some errors on Alpine Linux where $LTLIBINTL is non-empty:

./.libs/libcommon.a(libcommon_la-blkdev.o): In function `open_blkdev_or_file':
lib/blkdev.c:282: undefined reference to `libintl_gettext
collect2: error: ld returned 1 exit status

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-01 03:16:48 +02:00
Karel Zak a81b1946a1 libmount: (docs) add missing 'since' tags
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-23 13:32:45 +02:00
Karel Zak 7a5dbd2258 libmount: don't pass -1 to close() [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-17 12:45:30 +02:00
Karel Zak fdaba3eb62 libmount: fix memory leak [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-17 12:38:16 +02:00
Karel Zak 799d9e845f tests: (libmount) parse version from command line
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-17 11:28:19 +02:00
Karel Zak 8503c0ed30 libmount: (docs) remove unwanted tag
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-04-28 12:39:21 +02:00
Karel Zak 0361cb6f9b libmount: add read-only warning
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-04-28 11:03:24 +02:00
Karel Zak 7b53418bf0 libmount: (docs) add unused declarations
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-04-27 14:17:50 +02:00
Karel Zak ea848180dd libmount: add mnt_context_get_excode()
It's pretty complex task to make mount(8) and umount(8) return code
and generate error message. It seems better to do that in the libmount
rather than force all library users to duplicate mount(8) mk_exit_code()
functions. It also means that all the messages will be translated only
once. Changes:

* all error messages are printed by warn()
* no more multi-line messages
* all messages prefixed by mount target (mountpoint)
* library provides mount(8) compatible MNT_EX_* codes

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1429531
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-04-27 14:10:23 +02:00
Karel Zak 6dede2f2f7 libmount: support MS_RDONLY on write-protected devices
This feature is supported by mount(8) only. It seems better move
this code to libmount. The results is more simple mount(8) and the
feature is accessible for all libmount users.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-04-26 17:27:02 +02:00
Stanislav Brabec ecfeae90a2 libmount: Ensure utab.lock mode 644
If utab.lock is created by a process with a restricted umask, utab.lock is
created with restricted permissions. It breaks userspace monitor.

Ensure that the mode is always 644.

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
2017-04-18 11:13:32 +02:00
Sami Kerola a0a32456c8 libmount: fix file descriptor leak
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-04-10 15:40:40 +02:00
Sami Kerola 41427f97d9
tests: add static keyword where needed [smatch scan]
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-03-17 21:22:26 +00:00
Sami Kerola 08cce2e1cc libmount: fix use of preprocessor identifier
libmount/src/context_mount.c:990:5: warning: undefined preprocessor
identifier 'USE_LIBMOUNT_SUPPORT_MTAB'

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-03-13 14:48:07 +01:00
Karel Zak 7bb9ee99da libmount: cosmetic change to mnt_table_find_srcpath()
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-02-28 14:47:02 +01:00
Petr Vorel 443be11396 libmount: return tab entry for default node
This is useful for lsblk.

Signed-off-by: Petr Vorel <pvorel@suse.cz>
2017-02-28 14:41:42 +01:00
Sami Kerola 8791804065 misc: do not use plain 0 as NULL [smatch scan]
text-utils/tailf.c:69:21: warning: Using plain integer as NULL pointer

Since many 'struct option' has used zero as NULL make them more readable in
same go by reindenting, and using named argument requirements.

Reference: https://lwn.net/Articles/93577/
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-20 12:58:49 +01:00
Yuri Chornoivan a7349ee315 docs: Fix word repetitions 2017-02-13 14:10:12 +01:00
Karel Zak 1a3397906d libmount: make rootfs lookup by parent-id more robust
The root FS id really does not have to be the smallest one.

Reported-by: Michal Soltys <soltys@ziu.info>
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-02-01 16:20:12 +01:00
Stanislav Brabec 7b46647df4 libmount: Fix incorrect detach of reused loop device
If -oloop is used and the loop device is reused, the loop device is detached
after umount. It is incorrect as it could break the another task using the loop
device.

This is caused by mnt_context_enable_loopdel(,TRUE) that is called from
mnt_context_prepare_umount() whenever "loop" option is used, independently on
AUTOCLEAR flag.

Remove the "loop" option for reused devices to prevent detaching of reused loop
device.

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
2017-01-16 12:25:45 +01:00
Stanislav Brabec 3789806db2 libmount: fix mount -oloop=/dev/loopX regression
If mount option "loop" is used with an argument, it should be respected. Commit
8efad715 introduced a regression. Even with an argument, overlaying loop device
is searched and argument is ignored. It could have unexpected side effects.

If argument is set, never allocate a new loop device.

How to reproduce:
mkdir -p cdrom
mkisofs -o cdrom.iso cdrom/ 2>/dev/null
losetup /dev/loop0 cdrom.iso
strace mount -t auto -o ro,loop=/dev/loop1 cdrom.iso /mnt 2>&1 | grep ^mount
cat /proc/self/mountinfo | grep /mnt
umount /mnt
losetup -d /dev/loop0

mount("/dev/loop0", "/mnt", "iso9660", MS_MGC_VAL|MS_RDONLY, NULL) = 0
327 60 7:0 / /mnt ro,relatime shared:241 - iso9660 /dev/loop0 ro
losetup: /dev/loop0: detach failed: No such device or address

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
2017-01-16 12:25:45 +01:00
Stanislav Brabec 89958178f6 If mtab support is disabled, disable ro/rw mtab checks
Commit f9906424 introduced a check that should prevent different information in
mtab and /proc/mounts. The check can require significant amount of time, and for
systems without mtab support it has no sense.

Execute this code only on systems with mtab.

When a systems with large number of nodes (thousands) mount the filesystems
simultaneously, the time required for serialization causes the utimensat() to
take a large amount of time (tens of minutes) when a large number of nodes are
simultaneously updating the timestamp.

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
2017-01-10 17:32:32 +01:00
Karel Zak 7d395c75d1 libmount: support name=value for mnt_match_options()
$ findmnt --options mode=755
TARGET         SOURCE FSTYPE   OPTIONS
/sys/fs/cgroup tmpfs  tmpfs    rw,nosuid,nodev,noexec,relatime,mode=755
/dev           udev   devtmpfs rw,relatime,size=1983516k,nr_inodes=495879,mode=755

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-12-20 16:01:22 +01:00
Karel Zak db17f201b8 libmount: reimplement mnt_match_options()
Let's use optstr.c functions to parse pattern and options strings.
It's more robust that the old original mount(8) code and it supports
quotes in the options strings.

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-12-20 15:35:50 +01:00
Sébastien Helleu d673b74e9d docs: replace FTP by HTTPS in kernel.org URLs
The links to ftp://ftp.kernel.org/ are replaced by
https://www.kernel.org/.

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-12-19 11:22:26 +01:00
Karel Zak 80c31a0b59 findmnt: error on --target /non-exist
The original --target implementation (< v2.27) has been based on
stat(), so it was usable for valid paths only.

The new implementation is based on search in the mountinfo file, so it
works for arbitrary crazy path. This is not backwardly compatible and
if the path does not exist then it still returns at least root
directory mount entry.

This patch forces mnt_table_find_mountpoint() to check if the path is
valid before we search in the mountinfo file.

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-12-16 13:00:45 +01:00
Karel Zak 8048a826cc Merge branch 'build-fixes' of https://github.com/rudimeier/util-linux
* 'build-fixes' of https://github.com/rudimeier/util-linux:
  build-sys: don't clean *.img files
2016-12-09 15:37:09 +01:00
Karel Zak 0a14cc8bcc libmount: revert X-* and x-* meaning
Let's hope this is last change necessary to cleanup x-* usage:

  x-*  persistent option, stored in utab, available for umount, etc.
  X-*  fstab comment only

mount(8) supports x-mount.mkdir= as well as newly recommended X-mount.mkdir=

Advantages:

 * less invasive
 * does not require exception for x-systemd
 * does not require rename x-initrd to X-initrd

The systemd and dracut users will get the new (=fixed) functionality without a
change in fstab configuration. This is the primary goal.

Disadvantages:

 * not 100% compatible libmount behavior, x-* options have not been
   previously stored in utab. The API is the same, options will be still
   available, but on x-* libmount will write to /run/mount/utab. For now
   it seems only systemd uses x-*, and they like this behavior, so...

Addresses: https://github.com/systemd/systemd/pull/4515
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-12-09 15:36:14 +01:00
Ruediger Meier 38f75ebe1e build-sys: don't clean *.img files
Don't know why this was added in d78df0ac but it can't be right that
libmount/python removes these files in the toplevel builddir. Moreover
I've never seen such *.img files appearing during build at all.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-12-09 14:27:48 +01:00
Karel Zak 5c493bd92f libmount: use x-systemd options as X-*
The previous patch introduces X-* options namespace for options
that have to be maintained in user space.

Unfortunately, systemd users already use mount options that are
necessary by umount or another operations. The conclusion from
discussion with systemd guys is to store all the systemd options
in userspace.

It seems better to add one line exception to libmount than force all
fstab users to rename x-systemd to X-systemd.

Addresses: https://github.com/systemd/systemd/pull/3904
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-12-08 15:27:24 +01:00
Karel Zak 83601b1af9 libmount: introduce X-* comments
x-* are fstab only and not stored in userspace (utab). In some cases
it's not optional solution because the option is also necessary for
umount or another operations. The X-* is exactly the same as x-*, but
stored to utab (or mtab on old systems).

It's usually bad idea to store mount options in userspace, but it's
better to provide any solution that force users to bypass mount(8)
(and friends) and implement 3rd-party incompatible solutions.

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-12-08 14:55:02 +01:00
Karel Zak 3c4a3de0fc mount: append inverting options for mount.<type> on "users"
If you call mount(8) as root, then we need to append inverting options
(if specified by fstab) for "user" and "users" to /sbin/mount.<type>
command line, because for UID=0 mount.nfs follows command line rather
than the fstab setting.

This has been originally implemented by commit
a4c0cc75ff for the old mount(8). The
same feature is supported by libmount, unfortunately for "user" only.
We need the same also for "users" to be backwardly compatible.

Addresses: https://github.com/karelzak/util-linux/issues/368
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-10-27 15:30:20 +02:00
Karel Zak 9e13b1c1c7 libmount: fix null-checking [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-10-04 16:33:14 +02:00
Karel Zak 3e44e75dae libmount: paranoid change in mnt_table_is_fs_mounted()
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-09-29 11:55:07 +02:00
Aurelien Aptel 76d4fba2e4 libmount: fix mount -a for cifs
when mounting a cifs share, the src is actually an UNC path which can in
in several forms:

simple:            //host/share, //host/share/
including subpath: //host/share/sub/path

to check if the cifs fs is mounted we have to extract the subpath and
compare *that* to the root.

Signed-off-by: Aurelien Aptel <aaptel@suse.com>
2016-09-29 11:51:38 +02:00
Karel Zak 81b176c4da docs: some random fixes
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-09-27 12:52:47 +02:00
Filipe Brandenburger 727c689908 libmount: Preserve empty string value in optstr parsing
Recent mount (since the switch to libmount in v2.22) drops the '=' in
mount options that are set to an empty value.  For example, the command
line below will be affected:

  # mount -o rw,myopt='' -t tmpfs tmpfs /mnt/tmp

Fix that by preserving an empty string in the options passed to the
mount(2) syscall when they are present on the command line.

Add test cases to ensure empty string handling is working as expected
and in order to prevent regressions in the future.

Also tested manually by stracing mount commands (on a kernel which
accepts a special extra option, for testing purposes.)

Before this commit:

  # strace -e mount ./mount -t tmpfs -o rw,myopt='' tmpfs /mnt/tmp
  mount("tmpfs", "/mnt/tmp", "tmpfs", MS_MGC_VAL, "myarg") = -1 EINVAL (Invalid argument)

After this commit:

  # strace -e mount ./mount -t tmpfs -o rw,myopt='' tmpfs /mnt/tmp
  mount("tmpfs", "/mnt/tmp", "tmpfs", MS_MGC_VAL, "myopt=") = 0

All test cases pass, including newly added test cases.  Also checked
them with valgrind using:

  $ tests/run.sh --memcheck libmount/optstr

Fixes #332.

Signed-off-by: Filipe Brandenburger <filbranden@google.com>
2016-08-10 13:59:52 -07:00
Karel Zak d4e89dea4e libmount: ignore redundant slashes
///aaa/bbb and /aaa/bbb/ are the same paths. This is important
especially with NFS where number of slashes are not the same in
the /proc/self/mountinfo and fstab or utab. The regular URI is

 euler://tmp

but /proc contains

 euler:/tmp

Reported-by: Ales Novak <alnovak@suse.cz>
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-08-08 17:23:54 +02:00
Karel Zak dff7e16046 libmount: one iteration to detect overlap and reuse loopdev
The current code scans loopdevs to detect already used loop device and
another scan to detect overlap.

Let's use one scan only, for this purpose loopcxt_find_overlap() has
been modified to return info (rc==2) about full size and offset match.

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-08-04 11:48:26 +02:00
Karel Zak c444a71b1b lib/loopdev: cleanup sizelimit check
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-08-04 10:49:46 +02:00
Stanislav Brabec 8efad715b9 libmout: Reuse loop device safely
Add a safety check to mnt_context_setup_loopdev(). Only a loop device with equal
offset and sizelimit will be reused. If any overlapping loop device exists,
MNT_ERR_LOOPOVERLAP is returned.

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
2016-08-03 11:53:28 +02:00
Stanislav Brabec 74a4705a99 Add sizelimit to internal API
Fully safe checks of loop device need to check sizelimit. To prevent need of two
nearly equal functions, introduce sizelimit parameter to several internal
functions:
loopdev_is_used()
loopdev_find_by_backing_file()
loopcxt_is_used()
loopcxt_find_by_backing_file()

If sizelimit is zero, fall back to the old behavior (ignoring of sizelimit).

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
2016-08-03 11:53:28 +02:00
Stanislav Brabec 7e6b7035e7 libmount: Introduce new error: MNT_ERR_LOOPOVERLAP
This error code is intended for situations where overlapping loop device exists
and cannot be reused.

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
2016-08-03 11:53:28 +02:00
Stanislav Brabec 441cdba95b libmount: Fix possible crash in mnt_context_setup_loopdev()
If loopcxt_init() fails, Iloopcxt_deinit() should not be called.

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
2016-08-03 11:53:28 +02:00