From 95d9c1560753ae73b3829008dde9ca0c37551558 Mon Sep 17 00:00:00 2001 From: Christian Prochaska Date: Tue, 11 Jan 2022 21:29:22 +0100 Subject: [PATCH] libc vfs: open OSS 'info' file only once Issue #4372 --- repos/libports/src/lib/libc/vfs_plugin.cc | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/repos/libports/src/lib/libc/vfs_plugin.cc b/repos/libports/src/lib/libc/vfs_plugin.cc index a1f4b5373f..939c4cddbc 100644 --- a/repos/libports/src/lib/libc/vfs_plugin.cc +++ b/repos/libports/src/lib/libc/vfs_plugin.cc @@ -234,12 +234,18 @@ void Libc::Vfs_plugin::_with_info(File_descriptor &fd, FN const &fn) path.append_element("info"); try { - File_content const content(_alloc, *_root_dir, path.string(), - File_content::Limit{4096U}); - - content.xml([&] (Xml_node node) { - fn(node); }); - + /* + * Opening the info file repeatedly could be too expensive if + * file system servers are part of the VFS, because the directory + * status of the path would be checked at each VFS plugin every + * time. So, we open the file only once. + */ + static Readonly_file file { *_root_dir, path.string() }; + static char buffer[4096]; + Byte_range_ptr range(buffer, + min((size_t)(_root_dir->file_size(path.string())), + sizeof(buffer))); + with_xml_file_content(file, range, [&] (Xml_node node) { fn(node); }); } catch (...) { } }