Commit Graph

452 Commits

Author SHA1 Message Date
Karel Zak 1d15c4b273 libmount: (monitor) remove unnecessary epoll EPOLLPRI
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-09-11 11:37:49 +02:00
Karel Zak 0250174654 libmount: (monitor) don't check for regular mtab
The monitor supports utab only (as documented). It's application
responsibility to use libmount in the right way. It's overkill to
check for valid environment during monitor initialization.

For example systemd checks for regular mtab during boot, it's better
than try to be smart later in libmount monitor when system is already
running.

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-09-11 11:19:30 +02:00
Kir Kolyshkin 58dda170fb libmount: typo fixes
I was reading the code and found these mountinfo typos.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
2015-09-02 18:45:06 -07:00
Karel Zak 928f209cea libmount: fix compiler warning [-Wdiscarded-qualifiers]
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-08-31 11:38:58 +02:00
Karel Zak d92b8c3ba1 libmount: handle arbitrary line length for mounts
Based on patch from Kees Cook, he wrote:
> The kernel's maximum path length is PATH_MAX (4096). The use of BUFSIZ
> (8192) would seem sufficient for reading mountinfo files, but it's
> not. Paths may contain escaped characters (requiring 4x as many bytes
> to read), and filesystem options are of unknown length. To avoid
> mounts being either intentionally or unintentionally hidden from
> libmount and its users, we must accept arbitrary length lines when
> parsing.
>
> Long valid entries are currently ignored, with warnings like this:
> mount: /proc/self/mountinfo: parse error: ignore entry at line 11.
> mount: /proc/self/mountinfo: parse error: ignore entry at line 12.
>
> Instead of using a malloc on every line parsed from mount files, do it
> once per mount file context, growing it as needed. The general case
> will never grow it.

I have moved the parser stuff to the new struct libmnt_parser, maybe
we can move more things (e.g. libmnt_table->fmt) to this struct later.

Reported-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-08-27 10:49:39 +02:00
Sami Kerola 624e147ba2 misc: fix shadow declarations
sys-utils/zramctl.c: In function 'get_mm_stat':
sys-utils/zramctl.c:276:58: warning: declaration of 'inbytes' shadows a global declaration [-Wshadow]
 static char *get_mm_stat(struct zram *z, size_t idx, int inbytes)
sys-utils/zramctl.c:119:39: note: shadowed declaration is here
 static unsigned int raw, no_headings, inbytes;

libmount/src/tab.c: In function 'mnt_table_get_fs_root':
libmount/src/tab.c:1221:22: warning: declaration of 'fs' shadows a parameter [-Wshadow]
    struct libmnt_fs *fs = mnt_table_find_mountpoint(tb,
libmount/src/tab.c:1197:24: note: shadowed declaration is here
      struct libmnt_fs *fs,

disk-utils/fsck.minix.c: In function 'main':
disk-utils/fsck.minix.c:1364:17: warning: declaration of 'i' shadows a previous local [-Wshadow]
   unsigned long i, free;
disk-utils/fsck.minix.c:1250:6: note: shadowed declaration is here
  int i;

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-08-24 10:55:37 +02:00
Karel Zak d9579859c2 libmount: (monitor) fix docs
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-08-19 15:27:20 +02:00
Karel Zak 9ac77b8a78 libmount: add support for "bind,ro"
Now it's necessary t use two mount(8) calls to create a read-only
mount:

  mount /foo /bar -o bind
  mount /bar -o remount,ro,bind

This patch allows to specify "bind,ro" and the remount is done
automatically by libmount by additional mount(2) syscall. It's not
atomic of course.

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-08-17 11:54:26 +02:00
Karel Zak 41e554e303 libmount: fix typo in mnt_optstr_prepend_option()
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-08-05 13:39:06 +02:00
Karel Zak 941c734c56 libmount: variable dereferenced before check [smatch scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-08-05 12:46:56 +02:00
Karel Zak 2c6567799d build-sys: add --disable-assert
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-08-04 13:40:44 +02:00
Karel Zak cba392b661 libmount: cleanup assert() usage
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-08-04 13:21:42 +02:00
Karel Zak 6b9784b442 libmount: make mnt_get_filesystems() more robust [clang analyze]
The mnt_free_filesystems() relies on NULL as the last item in the
filesystems array. It's necessary to keep NULL there after failed
strdup() too, because we call mnt_free_filesystems() to deallocate
after error.

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-07-30 09:28:19 +02:00
Karel Zak 462a570340 libmount: sort pseudo filesystems by LC_COLLATE=C
Addresses: https://github.com/karelzak/util-linux/issues/212
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-07-29 12:43:45 +02:00
Karel Zak 7dc0f5c90e libmount: improve monitor to be usable for non-root users
The current implementation calls mkdir and open(O_CREATE) to
initialize /run/mount/utab.lock before it starts to monitor the file.
Unfortunately it makes the monitor useless for non-root processes
(e.g. systemd --user).

The new implementation adds inotify watch for the last existing
component in the path (/run/mount/utab.lock) and re-initialize
after a change. It makes the monitor robust enough for mkdir/rmdir
when monitor is already active.

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-19 12:30:40 +02:00
Ronny Chevalier 1280109fdc libmount: (docs) fix wording
Signed-off-by: Ronny Chevalier <chevalier.ronny@gmail.com>
2015-06-03 13:21:52 +02:00
Ronny Chevalier 8b1333423a libmount: (docs) fix typo
Signed-off-by: Ronny Chevalier <chevalier.ronny@gmail.com>
2015-06-03 13:06:59 +02:00
Karel Zak 28cdf9c612 libmount: do not call umount helper on --fake
The umount.<type> helpers does not support --fake option and it does
not make sense to call the helpers at all. All we need is to remove
mtab/utab entries.

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1172297
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-03 11:02:25 +02:00
Karel Zak 08e193e1e4 libmount: fix mnt_monitor_event_cleanup()
We have to call epoll to drain mountinfo events too. The problem is
visible if the monitor epoll FD is within another (top-level) epoll.

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-06-01 13:17:41 +02:00
Karel Zak d5dbd57b22 docs: fix gtk-docs related warnings
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-05-28 12:28:23 +02:00
Karel Zak 398f7f9d99 libmount: add note about flock() to docs
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-04-02 17:32:47 +02:00
Karel Zak 8c7f073aae libmount: add support for MS_LAZYTIME
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-03-30 12:43:45 +02:00
Karel Zak 209fd7a748 libmount: mark overlay as pseudo-FS
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-03-11 11:38:07 +01:00
Karel Zak c8b9ecebe9 libmount: add mnt_table_get_fs_root() to header file
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-03-11 11:11:19 +01:00
Karel Zak cc06a01ec5 libmount: cleanup fs root detection code
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-03-10 13:49:57 +01:00
Karel Zak cd41b385a0 findmnt: don't rely on st_dev for --target
The overlay filesystem does not provide usable st_dev (in traditional
UNIX way). It's necessary to search in /proc/self/mountinfo to detect
which path element is mountpoint.

$ findmnt --target /mnt/merged/dir-a/foo
TARGET      SOURCE  FSTYPE  OPTIONS
/mnt/merged overlay overlay rw,relatime,lowerdir=/mnt/low,upperdir=/mnt/high/data,workdir=/mnt/high/work

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-03-10 12:51:44 +01:00
Karel Zak 254743e4a6 build-sys: cleanup realtime lib usage
* check for timer_create()
* define dependence on timer_create() for flock
* rename CLOCKGETTIME_LIBS to REALTIME_LIBS

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-03-06 14:20:19 +01:00
Karel Zak 37290a5396 libmount: remove assert(arg) from public functions
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-02-16 14:17:54 +01:00
Karel Zak ff5ace78d6 libmount: improve remount logic
* fix fs type detection for remount
 * parse mtab only for remount and umount

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-02-16 13:39:33 +01:00
Karel Zak e3f72275ca libmount: add --enable-libmount-force-mountinfo
The default libmount mtab management depends on mtan symlink. If the
symlink exists than libmount parses /proc/self/mountinfo, otherwise it
parses regular classic /etc/mtab. This is backwardly compatible and
transparent solution.

Unfortunately, this is not robust enough because some broken init
scripts or 3-party mount helpers may remove the symlink and create
regular mtab file. This is pretty bad if initd (systemd) depends on
libmount.

Fortunately we known that mtab is absolutely unwanted on some distros,
so it's fine too ignore mtab at all and don't care about the symlink.

Reported-by: Martin Pitt <martin.pitt@ubuntu.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-02-16 12:49:49 +01:00
Karel Zak 60d29f827b libmount: read utab always when read mtab from /proc
Now libmount reads utab only when mtab filename is no explicitly
specified, but for example:

 mnt_table_parse_mtab(tb, "/proc/self/mountinfo");

ignores utab because filename points to regular file. This is mistake,
we wnat to read utab always when we read mount table from kernel.

Reported-by: Martin Pitt <martin.pitt@ubuntu.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-02-12 13:21:08 +01:00
Karel Zak 0c6d9b6300 Revert "libmount: MNT_OMODE_FORCE usage"
This reverts commit 6f41c5de40.
2015-02-10 11:40:56 +01:00
Fridolin Pokorny 6f41c5de40 libmount: MNT_OMODE_FORCE usage
Hi,

I have found out that libmount does not respect MNT_OMODE_FORCE mode.
I don't see any usage in sources and libmount does not respect this mode
when calling library functions. I'm proposing a patch to fix this.

Have a nice day!
Fridolin Pokorny
2015-02-10 11:18:51 +01:00
Karel Zak 0c8cd4ba7a libmount: fix type pointer usage
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-02-03 14:05:05 +01:00
Karel Zak 7396bdd468 libmount: fix possible mem leak in has_utab_entry() [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-29 11:03:49 +01:00
Karel Zak 7bc2fd3d23 libmount: fix mem leak in do_mount_by_types() [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-29 10:58:55 +01:00
Karel Zak 3df1a79ad5 libmount: add options map to docs
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-26 12:25:40 +01:00
Karel Zak 2498303575 libmount: revert "read mtab on remount" idea
It's backwardly incompatible nonsense to prefer mtab on remount.

 mount -o remount /foo

has to read mount options from fstab otherwise the remount has no
effect. (The ideal solution would be to read both mtab, then modify
the options according to fstab -- but for now more important is to be
backwardly compatible.)

References: https://bugzilla.redhat.com/show_bug.cgi?id=1182778
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-16 12:24:57 +01:00
Karel Zak 05cdd0bf45 libmount: (docs) add monitor example
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-13 12:13:09 +01:00
Karel Zak 2b6c532e17 docs: update API docs years
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-13 12:03:17 +01:00
Karel Zak 0cf8312703 libmount: cleanup gtk-docs warnings
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-13 11:57:15 +01:00
Sami Kerola 7ee26cbf02 maint: fix shadow declaration
This change fixes all shadow declarations.  The worth while to mention
fix is with libfdisk sun geometry.  It comes from bitops.h cpu_to_be16
macro that further expands from include/bits/byteswap.h that has the
shadowing.

libfdisk/src/sun.c:961:173: warning: declaration of '__v' shadows a previous local [-Wshadow]
libfdisk/src/sun.c:961:69: warning: shadowed declaration is here [-Wshadow]
libfdisk/src/sun.c:961:178: warning: declaration of '__x' shadows a previous local [-Wshadow]
libfdisk/src/sun.c:961:74: warning: shadowed declaration is here [-Wshadow]

That could have caused earlier some unexpected results.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-01-07 10:08:21 +01:00
Karel Zak f43fb23a2f libmount: (monitor) make mnt_monitor_next_changed() usable for epoll version too
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-06 16:19:02 +01:00
Karel Zak 8f52496d8e linmount: (monitor) refresh docs, headers and symbols table
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-06 16:19:02 +01:00
Karel Zak 3b2c2ba688 libmount: (monitor) use inotify for utab lock file
It's better than monitor utab directly. The utab is updated by
rename(2) and it's really tricky for inotify, because it's necessary
to monitor all /run/mount directory and then it's necessary to verify
that the renamed file is really "utab".

The new concept is without possible false positives and it also
triggers the change when utab update is really done.

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-06 16:19:02 +01:00
Karel Zak 3c5ed29a93 libmount: (monitor) add kernel mountninfo monitoring
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-06 16:19:02 +01:00
Karel Zak 9b4fc141d4 libmount: (monitor) cleanup wait/verify stuff
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-06 16:19:02 +01:00
Karel Zak f7ca1a6433 libmount: make public top-level monitor FD only
We need full control on changes evaluation, so it's better to
hide all in our private epoll. This change also significantly
simplify the API.

 mn = mnt_new_monitor();
 mnt_monitor_enable_userapce(mn, TRUE, NULL);
 mnt_monitor_enable_kenrel(mn, TRUE);

 fd = mnt_monitor_get_fd(mn);
 ...
   <use 'fd' in epoll controlled by your application>
 ...
 while (mnt_monitor_next_changed(mn, &filename, NULL) == 0)
 	printf("%s: change detected\n", filename);

Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-06 16:19:02 +01:00
Karel Zak 36813a2128 libmount: monitor unref function refactoring
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-06 16:19:02 +01:00
Karel Zak c6b1e56d26 libmount: cleanup monitor test
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-06 16:19:02 +01:00