fs/nilfs2/segment.c
Source file repositories/reference/linux-study-clean/fs/nilfs2/segment.c
File Facts
- System
- Linux kernel
- Corpus path
fs/nilfs2/segment.c- Extension
.c- Size
- 80555 bytes
- Lines
- 2922
- 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/pagemap.hlinux/buffer_head.hlinux/writeback.hlinux/bitops.hlinux/bio.hlinux/completion.hlinux/blkdev.hlinux/backing-dev.hlinux/freezer.hlinux/kthread.hlinux/crc32.hlinux/folio_batch.hlinux/slab.hlinux/sched/signal.hnilfs.hbtnode.hpage.hsegment.hsufile.hcpfile.hifile.hsegbuf.htrace/events/nilfs2.h
Detected Declarations
struct nilfs_sc_operationsstruct nilfs_segctor_wait_requestfunction nilfs_sc_cstage_incfunction nilfs_sc_cstage_setfunction nilfs_sc_cstage_getfunction nilfs_prepare_segment_lockfunction nilfs_transaction_beginfunction nilfs_transaction_commitfunction nilfs_transaction_abortfunction nilfs_relax_pressure_in_lockfunction test_bitfunction nilfs_transaction_lockfunction nilfs_transaction_unlockfunction nilfs_segctor_reset_segment_bufferfunction nilfs_segctor_zeropad_segsumfunction nilfs_segctor_feed_segmentfunction nilfs_segctor_add_super_rootfunction nilfs_segctor_segsum_block_requiredfunction nilfs_segctor_begin_finfofunction nilfs_segctor_end_finfofunction nilfs_segctor_add_file_blockfunction nilfs_collect_file_datafunction nilfs_collect_file_nodefunction nilfs_collect_file_bmapfunction nilfs_write_file_data_binfofunction nilfs_write_file_node_binfofunction nilfs_collect_dat_datafunction nilfs_collect_dat_bmapfunction nilfs_write_dat_data_binfofunction nilfs_write_dat_node_binfofunction nilfs_lookup_dirty_data_buffersfunction nilfs_lookup_dirty_node_buffersfunction nilfs_dispose_listfunction list_for_each_entry_safefunction nilfs_iput_work_funcfunction nilfs_test_metadata_dirtyfunction nilfs_segctor_cleanfunction nilfs_segctor_confirmfunction nilfs_segctor_clear_metadata_dirtyfunction nilfs_fill_in_file_bmapfunction nilfs_segctor_fill_in_file_bmapfunction list_for_each_entryfunction nilfs_write_root_mdt_inodefunction nilfs_segctor_fill_in_super_rootfunction nilfs_redirty_inodesfunction list_for_each_entryfunction nilfs_drop_collected_inodesfunction list_for_each_entry
Annotated Snippet
struct nilfs_sc_operations {
int (*collect_data)(struct nilfs_sc_info *, struct buffer_head *,
struct inode *);
int (*collect_node)(struct nilfs_sc_info *, struct buffer_head *,
struct inode *);
int (*collect_bmap)(struct nilfs_sc_info *, struct buffer_head *,
struct inode *);
void (*write_data_binfo)(struct nilfs_sc_info *,
struct nilfs_segsum_pointer *,
union nilfs_binfo *);
void (*write_node_binfo)(struct nilfs_sc_info *,
struct nilfs_segsum_pointer *,
union nilfs_binfo *);
};
/*
* Other definitions
*/
static void nilfs_segctor_start_timer(struct nilfs_sc_info *);
static void nilfs_segctor_do_flush(struct nilfs_sc_info *, int);
static void nilfs_segctor_do_immediate_flush(struct nilfs_sc_info *);
static void nilfs_dispose_list(struct the_nilfs *, struct list_head *, int);
#define nilfs_cnt32_ge(a, b) \
(typecheck(__u32, a) && typecheck(__u32, b) && \
((__s32)((a) - (b)) >= 0))
static int nilfs_prepare_segment_lock(struct super_block *sb,
struct nilfs_transaction_info *ti)
{
struct nilfs_transaction_info *cur_ti = current->journal_info;
void *save = NULL;
if (cur_ti) {
if (cur_ti->ti_magic == NILFS_TI_MAGIC)
return ++cur_ti->ti_count;
/*
* If journal_info field is occupied by other FS,
* it is saved and will be restored on
* nilfs_transaction_commit().
*/
nilfs_warn(sb, "journal info from a different FS");
save = current->journal_info;
}
if (!ti) {
ti = kmem_cache_alloc(nilfs_transaction_cachep, GFP_NOFS);
if (!ti)
return -ENOMEM;
ti->ti_flags = NILFS_TI_DYNAMIC_ALLOC;
} else {
ti->ti_flags = 0;
}
ti->ti_count = 0;
ti->ti_save = save;
ti->ti_magic = NILFS_TI_MAGIC;
current->journal_info = ti;
return 0;
}
/**
* nilfs_transaction_begin - start indivisible file operations.
* @sb: super block
* @ti: nilfs_transaction_info
* @vacancy_check: flags for vacancy rate checks
*
* nilfs_transaction_begin() acquires a reader/writer semaphore, called
* the segment semaphore, to make a segment construction and write tasks
* exclusive. The function is used with nilfs_transaction_commit() in pairs.
* The region enclosed by these two functions can be nested. To avoid a
* deadlock, the semaphore is only acquired or released in the outermost call.
*
* This function allocates a nilfs_transaction_info struct to keep context
* information on it. It is initialized and hooked onto the current task in
* the outermost call. If a pre-allocated struct is given to @ti, it is used
* instead; otherwise a new struct is assigned from a slab.
*
* When @vacancy_check flag is set, this function will check the amount of
* free space, and will wait for the GC to reclaim disk space if low capacity.
*
* Return: 0 on success, or one of the following negative error codes on
* failure:
* * %-ENOMEM - Insufficient memory available.
* * %-ENOSPC - No space left on device (if checking free space).
*/
int nilfs_transaction_begin(struct super_block *sb,
struct nilfs_transaction_info *ti,
int vacancy_check)
{
struct the_nilfs *nilfs;
Annotation
- Immediate include surface: `linux/pagemap.h`, `linux/buffer_head.h`, `linux/writeback.h`, `linux/bitops.h`, `linux/bio.h`, `linux/completion.h`, `linux/blkdev.h`, `linux/backing-dev.h`.
- Detected declarations: `struct nilfs_sc_operations`, `struct nilfs_segctor_wait_request`, `function nilfs_sc_cstage_inc`, `function nilfs_sc_cstage_set`, `function nilfs_sc_cstage_get`, `function nilfs_prepare_segment_lock`, `function nilfs_transaction_begin`, `function nilfs_transaction_commit`, `function nilfs_transaction_abort`, `function nilfs_relax_pressure_in_lock`.
- 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.