fs/f2fs/segment.c
Source file repositories/reference/linux-study-clean/fs/f2fs/segment.c
File Facts
- System
- Linux kernel
- Corpus path
fs/f2fs/segment.c- Extension
.c- Size
- 154848 bytes
- Lines
- 5929
- 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/fs.hlinux/f2fs_fs.hlinux/bio.hlinux/blkdev.hlinux/sched/mm.hlinux/prefetch.hlinux/kthread.hlinux/swap.hlinux/timer.hlinux/freezer.hlinux/sched/signal.hlinux/random.hf2fs.hsegment.hnode.hgc.hiostat.htrace/events/f2fs.h
Detected Declarations
struct check_zone_write_pointer_argsfunction __reverse_ulongfunction __reverse_ffsfunction __find_rev_nextfunction __find_rev_next_zero_bitfunction f2fs_need_SSRfunction f2fs_abort_atomic_writefunction __replace_atomic_write_blockfunction __complete_revoke_listfunction list_for_each_entry_safefunction __f2fs_commit_atomic_writefunction f2fs_commit_atomic_writefunction f2fs_balance_fsfunction excess_dirty_thresholdfunction f2fs_balance_fs_bgfunction __submit_flush_waitfunction submit_flush_waitfunction issue_flush_threadfunction llist_for_each_entry_safefunction f2fs_issue_flushfunction llist_for_each_entry_safefunction f2fs_create_flush_cmd_controlfunction f2fs_destroy_flush_cmd_controlfunction f2fs_flush_device_cachefunction __locate_dirty_segmentfunction __remove_dirty_segmentfunction locate_dirty_segmentfunction f2fs_dirty_to_prefreefunction f2fs_get_unusable_blocksfunction f2fs_disable_cp_againfunction get_free_segmentfunction f2fs_check_discard_treefunction __detach_discard_cmdfunction __remove_discard_cmdfunction f2fs_submit_discard_endiofunction __check_sit_bitmapfunction __init_discard_policyfunction __submit_zone_reset_cmdfunction __submit_discard_cmdfunction __insert_discard_cmdfunction __relocate_discard_cmdfunction __punch_discard_cmdfunction __update_discard_tree_rangefunction __queue_zone_reset_cmdfunction __queue_discard_cmdfunction __issue_discard_cmd_orderlyfunction __issue_discard_cmdfunction list_for_each_entry_safe
Annotated Snippet
struct check_zone_write_pointer_args {
struct f2fs_sb_info *sbi;
struct f2fs_dev_info *fdev;
};
static int check_zone_write_pointer_cb(struct blk_zone *zone, unsigned int idx,
void *data)
{
struct check_zone_write_pointer_args *args;
args = (struct check_zone_write_pointer_args *)data;
return check_zone_write_pointer(args->sbi, args->fdev, zone);
}
static int check_write_pointer(struct f2fs_sb_info *sbi)
{
int i, ret;
struct check_zone_write_pointer_args args;
for (i = 0; i < sbi->s_ndevs; i++) {
if (!bdev_is_zoned(FDEV(i).bdev))
continue;
args.sbi = sbi;
args.fdev = &FDEV(i);
ret = blkdev_report_zones(FDEV(i).bdev, 0, BLK_ALL_ZONES,
check_zone_write_pointer_cb, &args);
if (ret < 0)
return ret;
}
return 0;
}
int f2fs_check_and_fix_write_pointer(struct f2fs_sb_info *sbi)
{
int ret;
if (!f2fs_sb_has_blkzoned(sbi) || f2fs_readonly(sbi->sb) ||
f2fs_hw_is_readonly(sbi))
return 0;
f2fs_notice(sbi, "Checking entire write pointers");
ret = fix_curseg_write_pointer(sbi);
if (!ret)
ret = check_write_pointer(sbi);
return ret;
}
/*
* Return the number of usable blocks in a segment. The number of blocks
* returned is always equal to the number of blocks in a segment for
* segments fully contained within a sequential zone capacity or a
* conventional zone. For segments partially contained in a sequential
* zone capacity, the number of usable blocks up to the zone capacity
* is returned. 0 is returned in all other cases.
*/
static inline unsigned int f2fs_usable_zone_blks_in_seg(
struct f2fs_sb_info *sbi, unsigned int segno)
{
block_t seg_start, sec_start_blkaddr, sec_cap_blkaddr;
unsigned int secno;
if (!sbi->unusable_blocks_per_sec)
return BLKS_PER_SEG(sbi);
secno = GET_SEC_FROM_SEG(sbi, segno);
seg_start = START_BLOCK(sbi, segno);
sec_start_blkaddr = START_BLOCK(sbi, GET_SEG_FROM_SEC(sbi, secno));
sec_cap_blkaddr = sec_start_blkaddr + CAP_BLKS_PER_SEC(sbi);
/*
* If segment starts before zone capacity and spans beyond
* zone capacity, then usable blocks are from seg start to
* zone capacity. If the segment starts after the zone capacity,
* then there are no usable blocks.
*/
if (seg_start >= sec_cap_blkaddr)
return 0;
if (seg_start + BLKS_PER_SEG(sbi) > sec_cap_blkaddr)
return sec_cap_blkaddr - seg_start;
return BLKS_PER_SEG(sbi);
}
#else
int f2fs_check_and_fix_write_pointer(struct f2fs_sb_info *sbi)
{
return 0;
}
Annotation
- Immediate include surface: `linux/fs.h`, `linux/f2fs_fs.h`, `linux/bio.h`, `linux/blkdev.h`, `linux/sched/mm.h`, `linux/prefetch.h`, `linux/kthread.h`, `linux/swap.h`.
- Detected declarations: `struct check_zone_write_pointer_args`, `function __reverse_ulong`, `function __reverse_ffs`, `function __find_rev_next`, `function __find_rev_next_zero_bit`, `function f2fs_need_SSR`, `function f2fs_abort_atomic_write`, `function __replace_atomic_write_block`, `function __complete_revoke_list`, `function list_for_each_entry_safe`.
- 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.