fs/xfs/scrub/bitmap.c
Source file repositories/reference/linux-study-clean/fs/xfs/scrub/bitmap.c
File Facts
- System
- Linux kernel
- Corpus path
fs/xfs/scrub/bitmap.c- Extension
.c- Size
- 15302 bytes
- Lines
- 585
- 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
xfs_platform.hxfs_fs.hxfs_shared.hxfs_bit.hxfs_format.hxfs_trans_resv.hxfs_mount.hxfs_btree.hscrub/scrub.hscrub/bitmap.hlinux/interval_tree_generic.h
Detected Declarations
struct xbitmap64_nodestruct xbitmap32_nodefunction xbitmap64_clearfunction xbitmap64_setfunction xbitmap64_destroyfunction xbitmap64_initfunction xbitmap64_disunionfunction for_each_xbitmap64_extentfunction xbitmap64_hweightfunction xbitmap64_walkfunction for_each_xbitmap64_extentfunction xbitmap64_emptyfunction xbitmap64_testfunction xbitmap32_clearfunction xbitmap32_setfunction xbitmap32_destroyfunction xbitmap32_initfunction xbitmap32_disunionfunction for_each_xbitmap32_extentfunction xbitmap32_hweightfunction xbitmap32_walkfunction for_each_xbitmap32_extentfunction xbitmap32_emptyfunction xbitmap32_testfunction xbitmap32_count_set_regions
Annotated Snippet
struct xbitmap64_node {
struct rb_node bn_rbnode;
/* First set bit of this interval and subtree. */
uint64_t bn_start;
/* Last set bit of this interval. */
uint64_t bn_last;
/* Last set bit of this subtree. Do not touch this. */
uint64_t __bn_subtree_last;
};
/* Define our own interval tree type with uint64_t parameters. */
#define START(node) ((node)->bn_start)
#define LAST(node) ((node)->bn_last)
/*
* These functions are defined by the INTERVAL_TREE_DEFINE macro, but we'll
* forward-declare them anyway for clarity.
*/
static inline __maybe_unused void
xbitmap64_tree_insert(struct xbitmap64_node *node, struct rb_root_cached *root);
static inline __maybe_unused void
xbitmap64_tree_remove(struct xbitmap64_node *node, struct rb_root_cached *root);
static inline __maybe_unused struct xbitmap64_node *
xbitmap64_tree_iter_first(struct rb_root_cached *root, uint64_t start,
uint64_t last);
static inline __maybe_unused struct xbitmap64_node *
xbitmap64_tree_iter_next(struct xbitmap64_node *node, uint64_t start,
uint64_t last);
INTERVAL_TREE_DEFINE(struct xbitmap64_node, bn_rbnode, uint64_t,
__bn_subtree_last, START, LAST, static inline __maybe_unused,
xbitmap64_tree)
/* Iterate each interval of a bitmap. Do not change the bitmap. */
#define for_each_xbitmap64_extent(bn, bitmap) \
for ((bn) = rb_entry_safe(rb_first(&(bitmap)->xb_root.rb_root), \
struct xbitmap64_node, bn_rbnode); \
(bn) != NULL; \
(bn) = rb_entry_safe(rb_next(&(bn)->bn_rbnode), \
struct xbitmap64_node, bn_rbnode))
/* Clear a range of this bitmap. */
int
xbitmap64_clear(
struct xbitmap64 *bitmap,
uint64_t start,
uint64_t len)
{
struct xbitmap64_node *bn;
struct xbitmap64_node *new_bn;
uint64_t last = start + len - 1;
while ((bn = xbitmap64_tree_iter_first(&bitmap->xb_root, start, last))) {
if (bn->bn_start < start && bn->bn_last > last) {
uint64_t old_last = bn->bn_last;
/* overlaps with the entire clearing range */
xbitmap64_tree_remove(bn, &bitmap->xb_root);
bn->bn_last = start - 1;
xbitmap64_tree_insert(bn, &bitmap->xb_root);
/* add an extent */
new_bn = kmalloc_obj(struct xbitmap64_node,
XCHK_GFP_FLAGS);
if (!new_bn)
return -ENOMEM;
new_bn->bn_start = last + 1;
new_bn->bn_last = old_last;
xbitmap64_tree_insert(new_bn, &bitmap->xb_root);
} else if (bn->bn_start < start) {
/* overlaps with the left side of the clearing range */
xbitmap64_tree_remove(bn, &bitmap->xb_root);
bn->bn_last = start - 1;
xbitmap64_tree_insert(bn, &bitmap->xb_root);
} else if (bn->bn_last > last) {
/* overlaps with the right side of the clearing range */
xbitmap64_tree_remove(bn, &bitmap->xb_root);
bn->bn_start = last + 1;
xbitmap64_tree_insert(bn, &bitmap->xb_root);
break;
} else {
/* in the middle of the clearing range */
xbitmap64_tree_remove(bn, &bitmap->xb_root);
Annotation
- Immediate include surface: `xfs_platform.h`, `xfs_fs.h`, `xfs_shared.h`, `xfs_bit.h`, `xfs_format.h`, `xfs_trans_resv.h`, `xfs_mount.h`, `xfs_btree.h`.
- Detected declarations: `struct xbitmap64_node`, `struct xbitmap32_node`, `function xbitmap64_clear`, `function xbitmap64_set`, `function xbitmap64_destroy`, `function xbitmap64_init`, `function xbitmap64_disunion`, `function for_each_xbitmap64_extent`, `function xbitmap64_hweight`, `function xbitmap64_walk`.
- 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.