fs/ocfs2/buffer_head_io.c
Source file repositories/reference/linux-study-clean/fs/ocfs2/buffer_head_io.c
File Facts
- System
- Linux kernel
- Corpus path
fs/ocfs2/buffer_head_io.c- Extension
.c- Size
- 10959 bytes
- Lines
- 457
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/fs.hlinux/types.hlinux/highmem.hlinux/bio.hcluster/masklog.hocfs2.halloc.hinode.hjournal.huptodate.hbuffer_head_io.hocfs2_trace.h
Detected Declarations
enum ocfs2_state_bitsfunction ocfs2_write_blockfunction ocfs2_read_blocks_syncfunction ocfs2_read_blocksfunction lockedfunction ocfs2_check_super_or_backupfunction ocfs2_write_super_or_backup
Annotated Snippet
if (bhs[i] == NULL) {
bhs[i] = sb_getblk(osb->sb, block++);
if (bhs[i] == NULL) {
status = -ENOMEM;
mlog_errno(status);
break;
}
}
bh = bhs[i];
if (buffer_jbd(bh)) {
trace_ocfs2_read_blocks_sync_jbd(
(unsigned long long)bh->b_blocknr);
continue;
}
if (buffer_dirty(bh)) {
/* This should probably be a BUG, or
* at least return an error. */
mlog(ML_ERROR,
"trying to sync read a dirty "
"buffer! (blocknr = %llu), skipping\n",
(unsigned long long)bh->b_blocknr);
continue;
}
lock_buffer(bh);
if (buffer_jbd(bh)) {
#ifdef CATCH_BH_JBD_RACES
mlog(ML_ERROR,
"block %llu had the JBD bit set "
"while I was in lock_buffer!",
(unsigned long long)bh->b_blocknr);
BUG();
#else
unlock_buffer(bh);
continue;
#endif
}
bh_submit(bh, REQ_OP_READ, bh_end_read);
}
read_failure:
for (i = nr; i > 0; i--) {
bh = bhs[i - 1];
if (unlikely(status)) {
if (new_bh && bh) {
/* If middle bh fails, let previous bh
* finish its read and then put it to
* avoid bh leak
*/
if (!buffer_jbd(bh))
wait_on_buffer(bh);
put_bh(bh);
bhs[i - 1] = NULL;
} else if (bh && buffer_uptodate(bh)) {
clear_buffer_uptodate(bh);
}
continue;
}
/* No need to wait on the buffer if it's managed by JBD. */
if (!buffer_jbd(bh))
wait_on_buffer(bh);
if (!buffer_uptodate(bh)) {
/* Status won't be cleared from here on out,
* so we can safely record this and loop back
* to cleanup the other buffers. */
status = -EIO;
goto read_failure;
}
}
bail:
return status;
}
/* Caller must provide a bhs[] with all NULL or non-NULL entries, so it
* will be easier to handle read failure.
*/
int ocfs2_read_blocks(struct ocfs2_caching_info *ci, u64 block, int nr,
struct buffer_head *bhs[], int flags,
int (*validate)(struct super_block *sb,
struct buffer_head *bh))
{
int status = 0;
int i, ignore_cache = 0;
Annotation
- Immediate include surface: `linux/fs.h`, `linux/types.h`, `linux/highmem.h`, `linux/bio.h`, `cluster/masklog.h`, `ocfs2.h`, `alloc.h`, `inode.h`.
- Detected declarations: `enum ocfs2_state_bits`, `function ocfs2_write_block`, `function ocfs2_read_blocks_sync`, `function ocfs2_read_blocks`, `function locked`, `function ocfs2_check_super_or_backup`, `function ocfs2_write_super_or_backup`.
- 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.