fs/ocfs2/localalloc.c
Source file repositories/reference/linux-study-clean/fs/ocfs2/localalloc.c
File Facts
- System
- Linux kernel
- Corpus path
fs/ocfs2/localalloc.c- Extension
.c- Size
- 33846 bytes
- Lines
- 1319
- 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/fs.hlinux/types.hlinux/slab.hlinux/highmem.hlinux/bitops.hcluster/masklog.hocfs2.halloc.hblockcheck.hdlmglue.hinode.hjournal.hlocalalloc.hsuballoc.hsuper.hsysfile.hocfs2_trace.hbuffer_head_io.h
Detected Declarations
enum ocfs2_la_eventfunction ocfs2_la_default_mbfunction ocfs2_la_set_sizesfunction ocfs2_la_state_enabledfunction ocfs2_local_alloc_seen_free_bitsfunction ocfs2_la_enable_workerfunction ocfs2_alloc_should_use_localfunction ocfs2_load_local_allocfunction ocfs2_shutdown_local_allocfunction ocfs2_begin_local_alloc_recoveryfunction ocfs2_complete_local_alloc_recoveryfunction ocfs2_reserve_local_alloc_bitsfunction ocfs2_local_alloc_count_bitsfunction ocfs2_claim_local_alloc_bitsfunction ocfs2_free_local_alloc_bitsfunction ocfs2_local_alloc_count_bitsfunction ocfs2_local_alloc_find_clear_bitsfunction ocfs2_clear_local_allocfunction ocfs2_verify_zero_bitsfunction ocfs2_sync_local_to_mainfunction ocfs2_recalc_la_windowfunction ocfs2_local_alloc_reserve_for_windowfunction ocfs2_local_alloc_new_windowfunction ocfs2_local_alloc_slide_window
Annotated Snippet
ocfs2_local_alloc_count_bits(alloc)) {
status = ocfs2_error(osb->sb, "local alloc inode %llu says it has %u used bits, but a count shows %u\n",
(unsigned long long)le64_to_cpu(alloc->i_blkno),
le32_to_cpu(alloc->id1.bitmap1.i_used),
ocfs2_local_alloc_count_bits(alloc));
goto bail;
}
#endif
free_bits = le32_to_cpu(alloc->id1.bitmap1.i_total) -
le32_to_cpu(alloc->id1.bitmap1.i_used);
if (bits_wanted > free_bits) {
/* uhoh, window change time. */
status =
ocfs2_local_alloc_slide_window(osb, local_alloc_inode);
if (status < 0) {
if (status != -ENOSPC)
mlog_errno(status);
goto bail;
}
/*
* Under certain conditions, the window slide code
* might have reduced the number of bits available or
* disabled the local alloc entirely. Re-check
* here and return -ENOSPC if necessary.
*/
status = -ENOSPC;
if (!ocfs2_la_state_enabled(osb))
goto bail;
free_bits = le32_to_cpu(alloc->id1.bitmap1.i_total) -
le32_to_cpu(alloc->id1.bitmap1.i_used);
if (bits_wanted > free_bits)
goto bail;
}
ac->ac_inode = local_alloc_inode;
/* We should never use localalloc from another slot */
ac->ac_alloc_slot = osb->slot_num;
ac->ac_which = OCFS2_AC_USE_LOCAL;
get_bh(osb->local_alloc_bh);
ac->ac_bh = osb->local_alloc_bh;
status = 0;
bail:
if (status < 0 && local_alloc_inode) {
inode_unlock(local_alloc_inode);
iput(local_alloc_inode);
}
trace_ocfs2_reserve_local_alloc_bits(
(unsigned long long)ac->ac_max_block,
bits_wanted, osb->slot_num, status);
if (status)
mlog_errno(status);
return status;
}
int ocfs2_claim_local_alloc_bits(struct ocfs2_super *osb,
handle_t *handle,
struct ocfs2_alloc_context *ac,
u32 bits_wanted,
u32 *bit_off,
u32 *num_bits)
{
int status, start;
struct inode *local_alloc_inode;
void *bitmap;
struct ocfs2_dinode *alloc;
struct ocfs2_local_alloc *la;
BUG_ON(ac->ac_which != OCFS2_AC_USE_LOCAL);
local_alloc_inode = ac->ac_inode;
alloc = (struct ocfs2_dinode *) osb->local_alloc_bh->b_data;
la = OCFS2_LOCAL_ALLOC(alloc);
start = ocfs2_local_alloc_find_clear_bits(osb, alloc, &bits_wanted,
ac->ac_resv);
if (start == -1) {
/* TODO: Shouldn't we just BUG here? */
status = -ENOSPC;
mlog_errno(status);
goto bail;
}
bitmap = la->la_bitmap;
*bit_off = le32_to_cpu(la->la_bm_off) + start;
*num_bits = bits_wanted;
Annotation
- Immediate include surface: `linux/fs.h`, `linux/types.h`, `linux/slab.h`, `linux/highmem.h`, `linux/bitops.h`, `cluster/masklog.h`, `ocfs2.h`, `alloc.h`.
- Detected declarations: `enum ocfs2_la_event`, `function ocfs2_la_default_mb`, `function ocfs2_la_set_sizes`, `function ocfs2_la_state_enabled`, `function ocfs2_local_alloc_seen_free_bits`, `function ocfs2_la_enable_worker`, `function ocfs2_alloc_should_use_local`, `function ocfs2_load_local_alloc`, `function ocfs2_shutdown_local_alloc`, `function ocfs2_begin_local_alloc_recovery`.
- 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.