fs/ext4/page-io.c
Source file repositories/reference/linux-study-clean/fs/ext4/page-io.c
File Facts
- System
- Linux kernel
- Corpus path
fs/ext4/page-io.c- Extension
.c- Size
- 17251 bytes
- Lines
- 614
- 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.
- 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/blk-crypto.hlinux/fs.hlinux/time.hlinux/highuid.hlinux/pagemap.hlinux/quotaops.hlinux/string.hlinux/buffer_head.hlinux/writeback.hlinux/mpage.hlinux/namei.hlinux/uio.hlinux/bio.hlinux/workqueue.hlinux/kernel.hlinux/slab.hlinux/mm.hlinux/sched/mm.hext4_jbd2.hxattr.hacl.h
Detected Declarations
function ext4_init_pageiofunction ext4_exit_pageiofunction ext4_free_io_end_vecfunction buffer_io_errorfunction ext4_finish_biofunction bio_for_each_folio_allfunction ext4_release_io_endfunction finishfunction dump_completed_IOfunction ext4_io_end_defer_completionfunction ext4_add_complete_iofunction ext4_do_flush_completed_IOfunction ext4_end_io_rsv_workfunction ext4_put_io_end_deferfunction ext4_put_io_endfunction ext4_end_biofunction ext4_io_submitfunction ext4_io_submit_initfunction io_submit_init_biofunction io_submit_need_new_biofunction io_submit_add_bhfunction ext4_bio_write_folio
Annotated Snippet
if (fscrypt_is_bounce_folio(folio)) {
io_folio = folio;
folio = fscrypt_pagecache_folio(folio);
}
if (bio->bi_status) {
int err = blk_status_to_errno(bio->bi_status);
mapping_set_error(folio->mapping, err);
}
bh = head = folio_buffers(folio);
/*
* We check all buffers in the folio under b_uptodate_lock
* to avoid races with other end io clearing async_write flags
*/
spin_lock_irqsave(&head->b_uptodate_lock, flags);
do {
if (bh_offset(bh) < bio_start ||
bh_offset(bh) + bh->b_size > bio_end) {
if (buffer_async_write(bh))
under_io++;
continue;
}
clear_buffer_async_write(bh);
if (bio->bi_status) {
set_buffer_write_io_error(bh);
buffer_io_error(bh);
}
} while ((bh = bh->b_this_page) != head);
spin_unlock_irqrestore(&head->b_uptodate_lock, flags);
if (!under_io) {
fscrypt_free_bounce_page(&io_folio->page);
folio_end_writeback(folio);
}
}
}
static void ext4_release_io_end(ext4_io_end_t *io_end)
{
struct bio *bio, *next_bio;
BUG_ON(!list_empty(&io_end->list));
BUG_ON(io_end->flag & EXT4_IO_END_UNWRITTEN);
WARN_ON(io_end->handle);
for (bio = io_end->bio; bio; bio = next_bio) {
next_bio = bio->bi_private;
ext4_finish_bio(bio);
bio_put(bio);
}
ext4_free_io_end_vec(io_end);
kmem_cache_free(io_end_cachep, io_end);
}
/*
* On successful IO, check a range of space and convert unwritten extents to
* written. On IO failure, check if journal abort is needed. Note that
* we are protected from truncate touching same part of extent tree by the
* fact that truncate code waits for all DIO to finish (thus exclusion from
* direct IO is achieved) and also waits for writeback to complete. Thus we
* cannot get to ext4_ext_truncate() before all IOs overlapping that range are
* completed (happens from ext4_free_ioend()).
*/
static int ext4_end_io_end(ext4_io_end_t *io_end)
{
struct inode *inode = io_end->inode;
handle_t *handle = io_end->handle;
struct super_block *sb = inode->i_sb;
int ret = 0;
ext4_debug("ext4_end_io_nolock: io_end 0x%p from inode %llu,list->next 0x%p,"
"list->prev 0x%p\n",
io_end, inode->i_ino, io_end->list.next, io_end->list.prev);
/*
* Do not convert the unwritten extents if data writeback fails,
* or stale data may be exposed.
*/
io_end->handle = NULL; /* Following call will use up the handle */
if (unlikely(io_end->flag & EXT4_IO_END_FAILED)) {
ret = -EIO;
if (handle)
jbd2_journal_free_reserved(handle);
if (test_opt(sb, DATA_ERR_ABORT))
jbd2_journal_abort(EXT4_SB(sb)->s_journal, ret);
} else {
ret = ext4_convert_unwritten_io_end_vec(handle, io_end);
}
if (ret < 0 && !ext4_emergency_state(sb) &&
io_end->flag & EXT4_IO_END_UNWRITTEN) {
Annotation
- Immediate include surface: `linux/blk-crypto.h`, `linux/fs.h`, `linux/time.h`, `linux/highuid.h`, `linux/pagemap.h`, `linux/quotaops.h`, `linux/string.h`, `linux/buffer_head.h`.
- Detected declarations: `function ext4_init_pageio`, `function ext4_exit_pageio`, `function ext4_free_io_end_vec`, `function buffer_io_error`, `function ext4_finish_bio`, `function bio_for_each_folio_all`, `function ext4_release_io_end`, `function finish`, `function dump_completed_IO`, `function ext4_io_end_defer_completion`.
- 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.