Karel Zak [Thu, 15 Aug 2024 08:26:31 +0000 (10:26 +0200)]
libmount: add support for listmount()
The new listmount() syscall returns a list of unique mount IDs (just
uint64_t per node, nothing else). It makes it very fast and efficient.
* libmount supports two scenarios:
- fetch the whole mount table by mnt_table_fetch_listmount(); this is
an alternative to mnt_table_parse_file()
- on demand; this mode is an extension to the current functionality,
when enabled by mnt_table_enable_listmount(), then mnt_table_next_fs()
will ask the kernel for data by listmount.
If mnt_table_next_fs() iterates on the mount table in reverse order
(MNT_ITER_BACKWARD), then it reads mount nodes from the kernel in
reverse order too.
The advantage of the on-demand mode is that on machines with a huge
mount table (thousands of nodes), we can work with only a subset of
the table (usually the last few nodes with the most recently
mounted filesystems), and the kernel does not have to compose a complete
huge table. This should be an improvement over the mountinfo file.
The default is to read 512 nodes (IDs) by one listmount() call. This
size can be altered by mnt_table_listmount_set_stepsiz(). The default
size should be large enough for usual Linux machines.
It's also possible to set a sub-tree by mnt_table_listmount_set_id()
and a namespace by mnt_table_listmount_set_ns().
If libmnt_statmnt (on-demand statmount()) is assigned to the table,
then all filesystems in the table are automatically assigned to this
statmount() setup too. This allows for a completely on-demand
scenario.
while (mnt_table_next_fs(tb, itr, &fs) == 0) {
if (strcmp("vfat", mnt_fs_get_fstype(fs)) == 0)
print("%s", mnt_fs_get_fs_options(fs));
}
In this example, mnt_table_next_fs() serves as the frontend for
listmount() and mnt_fs_get_...() serves as the frontend for
statmount(). The fs-options are read from kernel only for "vfat"
filesystems.
Karel Zak [Wed, 14 Aug 2024 15:10:45 +0000 (17:10 +0200)]
libmount: add support for statmount()
* introduce libmnt_statmnt object to store statmount mask and buffer
(etc.)
* add API for libmnt_fs to retrieve data from the kernel using
statmount()
* support on-demand statmount() from old mnt_fs_get_...() functions
* allow libmnt_statmnt to be shared and reused between libmnt_fs
instances
* allow libmnt_statmnt to be assigned and used for filesystems in the
table (assign libmnt_statmnt to the table to make it usable for all
filesystems).
* allow temporary disabling of fetching data from the kernel to avoid
unwanted recursion in certain use-cases
* support namespaces for statmount() based on the libmnt_fs namespace
ID setting
* allow user-defined statmount masks to overwrite the default
Karel Zak [Tue, 11 Jun 2024 09:55:39 +0000 (11:55 +0200)]
libmount: Add API to get/set unique IDs
Since the Linux kernel version 6.8, there are two types of IDs
available: the "old" ID used in /proc/self/mountinfo, and a new 64-bit
unique ID that is never recycled. This new ID is provided by the
statx(STATX_MNT_ID_UNIQUE) and statmount() syscalls.
Note that this patch only adds the API for retrieving these unique
IDs, but the backing code has not been implemented yet.
Karel Zak [Mon, 22 Jul 2024 12:12:37 +0000 (14:12 +0200)]
libmount: add mount-api-utils.h to mountP.h
The new syscalls (statmount and fd-based mount) are already being
utilized in various areas within the library. Therefore, it would be
more efficient to include the syscalls header file in the private main
library header file.
Karel Zak [Wed, 14 Aug 2024 13:33:44 +0000 (15:33 +0200)]
include/mount-api-utils: add statmount and listmount
* Make the includes and ifdefs in the file more generic, to cover
other interfaces besides just HAVE_MOUNTFD_API.
* Add #ifdef HAVE_STATMOUNT_API to the header file.
* Add fallbacks for statmount and listmount masks and flags.
* Add a local definition of the structs mnt_id_req and statmount.
We do not want to depend on kernel headers for now, as all of this is
still under development. Installed headers may provide old versions,
and a solution based on #ifdef will still require local definition of
the structs.
* Add wrappers for the statmount() and listmount() syscalls.
* Add sys_statmount(), a wrapper for statmount() that reallocates the
statmount buffer (on EOVERFLOW errno) if it is not large enough.
Note that for now, we are directly using syscalls and do not require
libc support for statmount() and listmount(). The kernel API is very
extensible, as it is based on structs rather than syscall arguments.
Therefore, I doubt we will see any libc support in the near future.
The code uses the "ul_" prefix for locally defined variables and
functions to prevent conflicts with kernel headers and potential
future versions of libc.
Karel Zak [Wed, 8 Jan 2025 11:40:30 +0000 (12:40 +0100)]
Merge branch 'revise--test-cases' of https://github.com/masatake/util-linux
* 'revise--test-cases' of https://github.com/masatake/util-linux:
tests: (lsfd::mkfds_vsock) skip if diag socket for AF_VSOCK is unavailable
tests: (test_mkfds::sockdiag) support AF_VSOCK family
tests: (lsns::filter) skip if /proc/self/uid_map is not writable
Sam James [Wed, 8 Jan 2025 06:49:40 +0000 (06:49 +0000)]
meson: add missing `is_disabler` checks
Noticed this when looking at why the `check` target isn't created
with `-Dauto_features=disabled`. This doesn't fix that but it does
fix a bunch of issues I noticed along the way after a hint from Eli Schwartz.
Karel Zak [Fri, 3 Jan 2025 09:48:25 +0000 (10:48 +0100)]
Merge branch 'lsfd--vsock' of https://github.com/masatake/util-linux
* 'lsfd--vsock' of https://github.com/masatake/util-linux:
lsfd: support AF_VSOCK sockets
tests: (lsfd-functions.bash) add a missing constant
tests: (lsfd) quote '$' in patterns in a case/esac block
Use gtk-doc constructs to mark up formatted sections of documentation
so that they display properly in the rendered output.
- Enclose code samples with informalexample+programlisting tags
- Enclose preformatted blocks of text (tables) in same
- Present numbered lists in markdown format (leading 1., 2., etc.)
so that they're translated into HTML ordered lists
Karel Zak [Thu, 26 Dec 2024 11:06:08 +0000 (12:06 +0100)]
Merge branch 'lsfd--hyperlinks' of https://github.com/masatake/util-linux
* 'lsfd--hyperlinks' of https://github.com/masatake/util-linux:
lsfd: don't enable hyperlinks for deleted files
lsfd: enable hyperlinks only for regular files and directories
lsfd: add --hyperlink command line option
tests: (test_sysinfo) add a helper to call xgethostname
lsfd: consolidate add_column()
Karel Zak [Thu, 26 Dec 2024 10:34:10 +0000 (11:34 +0100)]
fstab.5 mount.8: add note about field separator
The value of the mount option X-mount.idmap= can contain spaces as
separators between mappings. Unfortunately, this conflicts with the
fstab format where fields are separated by spaces. Using quotes does
not solve this issue because fields are separated before they are
parsed.
This limitation of the fstab parser within libmount is due to backward
compatibility. The fstab format is a de-facto standard and is parsed
by many tools and libraries, including third-party shell scripts. It
would not be practical to introduce any improvements in libmount that
would make fstabs unparseable in other places.
Users must understand that in-field spaces must be escaped by \040.
For example, X-mount.idmap="0:0:1\040500:1000:1".
Addresses: https://github.com/util-linux/util-linux/issues/2829 Signed-off-by: Karel Zak <kzak@redhat.com>
LiviaMedeiros [Mon, 16 Dec 2024 10:40:37 +0000 (11:40 +0100)]
tests: add skips when IPv6 is not supported
Before this change on systems with disabled IPv6 (e.g. `CONFIG_IPV6 is
not set` in kernel config), `lsfd/mkfds-tcp6` and `lsfd/mkfds-udp6` were
failing, and `lsfd/option-inet` was hanging forever, making it
impossible to complete the tests.
Karel Zak [Mon, 2 Dec 2024 11:50:29 +0000 (12:50 +0100)]
lsfd: consolidate add_column()
* use only column IDs in add_column() callers
* don't work with "struct colinfo" in callers
* rename add_column_by_id() to add_hidden_column() as it's very
special function used only by filters
Karel Zak [Tue, 10 Dec 2024 11:24:59 +0000 (12:24 +0100)]
Merge branch 'ft-algorithm-params' of https://github.com/LiviaMedeiros/util-linux
* 'ft-algorithm-params' of https://github.com/LiviaMedeiros/util-linux:
zramctl: rename `--params` into `--algorithm-params`
zramctl: add support for `algorithm_params`
Maks Mishin [Tue, 10 Dec 2024 09:26:32 +0000 (12:26 +0300)]
sys-utils: (setpriv): fix potential memory leak
Dynamic memory, referenced by 'my_caps' is allocated by calling function 'xstrdup'
add then changed by calling of strsep function.
The free(my_caps) call is incorrect if my_caps != NULL, and points to some
place inside or outside the source string.
Zhaoming Luo [Mon, 9 Dec 2024 11:16:11 +0000 (19:16 +0800)]
hwclock: Support GNU Hurd
* configure.ac: add HURD so it can be used in conditional in am files
* sys-utils/Makemodule.am: compile hwclock for GNU Hurd
* sys-utils/hwclock-rtc.c: compile for GNU Hurd
* sys-utils/hwclock.c: compile for GNU Hurd
* sys-utils/hwclock.h: compile for GNU Hurd
Zhaoming Luo [Mon, 9 Dec 2024 02:11:54 +0000 (10:11 +0800)]
hwclock: Remove ioperm declare as it causes nested extern declare warning
The extern declaration causes the following warning:
```
CC sys-utils/hwclock-hwclock-cmos.o
sys-utils/hwclock-cmos.c: In function 'i386_iopl':
sys-utils/hwclock-cmos.c:356:20: warning: nested extern declaration of 'ioperm' [-Wnested-externs]
356 | extern int ioperm(unsigned long from, unsigned long num, int turn_on);
| ^~~~~~
sys-utils/hwclock-cmos.c:356:20: warning: redundant redeclaration of 'ioperm' [-Wredundant-decls]
In file included from sys-utils/hwclock-cmos.c:68:
/usr/include/i386-gnu/sys/io.h:29:12: note: previous declaration of 'ioperm' with type 'int(long unsigned int, long unsigned int, int)'
29 | extern int ioperm (unsigned long int __from, unsigned long int __num,
| ^~~~~~
CCLD hwclock
```
Karel Zak [Fri, 6 Dec 2024 09:05:25 +0000 (10:05 +0100)]
Merge branch 'posix-argument-order' of https://github.com/nilfsuser5678/util-linux
* 'posix-argument-order' of https://github.com/nilfsuser5678/util-linux:
libmount: exec mount helpers with posixly correct argument order
libmount/context_mount: fix argument number comments
nilfsuser5678 [Fri, 29 Nov 2024 17:27:12 +0000 (17:27 +0000)]
libmount: exec mount helpers with posixly correct argument order
This improves compatibility with non-gnu userspaces.
On systems where the libc provides posix getopt instead of gnu getopt,
mount helpers which use getopt to parse arguments will not parse
options which appear after non-option arguments. This patch ensures
mount/unmount work as expected in this situation.
mount: fix expected argument order for mount helpers in tests