fs/xfs/scrub/rcbag_btree.c

Source file repositories/reference/linux-study-clean/fs/xfs/scrub/rcbag_btree.c

File Facts

System
Linux kernel
Corpus path
fs/xfs/scrub/rcbag_btree.c
Extension
.c
Size
8650 bytes
Lines
353
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-or-later
/*
 * Copyright (c) 2022-2024 Oracle.  All Rights Reserved.
 * Author: Darrick J. Wong <djwong@kernel.org>
 */
#include "xfs_platform.h"
#include "xfs_fs.h"
#include "xfs_shared.h"
#include "xfs_format.h"
#include "xfs_trans_resv.h"
#include "xfs_mount.h"
#include "xfs_defer.h"
#include "xfs_btree.h"
#include "xfs_buf_mem.h"
#include "xfs_btree_mem.h"
#include "xfs_error.h"
#include "scrub/rcbag_btree.h"
#include "scrub/trace.h"

static struct kmem_cache	*rcbagbt_cur_cache;

STATIC void
rcbagbt_init_key_from_rec(
	union xfs_btree_key		*key,
	const union xfs_btree_rec	*rec)
{
	struct rcbag_key	*bag_key = (struct rcbag_key *)key;
	const struct rcbag_rec	*bag_rec = (const struct rcbag_rec *)rec;

	BUILD_BUG_ON(sizeof(struct rcbag_key) > sizeof(union xfs_btree_key));
	BUILD_BUG_ON(sizeof(struct rcbag_rec) > sizeof(union xfs_btree_rec));

	bag_key->rbg_startblock = bag_rec->rbg_startblock;
	bag_key->rbg_blockcount = bag_rec->rbg_blockcount;
}

STATIC void
rcbagbt_init_rec_from_cur(
	struct xfs_btree_cur	*cur,
	union xfs_btree_rec	*rec)
{
	struct rcbag_rec	*bag_rec = (struct rcbag_rec *)rec;
	struct rcbag_rec	*bag_irec = (struct rcbag_rec *)&cur->bc_rec;

	bag_rec->rbg_startblock = bag_irec->rbg_startblock;
	bag_rec->rbg_blockcount = bag_irec->rbg_blockcount;
	bag_rec->rbg_refcount = bag_irec->rbg_refcount;
}

STATIC int
rcbagbt_cmp_key_with_cur(
	struct xfs_btree_cur		*cur,
	const union xfs_btree_key	*key)
{
	struct rcbag_rec		*rec = (struct rcbag_rec *)&cur->bc_rec;
	const struct rcbag_key		*kp = (const struct rcbag_key *)key;

	return cmp_int(kp->rbg_startblock, rec->rbg_startblock) ?:
	       cmp_int(kp->rbg_blockcount, rec->rbg_blockcount);
}

STATIC int
rcbagbt_cmp_two_keys(
	struct xfs_btree_cur		*cur,
	const union xfs_btree_key	*k1,
	const union xfs_btree_key	*k2,
	const union xfs_btree_key	*mask)
{
	const struct rcbag_key		*kp1 = (const struct rcbag_key *)k1;
	const struct rcbag_key		*kp2 = (const struct rcbag_key *)k2;

	ASSERT(mask == NULL);

	return cmp_int(kp1->rbg_startblock, kp2->rbg_startblock) ?:
	       cmp_int(kp1->rbg_blockcount, kp2->rbg_blockcount);
}

STATIC int
rcbagbt_keys_inorder(
	struct xfs_btree_cur		*cur,
	const union xfs_btree_key	*k1,
	const union xfs_btree_key	*k2)
{
	const struct rcbag_key		*kp1 = (const struct rcbag_key *)k1;
	const struct rcbag_key		*kp2 = (const struct rcbag_key *)k2;

	if (kp1->rbg_startblock > kp2->rbg_startblock)
		return 0;
	if (kp1->rbg_startblock < kp2->rbg_startblock)
		return 1;

Annotation

Implementation Notes