fs/btrfs/ordered-data.c
Source file repositories/reference/linux-study-clean/fs/btrfs/ordered-data.c
File Facts
- System
- Linux kernel
- Corpus path
fs/btrfs/ordered-data.c- Extension
.c- Size
- 41244 bytes
- Lines
- 1372
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: implementation source
- Status
- source implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/slab.hlinux/blkdev.hlinux/writeback.hlinux/sched/mm.hmessages.hmisc.hctree.htransaction.hbtrfs_inode.hextent_io.hdisk-io.hcompression.hdelalloc-space.hqgroup.hsubpage.hfile.hblock-group.h
Detected Declarations
function entry_endfunction btrfs_range_overlapsfunction insert_ordered_extentfunction btrfs_add_ordered_sumfunction btrfs_mark_ordered_extent_errorfunction btrfs_mark_ordered_extent_truncatedfunction finish_ordered_fnfunction can_finish_ordered_extentfunction btrfs_queue_ordered_fnfunction btrfs_finish_ordered_extentfunction extentfunction btrfs_dec_test_ordered_pendingfunction btrfs_put_ordered_extentfunction btrfs_remove_ordered_extentfunction btrfs_run_ordered_extent_workfunction btrfs_wait_ordered_extentsfunction list_for_each_entry_safefunction btrfs_wait_ordered_rootsfunction btrfs_start_ordered_extent_nowritebackfunction btrfs_wait_ordered_rangefunction btrfs_get_ordered_extents_for_loggingfunction btrfs_lookup_first_ordered_extentfunction btrfs_lookup_first_ordered_extentfunction __tree_searchfunction btrfs_lock_and_flush_ordered_rangefunction btrfs_try_lock_ordered_rangefunction list_for_each_entry_safefunction ordered_data_initfunction ordered_data_exit
Annotated Snippet
if (cur >= entry_end) {
node = rb_next(node);
/* No more ordered extents, exit */
if (!node)
break;
entry = rb_entry(node, struct btrfs_ordered_extent,
rb_node);
/* Go to next ordered extent and continue */
cur = entry->file_offset;
continue;
}
/*
* | |<--- OE --->|
* cur
* Go to the start of OE.
*/
if (cur < entry->file_offset) {
cur = entry->file_offset;
continue;
}
/*
* Now we are definitely inside one ordered extent.
*
* |<--- OE --->|
* |
* cur
*/
this_end = min(entry_end, end);
len = this_end - cur;
ASSERT(len < U32_MAX);
if (can_finish_ordered_extent(entry, cur, len, uptodate)) {
spin_unlock(&inode->ordered_tree_lock);
btrfs_queue_ordered_fn(entry);
spin_lock(&inode->ordered_tree_lock);
}
cur += len;
}
spin_unlock(&inode->ordered_tree_lock);
}
/*
* Finish IO for one ordered extent across a given range. The range can only
* contain one ordered extent.
*
* @cached: The cached ordered extent. If not NULL, we can skip the tree
* search and use the ordered extent directly.
* Will be also used to store the finished ordered extent.
* @file_offset: File offset for the finished IO
* @io_size: Length of the finish IO range
*
* Return true if the ordered extent is finished in the range, and update
* @cached.
* Return false otherwise.
*
* NOTE: The range can NOT cross multiple ordered extents.
* Thus caller should ensure the range doesn't cross ordered extents.
*/
bool btrfs_dec_test_ordered_pending(struct btrfs_inode *inode,
struct btrfs_ordered_extent **cached,
u64 file_offset, u64 io_size)
{
struct rb_node *node;
struct btrfs_ordered_extent *entry = NULL;
bool finished = false;
spin_lock(&inode->ordered_tree_lock);
if (cached && *cached) {
entry = *cached;
goto have_entry;
}
node = ordered_tree_search(inode, file_offset);
if (!node)
goto out;
entry = rb_entry(node, struct btrfs_ordered_extent, rb_node);
have_entry:
if (!in_range(file_offset, entry->file_offset, entry->num_bytes))
goto out;
if (io_size > entry->bytes_left)
btrfs_crit(inode->root->fs_info,
"bad ordered accounting left %llu size %llu",
entry->bytes_left, io_size);
entry->bytes_left -= io_size;
Annotation
- Immediate include surface: `linux/slab.h`, `linux/blkdev.h`, `linux/writeback.h`, `linux/sched/mm.h`, `messages.h`, `misc.h`, `ctree.h`, `transaction.h`.
- Detected declarations: `function entry_end`, `function btrfs_range_overlaps`, `function insert_ordered_extent`, `function btrfs_add_ordered_sum`, `function btrfs_mark_ordered_extent_error`, `function btrfs_mark_ordered_extent_truncated`, `function finish_ordered_fn`, `function can_finish_ordered_extent`, `function btrfs_queue_ordered_fn`, `function btrfs_finish_ordered_extent`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.