fs/jffs2/gc.c
Source file repositories/reference/linux-study-clean/fs/jffs2/gc.c
File Facts
- System
- Linux kernel
- Corpus path
fs/jffs2/gc.c- Extension
.c- Size
- 45112 bytes
- Lines
- 1406
- 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/kernel.hlinux/mtd/mtd.hlinux/slab.hlinux/pagemap.hlinux/crc32.hlinux/compiler.hlinux/stat.hnodelist.hcompr.h
Detected Declarations
function jffs2_garbage_collect_passfunction read_inodefunction igetfunction jffs2_garbage_collect_livefunction jffs2_garbage_collect_pristinefunction jffs2_garbage_collect_metadatafunction jffs2_garbage_collect_direntfunction jffs2_garbage_collect_deletion_direntfunction jffs2_garbage_collect_holefunction jffs2_garbage_collect_dnode
Annotated Snippet
if (!ic->pino_nlink) {
jffs2_dbg(1, "Skipping check of ino #%d with nlink/pino zero\n",
ic->ino);
spin_unlock(&c->inocache_lock);
jffs2_xattr_delete_inode(c, ic);
continue;
}
switch(ic->state) {
case INO_STATE_CHECKEDABSENT:
case INO_STATE_PRESENT:
spin_unlock(&c->inocache_lock);
continue;
case INO_STATE_GC:
case INO_STATE_CHECKING:
pr_warn("Inode #%u is in state %d during CRC check phase!\n",
ic->ino, ic->state);
spin_unlock(&c->inocache_lock);
BUG();
case INO_STATE_READING:
/* We need to wait for it to finish, lest we move on
and trigger the BUG() above while we haven't yet
finished checking all its nodes */
jffs2_dbg(1, "Waiting for ino #%u to finish reading\n",
ic->ino);
/* We need to come back again for the _same_ inode. We've
made no progress in this case, but that should be OK */
c->check_ino = ic->ino;
mutex_unlock(&c->alloc_sem);
sleep_on_spinunlock(&c->inocache_wq, &c->inocache_lock);
return 0;
default:
BUG();
case INO_STATE_UNCHECKED:
;
}
ic->state = INO_STATE_CHECKING;
spin_unlock(&c->inocache_lock);
jffs2_dbg(1, "%s(): triggering inode scan of ino#%u\n",
__func__, ic->ino);
ret = jffs2_do_crccheck_inode(c, ic);
if (ret)
pr_warn("Returned error for crccheck of ino #%u. Expect badness...\n",
ic->ino);
jffs2_set_inocache_state(c, ic, INO_STATE_CHECKEDABSENT);
mutex_unlock(&c->alloc_sem);
return ret;
}
/* If there are any blocks which need erasing, erase them now */
if (!list_empty(&c->erase_complete_list) ||
!list_empty(&c->erase_pending_list)) {
spin_unlock(&c->erase_completion_lock);
mutex_unlock(&c->alloc_sem);
jffs2_dbg(1, "%s(): erasing pending blocks\n", __func__);
if (jffs2_erase_pending_blocks(c, 1))
return 0;
jffs2_dbg(1, "No progress from erasing block; doing GC anyway\n");
mutex_lock(&c->alloc_sem);
spin_lock(&c->erase_completion_lock);
}
/* First, work out which block we're garbage-collecting */
jeb = c->gcblock;
if (!jeb)
jeb = jffs2_find_gc_block(c);
if (!jeb) {
/* Couldn't find a free block. But maybe we can just erase one and make 'progress'? */
if (c->nr_erasing_blocks) {
spin_unlock(&c->erase_completion_lock);
mutex_unlock(&c->alloc_sem);
return -EAGAIN;
}
jffs2_dbg(1, "Couldn't find erase block to garbage collect!\n");
spin_unlock(&c->erase_completion_lock);
mutex_unlock(&c->alloc_sem);
return -EIO;
}
jffs2_dbg(1, "GC from block %08x, used_size %08x, dirty_size %08x, free_size %08x\n",
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/mtd/mtd.h`, `linux/slab.h`, `linux/pagemap.h`, `linux/crc32.h`, `linux/compiler.h`, `linux/stat.h`, `nodelist.h`.
- Detected declarations: `function jffs2_garbage_collect_pass`, `function read_inode`, `function iget`, `function jffs2_garbage_collect_live`, `function jffs2_garbage_collect_pristine`, `function jffs2_garbage_collect_metadata`, `function jffs2_garbage_collect_dirent`, `function jffs2_garbage_collect_deletion_dirent`, `function jffs2_garbage_collect_hole`, `function jffs2_garbage_collect_dnode`.
- 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.