fs/ext4/readpage.c
Source file repositories/reference/linux-study-clean/fs/ext4/readpage.c
File Facts
- System
- Linux kernel
- Corpus path
fs/ext4/readpage.c- Extension
.c- Size
- 12064 bytes
- Lines
- 456
- 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.
- 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/export.hlinux/mm.hlinux/kdev_t.hlinux/gfp.hlinux/bio.hlinux/fs.hlinux/buffer_head.hlinux/blk-crypto.hlinux/blkdev.hlinux/highmem.hlinux/prefetch.hlinux/mpage.hlinux/writeback.hlinux/backing-dev.hext4.htrace/events/ext4.h
Detected Declarations
struct bio_post_read_ctxenum bio_post_read_stepfunction __read_end_iofunction decrypt_workfunction verity_workfunction bio_post_read_processingfunction bio_post_read_requiredfunction BIOfunction ext4_set_bio_post_read_ctxfunction ext4_readpage_limitfunction ext4_mpage_readpagesfunction ext4_map_blocksfunction ext4_read_foliofunction ext4_readaheadfunction ext4_init_post_read_processingfunction ext4_exit_post_read_processing
Annotated Snippet
struct bio_post_read_ctx {
struct bio *bio;
struct fsverity_info *vi;
struct work_struct work;
unsigned int cur_step;
unsigned int enabled_steps;
};
static void __read_end_io(struct bio *bio)
{
struct folio_iter fi;
bio_for_each_folio_all(fi, bio)
folio_end_read(fi.folio, bio->bi_status == 0);
if (bio->bi_private)
mempool_free(bio->bi_private, bio_post_read_ctx_pool);
bio_put(bio);
}
static void bio_post_read_processing(struct bio_post_read_ctx *ctx);
static void decrypt_work(struct work_struct *work)
{
struct bio_post_read_ctx *ctx =
container_of(work, struct bio_post_read_ctx, work);
struct bio *bio = ctx->bio;
if (fscrypt_decrypt_bio(bio))
bio_post_read_processing(ctx);
else
__read_end_io(bio);
}
static void verity_work(struct work_struct *work)
{
struct bio_post_read_ctx *ctx =
container_of(work, struct bio_post_read_ctx, work);
struct bio *bio = ctx->bio;
struct fsverity_info *vi = ctx->vi;
/*
* fsverity_verify_bio() may call readahead() again, and although verity
* will be disabled for that, decryption may still be needed, causing
* another bio_post_read_ctx to be allocated. So to guarantee that
* mempool_alloc() never deadlocks we must free the current ctx first.
* This is safe because verity is the last post-read step.
*/
BUILD_BUG_ON(STEP_VERITY + 1 != STEP_MAX);
mempool_free(ctx, bio_post_read_ctx_pool);
bio->bi_private = NULL;
fsverity_verify_bio(vi, bio);
__read_end_io(bio);
}
static void bio_post_read_processing(struct bio_post_read_ctx *ctx)
{
/*
* 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.
*/
switch (++ctx->cur_step) {
case STEP_DECRYPT:
if (ctx->enabled_steps & (1 << STEP_DECRYPT)) {
INIT_WORK(&ctx->work, decrypt_work);
fscrypt_enqueue_decrypt_work(&ctx->work);
return;
}
ctx->cur_step++;
fallthrough;
case STEP_VERITY:
if (IS_ENABLED(CONFIG_FS_VERITY) &&
ctx->enabled_steps & (1 << STEP_VERITY)) {
INIT_WORK(&ctx->work, verity_work);
fsverity_enqueue_verify_work(&ctx->work);
return;
}
ctx->cur_step++;
fallthrough;
default:
__read_end_io(ctx->bio);
}
}
static bool bio_post_read_required(struct bio *bio)
{
return bio->bi_private && !bio->bi_status;
}
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/export.h`, `linux/mm.h`, `linux/kdev_t.h`, `linux/gfp.h`, `linux/bio.h`, `linux/fs.h`, `linux/buffer_head.h`.
- Detected declarations: `struct bio_post_read_ctx`, `enum bio_post_read_step`, `function __read_end_io`, `function decrypt_work`, `function verity_work`, `function bio_post_read_processing`, `function bio_post_read_required`, `function BIO`, `function ext4_set_bio_post_read_ctx`, `function ext4_readpage_limit`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: source implementation candidate.
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.