summaryrefslogtreecommitdiff
path: root/libmount/src
Commit message (Collapse)AuthorAgeFilesLines
* Merge branch 'libmount/syscall'Karel Zak2023-05-171-14/+9
|\
| * libmount: report failed syscall nameKarel Zak2023-04-251-14/+9
| | | | | | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* | libmount: allow overwrite how to use libblkidKarel Zak2023-05-093-1/+21
| | | | | | | | | | | | | | | | | | This is unnecessary for classic mount-like tasks, but application may use libmount in situation when the default for probing is not optimal. Addresses: https://github.com/util-linux/util-linux/issues/2214 Signed-off-by: Karel Zak <kzak@redhat.com>
* | libmount: (subdir) support unshared sessions tooKarel Zak2023-05-021-30/+56
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * enter original namespace for the final move_mount(), it means that the original unshare() (to create the temporary mount) will be ineffective for this final step. God bless FD based APIs (setns() and open_tree())! ;-) * improve cleanup code (call umount only once) * remember private namespace * update note in man page Addresses: https://github.com/util-linux/util-linux/pull/2198 Signed-off-by: Karel Zak <kzak@redhat.com>
* | libmount: fix some typosThomas Weißschuh2023-04-301-2/+2
| | | | | | | | Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
* | libmount: (legacy) fix typo in assert()Karel Zak2023-04-261-2/+3
| | | | | | | | | | Addresses: https://github.com/util-linux/util-linux/pull/2197 Signed-off-by: Karel Zak <kzak@redhat.com>
* | libmount: (mount) free hook data if new APi not avalableKarel Zak2023-04-262-0/+4
| | | | | | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* | libmount: improve ENOSYS fallbackKarel Zak2023-04-251-5/+26
|/ | | | | | | | | | | | | In some cases, for example: # mount -t foo,bar,ext4 /dev/sdc /mnt/test libmount calls fsopen() later (after mount preparation stage), but we need during preparation check if hook_mount.c stuff (new API) is usable. Let's do it by dummy fsopen() call. Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: fix copy & past typoKarel Zak2023-04-251-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: Don't silently accept an X-mount.idmap with only whitespaceChris Webb2023-04-251-2/+4
| | | | | | | | | | | X-mount.idmap accepts a series of whitespace-separated tokens. We reject an empty argument but silently accept an argument consisting of whitespace with no tokens. Test for the empty case more thoroughly. [kzak@redhat.com: - use skip_blank()] Signed-off-by: Chris Webb <chris@arachsys.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: recover from ENOSYS for the new APIKarel Zak2023-04-242-1/+16
| | | | | Addresses: https://github.com/util-linux/util-linux/pull/2188 Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: check for errors from prep-options hooksChris Webb2023-04-231-1/+1
| | | | | | | | | | | | fix_optstr() in context_mount.c calls the MNT_STAGE_PREP_OPTIONS hooks but discards returned errors. This suppresses error messages and can make invalid option strings 'fail open' in surprising ways. Handle error returns from these hooks correctly. No other callers of mnt_context_call_hooks() discard the return value, so other hooks aren't affected. Signed-off-by: Chris Webb <chris@arachsys.com>
* libmount: don't include mount-api-utils.h everywhereKarel Zak2023-04-205-2/+9
| | | | | | | Let's keep the file included only when the new kernel API is necessary. Signed-off-by: Karel Zak <kzak@redhat.com>
* Merge branch 'libmount/relative' of https://github.com/t-8ch/util-linuxKarel Zak2023-04-201-1/+1
|\ | | | | | | | | * 'libmount/relative' of https://github.com/t-8ch/util-linux: libmount: safe_stat: support relative filenames
| * libmount: safe_stat: support relative filenamesThomas Weißschuh2023-04-191-1/+1
| | | | | | | | | | | | | | By using AT_CWFD the call to statx() can also handle relative filenames. Without this safe_stat() which is called on the fstab, source, target... Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
* | libmount: improve hooks de-initializationKarel Zak2023-04-201-0/+4
| | | | | | | | | | | | Don't cleanup if all related to the hooks is already empty. Signed-off-by: Karel Zak <kzak@redhat.com>
* | libmount: fix optlist cache refreshKarel Zak2023-04-201-14/+8
|/ | | | | Fixes: https://github.com/util-linux/util-linux/issues/2182 Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: cleanup all stat() useKarel Zak2023-04-187-40/+43
| | | | | | | | | | | | | | | | | | * don't use STATX_MODE as we need only file type * use fstatat() or stat() as fallback on EOPNOTSUPP * use st_rdev from statx() too * rename to mnt_stat_mountpoint() to more generic mnt_safe_stat() * use mnt_is_path() on more places * cleanup mnt_context_*_excode() to not use stat() * use on others places mnt_safe_stat() Note that on some places stat() remaining, but it's not related to the mountpoints, it's about /run/mount/utab permissions, file locking and /dev/* permissions for non-root mounts. Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: use AT_STATX_DONT_SYNC when touch mountpointsKarel Zak2023-04-171-10/+69
| | | | | | | | | | | | | | * prefer statx() with AT_STATX_DONT_SYNC if available * keep fstatat() and stat() as fallback * add test to mnt_stat_mountpoint() The goal is to minimize situations when we need classic stat() because it triggers automount, and stat() syscall may hang on unreachable network filesystems. The automount issue was resolved years ago by AT_NO_AUTOMOUNT; now we can use statx() to fix also hangs on NFS. Addresses: https://github.com/util-linux/util-linux/issues/2049 Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: don't define struct stat is unnecessaryKarel Zak2023-04-174-4/+12
| | | | | | Let's introduce simple function to hide 'struct stat' if unnecessary. Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: fix superblock rw/ro reconfigurationKarel Zak2023-04-051-14/+33
| | | | | | | | | The classic mount(2) defaults to 'rw', but the new API does not reset superblock to 'rw' if the flag is not explicitly used for FSCONFIG_CMD_RECONFIGURE. Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=2180593 Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: (idmap) reuse tree FD, fix umountKarel Zak2023-03-273-33/+61
| | | | | | | | | | | * reuse already open mount tree; the tree could be already open due to regular mount, bind or remount operation * umount (MNT_DETACH) old target if we created a clone (but the operation is not a bind) Adedreses: https://github.com/util-linux/util-linux/issues/2130 Signed-off-by: Karel Zak <kzak@redhat.com>
* Merge branch 'fixes' of https://github.com/brauner/util-linuxKarel Zak2023-03-231-2/+6
|\ | | | | | | | | * 'fixes' of https://github.com/brauner/util-linux: idmap: kill child when writing the idmap fails
| * idmap: kill child when writing the idmap failsChristian Brauner2023-03-231-2/+6
| | | | | | | | | | | | | | | | This fixes the second issues reported in [1] where calling mount -o 'X-mount.idmap=[...]' just hangs. Fixes: https://github.com/util-linux/util-linux/issues/2130 [1] Signed-off-by: Christian Brauner <brauner@kernel.org>
* | libmount: fix user/users for superuserKarel Zak2023-03-231-3/+36
| | | | | | | | | | | | | | | | | | Always use MS_SECURE and MS_OWNERSECURE to mount fstab entries where is specified "user" or "users", although the current user is root. This bug has never been released (v2.39-rc1 only). Signed-off-by: Karel Zak <kzak@redhat.com>
* | libmount: fix MS_REMOUNT emulation by mount_setattr()Karel Zak2023-03-232-1/+21
| | | | | | | | | | | | | | | | | | | | | | The classic mount(MS_REMOUNT) means that all unspecified MS_NOxxx flags are remove (except MS_NOATIME). We need to follow this semantic when emulate remount by mount_setattr(), because "mount -o remount /" is the way how (for example) systemd resets root filesystem to default (e.g. ro->rw, etc.) Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=2180593 Signed-off-by: Karel Zak <kzak@redhat.com>
* | libmount: fix and cleanup relatime useKarel Zak2023-03-232-17/+39
| | | | | | | | | | | | | | | | * move atime logic to optlist * MOUNT_ATTR_RELATIME is zero, so we cannot use use "if (!attr)" to skip mount_setattr() Signed-off-by: Karel Zak <kzak@redhat.com>
* | libmount: add missing MOUNT_ATTR_NODEVKarel Zak2023-03-231-0/+2
| | | | | | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* | libmount: fix typo, improve debugKarel Zak2023-03-222-2/+5
|/ | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: dont ignore autofs mounts by defaultIan Kent2023-03-151-2/+2
| | | | | | | | | | | | | | | | | | | | Making libmount ingore autofs mounts by default can be a problem for systemd, I remember now what the problem was. autofs multi-mounts can be nested (and often are, think of a tree of NFS exports) where there are autofs file system mounts within NFS mounts and together with autofs mount triggers. In this case systemd needs to see all the mounts at shutdown when it is umounting the tree of mounts. We don't want to have to rely on modifications having been made to systemd for this to work properly so we can't make this the default behaviour in libmount. Fixes: 22147e08c987 (libmount: use autofs mount hint to ignore autofs mount entries) Signed-off-by: Ian Kent <raven@themaw.net> Cc: John Westerdale <jwesterd@redhat.com> Cc: Frank Hertz <fhirtz@redhat.com> Cc: Frank Sorenson <fsorenso@redhat.com>
* libmount: inhibit warning about mask being unusedThomas Weißschuh2023-03-051-1/+1
|
* libmount: (optstr) do not use xalloc.h in testKarel Zak2023-03-021-10/+24
| | | | | | | | It's technically valid to use xalloc.h in the tests, but then we mix regular malloc and xalloc in the same source file, and it makes "make checkxalloc" using difficult. Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: remove unimplemented symbolKarel Zak2023-03-021-1/+0
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: idmap: fix sock write to childPedro Tammela2023-03-011-1/+1
| | | | The current code writes to sock_fds[0], which is set to -1 on line 227, instead of the correct sock_fds[1]. As a cause, a simple `mount` command which uses idmapping and doesn't specify a user ns hangs indefinitely.
* libmount: treat comma as terminator in mnt_match_options()Karel Zak2023-02-281-1/+1
| | | | | | | | | | An alone "no" in the pattern is interpreted as an error; it should be also valid in case the keyword is followed by a comma, e.g. mnt_match_options("bla", "no,,"); Suggested-by: Sören Tempel <soeren@soeren-tempel.net> Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: make mnt_match_options() more robustKarel Zak2023-02-271-10/+55
| | | | | | | | | | | * don't allocate and use a buffer for the pattern if the pattern is empty * make it more obvious how empty pattern and empty optstr is evaluated * add regression test Reported-by: Sören Tempel <soeren@soeren-tempel.net> Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: move selinux stuff to hook moduleKarel Zak2023-02-226-177/+209
| | | | | | | | | * convert selinux contexts to raw format during "prep-options" stage * convert rootcontext=@target to raw context when final mountpoint path is available (after mkdir). Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: make it possible to define order of hooksKarel Zak2023-02-222-8/+88
| | | | | | | In some cases we have more hooks in the same stage and it's necessary to call some hooks after another. Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: create a hook to set rootcontext=@targetKarel Zak2023-02-225-7/+107
| | | | | | | | | | The final target (mountpoint) depends on others libmount functionality (X-mount.mkdir or --target-prefix). It means we cannot assume target when the library calls fix_opts() and translates selinux contexts. The solution is extra hook executed after mkdir. Signed-off-by: Karel Zak <kzak@redhat.com>
* mount: add rootcontext=@targetChristian Göttsche2023-02-211-4/+14
| | | | | | | | Add a special value for rootcontext=, namely `@target`, to set the root context of the new filesystem to the current context of the target mountpoint. Useful for in-memory filesystems, like tmpfs and ramfs. Closes: #1830
* libmount: declare array of LSM options constChristian Göttsche2023-02-211-4/+4
|
* libmount: add fsconfig() btrfs workaroundKarel Zak2023-02-164-2/+26
| | | | | | | | | | | | The new kernel mount API is not properly implemented in all FS drivers. See strace output: fsconfig(3, FSCONFIG_SET_STRING, "source", "/dev/sda", 0) = 0 fsconfig(3, FSCONFIG_SET_STRING, "context", "system_u:object_r:root_t:s0", 0) = 0 fsconfig(3, FSCONFIG_CMD_CREATE, NULL, NULL, 0) = -1 EINVAL (Invalid argument) Reported-by: Shinichiro Kawasaki <shinichiro.kawasaki@wdc.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: support "recursive" argument for VFS attributesKarel Zak2023-02-153-53/+113
| | | | | | | | | mount -o bind,ro=recursive,nosuid /foo /bar sets all sub-mount to read-only, but only /bar will be nosuid. Addresses: https://github.com/util-linux/util-linux/issues/1501 Signed-off-by: Karel Zak <kzak@redhat.com>
* include: add fallback for statxKarel Zak2023-02-131-0/+1
| | | | | Fixes: https://github.com/util-linux/util-linux/pull/2065 Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: don't require return argument in get-like functionsKarel Zak2023-01-245-56/+76
| | | | | Fixes: https://github.com/util-linux/util-linux/issues/2039 Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: use MNT_ERR_APPLYFLAGS for failed mount_setattr()Karel Zak2023-01-101-0/+6
| | | | | | | | | | | | | | | | | | The classic mount(2) based version uses MNT_ERR_APPLYFLAGS when not able to set flags and errno is EINVAL. This is expected by mnt_context_get_mount_excode() where libmount generates error messages for mount(8). Expected is: # mount --make-private /mnt/test mount: /mnt/test: not mount point or bad option. rather than generic error: mount: /mnt/test: wrong fs type, bad option, bad superblock on none ... Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: fix typo in debug messageKarel Zak2023-01-101-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: implement X-mount.auto-fstypesKarel Zak2023-01-092-1/+24
| | | | | Fixes: https://github.com/util-linux/util-linux/issues/1969 Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: (optlist) keep parsed options without quotesKarel Zak2023-01-093-32/+29
| | | | | | | | | | Some mount options uses quotes due to commas in the value, for example (SELinux) mount -o 'context="foo,bar"'. Let's keep this parsed values without quotes in options list. It will make things more simple. Signed-off-by: Karel Zak <kzak@redhat.com>
* libmount: ensure child hangs around until we persisted namespaceChristian Brauner2023-01-081-0/+10
| | | | | | | | | When we create a new namespace in a child process to persist it we need to ensure that the child hangs around. During exit the child will drop all references to its namespaces and so by the time we call open we might already fail to open the namespace. Fix this. Signed-off-by: Christian Brauner (Microsoft) <brauner@kernel.org>