fs/jfs/jfs_dmap.c
Source file repositories/reference/linux-study-clean/fs/jfs/jfs_dmap.c
File Facts
- System
- Linux kernel
- Corpus path
fs/jfs/jfs_dmap.c- Extension
.c- Size
- 116885 bytes
- Lines
- 4183
- 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/slab.hjfs_incore.hjfs_superblock.hjfs_dmap.hjfs_imap.hjfs_lock.hjfs_metapage.hjfs_debug.hjfs_discard.h
Detected Declarations
struct range2trimfunction check_dmapctlfunction dbMountfunction dbUnmountfunction dbSyncfunction dbFreefunction dbUpdatePMapfunction firstfunction dbAllocfunction dbReAllocfunction dbExtendfunction dbAllocNextfunction dbAllocNearfunction dbAllocAGfunction BPERDMAPfunction dbAllocAnyfunction dbDiscardAGfunction dbFindCtlfunction dbAllocCtlfunction dbAllocDmapLevfunction dbAllocDmapfunction dbFreeDmapfunction dbAllocBitsfunction dbFreeBitsfunction maximumfunction dbAdjCtlfunction partfunction levelfunction dbSplitfunction dbBackSplitfunction dbJoinfunction dbAdjTreefunction dbFindLeaffunction dbMaxBudfunction cnttzfunction cntlzfunction blkstol2function dbAllocBottomUpfunction dbAllocDmapBUfunction dbExtendFSfunction dbFinalizeBmapfunction dbInitDmapfunction dbInitDmapTreefunction dbInitTreefunction dbInitDmapCtlfunction dbGetL2AGSizefunction dbMapFileSizeToMapSize
Annotated Snippet
struct range2trim {
u64 blkno;
u64 nblocks;
} *totrim, *tt;
/* max blkno / nblocks pairs to trim */
int count = 0, range_cnt;
u64 max_ranges;
/* prevent others from writing new stuff here, while trimming */
IWRITE_LOCK(ipbmap, RDWRLOCK_DMAP);
nblocks = bmp->db_agfree[agno];
max_ranges = nblocks;
do_div(max_ranges, minlen);
range_cnt = min_t(u64, max_ranges + 1, 32 * 1024);
totrim = kmalloc_objs(struct range2trim, range_cnt, GFP_NOFS);
if (totrim == NULL) {
jfs_error(bmp->db_ipbmap->i_sb, "no memory for trim array\n");
IWRITE_UNLOCK(ipbmap);
return 0;
}
tt = totrim;
while (nblocks >= minlen) {
l2nb = BLKSTOL2(nblocks);
/* 0 = okay, -EIO = fatal, -ENOSPC -> try smaller block */
rc = dbAllocAG(bmp, agno, nblocks, l2nb, &blkno);
if (rc == 0) {
tt->blkno = blkno;
tt->nblocks = nblocks;
tt++; count++;
/* the whole ag is free, trim now */
if (bmp->db_agfree[agno] == 0)
break;
/* give a hint for the next while */
nblocks = bmp->db_agfree[agno];
continue;
} else if (rc == -ENOSPC) {
/* search for next smaller log2 block */
l2nb = BLKSTOL2(nblocks) - 1;
if (unlikely(l2nb < 0))
break;
nblocks = 1LL << l2nb;
} else {
/* Trim any already allocated blocks */
jfs_error(bmp->db_ipbmap->i_sb, "-EIO\n");
break;
}
/* check, if our trim array is full */
if (unlikely(count >= range_cnt - 1))
break;
}
IWRITE_UNLOCK(ipbmap);
tt->nblocks = 0; /* mark the current end */
for (tt = totrim; tt->nblocks != 0; tt++) {
/* when mounted with online discard, dbFree() will
* call jfs_issue_discard() itself */
if (!(JFS_SBI(sb)->flag & JFS_DISCARD))
jfs_issue_discard(ip, tt->blkno, tt->nblocks);
dbFree(ip, tt->blkno, tt->nblocks);
trimmed += tt->nblocks;
}
kfree(totrim);
return trimmed;
}
/*
* NAME: dbFindCtl()
*
* FUNCTION: starting at a specified dmap control page level and block
* number, search down the dmap control levels for a range of
* contiguous free blocks large enough to satisfy an allocation
* request for the specified number of free blocks.
*
* if sufficient contiguous free blocks are found, this routine
* returns the starting block number within a dmap page that
* contains or starts a range of contiqious free blocks that
* is sufficient in size.
*
* PARAMETERS:
* bmp - pointer to bmap descriptor
* level - starting dmap control page level.
* l2nb - log2 number of contiguous free blocks desired.
Annotation
- Immediate include surface: `linux/fs.h`, `linux/slab.h`, `jfs_incore.h`, `jfs_superblock.h`, `jfs_dmap.h`, `jfs_imap.h`, `jfs_lock.h`, `jfs_metapage.h`.
- Detected declarations: `struct range2trim`, `function check_dmapctl`, `function dbMount`, `function dbUnmount`, `function dbSync`, `function dbFree`, `function dbUpdatePMap`, `function first`, `function dbAlloc`, `function dbReAlloc`.
- 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.