fs/xfs/xfs_buf_item.c
Source file repositories/reference/linux-study-clean/fs/xfs/xfs_buf_item.c
File Facts
- System
- Linux kernel
- Corpus path
fs/xfs/xfs_buf_item.c- Extension
.c- Size
- 31636 bytes
- Lines
- 1087
- 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
xfs_platform.hxfs_fs.hxfs_shared.hxfs_format.hxfs_log_format.hxfs_trans_resv.hxfs_bit.hxfs_mount.hxfs_trans.hxfs_trans_priv.hxfs_buf_item.hxfs_inode.hxfs_inode_item.hxfs_quota.hxfs_dquot_item.hxfs_dquot.hxfs_trace.hxfs_log.hxfs_log_priv.hxfs_error.h
Detected Declarations
function xfs_buf_item_get_formatfunction xfs_buf_item_free_formatfunction xfs_buf_item_freefunction xfs_buf_item_relsefunction xfs_buf_log_check_iovecfunction xfs_buf_log_format_sizefunction xfs_buf_item_size_segmentfunction xfs_buf_inval_log_spacefunction xfs_buf_item_sizefunction xfs_buf_item_copy_iovecfunction xfs_buf_item_format_segmentfunction xfs_buf_item_formatfunction xfs_buf_item_unpinfunction xfs_buf_item_finish_stalefunction xfs_buf_item_pinfunction xfs_buf_item_pushfunction xfs_buf_item_putfunction xfs_trans_bholdfunction xfs_buf_item_committingfunction xfs_buf_item_committedfunction xfs_buf_item_precommitfunction xfs_buf_item_initfunction xfs_buf_item_log_segmentfunction xfs_buf_item_logfunction xfs_buf_item_dirty_formatfunction xfs_buf_item_done
Annotated Snippet
if (map_size > XFS_BLF_DATAMAP_SIZE) {
xfs_buf_item_free_format(bip);
kmem_cache_free(xfs_buf_item_cache, bip);
xfs_err(mp,
"buffer item dirty bitmap (%u uints) too small to reflect %u bytes!",
map_size,
BBTOB(bp->b_maps[i].bm_len));
return -EFSCORRUPTED;
}
bip->bli_formats[i].blf_type = XFS_LI_BUF;
bip->bli_formats[i].blf_blkno = bp->b_maps[i].bm_bn;
bip->bli_formats[i].blf_len = bp->b_maps[i].bm_len;
bip->bli_formats[i].blf_map_size = map_size;
}
bp->b_log_item = bip;
xfs_buf_hold(bp);
return 0;
}
/*
* Mark bytes first through last inclusive as dirty in the buf
* item's bitmap.
*/
static void
xfs_buf_item_log_segment(
uint first,
uint last,
uint *map)
{
uint first_bit;
uint last_bit;
uint bits_to_set;
uint bits_set;
uint word_num;
uint *wordp;
uint bit;
uint end_bit;
uint mask;
ASSERT(first < XFS_BLF_DATAMAP_SIZE * XFS_BLF_CHUNK * NBWORD);
ASSERT(last < XFS_BLF_DATAMAP_SIZE * XFS_BLF_CHUNK * NBWORD);
/*
* Convert byte offsets to bit numbers.
*/
first_bit = first >> XFS_BLF_SHIFT;
last_bit = last >> XFS_BLF_SHIFT;
/*
* Calculate the total number of bits to be set.
*/
bits_to_set = last_bit - first_bit + 1;
/*
* Get a pointer to the first word in the bitmap
* to set a bit in.
*/
word_num = first_bit >> BIT_TO_WORD_SHIFT;
wordp = &map[word_num];
/*
* Calculate the starting bit in the first word.
*/
bit = first_bit & (uint)(NBWORD - 1);
/*
* First set any bits in the first word of our range.
* If it starts at bit 0 of the word, it will be
* set below rather than here. That is what the variable
* bit tells us. The variable bits_set tracks the number
* of bits that have been set so far. End_bit is the number
* of the last bit to be set in this word plus one.
*/
if (bit) {
end_bit = min(bit + bits_to_set, (uint)NBWORD);
mask = ((1U << (end_bit - bit)) - 1) << bit;
*wordp |= mask;
wordp++;
bits_set = end_bit - bit;
} else {
bits_set = 0;
}
/*
* Now set bits a whole word at a time that are between
* first_bit and last_bit.
*/
Annotation
- Immediate include surface: `xfs_platform.h`, `xfs_fs.h`, `xfs_shared.h`, `xfs_format.h`, `xfs_log_format.h`, `xfs_trans_resv.h`, `xfs_bit.h`, `xfs_mount.h`.
- Detected declarations: `function xfs_buf_item_get_format`, `function xfs_buf_item_free_format`, `function xfs_buf_item_free`, `function xfs_buf_item_relse`, `function xfs_buf_log_check_iovec`, `function xfs_buf_log_format_size`, `function xfs_buf_item_size_segment`, `function xfs_buf_inval_log_space`, `function xfs_buf_item_size`, `function xfs_buf_item_copy_iovec`.
- 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.