Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 077d23c5 authored by Will Drewry's avatar Will Drewry Committed by Amit Pundir
Browse files

CHROMIUM: dm: boot time specification of dm=

This is a wrap-up of three patches pending upstream approval.
I'm bundling them because they are interdependent, and it'll be
easier to drop it on rebase later.

1. dm: allow a dm-fs-style device to be shared via dm-ioctl

Integrates feedback from Alisdair, Mike, and Kiyoshi.

Two main changes occur here:

- One function is added which allows for a programmatically created
mapped device to be inserted into the dm-ioctl hash table.  This binds
the device to a name and, optional, uuid which is needed by udev and
allows for userspace management of the mapped device.

- dm_table_complete() was extended to handle all of the final
functional changes required for the table to be operational once
called.

2. init: boot to device-mapper targets without an initr*

Add a dm= kernel parameter modeled after the md= parameter from
do_mounts_md.  It allows for device-mapper targets to be configured at
boot time for use early in the boot process (as the root device or
otherwise).  It also replaces /dev/XXX calls with major:minor opportunistically.

The format is dm="name uuid ro,table line 1,table line 2,...".  The
parser expects the comma to be safe to use as a newline substitute but,
otherwise, uses the normal separator of space.  Some attempt has been
made to make it forgiving of additional spaces (using skip_spaces()).

A mapped device created during boot will be assigned a minor of 0 and
may be access via /dev/dm-0.

An example dm-linear root with no uuid may look like:

root=/dev/dm-0  dm="lroot none ro, 0 4096 linear /dev/ubdb 0, 4096 4096 linear /dv/ubdc 0"

Once udev is started, /dev/dm-0 will become /dev/mapper/lroot.

Older upstream threads:
http://marc.info/?l=dm-devel&m=127429492521964&w=2
http://marc.info/?l=dm-devel&m=127429499422096&w=2
http://marc.info/?l=dm-devel&m=127429493922000&w=2

Latest upstream threads:
https://patchwork.kernel.org/patch/104859/
https://patchwork.kernel.org/patch/104860/
https://patchwork.kernel.org/patch/104861/



Bug: 27175947

Signed-off-by: default avatarWill Drewry <wad@chromium.org>

Review URL: http://codereview.chromium.org/2020011

Change-Id: I92bd53432a11241228d2e5ac89a3b20d19b05a31
parent 5ae143ff
Loading
Loading
Loading
Loading
+42 −0
Original line number Diff line number Diff line
Boot time creation of mapped devices
===================================

It is possible to configure a device mapper device to act as the root
device for your system in two ways.

The first is to build an initial ramdisk which boots to a minimal
userspace which configures the device, then pivot_root(8) in to it.

For simple device mapper configurations, it is possible to boot directly
using the following kernel command line:

dm="<name> <uuid> <ro>,table line 1,...,table line n"

name = the name to associate with the device
	after boot, udev, if used, will use that name to label
	the device node.
uuid = may be 'none' or the UUID desired for the device.
ro = may be "ro" or "rw".  If "ro", the device and device table will be
	marked read-only.

Each table line may be as normal when using the dmsetup tool except for
two variations:
1. Any use of commas will be interpreted as a newline
2. Quotation marks cannot be escaped and cannot be used without
   terminating the dm= argument.

Unless renamed by udev, the device node created will be dm-0 as the
first minor number for the device-mapper is used during early creation.

Example
=======

- Booting to a linear array made up of user-mode linux block devices:

  dm="lroot none 0, 0 4096 linear 98:16 0, 4096 4096 linear 98:32 0" \
  root=/dev/dm-0

Will boot to a rw dm-linear target of 8192 sectors split across two
block devices identified by their major:minor numbers.  After boot, udev
will rename this target to /dev/mapper/lroot (depending on the rules).
No uuid was assigned.
+6 −0
Original line number Diff line number Diff line
@@ -87,6 +87,7 @@ parameter is applicable:
	BLACKFIN Blackfin architecture is enabled.
	CLK	Common clock infrastructure is enabled.
	CMA	Contiguous Memory Area support is enabled.
	DM	Device mapper support is enabled.
	DRM	Direct Rendering Management support is enabled.
	DYNAMIC_DEBUG Build in debug messages and enable them at runtime
	EDD	BIOS Enhanced Disk Drive Services (EDD) is enabled
@@ -1025,6 +1026,11 @@ bytes respectively. Such letter suffixes can also be entirely omitted.

	dis_ucode_ldr	[X86] Disable the microcode loader.

	dm=		[DM] Allows early creation of a device-mapper device.
			See Documentation/device-mapper/boot.txt.

	dmasound=	[HW,OSS] Sound subsystem buff

	dma_debug=off	If the kernel is compiled with DMA_API_DEBUG support,
			this option disables the debugging code at boot.

+39 −0
Original line number Diff line number Diff line
@@ -1927,6 +1927,45 @@ void dm_interface_exit(void)
	dm_hash_exit();
}


/**
 * dm_ioctl_export - Permanently export a mapped device via the ioctl interface
 * @md: Pointer to mapped_device
 * @name: Buffer (size DM_NAME_LEN) for name
 * @uuid: Buffer (size DM_UUID_LEN) for uuid or NULL if not desired
 */
int dm_ioctl_export(struct mapped_device *md, const char *name,
		    const char *uuid)
{
	int r = 0;
	struct hash_cell *hc;

	if (!md) {
		r = -ENXIO;
		goto out;
	}

	/* The name and uuid can only be set once. */
	mutex_lock(&dm_hash_cells_mutex);
	hc = dm_get_mdptr(md);
	mutex_unlock(&dm_hash_cells_mutex);
	if (hc) {
		DMERR("%s: already exported", dm_device_name(md));
		r = -ENXIO;
		goto out;
	}

	r = dm_hash_insert(name, uuid, md);
	if (r) {
		DMERR("%s: could not bind to '%s'", dm_device_name(md), name);
		goto out;
	}

	/* Let udev know we've changed. */
	dm_kobject_uevent(md, KOBJ_CHANGE, dm_get_event_nr(md));
out:
	return r;
}
/**
 * dm_copy_name_and_uuid - Copy mapped device name & uuid into supplied buffers
 * @md: Pointer to mapped_device
+1 −0
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@
#include <linux/vmalloc.h>
#include <linux/blkdev.h>
#include <linux/namei.h>
#include <linux/mount.h>
#include <linux/ctype.h>
#include <linux/string.h>
#include <linux/slab.h>
+6 −0
Original line number Diff line number Diff line
@@ -407,6 +407,12 @@ void dm_put(struct mapped_device *md);
void dm_set_mdptr(struct mapped_device *md, void *ptr);
void *dm_get_mdptr(struct mapped_device *md);

/*
 * Export the device via the ioctl interface (uses mdptr).
 */
int dm_ioctl_export(struct mapped_device *md, const char *name,
		    const char *uuid);

/*
 * A device can still be used while suspended, but I/O is deferred.
 */
Loading