]> git.ipfire.org Git - thirdparty/util-linux.git/commit
libmount: add support for listmount()
authorKarel Zak <kzak@redhat.com>
Thu, 15 Aug 2024 08:26:31 +0000 (10:26 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 8 Jan 2025 12:57:42 +0000 (13:57 +0100)
commit4e345324988656fabb767cc6043fdf51b2cbfa21
tree5319257d70c2726d4be2fe893810d3890830db5b
parent30e61b122f1ee89576d0f852ea93adc9e381d8fa
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.

tb = mnt_new_table();
sm = mnt_new_statmnt();

mnt_table_refer_statmnt(tb, sm); /* enable statmount() */
mnt_table_enable_listmount(tb, 1); /* enable listmount() */

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.

Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/docs/libmount-sections.txt
libmount/meson.build
libmount/src/Makemodule.am
libmount/src/libmount.h.in
libmount/src/libmount.sym
libmount/src/mountP.h
libmount/src/tab.c
libmount/src/tab_listmount.c [new file with mode: 0644]