drivers/md/persistent-data/dm-btree-remove.c

Source file repositories/reference/linux-study-clean/drivers/md/persistent-data/dm-btree-remove.c

File Facts

System
Linux kernel
Corpus path
drivers/md/persistent-data/dm-btree-remove.c
Extension
.c
Size
19134 bytes
Lines
774
Domain
Driver Families
Bucket
drivers/md
Inferred role
Driver Families: exported/initcall integration point
Status
integration implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

struct child {
	unsigned int index;
	struct dm_block *block;
	struct btree_node *n;
};

static int init_child(struct dm_btree_info *info, struct dm_btree_value_type *vt,
		      struct btree_node *parent,
		      unsigned int index, struct child *result)
{
	int r, inc;
	dm_block_t root;

	result->index = index;
	root = value64(parent, index);

	r = dm_tm_shadow_block(info->tm, root, &btree_node_validator,
			       &result->block, &inc);
	if (r)
		return r;

	result->n = dm_block_data(result->block);

	if (inc)
		inc_children(info->tm, result->n, vt);

	*((__le64 *) value_ptr(parent, index)) =
		cpu_to_le64(dm_block_location(result->block));

	return 0;
}

static void exit_child(struct dm_btree_info *info, struct child *c)
{
	dm_tm_unlock(info->tm, c->block);
}

static int shift(struct btree_node *left, struct btree_node *right, int count)
{
	int r;
	uint32_t nr_left = le32_to_cpu(left->header.nr_entries);
	uint32_t nr_right = le32_to_cpu(right->header.nr_entries);
	uint32_t max_entries = le32_to_cpu(left->header.max_entries);
	uint32_t r_max_entries = le32_to_cpu(right->header.max_entries);

	if (max_entries != r_max_entries) {
		DMERR("node max_entries mismatch");
		return -EILSEQ;
	}

	if (nr_left - count > max_entries) {
		DMERR("node shift out of bounds");
		return -EINVAL;
	}

	if (nr_right + count > max_entries) {
		DMERR("node shift out of bounds");
		return -EINVAL;
	}

	if (!count)
		return 0;

	if (count > 0) {
		node_shift(right, count);
		r = node_copy(left, right, count);
		if (r)
			return r;
	} else {
		r = node_copy(left, right, count);
		if (r)
			return r;
		node_shift(right, count);
	}

	left->header.nr_entries = cpu_to_le32(nr_left - count);
	right->header.nr_entries = cpu_to_le32(nr_right + count);

	return 0;
}

static int __rebalance2(struct dm_btree_info *info, struct btree_node *parent,
			struct child *l, struct child *r)
{
	int ret;
	struct btree_node *left = l->n;
	struct btree_node *right = r->n;
	uint32_t nr_left = le32_to_cpu(left->header.nr_entries);
	uint32_t nr_right = le32_to_cpu(right->header.nr_entries);
	/*

Annotation

Implementation Notes