fs/nilfs2/segbuf.c
Source file repositories/reference/linux-study-clean/fs/nilfs2/segbuf.c
File Facts
- System
- Linux kernel
- Corpus path
fs/nilfs2/segbuf.c- Extension
.c- Size
- 12271 bytes
- Lines
- 473
- 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/buffer_head.hlinux/writeback.hlinux/crc32.hlinux/backing-dev.hlinux/slab.hpage.hsegbuf.h
Detected Declarations
struct nilfs_write_infofunction nilfs_segbuf_freefunction nilfs_segbuf_mapfunction nilfs_segbuf_map_contfunction nilfs_segbuf_set_next_segnumfunction nilfs_segbuf_extend_segsumfunction nilfs_segbuf_extend_payloadfunction nilfs_segbuf_resetfunction nilfs_segbuf_fill_in_segsumfunction nilfs_segbuf_fill_in_segsum_crcfunction list_for_each_entry_continuefunction nilfs_segbuf_fill_in_data_crcfunction list_for_each_entry_continuefunction nilfs_segbuf_fill_in_super_root_crcfunction nilfs_release_buffersfunction list_for_each_entry_safefunction nilfs_segbuf_clearfunction nilfs_clear_logsfunction nilfs_truncate_logsfunction nilfs_write_logsfunction list_for_each_entryfunction nilfs_wait_on_logsfunction list_for_each_entryfunction nilfs_add_checksums_on_logsfunction list_for_each_entryfunction nilfs_end_bio_writefunction nilfs_segbuf_submit_biofunction nilfs_segbuf_prepare_writefunction nilfs_segbuf_submit_bhfunction nilfs_segbuf_writefunction list_for_each_entryfunction list_for_each_entryfunction nilfs_segbuf_wait
Annotated Snippet
struct nilfs_write_info {
struct the_nilfs *nilfs;
struct bio *bio;
int start, end; /* The region to be submitted */
int rest_blocks;
int max_pages;
int nr_vecs;
sector_t blocknr;
};
static int nilfs_segbuf_write(struct nilfs_segment_buffer *segbuf,
struct the_nilfs *nilfs);
static int nilfs_segbuf_wait(struct nilfs_segment_buffer *segbuf);
struct nilfs_segment_buffer *nilfs_segbuf_new(struct super_block *sb)
{
struct nilfs_segment_buffer *segbuf;
segbuf = kmem_cache_alloc(nilfs_segbuf_cachep, GFP_NOFS);
if (unlikely(!segbuf))
return NULL;
segbuf->sb_super = sb;
INIT_LIST_HEAD(&segbuf->sb_list);
INIT_LIST_HEAD(&segbuf->sb_segsum_buffers);
INIT_LIST_HEAD(&segbuf->sb_payload_buffers);
segbuf->sb_super_root = NULL;
init_completion(&segbuf->sb_bio_event);
atomic_set(&segbuf->sb_err, 0);
segbuf->sb_nbio = 0;
return segbuf;
}
void nilfs_segbuf_free(struct nilfs_segment_buffer *segbuf)
{
kmem_cache_free(nilfs_segbuf_cachep, segbuf);
}
void nilfs_segbuf_map(struct nilfs_segment_buffer *segbuf, __u64 segnum,
unsigned long offset, struct the_nilfs *nilfs)
{
segbuf->sb_segnum = segnum;
nilfs_get_segment_range(nilfs, segnum, &segbuf->sb_fseg_start,
&segbuf->sb_fseg_end);
segbuf->sb_pseg_start = segbuf->sb_fseg_start + offset;
segbuf->sb_rest_blocks =
segbuf->sb_fseg_end - segbuf->sb_pseg_start + 1;
}
/**
* nilfs_segbuf_map_cont - map a new log behind a given log
* @segbuf: new segment buffer
* @prev: segment buffer containing a log to be continued
*/
void nilfs_segbuf_map_cont(struct nilfs_segment_buffer *segbuf,
struct nilfs_segment_buffer *prev)
{
segbuf->sb_segnum = prev->sb_segnum;
segbuf->sb_fseg_start = prev->sb_fseg_start;
segbuf->sb_fseg_end = prev->sb_fseg_end;
segbuf->sb_pseg_start = prev->sb_pseg_start + prev->sb_sum.nblocks;
segbuf->sb_rest_blocks =
segbuf->sb_fseg_end - segbuf->sb_pseg_start + 1;
}
void nilfs_segbuf_set_next_segnum(struct nilfs_segment_buffer *segbuf,
__u64 nextnum, struct the_nilfs *nilfs)
{
segbuf->sb_nextnum = nextnum;
segbuf->sb_sum.next = nilfs_get_segment_start_blocknr(nilfs, nextnum);
}
int nilfs_segbuf_extend_segsum(struct nilfs_segment_buffer *segbuf)
{
struct buffer_head *bh;
bh = sb_getblk(segbuf->sb_super,
segbuf->sb_pseg_start + segbuf->sb_sum.nsumblk);
if (unlikely(!bh))
return -ENOMEM;
lock_buffer(bh);
if (!buffer_uptodate(bh)) {
memset(bh->b_data, 0, bh->b_size);
set_buffer_uptodate(bh);
}
unlock_buffer(bh);
Annotation
- Immediate include surface: `linux/buffer_head.h`, `linux/writeback.h`, `linux/crc32.h`, `linux/backing-dev.h`, `linux/slab.h`, `page.h`, `segbuf.h`.
- Detected declarations: `struct nilfs_write_info`, `function nilfs_segbuf_free`, `function nilfs_segbuf_map`, `function nilfs_segbuf_map_cont`, `function nilfs_segbuf_set_next_segnum`, `function nilfs_segbuf_extend_segsum`, `function nilfs_segbuf_extend_payload`, `function nilfs_segbuf_reset`, `function nilfs_segbuf_fill_in_segsum`, `function nilfs_segbuf_fill_in_segsum_crc`.
- 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.