fs/btrfs/tests/qgroup-tests.c
Source file repositories/reference/linux-study-clean/fs/btrfs/tests/qgroup-tests.c
File Facts
- System
- Linux kernel
- Corpus path
fs/btrfs/tests/qgroup-tests.c- Extension
.c- Size
- 13379 bytes
- Lines
- 551
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/types.hbtrfs-tests.h../ctree.h../transaction.h../disk-io.h../qgroup.h../backref.h../fs.h../accessors.h
Detected Declarations
function Copyrightfunction add_tree_reffunction remove_extent_itemfunction remove_extent_reffunction test_no_shared_qgroupfunction test_multiple_refsfunction btrfs_test_qgroups
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2013 Facebook. All rights reserved.
*/
#include <linux/types.h>
#include "btrfs-tests.h"
#include "../ctree.h"
#include "../transaction.h"
#include "../disk-io.h"
#include "../qgroup.h"
#include "../backref.h"
#include "../fs.h"
#include "../accessors.h"
static int insert_normal_tree_ref(struct btrfs_root *root, u64 bytenr,
u64 num_bytes, u64 parent, u64 root_objectid)
{
struct btrfs_trans_handle trans;
struct btrfs_extent_item *item;
struct btrfs_extent_inline_ref *iref;
struct btrfs_tree_block_info *block_info;
BTRFS_PATH_AUTO_FREE(path);
struct extent_buffer *leaf;
struct btrfs_key ins;
u32 size = sizeof(*item) + sizeof(*iref) + sizeof(*block_info);
int ret;
btrfs_init_dummy_trans(&trans, NULL);
ins.objectid = bytenr;
ins.type = BTRFS_EXTENT_ITEM_KEY;
ins.offset = num_bytes;
path = btrfs_alloc_path();
if (!path) {
test_std_err(TEST_ALLOC_ROOT);
return -ENOMEM;
}
ret = btrfs_insert_empty_item(&trans, root, path, &ins, size);
if (ret) {
test_err("couldn't insert ref %d", ret);
return ret;
}
leaf = path->nodes[0];
item = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_extent_item);
btrfs_set_extent_refs(leaf, item, 1);
btrfs_set_extent_generation(leaf, item, 1);
btrfs_set_extent_flags(leaf, item, BTRFS_EXTENT_FLAG_TREE_BLOCK);
block_info = (struct btrfs_tree_block_info *)(item + 1);
btrfs_set_tree_block_level(leaf, block_info, 0);
iref = (struct btrfs_extent_inline_ref *)(block_info + 1);
if (parent > 0) {
btrfs_set_extent_inline_ref_type(leaf, iref,
BTRFS_SHARED_BLOCK_REF_KEY);
btrfs_set_extent_inline_ref_offset(leaf, iref, parent);
} else {
btrfs_set_extent_inline_ref_type(leaf, iref, BTRFS_TREE_BLOCK_REF_KEY);
btrfs_set_extent_inline_ref_offset(leaf, iref, root_objectid);
}
return 0;
}
static int add_tree_ref(struct btrfs_root *root, u64 bytenr, u64 num_bytes,
u64 parent, u64 root_objectid)
{
struct btrfs_trans_handle trans;
struct btrfs_extent_item *item;
BTRFS_PATH_AUTO_FREE(path);
struct btrfs_key key;
u64 refs;
int ret;
btrfs_init_dummy_trans(&trans, NULL);
key.objectid = bytenr;
key.type = BTRFS_EXTENT_ITEM_KEY;
key.offset = num_bytes;
path = btrfs_alloc_path();
if (!path) {
test_std_err(TEST_ALLOC_ROOT);
return -ENOMEM;
}
ret = btrfs_search_slot(&trans, root, &key, path, 0, 1);
if (ret) {
test_err("couldn't find extent ref");
Annotation
- Immediate include surface: `linux/types.h`, `btrfs-tests.h`, `../ctree.h`, `../transaction.h`, `../disk-io.h`, `../qgroup.h`, `../backref.h`, `../fs.h`.
- Detected declarations: `function Copyright`, `function add_tree_ref`, `function remove_extent_item`, `function remove_extent_ref`, `function test_no_shared_qgroup`, `function test_multiple_refs`, `function btrfs_test_qgroups`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: source implementation candidate.
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.