fs/buffer.c
Source file repositories/reference/linux-study-clean/fs/buffer.c
File Facts
- System
- Linux kernel
- Corpus path
fs/buffer.c- Extension
.c- Size
- 82662 bytes
- Lines
- 3096
- 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/kernel.hlinux/sched/signal.hlinux/syscalls.hlinux/fs.hlinux/iomap.hlinux/mm.hlinux/percpu.hlinux/slab.hlinux/capability.hlinux/blkdev.hlinux/blk-crypto.hlinux/file.hlinux/quotaops.hlinux/highmem.hlinux/export.hlinux/backing-dev.hlinux/writeback.hlinux/hash.hlinux/suspend.hlinux/buffer_head.hlinux/task_io_accounting_ops.hlinux/bio.hlinux/cpu.hlinux/bitops.hlinux/mpage.hlinux/bit_spinlock.hlinux/folio_batch.hlinux/sched/mm.htrace/events/block.hlinux/fscrypt.hlinux/fsverity.hlinux/sched/isolation.h
Detected Declarations
struct postprocess_bh_ctxstruct bh_lrustruct bh_accountingfunction Copyrightfunction __lock_bufferfunction unlock_bufferfunction buffer_check_dirty_writebackfunction __wait_on_bufferfunction buffer_io_errorfunction bio_endio_bhfunction end_buffer_read_syncfunction bh_submitfunction bh_submitfunction __find_get_block_slowfunction end_buffer_async_readfunction verify_bhfunction decrypt_bhfunction bh_end_async_readfunction bh_submitfunction fsyncfunction __remove_assoc_queuefunction remove_assoc_queuefunction mmb_has_buffersfunction fsyncfunction mmb_fsync_noflushfunction mmb_fsyncfunction write_boundary_blockfunction mmb_mark_buffer_dirtyfunction block_dirty_foliofunction syncfunction IOfunction link_dev_buffersfunction blkdev_max_blockfunction folio_init_buffersfunction grow_dev_foliofunction grow_buffersfunction __getblk_slowfunction block_read_full_foliofunction mark_buffer_write_io_errorfunction brelsefunction bforgetfunction buffer_set_crypto_ctxfunction __bh_submitfunction bh_submitfunction check_irqs_onfunction bh_lru_installfunction pagefunction lookup_bh_lru
Annotated Snippet
struct postprocess_bh_ctx {
struct work_struct work;
struct buffer_head *bh;
struct fsverity_info *vi;
};
static void verify_bh(struct work_struct *work)
{
struct postprocess_bh_ctx *ctx =
container_of(work, struct postprocess_bh_ctx, work);
struct buffer_head *bh = ctx->bh;
bool valid;
valid = fsverity_verify_blocks(ctx->vi, bh->b_folio, bh->b_size,
bh_offset(bh));
end_buffer_async_read(bh, valid);
kfree(ctx);
}
static void decrypt_bh(struct work_struct *work)
{
struct postprocess_bh_ctx *ctx =
container_of(work, struct postprocess_bh_ctx, work);
struct buffer_head *bh = ctx->bh;
int err;
err = fscrypt_decrypt_pagecache_blocks(bh->b_folio, bh->b_size,
bh_offset(bh));
if (err == 0 && ctx->vi) {
/*
* We use different work queues for decryption and for verity
* because verity may require reading metadata pages that need
* decryption, and we shouldn't recurse to the same workqueue.
*/
INIT_WORK(&ctx->work, verify_bh);
fsverity_enqueue_verify_work(&ctx->work);
return;
}
end_buffer_async_read(bh, err == 0);
kfree(ctx);
}
/*
* I/O completion handler for block_read_full_folio() - folios
* which come unlocked at the end of I/O.
*/
static void bh_end_async_read(struct bio *bio)
{
struct buffer_head *bh;
bool uptodate = bio_endio_bh(bio, &bh);
struct inode *inode = bh->b_folio->mapping->host;
bool decrypt = fscrypt_inode_uses_fs_layer_crypto(inode);
struct fsverity_info *vi = NULL;
/* needed by ext4 */
if (bh->b_folio->index < DIV_ROUND_UP(inode->i_size, PAGE_SIZE))
vi = fsverity_get_info(inode);
/* Decrypt (with fscrypt) and/or verify (with fsverity) if needed. */
if (uptodate && (decrypt || vi)) {
struct postprocess_bh_ctx *ctx = kmalloc_obj(*ctx, GFP_ATOMIC);
if (ctx) {
ctx->bh = bh;
ctx->vi = vi;
if (decrypt) {
INIT_WORK(&ctx->work, decrypt_bh);
fscrypt_enqueue_decrypt_work(&ctx->work);
} else {
INIT_WORK(&ctx->work, verify_bh);
fsverity_enqueue_verify_work(&ctx->work);
}
return;
}
uptodate = false;
}
end_buffer_async_read(bh, uptodate);
}
/**
* bh_end_async_write - I/O end handler for async folio writes
* @bio: The bio being completed.
*
* Pass this function to bh_submit() if you're doing the equivalent of
* block_write_full_folio(). That is, the folio is unlocked, and will
* have its writeback flag cleared once all async write buffers have
* completed.
*/
void bh_end_async_write(struct bio *bio)
{
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/sched/signal.h`, `linux/syscalls.h`, `linux/fs.h`, `linux/iomap.h`, `linux/mm.h`, `linux/percpu.h`, `linux/slab.h`.
- Detected declarations: `struct postprocess_bh_ctx`, `struct bh_lru`, `struct bh_accounting`, `function Copyright`, `function __lock_buffer`, `function unlock_buffer`, `function buffer_check_dirty_writeback`, `function __wait_on_buffer`, `function buffer_io_error`, `function bio_endio_bh`.
- 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.