]> git.ipfire.org Git - thirdparty/util-linux.git/commit
libmount: Reuse the guessed root device
authorViktor Rosendahl (BMW) <viktor.rosendahl@gmail.com>
Mon, 24 Oct 2022 09:36:03 +0000 (11:36 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 26 Oct 2022 08:46:58 +0000 (10:46 +0200)
commit4e8a8d3598022aec301760f99f15e2a628a532b0
tree86f6f5e95ecf0a1a3e028bf2d92da85537a18202
parent36e824e61edbb80aa2eb839516ce6a6398e37168
libmount: Reuse the guessed root device

Inside a container, the file /proc/self/mountinfo may contain many lines
with /dev/root. It is also quite likely that /dev/root is not visible
inside the container. This may cause mnt_guess_system_root() to try to use
libblkid before giving up, through mnt_resolve_spec() and
mnt_resolve_tag(), which calls blkid_evaluate_tag(). The call to
blkid_evaluate_tag() may trigger a scan of all block devices, which is
expensive.

For this reason, it doesn't make any sense for kernel_fs_postparse()
to call mnt_guess_system_root() more than once for every call to
mnt_table_parse_stream. Instead, save the result from the first call and
reuse it for all subsequent calls to kernel_fs_postparse(), so that there
is at most one call to mnt_guess_system_root() for every call
to mnt_table_parse_stream().

[kzak@redhat.com: - use sysroot_ prefix for the cached variables
  - simplify code logic in kernel_fs_postparse()
  - add free() to parser_cleanup()]

Signed-off-by: Viktor Rosendahl (BMW) <viktor.rosendahl@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/src/tab_parse.c