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.

Dependency Surface

Detected Declarations

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

Implementation Notes