Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make it thread-safe #1

Merged
merged 1 commit into from
Jul 9, 2024
Merged

make it thread-safe #1

merged 1 commit into from
Jul 9, 2024

Conversation

osvunikernel
Copy link
Owner

This patch modifies this fork of lwext4 to make is safe to interact with by multiple threads running in OSv.

The key assumption is, that OSv VFS layer provides necessary locking around all interactions with lwext4 to guard ext filesystem metadata (i-node table, directory entries, etc) modifications confined to specific vnode.

Beyond that, we add necessary locking around 3 key common data structures:

  • i-node bitmaps in ext4_ialloc.c
  • data block bitmaps in ext4_balloc.c
  • metadata blockcache in ext4_bcache.c and related files

More specifically following functions are protected with inode_alloc_lock()/unlock() to make sure no two files/directories get assigned same inode number:

  • ext4_ialloc_alloc_inode()
  • ext4_ialloc_free_inode()

Next, following functions are protected with block_alloc_lock()/unlock() to make sure no two files/directories use same data block:

  • ext4_balloc_alloc_block()
  • ext4_balloc_free_block()
  • ext4_balloc_free_blocks()

Finally, these functions in ext4_bcache.c and related source files are protected with bcache_lock()/unlock() to make sure the global metadata block cache access is synchronized:

  • ext4_bcache_invalidate_lba() in __ext4_balloc_free_block() and __ext4_balloc_free_blocks()
  • ext4_bcache_find_get(), ext4_block_flush_buf() and ext4_bcache_free() in ext4_block_flush_lba()
  • ext4_block_get_noread(), ext4_bcache_test_flag() ext4_bcache_free() in ext4_block_get()
  • ext4_bcache_free() in ext4_block_set()
  • ext4_block_get_noread() in ext4_trans_block_get_noread()

Ref gkostka#83
Ref cloudius-systems/osv#1179

This patch modifies this fork of lwext4 to make is safe to
interact with by multiple threads running in OSv.

The key assumption is, that OSv VFS layer provides necessary
locking around all interactions with lwext4 to guard ext filesystem
metadata (i-node table, directory entries, etc) modifications confined
to specific vnode.

Beyond that, we add necessary locking around 3 key common data
structures:
- i-node bitmaps in ext4_ialloc.c
- data block bitmaps in ext4_balloc.c
- metadata blockcache in ext4_bcache.c and related files

More specifically following functions are protected with
inode_alloc_lock()/unlock() to make sure no two files/directories
get assigned same inode number:
- ext4_ialloc_alloc_inode()
- ext4_ialloc_free_inode()

Next, following functions are protected with block_alloc_lock()/unlock()
to make sure no two files/directories use same data block:
- ext4_balloc_alloc_block()
- ext4_balloc_free_block()
- ext4_balloc_free_blocks()

Finally, these functions in ext4_bcache.c and related source files
are protected with bcache_lock()/unlock() to make sure the global
metadata block cache access is synchronized:
- ext4_bcache_invalidate_lba() in __ext4_balloc_free_block() and
  __ext4_balloc_free_blocks()
- ext4_bcache_find_get(), ext4_block_flush_buf() and ext4_bcache_free()
  in ext4_block_flush_lba()
- ext4_block_get_noread(), ext4_bcache_test_flag() ext4_bcache_free() in
  ext4_block_get()
- ext4_bcache_free() in ext4_block_set()
- ext4_block_get_noread() in ext4_trans_block_get_noread()

Ref gkostka#83
Ref cloudius-systems/osv#1179

Signed-off-by: Waldemar Kozaczuk <jwkozaczuk@gmail.com>
@osvunikernel osvunikernel self-assigned this Jul 9, 2024
@osvunikernel osvunikernel merged commit 006b0b2 into master Jul 9, 2024
@osvunikernel osvunikernel deleted the thread_safe branch July 9, 2024 01:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants