fs/btrfs/scrub.c
Source file repositories/reference/linux-study-clean/fs/btrfs/scrub.c
File Facts
- System
- Linux kernel
- Corpus path
fs/btrfs/scrub.c- Extension
.c- Size
- 100152 bytes
- Lines
- 3332
- 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
linux/blkdev.hlinux/ratelimit.hlinux/sched/mm.hctree.hdiscard.hvolumes.hdisk-io.hordered-data.htransaction.hbackref.hextent_io.hdev-replace.hraid56.hblock-group.hzoned.hfs.haccessors.hfile-item.hscrub.hraid-stripe-tree.h
Detected Declarations
struct scrub_ctxstruct scrub_sector_verificationstruct scrub_stripestruct scrub_ctxstruct scrub_warningstruct scrub_error_recordsenum scrub_stripe_flagsfunction release_scrub_stripefunction init_scrub_stripefunction wait_scrub_stripe_iofunction __scrub_blocked_if_neededfunction scrub_pause_onfunction scrub_pause_offfunction scrub_blocked_if_neededfunction scrub_free_ctxfunction scrub_put_ctxfunction scrub_print_warning_inodefunction scrub_print_common_warningfunction fill_writer_pointer_gapfunction scrub_stripe_get_paddrfunction scrub_verify_one_metadatafunction btrfs_stack_header_generationfunction scrub_verify_one_sectorfunction scrub_verify_one_stripefunction for_each_set_bitfunction calc_sector_numberfunction scrub_repair_read_endiofunction calc_next_mirrorfunction scrub_bio_add_sectorfunction scrub_stripe_submit_repair_readfunction for_each_set_bitfunction scrub_stripe_report_errorsfunction btrfs_submit_biofunction scrub_stripe_read_repair_workerfunction scrub_read_endiofunction scrub_write_endiofunction scrub_submit_write_biofunction biofunction for_each_set_bitfunction scrub_throttle_dev_iofunction get_raid56_logic_offsetfunction compare_extent_item_rangefunction btrfs_search_slotfunction get_extent_infofunction sync_write_pointer_for_zonedfunction fill_one_extent_infofunction scrub_stripe_reset_bitmapsfunction scrub_find_fill_first_stripe
Annotated Snippet
struct scrub_sector_verification {
union {
/*
* Csum pointer for data csum verification. Should point to a
* sector csum inside scrub_stripe::csums.
*
* NULL if this data sector has no csum.
*/
u8 *csum;
/*
* Extra info for metadata verification. All sectors inside a
* tree block share the same generation.
*/
u64 generation;
};
};
enum scrub_stripe_flags {
/* Set when @mirror_num, @dev, @physical and @logical are set. */
SCRUB_STRIPE_FLAG_INITIALIZED,
/* Set when the read-repair is finished. */
SCRUB_STRIPE_FLAG_REPAIR_DONE,
/*
* Set for data stripes if it's triggered from P/Q stripe.
* During such scrub, we should not report errors in data stripes, nor
* update the accounting.
*/
SCRUB_STRIPE_FLAG_NO_REPORT,
};
/*
* We have multiple bitmaps for one scrub_stripe.
* However each bitmap has at most (BTRFS_STRIPE_LEN / blocksize) bits,
* which is normally 16, and much smaller than BITS_PER_LONG (32 or 64).
*
* So to reduce memory usage for each scrub_stripe, we pack those bitmaps
* into a larger one.
*
* These enum records where the sub-bitmap are inside the larger one.
* Each subbitmap starts at scrub_bitmap_nr_##name * nr_sectors bit.
*/
enum {
/* Which blocks are covered by extent items. */
scrub_bitmap_nr_has_extent = 0,
/* Which blocks are metadata. */
scrub_bitmap_nr_is_metadata,
/*
* Which blocks have errors, including IO, csum, and metadata
* errors.
* This sub-bitmap is the OR results of the next few error related
* sub-bitmaps.
*/
scrub_bitmap_nr_error,
scrub_bitmap_nr_io_error,
scrub_bitmap_nr_csum_error,
scrub_bitmap_nr_meta_error,
scrub_bitmap_nr_meta_gen_error,
scrub_bitmap_nr_last,
};
#define SCRUB_STRIPE_MAX_FOLIOS (BTRFS_STRIPE_LEN / PAGE_SIZE)
/*
* Represent one contiguous range with a length of BTRFS_STRIPE_LEN.
*/
struct scrub_stripe {
struct scrub_ctx *sctx;
struct btrfs_block_group *bg;
struct folio *folios[SCRUB_STRIPE_MAX_FOLIOS];
struct scrub_sector_verification *sectors;
struct btrfs_device *dev;
u64 logical;
u64 physical;
u16 mirror_num;
/* Should be BTRFS_STRIPE_LEN / sectorsize. */
u16 nr_sectors;
/*
* How many data/meta extents are in this stripe. Only for scrub status
* reporting purposes.
*/
Annotation
- Immediate include surface: `linux/blkdev.h`, `linux/ratelimit.h`, `linux/sched/mm.h`, `ctree.h`, `discard.h`, `volumes.h`, `disk-io.h`, `ordered-data.h`.
- Detected declarations: `struct scrub_ctx`, `struct scrub_sector_verification`, `struct scrub_stripe`, `struct scrub_ctx`, `struct scrub_warning`, `struct scrub_error_records`, `enum scrub_stripe_flags`, `function release_scrub_stripe`, `function init_scrub_stripe`, `function wait_scrub_stripe_io`.
- 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.