ext4_swap_extents(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… ext4_swap_extents (kernel API manual, section 9, bestie)

Okay so bestie, buckle up β€” we're diving into ext4_swap_extents, and honestly? It's giving "does exactly what it says on the tin" energy. Let's go 🫢


✨ NAME ✨

ext4_swap_extents β€” swap extents between two inodes πŸ”


πŸŽ€ SYNOPSIS πŸŽ€

int ext4_swap_extents (handle_t *handle , struct inode *inode1 , struct
inode *inode2 , ext4_lblk_t lblk1 , ext4_lblk_t lblk2 , ext4_lblk_t
count , int unwritten , int *erp );

Yes, that's a lot of arguments. No, we're not skipping any of them. Come on πŸ’…


🌸 ARGUMENTS 🌸

  • handle β€” the handle for this transaction, like the VIP wristband for the whole operation 🎟️
  • inode1 β€” first inode. The main character (of the pair, anyway) πŸ‘‘
  • inode2 β€” second inode. Equally iconique, don't worry 🌟
  • lblk1 β€” start block for the first inode πŸ“
  • lblk2 β€” start block for the second inode πŸ“
  • count β€” number of blocks to swap. Yes, an actual count, not a vibe πŸ”’
  • unwritten β€” mark the second inode's extents as unwritten after the swap πŸ™ˆ
  • erp β€” pointer to save the error value. When things go sideways, this is where the receipts live 🧾

πŸ¦‹ DESCRIPTION πŸ¦‹

So this helper routine literally does exactly what it promises: it "swaps extents." That's the whole assignment, and it ate πŸ”₯

But β€” and this is the important part, bestie β€” all the other stuff is not its job. Page-cache locking consistency? Not here. bh mapping consistency? Nope. Extent's data copying? Also not here. All of that must be performed by the caller. It's giving "I did my part, you do yours" energy πŸ’€

πŸ”’ Locking

  • i_rwsem is held for both inodes
  • i_data_sem is locked for write for both inodes

⚠️ Assumptions

  • All pages from the requested range are locked for both inodes
fr fr, read the assumptions before you call this. It assumes you've already done the locking homework πŸ“šβœ¨

🌈 SEE ALSO 🌈

  • Kernel file ./fs/ext4/extents.c πŸ‘€

Anyway, that's the whole page, bestie β€” you're now officially educated on extent swapping πŸ§šβ€β™€οΈβœ¨

This little love letter comes from the source tree ./fs/ext4, dated October 2026 β€” and it's the ext4_swap_extents(9) page, in case you lost track πŸ’œ

πŸ“¦ where this page comes from