Skip to content

Commit d2d647a

Browse files
redpigBadhri Jagan Sridharan
authored and
Badhri Jagan Sridharan
committed
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: Will Drewry <[email protected]> Review URL: http://codereview.chromium.org/2020011 Change-Id: I92bd53432a11241228d2e5ac89a3b20d19b05a31
1 parent e947df5 commit d2d647a

File tree

9 files changed

+516
-0
lines changed

9 files changed

+516
-0
lines changed

Documentation/device-mapper/boot.txt

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
Boot time creation of mapped devices
2+
===================================
3+
4+
It is possible to configure a device mapper device to act as the root
5+
device for your system in two ways.
6+
7+
The first is to build an initial ramdisk which boots to a minimal
8+
userspace which configures the device, then pivot_root(8) in to it.
9+
10+
For simple device mapper configurations, it is possible to boot directly
11+
using the following kernel command line:
12+
13+
dm="<name> <uuid> <ro>,table line 1,...,table line n"
14+
15+
name = the name to associate with the device
16+
after boot, udev, if used, will use that name to label
17+
the device node.
18+
uuid = may be 'none' or the UUID desired for the device.
19+
ro = may be "ro" or "rw". If "ro", the device and device table will be
20+
marked read-only.
21+
22+
Each table line may be as normal when using the dmsetup tool except for
23+
two variations:
24+
1. Any use of commas will be interpreted as a newline
25+
2. Quotation marks cannot be escaped and cannot be used without
26+
terminating the dm= argument.
27+
28+
Unless renamed by udev, the device node created will be dm-0 as the
29+
first minor number for the device-mapper is used during early creation.
30+
31+
Example
32+
=======
33+
34+
- Booting to a linear array made up of user-mode linux block devices:
35+
36+
dm="lroot none 0, 0 4096 linear 98:16 0, 4096 4096 linear 98:32 0" \
37+
root=/dev/dm-0
38+
39+
Will boot to a rw dm-linear target of 8192 sectors split across two
40+
block devices identified by their major:minor numbers. After boot, udev
41+
will rename this target to /dev/mapper/lroot (depending on the rules).
42+
No uuid was assigned.

Documentation/kernel-parameters.txt

+6
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ parameter is applicable:
4646
BLACKFIN Blackfin architecture is enabled.
4747
CLK Common clock infrastructure is enabled.
4848
CMA Contiguous Memory Area support is enabled.
49+
DM Device mapper support is enabled.
4950
DRM Direct Rendering Management support is enabled.
5051
DYNAMIC_DEBUG Build in debug messages and enable them at runtime
5152
EDD BIOS Enhanced Disk Drive Services (EDD) is enabled
@@ -741,6 +742,11 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
741742
Disable PIN 1 of APIC timer
742743
Can be useful to work around chipset bugs.
743744

745+
dm= [DM] Allows early creation of a device-mapper device.
746+
See Documentation/device-mapper/boot.txt.
747+
748+
dmasound= [HW,OSS] Sound subsystem buffers
749+
744750
dma_debug=off If the kernel is compiled with DMA_API_DEBUG support,
745751
this option disables the debugging code at boot.
746752

drivers/md/dm-ioctl.c

+39
Original file line numberDiff line numberDiff line change
@@ -1846,6 +1846,45 @@ void dm_interface_exit(void)
18461846
dm_hash_exit();
18471847
}
18481848

1849+
1850+
/**
1851+
* dm_ioctl_export - Permanently export a mapped device via the ioctl interface
1852+
* @md: Pointer to mapped_device
1853+
* @name: Buffer (size DM_NAME_LEN) for name
1854+
* @uuid: Buffer (size DM_UUID_LEN) for uuid or NULL if not desired
1855+
*/
1856+
int dm_ioctl_export(struct mapped_device *md, const char *name,
1857+
const char *uuid)
1858+
{
1859+
int r = 0;
1860+
struct hash_cell *hc;
1861+
1862+
if (!md) {
1863+
r = -ENXIO;
1864+
goto out;
1865+
}
1866+
1867+
/* The name and uuid can only be set once. */
1868+
mutex_lock(&dm_hash_cells_mutex);
1869+
hc = dm_get_mdptr(md);
1870+
mutex_unlock(&dm_hash_cells_mutex);
1871+
if (hc) {
1872+
DMERR("%s: already exported", dm_device_name(md));
1873+
r = -ENXIO;
1874+
goto out;
1875+
}
1876+
1877+
r = dm_hash_insert(name, uuid, md);
1878+
if (r) {
1879+
DMERR("%s: could not bind to '%s'", dm_device_name(md), name);
1880+
goto out;
1881+
}
1882+
1883+
/* Let udev know we've changed. */
1884+
dm_kobject_uevent(md, KOBJ_CHANGE, dm_get_event_nr(md));
1885+
out:
1886+
return r;
1887+
}
18491888
/**
18501889
* dm_copy_name_and_uuid - Copy mapped device name & uuid into supplied buffers
18511890
* @md: Pointer to mapped_device

drivers/md/dm-table.c

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <linux/vmalloc.h>
1212
#include <linux/blkdev.h>
1313
#include <linux/namei.h>
14+
#include <linux/mount.h>
1415
#include <linux/ctype.h>
1516
#include <linux/string.h>
1617
#include <linux/slab.h>

include/linux/device-mapper.h

+6
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,12 @@ void dm_put(struct mapped_device *md);
380380
void dm_set_mdptr(struct mapped_device *md, void *ptr);
381381
void *dm_get_mdptr(struct mapped_device *md);
382382

383+
/*
384+
* Export the device via the ioctl interface (uses mdptr).
385+
*/
386+
int dm_ioctl_export(struct mapped_device *md, const char *name,
387+
const char *uuid);
388+
383389
/*
384390
* A device can still be used while suspended, but I/O is deferred.
385391
*/

init/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ mounts-y := do_mounts.o
1515
mounts-$(CONFIG_BLK_DEV_RAM) += do_mounts_rd.o
1616
mounts-$(CONFIG_BLK_DEV_INITRD) += do_mounts_initrd.o
1717
mounts-$(CONFIG_BLK_DEV_MD) += do_mounts_md.o
18+
mounts-$(CONFIG_BLK_DEV_DM) += do_mounts_dm.o
1819

1920
# dependencies on generated files need to be listed explicitly
2021
$(obj)/version.o: include/generated/compile.h

init/do_mounts.c

+1
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,7 @@ void __init prepare_namespace(void)
551551
wait_for_device_probe();
552552

553553
md_run_setup();
554+
dm_run_setup();
554555

555556
if (saved_root_name[0]) {
556557
root_device_name = saved_root_name;

init/do_mounts.h

+10
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,13 @@ void md_run_setup(void);
7474
static inline void md_run_setup(void) {}
7575

7676
#endif
77+
78+
#ifdef CONFIG_BLK_DEV_DM
79+
80+
void dm_run_setup(void);
81+
82+
#else
83+
84+
static inline void dm_run_setup(void) {}
85+
86+
#endif

0 commit comments

Comments
 (0)