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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
///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>
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>
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>
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>
This error code is intended for situations where overlapping loop device exists
and cannot be reused.
Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
Fix various typos in error messages, warnings, debug strings,
comments and names of static functions.
Signed-off-by: Sebastian Rasmussen <sebras@gmail.com>
For petty long time we have strdup_to_struct_member() macro to avoid
duplicate code when strdup() strings in setter functions. Let's use it
for libmount.
Signed-off-by: Karel Zak <kzak@redhat.com>
According to the Al Viro[1], kernel has no way to detect that a single file is
used by multiple loop devices, and multiple mounts of the same file using
different loop devices will result in a data corruption. Exactly this now
happens, if multiple btrfs sub-volumes in one file are mounted with "-oloop".
Make use of multiple -oloop mounting the same file safe: Do a loop devices
lookup, and if a loop device is already initialized, use it.
Hopefully it is possible, as "losetup -d" will return OK, even if the device
itself is in use, and is not released.
Problems:
There is a risk of race condition between the lookup and real mount.
Once loop device is initialized read-only, kernel offers no way to turn it to
read-write. It has to fail.
References:
https://lkml.org/lkml/2016/2/26/897
Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
First parse options, then initialize context.
No change in function.
The change is needed for loop device reuse.
Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
The file mtab is evil and already unused by mainstream distributions.
Now libmount is able to detect mtab->/proc/mounts and use
/proc/self/mountinfo if necessary. This heuristic seems overkill in
many cases. It's also dangerous on systems where mountinfo is strongly
required (systemd based distros).
This patch #ifdefs mtab code and forces libmount to always use
/proc/self/mountinfo.
The new configure option --enable-libmount-support-mtab is necessary
to enable old behavior to support mtab.
Signed-off-by: Karel Zak <kzak@redhat.com>
The path canonicalization is expensive and in many cases unwanted due
to problems with readlink() on unreachable NFS and automounters.
This patch add a possibility to search also by $(CWD)/<path> if the
<path> is relative to reduce number of situation when we convert the
path to the canonical absolute path.
The common use-case:
# cd /some/long/path
# umount ./mountpoint
old version:
15543: libmount: TAB: [0x560a99a54230]: lookup TARGET: './test'
15543: libmount: CACHE: [0x560a99a54290]: canonicalize path ./test
15543: libmount: CACHE: [0x560a99a54290]: add entry [ 1] (path): /mnt/test: ./test
15543: libmount: TAB: [0x560a99a54230]: lookup canonical TARGET: '/mnt/test'
15543: libmount: CXT: [0x560a99a54050]: umount fs: /mnt/test
new version:
15597: libmount: TAB: [0xabf230]: lookup TARGET: './test'
15597: libmount: TAB: [0xabf230]: lookup absolute TARGET: '/mnt/test'
15597: libmount: CXT: [0xabf050]: umount fs: /mnt/test
Signed-off-by: Karel Zak <kzak@redhat.com>
The function mnt_table_get_fs_root() should be robust enough to accept
NULL as mountinfo -- the right behaviour is to default to '/'.
The set_fs_root() (tab_update.c) has to understand when mountinfo is
necessary (for bind mounts and btrfs).
Reported-by: Stanislav Brabec <sbrabec@suse.cz>
Signed-off-by: Karel Zak <kzak@redhat.com>
Currently the code supports /dev/name or PARTUUID= only. We also
need to support 'maj:min' and 'hexhex' notations.
Reported-by: George Spelvin <linux@horizon.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
clang warning:
libmount/src/tab.c:1833:6: warning: variable 'rc' is used uninitialized whenever
'if' condition is true [-Wsometimes-uninitialized]
if (!mpc)
^~~~
icc printf warnings:
libmount/src/monitor.c(348): warning #2279: printf/scanf format not a string literal and no format arguments
DBG(MONITOR, ul_debugobj(mn, status == 1 ? " success" : " nothing"));
^
login-utils/vipw.c(348): warning #2279: printf/scanf format not a string literal and no format arguments
: _("You are using shadow passwords on this system.\n"));
^
icc enum warnings:
disk-utils/fdisk-menu.c(150): warning #188: enumerated type mixed with another type
.exclude = FDISK_DISKLABEL_GPT | FDISK_DISKLABEL_BSD,
^
libsmartcols/src/table_print.c(750): warning #188: enumerated type mixed with another type
&width, align,
^
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
BSD/Linux systems stick major/minor/makedev in sysmacros.h. Newer Linux
libraries have been moving away from including sysmacros.h implicitly via
sys/types.h, so include it directly.
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
This include was added just one month ago in 5a971329 but I don't see
what it was good for. It's missing in musl libc.
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
I have validated that we are still compatible at least back to
- openSUSE 11.4
- SLE 11
- RHEL/CentOS 6
- OSX 10.10.x, (Xcode 6.3)
- FreeBSD 10.2
Confirmed incompatibility:
- OSX 10.9.x, (Xcode 6.2)
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
Looks like it got lost in ce4dd666.
Compiler warning discoverd this issue:
libmount/src/fs.c:1171:5: warning: no previous prototype for 'mnt_fs_set_priority' [-Wmissing-prototypes]
int mnt_fs_set_priority(struct libmnt_fs *fs, int prio)
^
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
We were missing our nice compliler warnings for many programs
and libs. See next commits how many trivial and non-trival
warnings have to be fixed.
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
This was a major showstopper when building on a system where
LTLIBINTL libs are needed (e.g. OSX). Maybe there are a few test
programs which wouldn't need LDADD ... never mind.
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
The function does not detect already mounted loop devices on systems
with regular /etc/mtab file.
The patch also improves test_is_mounted() to be useful with mtab.
Reported-by: Ruediger Meier <sweet_f_a@gmx.de>
Signed-off-by: Karel Zak <kzak@redhat.com>
For easier review, the fix of libmount comes in two patches:
PATCH 1/2: libmount: run btrfs subvol checks for "subvolid" option
PATCH 2/2: code re-indentation
No code change is present in this patch.
Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
It is possible to identify btrfs subvolume with "subvolid" instead of "subvol".
In such case, btrfs specific check mistakenly assumes that the default subvolume
is going to be mounted, even if subvolid specifies id of non-default subvolume.
Implement a code for "subvolid" option.
For easier review, this fix comes in two patches:
PATCH 1/2: libmount: run btrfs subvol checks for "subvolid" option
PATCH 2/2: code re-indentation
How to reproduce:
truncate -s1G btrfs_test.img
mkdir -p btrfs_mnt
/sbin/mkfs.btrfs -f -d single -m single ./btrfs_test.img
mount -o loop btrfs_test.img btrfs_mnt
pushd .
cd btrfs_mnt
mkdir -p d0/dd0/ddd0
cd d0/dd0/ddd0
touch file{1..5}
btrfs subvol create s1
cd s1
touch file{1..5}
mkdir -p d1/dd1/ddd1
cd d1/dd1/ddd1
btrfs subvol create s2
rid=$(btrfs inspect rootid s2)
echo new default $rid
btrfs subvol get-default .
btrfs subvol set-default $rid .
popd
DEFAULT_SUBVOLID=`btrfs subvolume get-default btrfs_mnt | while read dummy id rest ; do echo $id ; done`
NON_DEFAULT_SUBVOLID=`btrfs subvolume list btrfs_mnt | while read dummy id rest ; do if test $id = $DEFAULT_SUBVOLID ; then continue ; fi ; echo $id ; done`
umount btrfs_mnt
losetup /dev/loop0 $PWD/btrfs_test.img
echo "/dev/loop0 $PWD/btrfs_mnt btrfs subvolid=$NON_DEFAULT_SUBVOLID 0 0" >>/etc/fstab
./mount -a
./mount -a
umount btrfs_mnt
sed -i "/\/dev\/loop0/d" /etc/fstab
losetup -d /dev/loop0
rm btrfs_test.img
rmdir btrfs_mnt
Current behavior of second "mount -a":
mount: /dev/loop0 is already mounted or /root/btrfs_mnt busy
/dev/loop0 is already mounted on /root/btrfs_mnt
Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
It is possible to mount btrfs using "auto" keyword in fstab. In such
case, btrfs specific checks are skipped. Run them for "auto" as well.
Looking at the code, it is a safe approach. In case of btrfs, it will do
what is needed, in case of no btrfs, btrfs_get_default_subvol_id() will
fail, and the rest of the code is skipped.
How to reproduce:
See reproducer in 2cd28fc and replace fstab line by
echo "/dev/loop0 $PWD/btrfs_mnt btrfs auto 0 0" >>/etc/fstab
Current behavior of second "mount -a":
mount: /dev/loop0 is already mounted or /root/btrfs_mnt busy
/dev/loop0 is already mounted on /root/btrfs_mnt
Testcases for btrfs and ext4:
truncate -s1G btrfs_test.img
truncate -s1G ext4_test.img
mkdir -p btrfs_mnt
mkdir -p ext4_mnt
/sbin/mkfs.btrfs -f -d single -m single ./btrfs_test.img
/sbin/mkfs.ext4 ./ext4_test.img
losetup /dev/loop0 $PWD/btrfs_test.img
losetup /dev/loop1 $PWD/ext4_test.img
echo "/dev/loop0 $PWD/btrfs_mnt auto defaults 0 0" >>/etc/fstab
echo "/dev/loop1 $PWD/ext4_mnt auto defaults 0 0" >>/etc/fstab
./mount -a
./mount -a
umount btrfs_mnt
umount ext4_mnt
sed -i "/\/dev\/loop[01]/d" /etc/fstab
losetup -d /dev/loop0
losetup -d /dev/loop1
rm btrfs_test.img
rm ext4_test.img
rmdir btrfs_mnt
rmdir ext4_mnt
Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
This fixes a failure of `make install DESTDIR=...` when trying to relink
pylibmount against libmount.la.
libtool will look for libmount.so under ${DESTDIR}/${libdir}, but if it
is not yet present, it will assume it is a system installed library and
use -lmount instead.
This makes the install order significant.
Automake lists the install entries in alphabetical order, and as
install-pylibmountexecLTLIBRARIES < install-usrlib_execLTLIBRARIES,
make will try to install pylibmount.so before libmount.so is present
in the DESTDIR, which will then cause libtool to fallback to -lmount
when relinking. This causes the error below:
libtool: install: warning: relinking `pylibmount.la'
libtool: install: (... libtool --mode=relink gcc -o pylibmount.la \
-rpath /usr/lib/python2.7/dist-packages/libmount \
libmount/python/*.lo libmount.la ... -lpython2.7 \
-inst-prefix-dir /path/to/destdir)
/usr/bin/ld: cannot find -lmount
collect2: error: ld returned 1 exit status
libtool: install: error: relink `pylibmount.la' ...
make[3]: *** [install-pylibmountexecLTLIBRARIES] Error 1
Work around this issue by using a zz_ prefix for the pylibmount exec
dir, in order to install it last.
This does not work if parallel make is used for the install step, but
that should be a minor issue (parallel install is probably not that
useful for util-linux, which is not that large a package to actually
benefit from it.) The proper fix should be to introduce a make
dependency of target install-pylibmountexecLTLIBRARIES on target
install-usrlib_execLTLIBRARIES, but unfortunately there is no good way
to accomplish that in automake without overriding it completely.
This issue seems to be previously encountered in automake context, since
automake includes a hack to insert such a dependency rule to install all
libLTLIBRARIES before attempting to install binPROGRAMS, initially
introduced in the commit below:
http://git.savannah.gnu.org/cgit/automake.git/commit/?id=bd4a1d5ad1a72fa780a8b7fd6c365a5dad2e6220
Also, a related bug from Ubuntu tracker:
https://bugs.launchpad.net/ubuntu/+source/util-linux/+bug/1442076
Tested that `make install` starts working again after this commit, even
when libmount-dev is not installed on the system. Also confirmed that
`make distcheck` is now functional.
Confirmed that both __init__.py and the .so library are still installed
in the Python directory.
Tested that it still works without python-devel installed, also
inspected Makefile.in which looks correct.
Tested that `make install pylibmountexecdir=...` still works to override
destination directory at `make install` time.
Signed-off-by: Filipe Brandenburger <filbranden@google.com>
- add --with-btrfs (enabled by default)
- check for linux/btrfs.h
- add "btrfs" to libmount features list (see mount -V)
- #ifdef HAVE_BTRFS_SUPPORT for all btrfs stuff in libmount
Signed-off-by: Karel Zak <kzak@redhat.com>
When mounting btrfs volume without subvol= and subvolid=, and the
btrfs volume has default subvolume defined, mount() mounts the default
subvolume and not the volume root as other filesystems do.
To handle this situation correctly (for example for "mount -a"),
libmount has to be capable to detect default subvolume.
Add btrfs.c and btrfs.h that implement needed functions.
This patch adds mnt_table_find_target_with_option() to the library API.
Known problems not covered by this patch:
- Use of subvolid= in fstab is not yet handled.
- Use of type auto in combination with subvol= in fstab is not yet
handled.
- Use of btrfs in loop devices, where image file is specified in fstab is
not yet handled (use of /dev/loop0 in fstab works).
- If fstab uses subvol=, and subvol path changes since last "mount -a",
subsequent "mount -a" will not recognize that it is already mounted,
and it will attempt to mount it second time. To fix it, libmount should
remember subvolid in time of mount (subvolid is unique for the
subvolume, subvol is not).
- mountinfo contains subvol and subvolid since kernel 4.2. Before kernel
4.2, there is no reasonable way to solve this situation. (One would
create temporary mount point, mount the default, call needed ioctl() to
determine what was mounted, deduce the default subvolume, compare it
with subvolume of mounted volume, unmount and return result.)
How to reproduce:
truncate -s1G btrfs_test.img
mkdir -p btrfs_mnt
/sbin/mkfs.btrfs -f -d single -m single ./btrfs_test.img
mount -o loop btrfs_test.img btrfs_mnt
pushd .
cd btrfs_mnt
mkdir -p d0/dd0/ddd0
cd d0/dd0/ddd0
touch file{1..5}
btrfs subvol create s1
cd s1
touch file{1..5}
mkdir -p d1/dd1/ddd1
cd d1/dd1/ddd1
btrfs subvol create s2
rid=$(btrfs inspect rootid s2)
echo new default $rid
btrfs subvol get-default .
btrfs subvol set-default $rid .
popd
umount btrfs_mnt
losetup /dev/loop0 $PWD/btrfs_test.img
echo "/dev/loop0 $PWD/btrfs_mnt btrfs defaults 0 0" >>/etc/fstab
mount -a
mount -a
umount btrfs_mnt
sed -i "/\/dev\/loop0/d" /etc/fstab
losetup -d /dev/loop0
rm btrfs_test.img
rmdir btrfs_mnt
Current behavior:
mount: /dev/loop0 is already mounted or /root/btrfs_mnt busy
/dev/loop0 is already mounted on /root/btrfs_mnt
Expected behavior is to ignore already mounted FS.
[kzak@redhat.com: - make 'var' optional for mnt_table_find_target_with_option(),
- add mnt_table_find_target_with_option() to symbols table and docs
- add "btrfs" string between supported debug modes
- minor coding style changes]
Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
Cc: David Štěrba <dsterba@suse.cz>
Signed-off-by: Karel Zak <kzak@redhat.com>
[libblkid/src/superblocks/zfs.c:179]: (portability) 'label' is of type 'const void *'. When using void pointers in calculations, the behaviour is undefined.
[libblkid/src/superblocks/zfs.c:237]: (portability) 'label' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.
[libblkid/src/topology/topology.c:221]: (portability) 'chn.data' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.
[libmount/src/fs.c:153]: (portability) 'old' is of type 'const void *'. When using void pointers in calculations, the behaviour is undefined.
[libmount/src/fs.c:154]: (portability) 'new' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined.
sysconf(_SC_GETPW_R_SIZE_MAX) returns initial suggested size for pwd
buffer (see getpwnam_r man page or POSIX). This is not large enough in
some cases.
Yes, this sysconf option is misnamed (should be _SC_GETPW_R_SIZE_MIN).
Signed-off-by: Karel Zak <kzak@redhat.com>
fstab:
/dev/sdc /mnt/test btrfs subvol=/anydir
/mnt/test /mnt/test2 auto bind
and "mount -a" does not detect that /mnt/test2 is already mounted.
Reported-by: Stanislav Brabec <sbrabec@suse.cz>
Signed-off-by: Karel Zak <kzak@redhat.com>
The current libmount version returns error when no able to convert
username/groupname to uid/git.
# mount mount /dev/sda1 /mnt/test -o uid=ignore
# mount: failed to parse mount options
This is regression, the original mount(8) has ignored possible unknown
user/group names and the option has been used unconverted (with the
original value). For example UDF kernel driver depends on this behavior
and "uid=ignore" (or "forgot") is a valid mount option.
Fixed version (unit test):
./test_mount_optstr --fix uid=kzak,gid=forgot,aaa,bbb
optstr: uid=kzak,gid=forgot,aaa,bbb
fixed: uid=1000,gid=forgot,aaa,bbb
Reported-By: Anthony DeRobertis <anthony@derobert.net>
Addresses: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=801527
Signed-off-by: Karel Zak <kzak@redhat.com>
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>
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>
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>
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>
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>
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>
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>
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>
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>
* 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>
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>
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>
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