summaryrefslogtreecommitdiffstats
path: root/libmount/src/context_umount.c
Commit message (Collapse)AuthorAgeFilesLines
* libmount: fix memory leak on error [coverity scan]Karel Zak2019-05-151-2/+3
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: (fuse) follow only user_id= on umountKarel Zak2018-11-301-27/+8Star
| | | | | | | | | | | | | 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>
* libmount: Support unmount FUSE mountsRian Hunter2018-11-301-1/+81
| | | | | | | | | | | | | | | | | 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>
* libmount: cleanup licenses sections in the filesKarel Zak2018-08-161-3/+8
| | | | | | | | | * 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>
* libmount: cleanup const in umount codeKarel Zak2018-07-201-4/+4
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: switch namespace when appropriateVaclav Dolezal2018-06-111-1/+48
| | | | Signed-off-by: Vaclav Dolezal <vdolezal@redhat.com>
* libmount: support for namespaces for helpersVaclav Dolezal2018-06-111-2/+18
| | | | Signed-off-by: Vaclav Dolezal <vdolezal@redhat.com>
* libmount: added error MNT_ERR_NAMESPACEVaclav Dolezal2018-06-111-0/+8
| | | | Signed-off-by: Vaclav Dolezal <vdolezal@redhat.com>
* libmount: don't use MS_MGC_VAL magic in mount(2) syscallKarel Zak2018-06-011-1/+1
| | | | | | | | | 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>
* bugfix: fix possible segfault during umount -aRichard Fuchs2018-04-171-1/+2
| | | | | | | 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.
* libmount: Allow MNT_FORCE and MNT_DETACH at umountJoshua Watt2017-11-081-1/+1
| | | | | | | | | 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>
* libmount: check waitpid() return codeKarel Zak2017-11-061-5/+11
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: Use waitpid() when waiting for mount helper child processVratislav Podzimek2017-11-061-2/+4
| | | | | | | | | | | | | 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>
* libmount: export locking errors as MNT_EX_FILEIOKarel Zak2017-09-151-1/+10
| | | | | | | | | | | | 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>
* libmount: use _exit() in <type> handlersKarel Zak2017-06-291-3/+3
| | | | | | | 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>
* misc: remove stray semicolonsSami Kerola2017-06-141-1/+1
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* misc: fix reassigned values before old ones has been used [cppcheck]Sami Kerola2017-06-141-1/+1
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* libmount: (umount) use mount table filter on -c onlyKarel Zak2017-06-071-2/+9
| | | | | | | 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>
* libmount: use mount table filter on --no-canonicalizeKarel Zak2017-06-071-8/+12
| | | | | | | 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>
* umount: never 'stat' the path when "-c" is given.NeilBrown2017-06-061-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* libmount: fix memory leak [coverity scan]Karel Zak2017-05-171-1/+5
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: add mnt_context_get_excode()Karel Zak2017-04-271-0/+80
| | | | | | | | | | | | | | | | 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>
* Add sizelimit to internal APIStanislav Brabec2016-08-031-1/+1
| | | | | | | | | | | | | | 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>
* libmount, look: remove dead code [oclint]Sami Kerola2016-07-211-1/+0Star
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* misc: Fix various typosSebastian Rasmussen2016-05-311-1/+1
| | | | | | | Fix various typos in error messages, warnings, debug strings, comments and names of static functions. Signed-off-by: Sebastian Rasmussen <sebras@gmail.com>
* libmount: fix mnt_table_parse_mtab() logicKarel Zak2016-04-151-3/+3
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: add 'force-mountinfo' to features list, improve debugKarel Zak2016-02-011-7/+4Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: add comment, remove TODO itemKarel Zak2015-12-101-0/+4
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: use fstatat(AT_NO_AUTOMOUNT) for mountpointsKarel Zak2015-12-091-2/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: cleanup assert() usageKarel Zak2015-08-041-8/+3Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: do not call umount helper on --fakeKarel Zak2015-06-031-0/+6
| | | | | | | | | 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>
* libmount: fix possible mem leak in has_utab_entry() [coverity scan]Karel Zak2015-01-291-3/+10
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: add private mnt_context_get_mtab_for_target()Karel Zak2014-11-191-35/+6Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* umount: read mountinfo if --detach-loop givenRobert Schiele2014-09-221-1/+3
| | | | | | | | | | Don't use the optimization not to read mountinfo from commit 6a52473ecd877227f6f7da2b95da0b51593ffec1 if --detach-loop was given since we need the name of the loop device in that case and with the optimization this is not present and thus the detach operation obviously fails. Signed-off-by: Robert Schiele <rschiele@gmail.com>
* libmount: use -t for type.subtype in helpers APIKarel Zak2014-08-211-2/+4
| | | | | References: https://github.com/karelzak/util-linux/issues/116 Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: don't touch mtab when mount -n specifiedKarel Zak2014-06-171-4/+4
| | | | | Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1109367 Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: use new debug functionsKarel Zak2014-03-211-39/+37Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* umount: don't use mountinfo if possibleKarel Zak2014-03-031-2/+83
| | | | | | | | | | | | | | | | | | | | | | | | The umount(8) always parses /proc/self/mountinfo to get fstype and to merge kernel mount options with userspace mount options from /run/mount/utab. This behavior is overkill in many cases and it's pretty expensive as kernel has to always compose *whole* mountinfo. This performance disadvantage is visible for crazy use-cases with huge number of mountpoints and frequently called umount(8). It seems that we can bypass /proc/self/mountinfo by statfs() to get filesystem type (statfs.f_type magic) and analyze /run/mount/utab before we parse mountinfo. This optimization is not used when: * umount(8) executed by non-root (as user= in utab is expected) * umount --lazy / --force (target is probably unreachable NFS, then use statfs() is pretty bad idea) * target is not a directory (e.g. umount /dev/sda1) * there is (deprecated) writeable mtab Reported-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: small cleanup in umount codeKarel Zak2013-09-271-2/+5
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: free username after checkDave Reisner2013-09-201-0/+2
| | | | | | | | | | | | | | | Leak reported by valgrind: ==14226== 7 bytes in 1 blocks are definitely lost in loss record 1 of 1 ==14226== at 0x4C2757B: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==14226== by 0x5534839: strdup (in /usr/lib/libc-2.18.so) ==14226== by 0x4E53FE0: mnt_get_username (utils.c:560) ==14226== by 0x4E456A5: mnt_context_prepare_umount (context_umount.c:413) ==14226== by 0x4E464F7: mnt_context_umount (context_umount.c:851) ==14226== by 0x403476: umount_one (umount.c:299) ==14226== by 0x402B34: main (umount.c:629) Signed-off-by: Dave Reisner <dreisner@archlinux.org>
* libmount: be robust when work with loopdev backing file pathsKarel Zak2013-08-051-5/+5
| | | | | | | | It's usually unnecessary as we compare devno and ino, but let's use absolute paths for situations when it's necessary to compare paths as strings. Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: canonicalize for conversion from loopdev backing fileKarel Zak2013-08-051-1/+6
| | | | | | | | | | | | # mount foo.img /mnt # umount foo.img umount: foo.img: not mounted The loopdev code (and sysfs backing_file) uses absolute paths, but libmount does not canonicalize the path before lookup for the backing file. References: https://bugzilla.redhat.com/show_bug.cgi?id=950497 Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: fix typosOndrej Oprala2013-08-051-16/+16
| | | | Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
* libmount: be robust for empty target/source stringsKarel Zak2013-06-171-2/+11
| | | | | | | | | | * lib/canonicalize.c: don't interpret empty strings as relative paths * libmount: more robust libmnt_table find function and debug messages References: https://bugzilla.novell.com/show_bug.cgi?id=825150 Signed-off-by: Karel Zak <kzak@redhat.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: don't ignore root fs on umount -aKarel Zak2013-05-141-4/+1Star
| | | | | | | | | | The release v2.22 (the new umount) introduces a regression when root fs is excluded from umount --all. There is not reason for this exception. The libmount should be smart enough to disable mtab update after rootfs umount. Reported-by: Bruce Dubbs <bruce.dubbs@gmail.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount, col: remove redundant null checks [smatch scan]Sami Kerola2013-04-091-4/+2Star
| | | | | | | | libmount/src/context_umount.c:174 mnt_context_find_umount_fs() info: redundant null check on loopdev calling free() libmount/src/context_umount.c:179 mnt_context_find_umount_fs() info: redundant null check on loopdev calling free() text-utils/col.c:406 flush_lines() info: redundant null check on l->l_line calling free() Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* libmount: umount crashes when trying to umount a non-mountpointKarel Zak2013-03-251-2/+2
| | | | | Reported-by: Mantas Mikulėnas <grawity@gmail.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: export umount mountpoint look up codeKarel Zak2013-02-261-25/+57
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: don't try to play with loopdevs if umount argument is really ↵Karel Zak2012-11-151-3/+6
| | | | | | mountpoint Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: don't use umount optimization for -l or -fKarel Zak2012-10-151-1/+3
| | | | | | | | | | The options -l (lazy) and -f (force) means that the mountpoint may be unreadable (for example because NFS server is unreadable). So we should not try to be smart in this case and we should try to minimize number of situations when stat() or readlink() is used for the mountpoint. Signed-off-by: Karel Zak <kzak@redhat.com>