fs/xfs/xfs_zone_alloc.c
Source file repositories/reference/linux-study-clean/fs/xfs/xfs_zone_alloc.c
File Facts
- System
- Linux kernel
- Corpus path
fs/xfs/xfs_zone_alloc.c- Extension
.c- Size
- 37876 bytes
- Lines
- 1440
- 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
xfs_platform.hxfs_shared.hxfs_format.hxfs_log_format.hxfs_error.hxfs_trans_resv.hxfs_mount.hxfs_inode.hxfs_iomap.hxfs_trans.hxfs_alloc.hxfs_bmap.hxfs_bmap_btree.hxfs_trans_space.hxfs_refcount.hxfs_rtbitmap.hxfs_rtrmap_btree.hxfs_zone_alloc.hxfs_zone_priv.hxfs_zones.hxfs_trace.hxfs_mru_cache.h
Detected Declarations
struct xfs_init_zonesenum xfs_zone_alloc_scorefunction Copyrightfunction xfs_open_zone_putfunction xfs_zone_bucketfunction xfs_zone_add_to_bucketfunction xfs_zone_remove_from_bucketfunction xfs_zone_account_reclaimablefunction xfs_zoned_have_reclaimablefunction xfs_open_zone_mark_fullfunction xfs_zone_inc_writtenfunction xfs_zone_skip_blocksfunction xfs_zoned_map_extentfunction xfs_zoned_end_iofunction xfs_zone_free_blocksfunction xfs_init_open_zonefunction xfs_open_zonefunction xfs_try_open_zonefunction xfs_try_use_zonefunction xfs_select_open_zone_lrufunction xfs_select_open_zone_mrufunction xfs_inode_write_hintfunction xfs_zoned_pack_tightfunction xfs_select_zone_nowaitfunction xfs_select_zonefunction xfs_zone_alloc_blocksfunction xfs_mark_rtg_boundaryfunction xfs_get_cached_zonefunction xfs_set_cached_zonefunction xfs_submit_zoned_biofunction xfs_zone_alloc_and_submitfunction xfs_zoned_wake_allfunction xfs_zone_rgbno_is_validfunction xfs_zone_mark_freefunction xfs_free_open_zonesfunction xfs_validate_blk_zonefunction xfs_init_zonefunction xfs_max_open_zonesfunction xfs_calc_open_zonesfunction xfs_alloc_bucket_bitmapfunction xfs_alloc_zone_infofunction xfs_free_zone_infofunction xfs_report_zonesfunction xfs_zone_is_convfunction xfs_find_fullest_conventional_open_zonefunction xfs_finish_spurious_open_zonesfunction xfs_mount_zonesfunction xfs_unmount_zones
Annotated Snippet
struct xfs_init_zones {
uint32_t zone_size;
uint32_t zone_capacity;
uint64_t available;
uint64_t reclaimable;
};
/*
* For sequential write required zones, we restart writing at the hardware write
* pointer returned by xfs_validate_blk_zone().
*
* For conventional zones or conventional devices we have to query the rmap to
* find the highest recorded block and set the write pointer to the block after
* that. In case of a power loss this misses blocks where the data I/O has
* completed but not recorded in the rmap yet, and it also rewrites blocks if
* the most recently written ones got deleted again before unmount, but this is
* the best we can do without hardware support.
*/
static int
xfs_query_write_pointer(
struct xfs_init_zones *iz,
struct xfs_rtgroup *rtg,
xfs_rgblock_t *write_pointer)
{
struct xfs_mount *mp = rtg_mount(rtg);
struct block_device *bdev = mp->m_rtdev_targp->bt_bdev;
sector_t start = xfs_gbno_to_daddr(&rtg->rtg_group, 0);
xfs_rgblock_t highest_rgbno;
struct blk_zone zone = {};
int error;
if (bdev_is_zoned(bdev)) {
error = blkdev_get_zone_info(bdev, start, &zone);
if (error)
return error;
if (zone.start != start) {
xfs_warn(mp, "mismatched zone start: 0x%llx/0x%llx.",
zone.start, start);
return -EFSCORRUPTED;
}
if (!xfs_validate_blk_zone(mp, &zone, rtg_rgno(rtg),
iz->zone_size, iz->zone_capacity,
write_pointer))
return -EFSCORRUPTED;
/*
* Use the hardware write pointer returned by
* xfs_validate_blk_zone for sequential write required zones,
* else fall through to the rmap-based estimation below.
*/
if (zone.cond != BLK_ZONE_COND_NOT_WP)
return 0;
}
xfs_rtgroup_lock(rtg, XFS_RTGLOCK_RMAP);
highest_rgbno = xfs_rtrmap_highest_rgbno(rtg);
xfs_rtgroup_unlock(rtg, XFS_RTGLOCK_RMAP);
if (highest_rgbno == NULLRGBLOCK)
*write_pointer = 0;
else
*write_pointer = highest_rgbno + 1;
return 0;
}
static int
xfs_init_zone(
struct xfs_init_zones *iz,
struct xfs_rtgroup *rtg,
xfs_rgblock_t write_pointer)
{
struct xfs_mount *mp = rtg_mount(rtg);
struct xfs_zone_info *zi = mp->m_zone_info;
uint32_t used = rtg_rmap(rtg)->i_used_blocks;
int error;
if (write_pointer > rtg->rtg_extents) {
xfs_warn(mp, "zone %u has invalid write pointer (0x%x).",
rtg_rgno(rtg), write_pointer);
return -EFSCORRUPTED;
}
if (used > rtg->rtg_extents) {
xfs_warn(mp,
"zone %u has used counter (0x%x) larger than zone capacity (0x%llx).",
rtg_rgno(rtg), used, rtg->rtg_extents);
return -EFSCORRUPTED;
}
Annotation
- Immediate include surface: `xfs_platform.h`, `xfs_shared.h`, `xfs_format.h`, `xfs_log_format.h`, `xfs_error.h`, `xfs_trans_resv.h`, `xfs_mount.h`, `xfs_inode.h`.
- Detected declarations: `struct xfs_init_zones`, `enum xfs_zone_alloc_score`, `function Copyright`, `function xfs_open_zone_put`, `function xfs_zone_bucket`, `function xfs_zone_add_to_bucket`, `function xfs_zone_remove_from_bucket`, `function xfs_zone_account_reclaimable`, `function xfs_zoned_have_reclaimable`, `function xfs_open_zone_mark_full`.
- 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.