fs/nilfs2/the_nilfs.c
Source file repositories/reference/linux-study-clean/fs/nilfs2/the_nilfs.c
File Facts
- System
- Linux kernel
- Corpus path
fs/nilfs2/the_nilfs.c- Extension
.c- Size
- 24748 bytes
- Lines
- 940
- 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/buffer_head.hlinux/slab.hlinux/blkdev.hlinux/backing-dev.hlinux/log2.hlinux/crc32.hnilfs.hsegment.halloc.hcpfile.hsufile.hdat.hsegbuf.h
Detected Declarations
function nilfs_set_last_segmentfunction destroy_nilfsfunction nilfs_load_super_rootfunction nilfs_init_recovery_infofunction nilfs_clear_recovery_infofunction nilfs_store_log_cursorfunction nilfs_get_blocksizefunction load_nilfsfunction nilfs_max_sizefunction nilfs_nrsvsegsfunction nilfs_max_segment_countfunction nilfs_set_nsegmentsfunction nilfs_store_disk_layoutfunction nilfs_valid_sbfunction nilfs_sb2_bad_offsetfunction nilfs_release_super_blockfunction nilfs_fall_back_super_blockfunction nilfs_swap_super_blockfunction nilfs_load_super_blockfunction init_nilfsfunction nilfs_discard_segmentsfunction nilfs_count_free_blocksfunction nilfs_near_disk_fullfunction nilfs_find_or_create_rootfunction nilfs_put_root
Annotated Snippet
ilog2(NILFS_MAX_BLOCK_SIZE) - BLOCK_SIZE_BITS)) {
nilfs_err(sb, "too large filesystem blocksize: 2 ^ %u KiB",
shift_bits);
return -EINVAL;
}
*blocksize = BLOCK_SIZE << shift_bits;
return 0;
}
/**
* load_nilfs - load and recover the nilfs
* @nilfs: the_nilfs structure to be released
* @sb: super block instance used to recover past segment
*
* load_nilfs() searches and load the latest super root,
* attaches the last segment, and does recovery if needed.
* The caller must call this exclusively for simultaneous mounts.
*
* Return: 0 on success, or one of the following negative error codes on
* failure:
* * %-EINVAL - No valid segment found.
* * %-EIO - I/O error.
* * %-ENOMEM - Insufficient memory available.
* * %-EROFS - Read only device or RO compat mode (if recovery is required)
*/
int load_nilfs(struct the_nilfs *nilfs, struct super_block *sb)
{
struct nilfs_recovery_info ri;
unsigned int s_flags = sb->s_flags;
int really_read_only = bdev_read_only(nilfs->ns_bdev);
int valid_fs = nilfs_valid_fs(nilfs);
int err;
if (!valid_fs) {
nilfs_warn(sb, "mounting unchecked fs");
if (s_flags & SB_RDONLY) {
nilfs_info(sb,
"recovery required for readonly filesystem");
nilfs_info(sb,
"write access will be enabled during recovery");
}
}
nilfs_init_recovery_info(&ri);
err = nilfs_search_super_root(nilfs, &ri);
if (unlikely(err)) {
struct nilfs_super_block **sbp = nilfs->ns_sbp;
int blocksize;
if (err != -EINVAL)
goto scan_error;
if (!nilfs_valid_sb(sbp[1])) {
nilfs_warn(sb,
"unable to fall back to spare super block");
goto scan_error;
}
nilfs_info(sb, "trying rollback from an earlier position");
/*
* restore super block with its spare and reconfigure
* relevant states of the nilfs object.
*/
memcpy(sbp[0], sbp[1], nilfs->ns_sbsize);
nilfs->ns_crc_seed = le32_to_cpu(sbp[0]->s_crc_seed);
nilfs->ns_sbwtime = le64_to_cpu(sbp[0]->s_wtime);
/* verify consistency between two super blocks */
err = nilfs_get_blocksize(sb, sbp[0], &blocksize);
if (err)
goto scan_error;
if (blocksize != nilfs->ns_blocksize) {
nilfs_warn(sb,
"blocksize differs between two super blocks (%d != %d)",
blocksize, nilfs->ns_blocksize);
err = -EINVAL;
goto scan_error;
}
err = nilfs_store_log_cursor(nilfs, sbp[0]);
if (err)
goto scan_error;
/* drop clean flag to allow roll-forward and recovery */
nilfs->ns_mount_state &= ~NILFS_VALID_FS;
valid_fs = 0;
err = nilfs_search_super_root(nilfs, &ri);
Annotation
- Immediate include surface: `linux/buffer_head.h`, `linux/slab.h`, `linux/blkdev.h`, `linux/backing-dev.h`, `linux/log2.h`, `linux/crc32.h`, `nilfs.h`, `segment.h`.
- Detected declarations: `function nilfs_set_last_segment`, `function destroy_nilfs`, `function nilfs_load_super_root`, `function nilfs_init_recovery_info`, `function nilfs_clear_recovery_info`, `function nilfs_store_log_cursor`, `function nilfs_get_blocksize`, `function load_nilfs`, `function nilfs_max_size`, `function nilfs_nrsvsegs`.
- 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.