fs/iomap/buffered-io.c
Source file repositories/reference/linux-study-clean/fs/iomap/buffered-io.c
File Facts
- System
- Linux kernel
- Corpus path
fs/iomap/buffered-io.c- Extension
.c- Size
- 61291 bytes
- Lines
- 2069
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/iomap.hlinux/buffer_head.hlinux/writeback.hlinux/swap.hlinux/migrate.hlinux/fserror.hlinux/fsverity.hinternal.htrace.h../internal.h
Detected Declarations
struct iomap_folio_statefunction ifs_is_fully_uptodatefunction ifs_next_uptodate_blockfunction ifs_next_nonuptodate_blockfunction ifs_set_range_uptodatefunction iomap_set_range_uptodatefunction ifs_next_dirty_blockfunction ifs_next_clean_blockfunction ifs_find_dirty_rangefunction iomap_find_dirty_rangefunction ifs_clear_range_dirtyfunction iomap_clear_range_dirtyfunction ifs_set_range_dirtyfunction iomap_set_range_dirtyfunction ifs_freefunction iomap_bytes_to_truncatefunction iomap_adjust_read_rangefunction iomap_block_needs_zeroingfunction iomap_read_inline_datafunction iomap_finish_folio_readfunction iomap_read_initfunction bytesfunction iomap_read_folio_iterfunction iomap_read_foliofunction iomap_readahead_iterfunction iomap_readaheadfunction iomap_is_partially_uptodatefunction iomap_release_foliofunction iomap_invalidate_foliofunction iomap_dirty_foliofunction iomap_write_failedfunction __iomap_write_beginfunction __iomap_put_foliofunction iomap_trim_folio_rangefunction iomap_write_begin_inlinefunction iomap_write_beginfunction flightfunction __iomap_write_endfunction iomap_write_end_inlinefunction iomap_write_endfunction iomap_write_iterfunction iomap_file_buffered_writefunction iomap_fsverity_writefunction iomap_write_delalloc_ifs_punchfunction iomap_write_delalloc_punchfunction iomap_write_delalloc_scanfunction punchfunction iomap_unshare_iter
Annotated Snippet
struct iomap_folio_state {
spinlock_t state_lock;
unsigned int read_bytes_pending;
atomic_t write_bytes_pending;
/*
* Each block has two bits in this bitmap:
* Bits [0..blocks_per_folio) has the uptodate status.
* Bits [b_p_f...(2*b_p_f)) has the dirty status.
*/
unsigned long state[];
};
static inline bool ifs_is_fully_uptodate(struct folio *folio,
struct iomap_folio_state *ifs)
{
struct inode *inode = folio->mapping->host;
return bitmap_full(ifs->state, i_blocks_per_folio(inode, folio));
}
/*
* Find the next uptodate block in the folio. end_blk is inclusive.
* If no uptodate block is found, this will return end_blk + 1.
*/
static unsigned ifs_next_uptodate_block(struct folio *folio,
unsigned start_blk, unsigned end_blk)
{
struct iomap_folio_state *ifs = folio->private;
return find_next_bit(ifs->state, end_blk + 1, start_blk);
}
/*
* Find the next non-uptodate block in the folio. end_blk is inclusive.
* If no non-uptodate block is found, this will return end_blk + 1.
*/
static unsigned ifs_next_nonuptodate_block(struct folio *folio,
unsigned start_blk, unsigned end_blk)
{
struct iomap_folio_state *ifs = folio->private;
return find_next_zero_bit(ifs->state, end_blk + 1, start_blk);
}
static bool ifs_set_range_uptodate(struct folio *folio,
struct iomap_folio_state *ifs, size_t off, size_t len)
{
struct inode *inode = folio->mapping->host;
unsigned int first_blk = off >> inode->i_blkbits;
unsigned int last_blk = (off + len - 1) >> inode->i_blkbits;
unsigned int nr_blks = last_blk - first_blk + 1;
bitmap_set(ifs->state, first_blk, nr_blks);
return ifs_is_fully_uptodate(folio, ifs);
}
static void iomap_set_range_uptodate(struct folio *folio, size_t off,
size_t len)
{
struct iomap_folio_state *ifs = folio->private;
unsigned long flags;
bool mark_uptodate = true;
if (folio_test_uptodate(folio))
return;
if (ifs) {
spin_lock_irqsave(&ifs->state_lock, flags);
/*
* If a read with bytes pending is in progress, we must not call
* folio_mark_uptodate(). The read completion path
* (iomap_read_end()) will call folio_end_read(), which uses XOR
* semantics to set the uptodate bit. If we set it here, the XOR
* in folio_end_read() will clear it, leaving the folio not
* uptodate.
*/
mark_uptodate = ifs_set_range_uptodate(folio, ifs, off, len) &&
!ifs->read_bytes_pending;
spin_unlock_irqrestore(&ifs->state_lock, flags);
}
if (mark_uptodate)
folio_mark_uptodate(folio);
}
/*
* Find the next dirty block in the folio. end_blk is inclusive.
* If no dirty block is found, this will return end_blk + 1.
*/
Annotation
- Immediate include surface: `linux/iomap.h`, `linux/buffer_head.h`, `linux/writeback.h`, `linux/swap.h`, `linux/migrate.h`, `linux/fserror.h`, `linux/fsverity.h`, `internal.h`.
- Detected declarations: `struct iomap_folio_state`, `function ifs_is_fully_uptodate`, `function ifs_next_uptodate_block`, `function ifs_next_nonuptodate_block`, `function ifs_set_range_uptodate`, `function iomap_set_range_uptodate`, `function ifs_next_dirty_block`, `function ifs_next_clean_block`, `function ifs_find_dirty_range`, `function iomap_find_dirty_range`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: integration 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.