libc vfs: open OSS 'info' file only once

Issue #4372
This commit is contained in:
Christian Prochaska 2022-01-11 21:29:22 +01:00 committed by Christian Helmuth
parent 8ced0f184e
commit 95d9c15607

View File

@ -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 (...) { }
}