fs/nilfs2/alloc.c
Source file repositories/reference/linux-study-clean/fs/nilfs2/alloc.c
File Facts
- System
- Linux kernel
- Corpus path
fs/nilfs2/alloc.c- Extension
.c- Size
- 27911 bytes
- Lines
- 959
- 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/types.hlinux/buffer_head.hlinux/fs.hlinux/bitops.hlinux/slab.hmdt.halloc.h
Detected Declarations
function Copyrightfunction nilfs_palloc_groups_countfunction nilfs_palloc_init_blockgroupfunction nilfs_palloc_groupfunction nilfs_palloc_desc_blkofffunction nilfs_palloc_bitmap_blkofffunction nilfs_palloc_group_desc_nfreesfunction nilfs_palloc_group_desc_add_entriesfunction nilfs_palloc_entry_blkofffunction nilfs_palloc_desc_block_initfunction nilfs_palloc_get_blockfunction likelyfunction nilfs_palloc_delete_blockfunction nilfs_palloc_get_desc_blockfunction nilfs_palloc_get_bitmap_blockfunction nilfs_palloc_delete_bitmap_blockfunction nilfs_palloc_get_entry_blockfunction nilfs_palloc_delete_entry_blockfunction nilfs_palloc_group_desc_offsetfunction nilfs_palloc_bitmap_offsetfunction nilfs_palloc_entry_offsetfunction nilfs_palloc_find_available_slotfunction nilfs_palloc_rest_groups_in_desc_blockfunction nilfs_palloc_count_desc_blocksfunction nilfs_palloc_mdt_file_can_growfunction nilfs_palloc_count_max_entriesfunction nilfs_palloc_prepare_alloc_entryfunction nilfs_palloc_commit_alloc_entryfunction nilfs_palloc_commit_free_entryfunction nilfs_palloc_abort_alloc_entryfunction nilfs_palloc_prepare_free_entryfunction nilfs_palloc_abort_free_entryfunction nilfs_palloc_freevfunction nilfs_palloc_setup_cachefunction nilfs_palloc_clear_cachefunction nilfs_palloc_destroy_cache
Annotated Snippet
likely(buffer_uptodate(prev->bh))) {
get_bh(prev->bh);
*bhp = prev->bh;
spin_unlock(lock);
return 0;
}
spin_unlock(lock);
ret = nilfs_mdt_get_block(inode, blkoff, create, init_block, bhp);
if (!ret) {
spin_lock(lock);
/*
* The following code must be safe for change of the
* cache contents during the get block call.
*/
brelse(prev->bh);
get_bh(*bhp);
prev->bh = *bhp;
prev->blkoff = blkoff;
spin_unlock(lock);
}
return ret;
}
/**
* nilfs_palloc_delete_block - delete a block on the persistent allocator file
* @inode: inode of metadata file using this allocator
* @blkoff: block offset
* @prev: nilfs_bh_assoc struct of the last used buffer
* @lock: spin lock protecting @prev
*
* Return: 0 on success, or one of the following negative error codes on
* failure:
* * %-EIO - I/O error (including metadata corruption).
* * %-ENOENT - Non-existent block.
* * %-ENOMEM - Insufficient memory available.
*/
static int nilfs_palloc_delete_block(struct inode *inode, unsigned long blkoff,
struct nilfs_bh_assoc *prev,
spinlock_t *lock)
{
spin_lock(lock);
if (prev->bh && blkoff == prev->blkoff) {
brelse(prev->bh);
prev->bh = NULL;
}
spin_unlock(lock);
return nilfs_mdt_delete_block(inode, blkoff);
}
/**
* nilfs_palloc_get_desc_block - get buffer head of a group descriptor block
* @inode: inode of metadata file using this allocator
* @group: group number
* @create: create flag
* @bhp: pointer to store the resultant buffer head
*
* Return: 0 on success, or a negative error code on failure.
*/
static int nilfs_palloc_get_desc_block(struct inode *inode,
unsigned long group,
int create, struct buffer_head **bhp)
{
struct nilfs_palloc_cache *cache = NILFS_MDT(inode)->mi_palloc_cache;
return nilfs_palloc_get_block(inode,
nilfs_palloc_desc_blkoff(inode, group),
create, nilfs_palloc_desc_block_init,
bhp, &cache->prev_desc, &cache->lock);
}
/**
* nilfs_palloc_get_bitmap_block - get buffer head of a bitmap block
* @inode: inode of metadata file using this allocator
* @group: group number
* @create: create flag
* @bhp: pointer to store the resultant buffer head
*
* Return: 0 on success, or a negative error code on failure.
*/
static int nilfs_palloc_get_bitmap_block(struct inode *inode,
unsigned long group,
int create, struct buffer_head **bhp)
{
struct nilfs_palloc_cache *cache = NILFS_MDT(inode)->mi_palloc_cache;
return nilfs_palloc_get_block(inode,
nilfs_palloc_bitmap_blkoff(inode, group),
create, NULL, bhp,
&cache->prev_bitmap, &cache->lock);
Annotation
- Immediate include surface: `linux/types.h`, `linux/buffer_head.h`, `linux/fs.h`, `linux/bitops.h`, `linux/slab.h`, `mdt.h`, `alloc.h`.
- Detected declarations: `function Copyright`, `function nilfs_palloc_groups_count`, `function nilfs_palloc_init_blockgroup`, `function nilfs_palloc_group`, `function nilfs_palloc_desc_blkoff`, `function nilfs_palloc_bitmap_blkoff`, `function nilfs_palloc_group_desc_nfrees`, `function nilfs_palloc_group_desc_add_entries`, `function nilfs_palloc_entry_blkoff`, `function nilfs_palloc_desc_block_init`.
- 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.