drivers/md/dm-ioctl.c

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

File Facts

System
Linux kernel
Corpus path
drivers/md/dm-ioctl.c
Extension
.c
Size
58286 bytes
Lines
2495
Domain
Driver Families
Bucket
drivers/md
Inferred role
Driver Families: operation-table or driver-model contract
Status
pattern 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

static const struct file_operations _ctl_fops = {
	.open    = dm_open,
	.release = dm_release,
	.poll    = dm_poll,
	.unlocked_ioctl	 = dm_ctl_ioctl,
	.compat_ioctl = dm_compat_ctl_ioctl,
	.owner	 = THIS_MODULE,
	.llseek  = noop_llseek,
};

static struct miscdevice _dm_misc = {
	.minor		= MAPPER_CTRL_MINOR,
	.name		= DM_NAME,
	.nodename	= DM_DIR "/" DM_CONTROL_NODE,
	.fops		= &_ctl_fops
};

MODULE_ALIAS_MISCDEV(MAPPER_CTRL_MINOR);
MODULE_ALIAS("devname:" DM_DIR "/" DM_CONTROL_NODE);

/*
 * Create misc character device and link to DM_DIR/control.
 */
int __init dm_interface_init(void)
{
	int r;

	r = misc_register(&_dm_misc);
	if (r) {
		DMERR("misc_register failed for control device");
		return r;
	}

	DMINFO("%d.%d.%d%s initialised: %s", DM_VERSION_MAJOR,
	       DM_VERSION_MINOR, DM_VERSION_PATCHLEVEL, DM_VERSION_EXTRA,
	       DM_DRIVER_EMAIL);
	return 0;
}

void dm_interface_exit(void)
{
	misc_deregister(&_dm_misc);
	dm_hash_exit();
}

/**
 * dm_copy_name_and_uuid - Copy mapped device name & uuid into supplied buffers
 * @md: Pointer to mapped_device
 * @name: Buffer (size DM_NAME_LEN) for name
 * @uuid: Buffer (size DM_UUID_LEN) for uuid or empty string if uuid not defined
 */
int dm_copy_name_and_uuid(struct mapped_device *md, char *name, char *uuid)
{
	int r = 0;
	struct hash_cell *hc;

	if (!md)
		return -ENXIO;

	mutex_lock(&dm_hash_cells_mutex);
	hc = dm_get_mdptr(md);
	if (!hc) {
		r = -ENXIO;
		goto out;
	}

	if (name)
		strcpy(name, hc->name);
	if (uuid)
		strcpy(uuid, hc->uuid ? : "");

out:
	mutex_unlock(&dm_hash_cells_mutex);

	return r;
}
EXPORT_SYMBOL_GPL(dm_copy_name_and_uuid);

/**
 * dm_early_create - create a mapped device in early boot.
 *
 * @dmi: Contains main information of the device mapping to be created.
 * @spec_array: array of pointers to struct dm_target_spec. Describes the
 * mapping table of the device.
 * @target_params_array: array of strings with the parameters to a specific
 * target.
 *
 * Instead of having the struct dm_target_spec and the parameters for every
 * target embedded at the end of struct dm_ioctl (as performed in a normal
 * ioctl), pass them as arguments, so the caller doesn't need to serialize them.

Annotation

Implementation Notes