drivers/md/bcache/bset.h

Source file repositories/reference/linux-study-clean/drivers/md/bcache/bset.h

File Facts

System
Linux kernel
Corpus path
drivers/md/bcache/bset.h
Extension
.h
Size
20031 bytes
Lines
606
Domain
Driver Families
Bucket
drivers/md
Inferred role
Driver Families: implementation source
Status
source 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 bset_tree {
	/*
	 * We construct a binary tree in an array as if the array
	 * started at 1, so that things line up on the same cachelines
	 * better: see comments in bset.c at cacheline_to_bkey() for
	 * details
	 */

	/* size of the binary tree and prev array */
	unsigned int		size;

	/* function of size - precalculated for to_inorder() */
	unsigned int		extra;

	/* copy of the last key in the set */
	struct bkey		end;
	struct bkey_float	*tree;

	/*
	 * The nodes in the bset tree point to specific keys - this
	 * array holds the sizes of the previous key.
	 *
	 * Conceptually it's a member of struct bkey_float, but we want
	 * to keep bkey_float to 4 bytes and prev isn't used in the fast
	 * path.
	 */
	uint8_t			*prev;

	/* The actual btree node, with pointers to each sorted set */
	struct bset		*data;
};

struct btree_keys_ops {
	bool		(*sort_cmp)(struct btree_iter_set l,
				    struct btree_iter_set r);
	struct bkey	*(*sort_fixup)(struct btree_iter *iter,
				       struct bkey *tmp);
	bool		(*insert_fixup)(struct btree_keys *b,
					struct bkey *insert,
					struct btree_iter *iter,
					struct bkey *replace_key);
	bool		(*key_invalid)(struct btree_keys *bk,
				       const struct bkey *k);
	bool		(*key_bad)(struct btree_keys *bk,
				   const struct bkey *k);
	bool		(*key_merge)(struct btree_keys *bk,
				     struct bkey *l, struct bkey *r);
	void		(*key_to_text)(char *buf,
				       size_t size,
				       const struct bkey *k);
	void		(*key_dump)(struct btree_keys *keys,
				    const struct bkey *k);

	/*
	 * Only used for deciding whether to use START_KEY(k) or just the key
	 * itself in a couple places
	 */
	bool		is_extents;
};

struct btree_keys {
	const struct btree_keys_ops	*ops;
	uint8_t			page_order;
	uint8_t			nsets;
	unsigned int		last_set_unwritten:1;
	bool			*expensive_debug_checks;

	/*
	 * Sets of sorted keys - the real btree node - plus a binary search tree
	 *
	 * set[0] is special; set[0]->tree, set[0]->prev and set[0]->data point
	 * to the memory we have allocated for this btree node. Additionally,
	 * set[0]->data points to the entire btree node as it exists on disk.
	 */
	struct bset_tree	set[MAX_BSETS];
};

static inline struct bset_tree *bset_tree_last(struct btree_keys *b)
{
	return b->set + b->nsets;
}

static inline bool bset_written(struct btree_keys *b, struct bset_tree *t)
{
	return t <= b->set + b->nsets - b->last_set_unwritten;
}

static inline bool bkey_written(struct btree_keys *b, struct bkey *k)
{
	return !b->last_set_unwritten || k < b->set[b->nsets].data->start;

Annotation

Implementation Notes