fs/btrfs/dev-replace.c
Source file repositories/reference/linux-study-clean/fs/btrfs/dev-replace.c
File Facts
- System
- Linux kernel
- Corpus path
fs/btrfs/dev-replace.c- Extension
.c- Size
- 39810 bytes
- Lines
- 1322
- 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.
- 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/kthread.hlinux/math64.hmisc.hctree.hdisk-io.htransaction.hvolumes.hasync-thread.hdev-replace.hsysfs.hzoned.hblock-group.hfs.haccessors.hscrub.h
Detected Declarations
function btrfs_init_dev_replacefunction btrfs_init_dev_replace_tgtdevfunction list_for_each_entryfunction btrfs_run_dev_replacefunction mark_block_group_to_copyfunction btrfs_for_each_slotfunction btrfs_finish_block_group_to_copyfunction btrfs_dev_replace_startfunction btrfs_check_replace_dev_namesfunction btrfs_dev_replace_by_ioctlfunction btrfs_rm_dev_replace_blockedfunction btrfs_rm_dev_replace_unblockedfunction btrfs_set_target_alloc_statefunction btrfs_dev_replace_update_device_in_mapping_treefunction btrfs_dev_replace_finishingfunction btrfs_dev_replace_progressfunction btrfs_dev_replace_statusfunction btrfs_dev_replace_cancelfunction btrfs_dev_replace_suspend_for_unmountfunction btrfs_resume_dev_replace_asyncfunction btrfs_dev_replace_kthreadfunction btrfs_dev_replace_is_ongoingfunction btrfs_bio_counter_subfunction btrfs_bio_counter_inc_blocked
Annotated Snippet
if (unlikely(btrfs_find_device(fs_info->fs_devices, &args))) {
btrfs_err(fs_info,
"found replace target device without a valid replace item");
return -EUCLEAN;
}
dev_replace->replace_state =
BTRFS_IOCTL_DEV_REPLACE_STATE_NEVER_STARTED;
dev_replace->cont_reading_from_srcdev_mode =
BTRFS_DEV_REPLACE_ITEM_CONT_READING_FROM_SRCDEV_MODE_ALWAYS;
dev_replace->time_started = 0;
dev_replace->time_stopped = 0;
atomic64_set(&dev_replace->num_write_errors, 0);
atomic64_set(&dev_replace->num_uncorrectable_read_errors, 0);
dev_replace->cursor_left = 0;
dev_replace->committed_cursor_left = 0;
dev_replace->cursor_left_last_write_of_item = 0;
dev_replace->cursor_right = 0;
dev_replace->srcdev = NULL;
dev_replace->tgtdev = NULL;
dev_replace->is_valid = 0;
dev_replace->item_needs_writeback = 0;
return 0;
}
slot = path->slots[0];
eb = path->nodes[0];
item_size = btrfs_item_size(eb, slot);
ptr = btrfs_item_ptr(eb, slot, struct btrfs_dev_replace_item);
if (item_size != sizeof(struct btrfs_dev_replace_item)) {
btrfs_warn(fs_info,
"dev_replace entry found has unexpected size, ignore entry");
goto no_valid_dev_replace_entry_found;
}
src_devid = btrfs_dev_replace_src_devid(eb, ptr);
dev_replace->cont_reading_from_srcdev_mode =
btrfs_dev_replace_cont_reading_from_srcdev_mode(eb, ptr);
dev_replace->replace_state = btrfs_dev_replace_replace_state(eb, ptr);
dev_replace->time_started = btrfs_dev_replace_time_started(eb, ptr);
dev_replace->time_stopped =
btrfs_dev_replace_time_stopped(eb, ptr);
atomic64_set(&dev_replace->num_write_errors,
btrfs_dev_replace_num_write_errors(eb, ptr));
atomic64_set(&dev_replace->num_uncorrectable_read_errors,
btrfs_dev_replace_num_uncorrectable_read_errors(eb, ptr));
dev_replace->cursor_left = btrfs_dev_replace_cursor_left(eb, ptr);
dev_replace->committed_cursor_left = dev_replace->cursor_left;
dev_replace->cursor_left_last_write_of_item = dev_replace->cursor_left;
dev_replace->cursor_right = btrfs_dev_replace_cursor_right(eb, ptr);
dev_replace->is_valid = 1;
dev_replace->item_needs_writeback = 0;
switch (dev_replace->replace_state) {
case BTRFS_IOCTL_DEV_REPLACE_STATE_NEVER_STARTED:
case BTRFS_IOCTL_DEV_REPLACE_STATE_FINISHED:
case BTRFS_IOCTL_DEV_REPLACE_STATE_CANCELED:
/*
* We don't have an active replace item but if there is a
* replace target, fail the mount.
*/
if (unlikely(btrfs_find_device(fs_info->fs_devices, &args))) {
btrfs_err(fs_info,
"replace without active item, run 'device scan --forget' on the target device");
ret = -EUCLEAN;
} else {
dev_replace->srcdev = NULL;
dev_replace->tgtdev = NULL;
}
break;
case BTRFS_IOCTL_DEV_REPLACE_STATE_STARTED:
case BTRFS_IOCTL_DEV_REPLACE_STATE_SUSPENDED:
dev_replace->tgtdev = btrfs_find_device(fs_info->fs_devices, &args);
args.devid = src_devid;
dev_replace->srcdev = btrfs_find_device(fs_info->fs_devices, &args);
/*
* allow 'btrfs dev replace_cancel' if src/tgt device is
* missing
*/
if (unlikely(!dev_replace->srcdev && !btrfs_test_opt(fs_info, DEGRADED))) {
ret = -EIO;
btrfs_warn(fs_info,
"cannot mount because device replace operation is ongoing and");
btrfs_warn(fs_info,
"srcdev (devid %llu) is missing, need to run 'btrfs dev scan'?",
src_devid);
}
if (unlikely(!dev_replace->tgtdev && !btrfs_test_opt(fs_info, DEGRADED))) {
ret = -EIO;
btrfs_warn(fs_info,
Annotation
- Immediate include surface: `linux/sched.h`, `linux/bio.h`, `linux/slab.h`, `linux/blkdev.h`, `linux/kthread.h`, `linux/math64.h`, `misc.h`, `ctree.h`.
- Detected declarations: `function btrfs_init_dev_replace`, `function btrfs_init_dev_replace_tgtdev`, `function list_for_each_entry`, `function btrfs_run_dev_replace`, `function mark_block_group_to_copy`, `function btrfs_for_each_slot`, `function btrfs_finish_block_group_to_copy`, `function btrfs_dev_replace_start`, `function btrfs_check_replace_dev_names`, `function btrfs_dev_replace_by_ioctl`.
- 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.