drivers/md/dm-table.c

Source file repositories/reference/linux-study-clean/drivers/md/dm-table.c

File Facts

System
Linux kernel
Corpus path
drivers/md/dm-table.c
Extension
.c
Size
55373 bytes
Lines
2232
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 dm_crypto_profile {
	struct blk_crypto_profile profile;
	struct mapped_device *md;
};

static int dm_keyslot_evict_callback(struct dm_target *ti, struct dm_dev *dev,
				     sector_t start, sector_t len, void *data)
{
	const struct blk_crypto_key *key = data;

	blk_crypto_evict_key(dev->bdev, key);
	return 0;
}

/*
 * When an inline encryption key is evicted from a device-mapper device, evict
 * it from all the underlying devices.
 */
static int dm_keyslot_evict(struct blk_crypto_profile *profile,
			    const struct blk_crypto_key *key, unsigned int slot)
{
	struct mapped_device *md =
		container_of(profile, struct dm_crypto_profile, profile)->md;
	struct dm_table *t;
	int srcu_idx;

	t = dm_get_live_table(md, &srcu_idx);
	if (!t)
		goto put_live_table;

	for (unsigned int i = 0; i < t->num_targets; i++) {
		struct dm_target *ti = dm_table_get_target(t, i);

		if (!ti->type->iterate_devices)
			continue;
		ti->type->iterate_devices(ti, dm_keyslot_evict_callback,
					  (void *)key);
	}

put_live_table:
	dm_put_live_table(md, srcu_idx);
	return 0;
}

enum dm_wrappedkey_op {
	DERIVE_SW_SECRET,
	IMPORT_KEY,
	GENERATE_KEY,
	PREPARE_KEY,
};

struct dm_wrappedkey_op_args {
	enum dm_wrappedkey_op op;
	int err;
	union {
		struct {
			const u8 *eph_key;
			size_t eph_key_size;
			u8 *sw_secret;
		} derive_sw_secret;
		struct {
			const u8 *raw_key;
			size_t raw_key_size;
			u8 *lt_key;
		} import_key;
		struct {
			u8 *lt_key;
		} generate_key;
		struct {
			const u8 *lt_key;
			size_t lt_key_size;
			u8 *eph_key;
		} prepare_key;
	};
};

static int dm_wrappedkey_op_callback(struct dm_target *ti, struct dm_dev *dev,
				     sector_t start, sector_t len, void *data)
{
	struct dm_wrappedkey_op_args *args = data;
	struct block_device *bdev = dev->bdev;
	struct blk_crypto_profile *profile =
		bdev_get_queue(bdev)->crypto_profile;
	int err = -EOPNOTSUPP;

	switch (args->op) {
	case DERIVE_SW_SECRET:
		err = blk_crypto_derive_sw_secret(
					bdev,
					args->derive_sw_secret.eph_key,

Annotation

Implementation Notes