fs/btrfs/tests/delayed-refs-tests.c

Source file repositories/reference/linux-study-clean/fs/btrfs/tests/delayed-refs-tests.c

File Facts

System
Linux kernel
Corpus path
fs/btrfs/tests/delayed-refs-tests.c
Extension
.c
Size
25124 bytes
Lines
1017
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 ref_head_check {
	u64 bytenr;
	u64 num_bytes;
	int ref_mod;
	int total_ref_mod;
	int must_insert;
};

struct ref_node_check {
	u64 bytenr;
	u64 num_bytes;
	int ref_mod;
	enum btrfs_delayed_ref_action action;
	u8 type;
	u64 parent;
	u64 root;
	u64 owner;
	u64 offset;
};

static enum btrfs_ref_type ref_type_from_disk_ref_type(u8 type)
{
	if ((type == BTRFS_TREE_BLOCK_REF_KEY) ||
	    (type == BTRFS_SHARED_BLOCK_REF_KEY))
		return BTRFS_REF_METADATA;
	return BTRFS_REF_DATA;
}

static void delete_delayed_ref_head(struct btrfs_trans_handle *trans,
				    struct btrfs_delayed_ref_head *head)
{
	struct btrfs_fs_info *fs_info = trans->fs_info;
	struct btrfs_delayed_ref_root *delayed_refs =
		&trans->transaction->delayed_refs;

	spin_lock(&delayed_refs->lock);
	spin_lock(&head->lock);
	btrfs_delete_ref_head(fs_info, delayed_refs, head);
	spin_unlock(&head->lock);
	spin_unlock(&delayed_refs->lock);

	btrfs_delayed_ref_unlock(head);
	btrfs_put_delayed_ref_head(head);
}

static void delete_delayed_ref_node(struct btrfs_delayed_ref_head *head,
				    struct btrfs_delayed_ref_node *node)
{
	rb_erase_cached(&node->ref_node, &head->ref_tree);
	RB_CLEAR_NODE(&node->ref_node);
	if (!list_empty(&node->add_list))
		list_del_init(&node->add_list);
	btrfs_put_delayed_ref(node);
}

static int validate_ref_head(struct btrfs_delayed_ref_head *head,
			     struct ref_head_check *check)
{
	if (head->bytenr != check->bytenr) {
		test_err("invalid bytenr have: %llu want: %llu", head->bytenr,
			 check->bytenr);
		return -EINVAL;
	}

	if (head->num_bytes != check->num_bytes) {
		test_err("invalid num_bytes have: %llu want: %llu",
			 head->num_bytes, check->num_bytes);
		return -EINVAL;
	}

	if (head->ref_mod != check->ref_mod) {
		test_err("invalid ref_mod have: %d want: %d", head->ref_mod,
			 check->ref_mod);
		return -EINVAL;
	}

	if (head->total_ref_mod != check->total_ref_mod) {
		test_err("invalid total_ref_mod have: %d want: %d",
			 head->total_ref_mod, check->total_ref_mod);
		return -EINVAL;
	}

	if (head->must_insert_reserved != check->must_insert) {
		test_err("invalid must_insert have: %d want: %d",
			 head->must_insert_reserved, check->must_insert);
		return -EINVAL;
	}

	return 0;
}

Annotation

Implementation Notes