fs/btrfs/raid56.c
Source file repositories/reference/linux-study-clean/fs/btrfs/raid56.c
File Facts
- System
- Linux kernel
- Corpus path
fs/btrfs/raid56.c- Extension
.c- Size
- 84607 bytes
- Lines
- 3045
- 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/sched.hlinux/bio.hlinux/slab.hlinux/blkdev.hlinux/raid/pq.hlinux/hash.hlinux/list_sort.hlinux/raid/xor.hlinux/mm.hmessages.hctree.hdisk-io.hvolumes.hraid56.hasync-thread.hfile-item.hbtrfs_inode.h
Detected Declarations
struct btrfs_stripe_hashstruct btrfs_stripe_hash_tablestruct btrfs_plug_cbfunction Copyrightfunction btrfs_dump_rbiofunction free_raid_bio_pointersfunction free_raid_biofunction start_async_workfunction btrfs_alloc_stripe_hash_tablefunction memcpy_from_bio_to_stripefunction cache_rbio_pagesfunction rbio_bucketfunction page_nr_to_sector_nrfunction page_nr_to_num_sectorsfunction full_page_sectors_uptodatefunction index_stripe_sectorsfunction steal_rbio_pagefunction is_data_stripe_pagefunction steal_rbiofunction merge_rbiofunction __remove_rbio_from_cachefunction remove_rbio_from_cachefunction btrfs_clear_rbio_cachefunction btrfs_free_stripe_hash_tablefunction cache_rbiofunction stripefunction directionfunction rbio_sector_indexfunction rbio_paddr_indexfunction rbio_stripe_paddrfunction rbio_pstripe_paddrfunction rbio_qstripe_paddrfunction lock_stripe_addfunction list_for_each_entryfunction unlock_stripefunction rbio_endio_bio_listfunction rbio_orig_end_iofunction scoped_guardfunction sector_paddr_in_rbiofunction scoped_guardfunction alloc_rbio_pagesfunction alloc_rbio_parity_pagesfunction get_rbio_vertical_errorsfunction bio_add_paddrsfunction rbio_add_io_paddrsfunction index_one_biofunction btrfs_bio_for_each_blockfunction index_rbio_pages
Annotated Snippet
struct btrfs_stripe_hash {
struct list_head hash_list;
spinlock_t lock;
};
/* Used by the raid56 code to lock stripes for read/modify/write */
struct btrfs_stripe_hash_table {
struct list_head stripe_cache;
spinlock_t cache_lock;
int cache_size;
struct btrfs_stripe_hash table[];
};
/*
* The PFN may still be valid, but our paddrs should always be block size
* aligned, thus such -1 paddr is definitely not a valid one.
*/
#define INVALID_PADDR (~(phys_addr_t)0)
static void rmw_rbio_work(struct work_struct *work);
static void rmw_rbio_work_locked(struct work_struct *work);
static void index_rbio_pages(struct btrfs_raid_bio *rbio);
static int alloc_rbio_pages(struct btrfs_raid_bio *rbio);
static int finish_parity_scrub(struct btrfs_raid_bio *rbio);
static void scrub_rbio_work_locked(struct work_struct *work);
static void free_raid_bio_pointers(struct btrfs_raid_bio *rbio)
{
bitmap_free(rbio->error_bitmap);
bitmap_free(rbio->stripe_uptodate_bitmap);
kfree(rbio->stripe_pages);
kfree(rbio->bio_paddrs);
kfree(rbio->stripe_paddrs);
kfree(rbio->finish_pointers);
}
static void free_raid_bio(struct btrfs_raid_bio *rbio)
{
int i;
if (!refcount_dec_and_test(&rbio->refs))
return;
WARN_ON(!list_empty(&rbio->stripe_cache));
WARN_ON(!list_empty(&rbio->hash_list));
WARN_ON(!bio_list_empty(&rbio->bio_list));
for (i = 0; i < rbio->nr_pages; i++) {
if (rbio->stripe_pages[i]) {
__free_page(rbio->stripe_pages[i]);
rbio->stripe_pages[i] = NULL;
}
}
btrfs_put_bioc(rbio->bioc);
free_raid_bio_pointers(rbio);
kfree(rbio);
}
static void start_async_work(struct btrfs_raid_bio *rbio, work_func_t work_func)
{
INIT_WORK(&rbio->work, work_func);
queue_work(rbio->bioc->fs_info->rmw_workers, &rbio->work);
}
/*
* the stripe hash table is used for locking, and to collect
* bios in hopes of making a full stripe
*/
int btrfs_alloc_stripe_hash_table(struct btrfs_fs_info *info)
{
struct btrfs_stripe_hash_table *table;
struct btrfs_stripe_hash_table *x;
struct btrfs_stripe_hash *cur;
struct btrfs_stripe_hash *h;
unsigned int num_entries = 1U << BTRFS_STRIPE_HASH_TABLE_BITS;
if (info->stripe_hash_table)
return 0;
/*
* The table is large, starting with order 4 and can go as high as
* order 7 in case lock debugging is turned on.
*
* Try harder to allocate and fallback to vmalloc to lower the chance
* of a failing mount.
*/
table = kvzalloc_flex(*table, table, num_entries);
if (!table)
Annotation
- Immediate include surface: `linux/sched.h`, `linux/bio.h`, `linux/slab.h`, `linux/blkdev.h`, `linux/raid/pq.h`, `linux/hash.h`, `linux/list_sort.h`, `linux/raid/xor.h`.
- Detected declarations: `struct btrfs_stripe_hash`, `struct btrfs_stripe_hash_table`, `struct btrfs_plug_cb`, `function Copyright`, `function btrfs_dump_rbio`, `function free_raid_bio_pointers`, `function free_raid_bio`, `function start_async_work`, `function btrfs_alloc_stripe_hash_table`, `function memcpy_from_bio_to_stripe`.
- 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.