fs/btrfs/zoned.c
Source file repositories/reference/linux-study-clean/fs/btrfs/zoned.c
File Facts
- System
- Linux kernel
- Corpus path
fs/btrfs/zoned.c- Extension
.c- Size
- 90300 bytes
- Lines
- 3262
- 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/bitops.hlinux/slab.hlinux/blkdev.hlinux/sched/mm.hlinux/atomic.hlinux/vmalloc.hctree.hvolumes.hzoned.hdisk-io.hblock-group.hdev-replace.hspace-info.hfs.haccessors.hbio.htransaction.hsysfs.h
Detected Declarations
struct zone_infofunction sb_zone_is_fullfunction copy_zone_info_cbfunction sb_write_pointerfunction sb_zone_numberfunction zone_start_sectorfunction zone_start_physicalfunction blkdev_report_zonesfunction btrfs_get_dev_zonesfunction calculate_emulated_zone_sizefunction btrfs_get_dev_zone_info_all_devicesfunction btrfs_get_max_active_zonesfunction btrfs_get_dev_zone_infofunction btrfs_destroy_dev_zone_infofunction btrfs_get_dev_zonefunction btrfs_check_for_zoned_devicefunction list_for_each_entryfunction btrfs_check_zoned_modefunction list_for_each_entryfunction btrfs_create_chunkfunction btrfs_check_mountopts_zonedfunction sb_log_locationfunction btrfs_sb_log_location_bdevfunction btrfs_sb_log_locationfunction is_sb_log_zonefunction btrfs_advance_sb_logfunction btrfs_reset_sb_log_zonesfunction btrfs_find_allocatable_zonesfunction btrfs_dev_set_active_zonefunction btrfs_dev_clear_active_zonefunction btrfs_reset_device_zonefunction btrfs_ensure_empty_zonesfunction calculate_alloc_pointerfunction btrfs_make_block_groupfunction btrfs_load_zone_infofunction btrfs_load_block_group_singlefunction btrfs_load_block_group_dupfunction btrfs_load_block_group_raid1function btrfs_load_block_group_raid0function btrfs_load_block_group_raid10function btrfs_load_block_group_by_raid_typefunction btrfs_load_block_group_zone_infofunction btrfs_calc_zone_unusablefunction btrfs_use_zone_appendfunction btrfs_record_physical_zonedfunction btrfs_rewrite_logical_zonedfunction btrfs_zoned_split_orderedfunction btrfs_finish_ordered_zoned
Annotated Snippet
struct zone_info {
u64 physical;
u64 capacity;
u64 alloc_offset;
};
static int btrfs_load_zone_info(struct btrfs_fs_info *fs_info, int zone_idx,
struct zone_info *info, unsigned long *active,
struct btrfs_chunk_map *map, bool new)
{
struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace;
struct btrfs_device *device;
bool dev_replace_is_ongoing = false;
unsigned int nofs_flag;
struct blk_zone zone;
int ret;
info->physical = map->stripes[zone_idx].physical;
down_read(&dev_replace->rwsem);
device = map->stripes[zone_idx].dev;
if (!device->bdev) {
up_read(&dev_replace->rwsem);
info->alloc_offset = WP_MISSING_DEV;
return 0;
}
/* Consider a zone as active if we can allow any number of active zones. */
if (!device->zone_info->max_active_zones)
__set_bit(zone_idx, active);
if (!btrfs_dev_is_sequential(device, info->physical)) {
up_read(&dev_replace->rwsem);
info->alloc_offset = WP_CONVENTIONAL;
info->capacity = device->zone_info->zone_size;
return 0;
}
ASSERT(!new || btrfs_dev_is_empty_zone(device, info->physical));
/* This zone will be used for allocation, so mark this zone non-empty. */
btrfs_dev_clear_zone_empty(device, info->physical);
dev_replace_is_ongoing = btrfs_dev_replace_is_ongoing(dev_replace);
if (dev_replace_is_ongoing && dev_replace->tgtdev != NULL)
btrfs_dev_clear_zone_empty(dev_replace->tgtdev, info->physical);
/*
* The group is mapped to a sequential zone. Get the zone write pointer
* to determine the allocation offset within the zone.
*/
WARN_ON(!IS_ALIGNED(info->physical, fs_info->zone_size));
if (new) {
sector_t capacity;
capacity = bdev_zone_capacity(device->bdev, info->physical >> SECTOR_SHIFT);
up_read(&dev_replace->rwsem);
info->alloc_offset = 0;
info->capacity = capacity << SECTOR_SHIFT;
return 0;
}
nofs_flag = memalloc_nofs_save();
ret = btrfs_get_dev_zone(device, info->physical, &zone);
memalloc_nofs_restore(nofs_flag);
if (ret) {
up_read(&dev_replace->rwsem);
if (ret != -EIO && ret != -EOPNOTSUPP)
return ret;
info->alloc_offset = WP_MISSING_DEV;
return 0;
}
if (unlikely(zone.type == BLK_ZONE_TYPE_CONVENTIONAL)) {
btrfs_err(fs_info,
"zoned: unexpected conventional zone %llu on device %s (devid %llu)",
zone.start << SECTOR_SHIFT, rcu_dereference(device->name),
device->devid);
up_read(&dev_replace->rwsem);
return -EIO;
}
info->capacity = (zone.capacity << SECTOR_SHIFT);
switch (zone.cond) {
case BLK_ZONE_COND_OFFLINE:
case BLK_ZONE_COND_READONLY:
Annotation
- Immediate include surface: `linux/bitops.h`, `linux/slab.h`, `linux/blkdev.h`, `linux/sched/mm.h`, `linux/atomic.h`, `linux/vmalloc.h`, `ctree.h`, `volumes.h`.
- Detected declarations: `struct zone_info`, `function sb_zone_is_full`, `function copy_zone_info_cb`, `function sb_write_pointer`, `function sb_zone_number`, `function zone_start_sector`, `function zone_start_physical`, `function blkdev_report_zones`, `function btrfs_get_dev_zones`, `function calculate_emulated_zone_size`.
- 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.