fs/xfs/scrub/rcbag.c

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

File Facts

System
Linux kernel
Corpus path
fs/xfs/scrub/rcbag.c
Extension
.c
Size
6037 bytes
Lines
308
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

struct rcbag {
	struct xfs_mount	*mp;
	struct xfbtree		xfbtree;
	uint64_t		nr_items;
};

int
rcbag_init(
	struct xfs_mount	*mp,
	struct xfs_buftarg	*btp,
	struct rcbag		**bagp)
{
	struct rcbag		*bag;
	int			error;

	bag = kzalloc_obj(struct rcbag, XCHK_GFP_FLAGS);
	if (!bag)
		return -ENOMEM;

	bag->nr_items = 0;
	bag->mp = mp;

	error = rcbagbt_mem_init(mp, &bag->xfbtree, btp);
	if (error)
		goto out_bag;

	*bagp = bag;
	return 0;

out_bag:
	kfree(bag);
	return error;
}

void
rcbag_free(
	struct rcbag		**bagp)
{
	struct rcbag		*bag = *bagp;

	xfbtree_destroy(&bag->xfbtree);
	kfree(bag);
	*bagp = NULL;
}

/* Track an rmap in the refcount bag. */
int
rcbag_add(
	struct rcbag			*bag,
	struct xfs_trans		*tp,
	const struct xfs_rmap_irec	*rmap)
{
	struct rcbag_rec		bagrec;
	struct xfs_mount		*mp = bag->mp;
	struct xfs_btree_cur		*cur;
	int				has;
	int				error;

	cur = rcbagbt_mem_cursor(mp, tp, &bag->xfbtree);
	error = rcbagbt_lookup_eq(cur, rmap, &has);
	if (error)
		goto out_cur;

	if (has) {
		error = rcbagbt_get_rec(cur, &bagrec, &has);
		if (error)
			goto out_cur;
		if (!has) {
			error = -EFSCORRUPTED;
			goto out_cur;
		}

		bagrec.rbg_refcount++;
		error = rcbagbt_update(cur, &bagrec);
		if (error)
			goto out_cur;
	} else {
		bagrec.rbg_startblock = rmap->rm_startblock;
		bagrec.rbg_blockcount = rmap->rm_blockcount;
		bagrec.rbg_refcount = 1;

		error = rcbagbt_insert(cur, &bagrec, &has);
		if (error)
			goto out_cur;
		if (!has) {
			error = -EFSCORRUPTED;
			goto out_cur;
		}
	}

Annotation

Implementation Notes