fs/xfs/libxfs/xfs_group.c
Source file repositories/reference/linux-study-clean/fs/xfs/libxfs/xfs_group.c
File Facts
- System
- Linux kernel
- Corpus path
fs/xfs/libxfs/xfs_group.c- Extension
.c- Size
- 5107 bytes
- Lines
- 231
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
xfs_platform.hxfs_shared.hxfs_format.hxfs_trans_resv.hxfs_mount.hxfs_error.hxfs_trace.hxfs_extent_busy.hxfs_group.h
Detected Declarations
function Copyrightfunction xfs_group_holdfunction xfs_group_putfunction xfs_group_grabfunction xfs_group_next_rangefunction xfs_group_grab_next_markfunction xfs_group_relefunction xfs_group_freefunction xfs_group_insertfunction xfs_group_get_by_fsb
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2018 Red Hat, Inc.
*/
#include "xfs_platform.h"
#include "xfs_shared.h"
#include "xfs_format.h"
#include "xfs_trans_resv.h"
#include "xfs_mount.h"
#include "xfs_error.h"
#include "xfs_trace.h"
#include "xfs_extent_busy.h"
#include "xfs_group.h"
/*
* Groups can have passive and active references.
*
* For passive references the code freeing a group is responsible for cleaning
* up objects that hold the passive references (e.g. cached buffers).
* Routines manipulating passive references are xfs_group_get, xfs_group_hold
* and xfs_group_put.
*
* Active references are for short term access to the group for walking trees or
* accessing state. If a group is being shrunk or offlined, the lookup will fail
* to find that group and return NULL instead.
* Routines manipulating active references are xfs_group_grab and
* xfs_group_rele.
*/
struct xfs_group *
xfs_group_get(
struct xfs_mount *mp,
uint32_t index,
enum xfs_group_type type)
{
struct xfs_group *xg;
rcu_read_lock();
xg = xa_load(&mp->m_groups[type].xa, index);
if (xg) {
trace_xfs_group_get(xg, _RET_IP_);
ASSERT(atomic_read(&xg->xg_ref) >= 0);
atomic_inc(&xg->xg_ref);
}
rcu_read_unlock();
return xg;
}
struct xfs_group *
xfs_group_hold(
struct xfs_group *xg)
{
ASSERT(atomic_read(&xg->xg_ref) > 0 ||
atomic_read(&xg->xg_active_ref) > 0);
trace_xfs_group_hold(xg, _RET_IP_);
atomic_inc(&xg->xg_ref);
return xg;
}
void
xfs_group_put(
struct xfs_group *xg)
{
trace_xfs_group_put(xg, _RET_IP_);
ASSERT(atomic_read(&xg->xg_ref) > 0);
atomic_dec(&xg->xg_ref);
}
struct xfs_group *
xfs_group_grab(
struct xfs_mount *mp,
uint32_t index,
enum xfs_group_type type)
{
struct xfs_group *xg;
rcu_read_lock();
xg = xa_load(&mp->m_groups[type].xa, index);
if (xg) {
trace_xfs_group_grab(xg, _RET_IP_);
if (!atomic_inc_not_zero(&xg->xg_active_ref))
xg = NULL;
}
rcu_read_unlock();
return xg;
}
Annotation
- Immediate include surface: `xfs_platform.h`, `xfs_shared.h`, `xfs_format.h`, `xfs_trans_resv.h`, `xfs_mount.h`, `xfs_error.h`, `xfs_trace.h`, `xfs_extent_busy.h`.
- Detected declarations: `function Copyright`, `function xfs_group_hold`, `function xfs_group_put`, `function xfs_group_grab`, `function xfs_group_next_range`, `function xfs_group_grab_next_mark`, `function xfs_group_rele`, `function xfs_group_free`, `function xfs_group_insert`, `function xfs_group_get_by_fsb`.
- 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.