mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 12:05:15 +00:00
Kernel/Ext2FS: Don't hog inode lock in traverse_as_directory()
Reimplement directory traversal in terms of read_bytes() instead of doing direct block access. This lets us avoid taking the inode lock while iterating over the directory contents.
This commit is contained in:
parent
abbd237ec1
commit
41c0009f6d
Notes:
sideshowbarker
2024-07-18 08:57:01 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/41c0009f6d3
1 changed files with 6 additions and 10 deletions
|
@ -1079,25 +1079,21 @@ Ext2FS::FeaturesReadOnly Ext2FS::get_features_readonly() const
|
|||
|
||||
KResult Ext2FSInode::traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)> callback) const
|
||||
{
|
||||
Locker locker(m_lock);
|
||||
VERIFY(is_directory());
|
||||
|
||||
u8 buffer[max_block_size];
|
||||
auto buf = UserOrKernelBuffer::for_kernel_buffer(buffer);
|
||||
|
||||
auto block_size = fs().block_size();
|
||||
bool allow_cache = true;
|
||||
|
||||
if (m_block_list.is_empty())
|
||||
m_block_list = compute_block_list();
|
||||
auto file_size = size();
|
||||
|
||||
// Directory entries are guaranteed not to span multiple blocks,
|
||||
// so we can iterate over blocks separately.
|
||||
for (auto& block_index : m_block_list) {
|
||||
VERIFY(block_index.value() != 0);
|
||||
if (auto result = fs().read_block(block_index, &buf, block_size, 0, allow_cache); result.is_error()) {
|
||||
return result;
|
||||
}
|
||||
|
||||
for (u64 offset = 0; offset < file_size; offset += block_size) {
|
||||
if (auto result = read_bytes(offset, block_size, buf, nullptr); result.is_error())
|
||||
return result.error();
|
||||
|
||||
auto* entry = reinterpret_cast<ext2_dir_entry_2*>(buffer);
|
||||
auto* entries_end = reinterpret_cast<ext2_dir_entry_2*>(buffer + block_size);
|
||||
while (entry < entries_end) {
|
||||
|
|
Loading…
Add table
Reference in a new issue