fs/nilfs2/recovery.c
Source file repositories/reference/linux-study-clean/fs/nilfs2/recovery.c
File Facts
- System
- Linux kernel
- Corpus path
fs/nilfs2/recovery.c- Extension
.c- Size
- 26250 bytes
- Lines
- 1017
- 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/blkdev.hlinux/swap.hlinux/slab.hlinux/crc32.hnilfs.hsegment.hsufile.hpage.hsegbuf.h
Detected Declarations
struct nilfs_recovery_blockstruct nilfs_segment_entryfunction nilfs_warn_segment_errorfunction nilfs_compute_checksumfunction nilfs_read_super_root_blockfunction nilfs_read_log_headerfunction nilfs_validate_logfunction nilfs_skip_summary_infofunction nilfs_scan_dsync_logfunction dispose_recovery_listfunction nilfs_segment_list_addfunction nilfs_dispose_segment_listfunction nilfs_prepare_segment_for_recoveryfunction nilfs_recovery_copy_blockfunction nilfs_recover_dsync_blocksfunction list_for_each_entry_safefunction nilfs_do_roll_forwardfunction nilfs_finish_roll_forwardfunction nilfs_abort_roll_forwardfunction nilfs_salvage_orphan_logsfunction nilfs_search_super_root
Annotated Snippet
struct nilfs_recovery_block {
ino_t ino; /*
* Inode number of the file that this block
* belongs to
*/
sector_t blocknr; /* block number */
__u64 vblocknr; /* virtual block number */
unsigned long blkoff; /* File offset of the data block (per block) */
struct list_head list;
};
static int nilfs_warn_segment_error(struct super_block *sb, int err)
{
const char *msg = NULL;
switch (err) {
case NILFS_SEG_FAIL_IO:
nilfs_err(sb, "I/O error reading segment");
return -EIO;
case NILFS_SEG_FAIL_MAGIC:
msg = "Magic number mismatch";
break;
case NILFS_SEG_FAIL_SEQ:
msg = "Sequence number mismatch";
break;
case NILFS_SEG_FAIL_CHECKSUM_SUPER_ROOT:
msg = "Checksum error in super root";
break;
case NILFS_SEG_FAIL_CHECKSUM_FULL:
msg = "Checksum error in segment payload";
break;
case NILFS_SEG_FAIL_CONSISTENCY:
msg = "Inconsistency found";
break;
case NILFS_SEG_NO_SUPER_ROOT:
msg = "No super root in the last segment";
break;
default:
nilfs_err(sb, "unrecognized segment error %d", err);
return -EINVAL;
}
nilfs_warn(sb, "invalid segment: %s", msg);
return -EINVAL;
}
/**
* nilfs_compute_checksum - compute checksum of blocks continuously
* @nilfs: nilfs object
* @bhs: buffer head of start block
* @sum: place to store result
* @offset: offset bytes in the first block
* @check_bytes: number of bytes to be checked
* @start: DBN of start block
* @nblock: number of blocks to be checked
*
* Return: 0 on success, or %-EIO if an I/O error occurs.
*/
static int nilfs_compute_checksum(struct the_nilfs *nilfs,
struct buffer_head *bhs, u32 *sum,
unsigned long offset, u64 check_bytes,
sector_t start, unsigned long nblock)
{
unsigned int blocksize = nilfs->ns_blocksize;
unsigned long size;
u32 crc;
BUG_ON(offset >= blocksize);
check_bytes -= offset;
size = min_t(u64, check_bytes, blocksize - offset);
crc = crc32_le(nilfs->ns_crc_seed,
(unsigned char *)bhs->b_data + offset, size);
if (--nblock > 0) {
do {
struct buffer_head *bh;
bh = __bread(nilfs->ns_bdev, ++start, blocksize);
if (!bh)
return -EIO;
check_bytes -= size;
size = min_t(u64, check_bytes, blocksize);
crc = crc32_le(crc, bh->b_data, size);
brelse(bh);
} while (--nblock > 0);
}
*sum = crc;
return 0;
}
/**
Annotation
- Immediate include surface: `linux/buffer_head.h`, `linux/blkdev.h`, `linux/swap.h`, `linux/slab.h`, `linux/crc32.h`, `nilfs.h`, `segment.h`, `sufile.h`.
- Detected declarations: `struct nilfs_recovery_block`, `struct nilfs_segment_entry`, `function nilfs_warn_segment_error`, `function nilfs_compute_checksum`, `function nilfs_read_super_root_block`, `function nilfs_read_log_header`, `function nilfs_validate_log`, `function nilfs_skip_summary_info`, `function nilfs_scan_dsync_log`, `function dispose_recovery_list`.
- 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.