fs/xfs/xfs_filestream.c
Source file repositories/reference/linux-study-clean/fs/xfs/xfs_filestream.c
File Facts
- System
- Linux kernel
- Corpus path
fs/xfs/xfs_filestream.c- Extension
.c- Size
- 10062 bytes
- Lines
- 397
- 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
xfs_platform.hxfs_shared.hxfs_format.hxfs_log_format.hxfs_trans_resv.hxfs_mount.hxfs_inode.hxfs_bmap.hxfs_bmap_util.hxfs_alloc.hxfs_mru_cache.hxfs_trace.hxfs_ag.hxfs_ag_resv.hxfs_trans.hxfs_filestream.h
Detected Declarations
struct xfs_fstrm_itemenum xfs_fstrm_allocfunction xfs_fstrm_free_funcfunction xfs_filestream_pick_agfunction xfs_bmap_longest_free_extentfunction for_each_perag_wrapfunction xfs_filestream_get_parentfunction xfs_filestream_lookup_associationfunction xfs_filestream_create_associationfunction xfs_filestream_select_agfunction xfs_filestream_deassociatefunction xfs_filestream_mountfunction xfs_filestream_unmount
Annotated Snippet
struct xfs_fstrm_item {
struct xfs_mru_cache_elem mru;
struct xfs_perag *pag; /* AG in use for this directory */
};
enum xfs_fstrm_alloc {
XFS_PICK_USERDATA = 1,
XFS_PICK_LOWSPACE = 2,
};
static void
xfs_fstrm_free_func(
void *data,
struct xfs_mru_cache_elem *mru)
{
struct xfs_fstrm_item *item =
container_of(mru, struct xfs_fstrm_item, mru);
struct xfs_perag *pag = item->pag;
trace_xfs_filestream_free(pag, mru->key);
atomic_dec(&pag->pagf_fstrms);
xfs_perag_rele(pag);
kfree(item);
}
/*
* Scan the AGs starting at start_agno looking for an AG that isn't in use and
* has at least minlen blocks free. If no AG is found to match the allocation
* requirements, pick the AG with the most free space in it.
*/
static int
xfs_filestream_pick_ag(
struct xfs_alloc_arg *args,
xfs_ino_t pino,
xfs_agnumber_t start_agno,
int flags,
xfs_extlen_t *longest)
{
struct xfs_mount *mp = args->mp;
struct xfs_perag *pag;
struct xfs_perag *max_pag = NULL;
xfs_extlen_t minlen = *longest;
xfs_extlen_t minfree, maxfree = 0;
xfs_agnumber_t agno;
bool first_pass = true;
/* 2% of an AG's blocks must be free for it to be chosen. */
minfree = mp->m_sb.sb_agblocks / 50;
restart:
for_each_perag_wrap(mp, start_agno, agno, pag) {
int err;
trace_xfs_filestream_scan(pag, pino);
*longest = 0;
err = xfs_bmap_longest_free_extent(pag, NULL, longest);
if (err) {
if (err == -EAGAIN) {
/* Couldn't lock the AGF, skip this AG. */
err = 0;
continue;
}
xfs_perag_rele(pag);
if (max_pag)
xfs_perag_rele(max_pag);
return err;
}
/* Keep track of the AG with the most free blocks. */
if (pag->pagf_freeblks > maxfree) {
maxfree = pag->pagf_freeblks;
if (max_pag)
xfs_perag_rele(max_pag);
atomic_inc(&pag_group(pag)->xg_active_ref);
max_pag = pag;
}
/*
* The AG reference count does two things: it enforces mutual
* exclusion when examining the suitability of an AG in this
* loop, and it guards against two filestreams being established
* in the same AG as each other.
*/
if (atomic_inc_return(&pag->pagf_fstrms) <= 1) {
if (((minlen && *longest >= minlen) ||
(!minlen && pag->pagf_freeblks >= minfree)) &&
(!xfs_perag_prefers_metadata(pag) ||
!(flags & XFS_PICK_USERDATA) ||
Annotation
- Immediate include surface: `xfs_platform.h`, `xfs_shared.h`, `xfs_format.h`, `xfs_log_format.h`, `xfs_trans_resv.h`, `xfs_mount.h`, `xfs_inode.h`, `xfs_bmap.h`.
- Detected declarations: `struct xfs_fstrm_item`, `enum xfs_fstrm_alloc`, `function xfs_fstrm_free_func`, `function xfs_filestream_pick_ag`, `function xfs_bmap_longest_free_extent`, `function for_each_perag_wrap`, `function xfs_filestream_get_parent`, `function xfs_filestream_lookup_association`, `function xfs_filestream_create_association`, `function xfs_filestream_select_ag`.
- 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.