dm: allow a dm-fs-style device to be shared via dm-ioctl
Subsystems (4)
PATCH v3 1/3 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.
--- drivers/md/dm-ioctl.c | 72 +++++++++++++++++++++------------------- drivers/md/dm-table.c | 50 ++++++++++++++++++++++++++++- include/linux/device-mapper.h | 6 +++ 3 files changed, 93 insertions(+), 35 deletions(-)
drivers/md/dm-ioctl.c +38 -34
@@ -1112,28 +1112,9 @@ static int populate_table(struct dm_table *table, next = spec->next; } - r =dm_table_set_type (table); -if (r) { -DMWARN ("unable to set table type" ); -return r; - } -return dm_table_complete (table); } -static int table_prealloc_integrity (struct dm_table *t, -struct mapped_device *md) -{ -struct list_head *devices =dm_table_get_devices (t); -struct dm_dev_internal *dd; - -list_for_each_entry (dd, devices, list) -if (bdev_get_integrity (dd->dm_dev.bdev)) -return blk_integrity_register (dm_disk (md),NULL ); - -return 0 ; -} -static int table_load (struct dm_ioctl *param,size_t param_size) {int r;
@@ -1155,21 +1136,6 @@ static int table_load(struct dm_ioctl *param, size_t param_size) goto out; } - r =table_prealloc_integrity (t, md); -if (r) { -DMERR ("%s: could not register integrity profile." , -dm_device_name (md)); -dm_table_destroy (t); - goto out; - } - - r =dm_table_alloc_md_mempools (t); -if (r) { -DMWARN ("unable to allocate mempools for this table" ); -dm_table_destroy (t); - goto out; - } -down_write (&_hash_lock); hc =dm_get_mdptr (md);if (!hc || hc->md != md) {
@@ -1637,6 +1603,44 @@ 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
drivers/md/dm-table.c +49 -1
62 lines not on this page · raw message
include/linux/device-mapper.h +6 -0
@@ -215,6 +215,12 @@ 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. */ int dm_suspend (struct mapped_device *md,unsigned suspend_flags);
Signature · 1 line
1.7.0.4
PATCH v3 2/3 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).
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 0, 0 4096 linear /dev/ubdb 0, 4096 4096 linear /dv/ubdc 0"
Once udev is started, /dev/dm-0 will become /dev/mapper/lroot.
--- Documentation/device-mapper/boot.txt | 42 ++++ Documentation/kernel-parameters.txt | 4 + init/Makefile | 1 + init/do_mounts.c | 1 + init/do_mounts.h | 10 + init/do_mounts_dm.c | 353 ++++++++++++++++++++++++++++++++++ 6 files changed, 411 insertions(+), 0 deletions(-) create mode 100644 Documentation/device-mapper/boot.txt create mode 100644 init/do_mounts_dm.c
Documentation/device-mapper/boot.txt new file +42 -0
@@ -0,0 +1,42 @@ +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 0 or 1. If non-zero, 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.
Documentation/kernel-parameters.txt +4 -0
@@ -43,6 +43,7 @@ parameter is applicable: AVR32 AVR32 architecture is enabled. AX25 Appropriate AX.25 support is enabled. BLACKFIN Blackfin architecture is enabled. + DM Device mapper support is enabled. DRM Direct Rendering Management support is enabled. EDD BIOS Enhanced Disk Drive Services (EDD) is enabled EFI EFI Partitioning (GPT) is enabled
@@ -654,6 +655,9 @@ and is between 256 and 4096 characters. It is defined in the file Disable PIN 1 of APIC timer Can be useful to work around chipset bugs. + dm= [DM] Allows early creation of a device-mapper device. + See Documentation/device-mapper/boot.txt. + dmasound= [HW,OSS] Sound subsystem buffers dma_debug=off If the kernel is compiled with DMA_API_DEBUG support,
init/Makefile +1 -0
@@ -14,6 +14,7 @@ mounts-y := do_mounts.o mounts-$(CONFIG_BLK_DEV_RAM) += do_mounts_rd.o mounts-$(CONFIG_BLK_DEV_INITRD) += do_mounts_initrd.o mounts-$(CONFIG_BLK_DEV_MD) += do_mounts_md.o +mounts-$(CONFIG_BLK_DEV_DM) += do_mounts_dm.o # dependencies on generated files need to be listed explicitly $(obj)/version.o: include/generated/compile.h
init/do_mounts.c +1 -0
@@ -383,6 +383,7 @@ void __init prepare_namespace(void)wait_for_device_probe ();md_run_setup (); +dm_run_setup ();if (saved_root_name[0 ]) { root_device_name = saved_root_name;
init/do_mounts.h +10 -0
@@ -74,3 +74,13 @@ void md_run_setup(void);static inline void md_run_setup (void ) {}#endif + +#ifdef CONFIG_BLK_DEV_DM + +void dm_run_setup (void ); + +#else + +static inline void dm_run_setup (void ) {} + +#endif
init/do_mounts_dm.c new file +353 -0
353 lines not on this page · raw message
Signature · 1 line
1.7.0.4
Re: [PATCH v3 2/3] init: boot to device-mapper targets without an initr*
Quoted 5 lines
An example dm-linear root with no uuid may look like:
root=/dev/dm-0 dm="lroot none 0, 0 4096 linear
/dev/ubdb0, 4096 4096 linear /dv/ubdc 0"Once udev is started,
/dev/dm-0will become/dev/mapper/lroot.
Hi,
I'm having the problem that the device - for example - won't come available at "/dev/mapper/lroot" but at "/dev/mapper/lroot ". There is an additional space at the end of the name, which is...lets say not so good. The problem is exists already in the dm_setup_args.name field, so I think is a problem parsing the arguments.
I'm new around here, so I don't know how things work. Should I look into the problem myself and post a fix, or will the author of the patch?
Anselm
Re: [PATCH v3 2/3] init: boot to device-mapper targets without an initr*
Quoted 11 lines · Anselm Busse
Quoted 5 lines
An example dm-linear root with no uuid may look like:
root=/dev/dm-0 dm="lroot none 0, 0 4096 linear
/dev/ubdb0, 4096 4096 linear /dv/ubdc 0"Once udev is started,
/dev/dm-0will become/dev/mapper/lroot.Hi,
I'm having the problem that the device - for example - won't come available at "
/dev/mapper/lroot" but at "/dev/mapper/lroot". There is an additional space at the end of the name, which is...lets say not so good. The problem is exists already in the dm_setup_args.name field, so I think is a problem parsing the arguments.I'm new around here, so I don't know how things work. Should I look into the problem myself and post a fix, or will the author of the patch?
Hi Anselm!
I'm new around here too :) There is an off-by-one where it calls strlcpy(..., len + 1). I have a new patch to post but have been traveling and haven't had a chance to get it posted. I'll try to mail it out today!
I think that since I have posted the patch but it hasn't yet been picked up, the best thing (for me) was just to mail the list like you did and let the author (me) know there is an issue in the patch, and then see if they are responsive before posting your own patch. But maybe someone who isn't new here should respond :)
Needless to say, I'll post a new patch soon. The fix is:
+ strlcpy(dm_setup_args.name, str, len + 1); /* includes nul */
becomes
+ strlcpy(dm_setup_args.name, str, len); /* includes nul */
because I've already incremented len in the previous line.
cheers!
will
PATCH v3 3/3 dm: lookup devices by path with name_to_dev_t
In reply to Will DrewryReplace major:minor parsing with name_to_dev_t. This maintains the current functionality (as the code was the same), but adds support for the hexadecimal dev as well as device lookup before the root filesystem is available. The latter is the motivation for this change.
It still falls back to lookup_bdev() for cases where the inode on disk provides more information than the name (and the path exceeds the length handled by name_to_dev_t).
--- drivers/md/dm-table.c | 16 ++++++++-------- 1 files changed, 8 insertions(+), 8 deletions(-)
drivers/md/dm-table.c +8 -8
@@ -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>
@@ -434,17 +435,16 @@ static int __table_get_device(struct dm_table *t, struct dm_target *ti,int r;dev_t uninitialized_var (dev );struct dm_dev_internal *dd; -unsigned int major, minor; +char base_path[32 ];/* size from name_to_dev_t */ BUG_ON (!t); -if (sscanf (path,"%u:%u" , &major, &minor) ==2 ) { -/* Extract the major/minor numbers */ - dev =MKDEV (major, minor); -if (MAJOR (dev) != major ||MINOR (dev) != minor) -return -EOVERFLOW ; - }else { -/* convert the path to a device */ +/* stage the shorter path for name_to_dev_t. */ +strncpy (base_path, path,sizeof (base_path)); + +/* lookup by major:minor or registered device name */ +if (!(dev =name_to_dev_t (base_path))) { +/* convert the path to a device by finding its inode */ struct block_device *bdev =lookup_bdev (path);if (IS_ERR (bdev))
Signature · 1 line
1.7.0.4
Alasdair G Kergon
maintainerRe: [dm-devel] [PATCH v3 3/3] dm: lookup devices by path with name_to_dev_t
Quoted 9 lines · Will Drewry
Replace major:minor parsing with
name_to_dev_t. This maintains the current functionality (as the code was the same), but adds support for the hexadecimal dev as well as device lookup before the root filesystem is available. The latter is the motivation for this change.It still falls back to
lookup_bdev()for cases where the inode on disk provides more information than the name (and the path exceeds the length handled byname_to_dev_t).
I'll apply this, but anyone debugging problems in future should note the functional change here: the standard in-kernel device names will now take precedence over the inodes in /dev if the two don't match and this might confuse people. As it's technically an interface change, I'll bump the version number so userspace can detect this if it ever needs to.
Alasdair
Alasdair G Kergon
maintainerRe: [dm-devel] [PATCH v3 3/3] dm: lookup devices by path with name_to_dev_t
In reply to Will Drewrydrivers/md/dm-table.c static int __table_get_device(struct dm_table *t, struct dm_target *ti, · line 443
Quoted 4 lines · Will Drewry
drivers/md/dm-table.c +3
-0+char base_path[32 ];/* size from name_to_dev_t */ +/* stage the shorter path for name_to_dev_t. */ +strncpy (base_path, path,sizeof (base_path));
I'm dropping that, and just passing path directly, so the strlen test will be used. (There's a "name += 5" in there so 32 would ignore any longer standard names anyway.)
Alasdair
Re: [dm-devel] [PATCH v3 3/3] dm: lookup devices by path with name_to_dev_t
Quoted 1 line · Alasdair G Kergon
I'll apply this, [snip]
Thanks!
Quoted 9 lines · Alasdair G Kergon
Quoted 4 lines · Will Drewry
+ char base_path[32]; /* size from
name_to_dev_t*/+ /* stage the shorter path for
name_to_dev_t. */
+strncpy(base_path, path, sizeof(base_path));I'm dropping that, and just passing path directly, so the strlen test will be used. (There's a "name += 5" in there so 32 would ignore any longer standard names anyway.)
Sounds good. And nice catch on the truncation with 32 - in an attempt to minimize the extra copying, I went a bit too far!
fwiw, the only reason for the copy was because |path| is a const in the function but not when passed to name_to_dev_t. I wasn't sure what the preferred practice was so I just duped the data needed.
cheers!
will
Alasdair G Kergon
maintainerRe: [dm-devel] [PATCH v3 3/3] dm: lookup devices by path with name_to_dev_t
Quoted 4 lines · Will Drewry
fwiw, the only reason for the copy was because |path| is a const in the function but not when passed to
name_to_dev_t. I wasn't sure what the preferred practice was so I just duped the data needed.
Well check that it is treated as 'const' and send a separate patch to the maintainer to add const, perhaps? If it isn't const (why would that be?), then yes we'd need to copy it.
Alasdair
Re: [dm-devel] [PATCH v3 3/3] dm: lookup devices by path with name_to_dev_t
Quoted 9 lines · Alasdair G Kergon
Quoted 4 lines · Will Drewry
fwiw, the only reason for the copy was because |path| is a const in the function but not when passed to
name_to_dev_t. I wasn't sure what the preferred practice was so I just duped the data needed.Well check that it is treated as 'const' and send a separate patch to the maintainer to add const, perhaps? If it isn't const (why would that be?), then yes we'd need to copy it.
I'll cross-check the code again and send a patch out if it looks like it is const-safe.
thanks,
will
Re: [PATCH v3 3/3] dm: lookup devices by path with name_to_dev_t
Quoted 7 lines · Will Drewry
Quoted 6 lines · Alasdair G Kergon
Quoted 4 lines · Will Drewry
fwiw, the only reason for the copy was because |path| is a const in the function but not when passed to
name_to_dev_t. I wasn't sure what the preferred practice was so I just duped the data needed.
Quoted 6 lines
Quoted 3 lines
Well check that it is treated as 'const' and send a separate patch to the maintainer to add const, perhaps? If it isn't const (why would that be?), then yes we'd need to copy it.
I'll cross-check the code again and send a patch out if it looks like it is const-safe.
Also, it would see that name_to_dev_t is EXPORT_SYMBOL?
Mike
Re: [PATCH v3 3/3] dm: lookup devices by path with name_to_dev_t
Quoted 10 lines · Mike Snitzer
Quoted 7 lines · Will Drewry
Quoted 6 lines · Alasdair G Kergon
Quoted 4 lines · Will Drewry
fwiw, the only reason for the copy was because |path| is a const in the function but not when passed to
name_to_dev_t. I wasn't sure what the preferred practice was so I just duped the data needed.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Well check that it is treated as 'const' and send a separate patch to the maintainer to add const, perhaps? If it isn't const (why would that be?), then yes we'd need to copy it.
I'll cross-check the code again and send a patch out if it looks like it is const-safe.
Also, it would see that
name_to_dev_tisEXPORT_SYMBOL?
Bleh, I typed that way too quick:
Also, it would seem that name_to_dev_t is _not_ EXPORT_SYMBOL?
Regards,
Mike
Re: [PATCH v3 3/3] dm: lookup devices by path with name_to_dev_t
Quoted 17 lines · Mike Snitzer
Quoted 14 lines · Mike Snitzer
Quoted 11 lines · Will Drewry
Quoted 9 lines · Alasdair G Kergon
Quoted 4 lines · Will Drewry
fwiw, the only reason for the copy was because |path| is a const in the function but not when passed to
name_to_dev_t. I wasn't sure what the preferred practice was so I just duped the data needed.Well check that it is treated as 'const' and send a separate patch to the maintainer to add const, perhaps? If it isn't const (why would that be?), then yes we'd need to copy it.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
I'll cross-check the code again and send a patch out if it looks like it is const-safe.
Also, it would see that
name_to_dev_tisEXPORT_SYMBOL?Bleh, I typed that way too quick:
Also, it would seem thatname_to_dev_tis _not_EXPORT_SYMBOL?
I've just mailed out a patch for each issue:
- const char *: https://patchwork.kernel.org/patch/102228/
- export_symbol: https://patchwork.kernel.org/patch/102229/
Cheers!
will
PATCH 1/2 dm: ensure dm_table_complete() completes a table for use
In reply to Will DrewryThis patchset breaks up the patch linked below:
https://patchwork.kernel.org/patch/101026/
This change unifies the various checks and finalization that occurs on a table prior to use. By doing so, it allows table construction without traversing the dm-ioctl interface.
--- drivers/md/dm-ioctl.c | 34 --------------------------------- drivers/md/dm-table.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 35 deletions(-)
drivers/md/dm-ioctl.c +0 -34
@@ -1112,28 +1112,9 @@ static int populate_table(struct dm_table *table, next = spec->next; } - r =dm_table_set_type (table); -if (r) { -DMWARN ("unable to set table type" ); -return r; - } -return dm_table_complete (table); } -static int table_prealloc_integrity (struct dm_table *t, -struct mapped_device *md) -{ -struct list_head *devices =dm_table_get_devices (t); -struct dm_dev_internal *dd; - -list_for_each_entry (dd, devices, list) -if (bdev_get_integrity (dd->dm_dev.bdev)) -return blk_integrity_register (dm_disk (md),NULL ); - -return 0 ; -} -static int table_load (struct dm_ioctl *param,size_t param_size) {int r;
@@ -1155,21 +1136,6 @@ static int table_load(struct dm_ioctl *param, size_t param_size) goto out; } - r =table_prealloc_integrity (t, md); -if (r) { -DMERR ("%s: could not register integrity profile." , -dm_device_name (md)); -dm_table_destroy (t); - goto out; - } - - r =dm_table_alloc_md_mempools (t); -if (r) { -DMWARN ("unable to allocate mempools for this table" ); -dm_table_destroy (t); - goto out; - } -down_write (&_hash_lock); hc =dm_get_mdptr (md);if (!hc || hc->md != md) {
drivers/md/dm-table.c +49 -1
62 lines not on this page · raw message
Signature · 1 line
1.7.0.4
PATCH 2/2 dm: export a table+mapped device to the ioctl interface
In reply to Will DrewryIf a mapped device and table is configured without traversing the dm-ioctl interface (dm-fs-style), then it will not be bound to a name or uuid. This means that it will be inaccessible for userspace management and udev will be unhappy with the lack of a name or uuid.
The function added in this change performs the required association to transition to being managed by the ioctl interface.
--- drivers/md/dm-ioctl.c | 38 ++++++++++++++++++++++++++++++++++++++ include/linux/device-mapper.h | 6 ++++++ 2 files changed, 44 insertions(+), 0 deletions(-)
drivers/md/dm-ioctl.c +38 -0
@@ -1604,6 +1604,44 @@ void dm_interface_exit(void) }/** +* 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 * @name: Buffer (size DM_NAME_LEN) for name
include/linux/device-mapper.h +6 -0
@@ -215,6 +215,12 @@ 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. */ int dm_suspend (struct mapped_device *md,unsigned suspend_flags);
Signature · 1 line
1.7.0.4
PATCH v4 1/3 dm: ensure dm_table_complete() completes a table for use
In reply to Will DrewryThis change unifies the various checks and finalization that occurs on a table prior to use. By doing so, it allows table construction without traversing the dm-ioctl interface.
v4: same as v3 but rebundling
--- drivers/md/dm-ioctl.c | 34 --------------------------------- drivers/md/dm-table.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 35 deletions(-)
drivers/md/dm-ioctl.c +0 -34
@@ -1112,28 +1112,9 @@ static int populate_table(struct dm_table *table, next = spec->next; } - r =dm_table_set_type (table); -if (r) { -DMWARN ("unable to set table type" ); -return r; - } -return dm_table_complete (table); } -static int table_prealloc_integrity (struct dm_table *t, -struct mapped_device *md) -{ -struct list_head *devices =dm_table_get_devices (t); -struct dm_dev_internal *dd; - -list_for_each_entry (dd, devices, list) -if (bdev_get_integrity (dd->dm_dev.bdev)) -return blk_integrity_register (dm_disk (md),NULL ); - -return 0 ; -} -static int table_load (struct dm_ioctl *param,size_t param_size) {int r;
@@ -1155,21 +1136,6 @@ static int table_load(struct dm_ioctl *param, size_t param_size) goto out; } - r =table_prealloc_integrity (t, md); -if (r) { -DMERR ("%s: could not register integrity profile." , -dm_device_name (md)); -dm_table_destroy (t); - goto out; - } - - r =dm_table_alloc_md_mempools (t); -if (r) { -DMWARN ("unable to allocate mempools for this table" ); -dm_table_destroy (t); - goto out; - } -down_write (&_hash_lock); hc =dm_get_mdptr (md);if (!hc || hc->md != md) {
drivers/md/dm-table.c +49 -1
62 lines not on this page · raw message
Signature · 1 line
1.7.0.4
PATCH v4 2/3 dm: export a table+mapped device to the ioctl interface
In reply to Will DrewryIf a mapped device and table is configured without traversing the dm-ioctl interface (dm-fs-style), then it will not be bound to a name or uuid. This means that it will be inaccessible for userspace management and udev will be unhappy with the lack of a name or uuid.
The function added in this change performs the required association to transition to being managed by the ioctl interface.
v4: same as v3 but keeping bundled
--- drivers/md/dm-ioctl.c | 38 ++++++++++++++++++++++++++++++++++++++ include/linux/device-mapper.h | 6 ++++++ 2 files changed, 44 insertions(+), 0 deletions(-)
drivers/md/dm-ioctl.c +38 -0
@@ -1604,6 +1604,44 @@ void dm_interface_exit(void) }/** +* 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 * @name: Buffer (size DM_NAME_LEN) for name
include/linux/device-mapper.h +6 -0
@@ -215,6 +215,12 @@ 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. */ int dm_suspend (struct mapped_device *md,unsigned suspend_flags);
Signature · 1 line
1.7.0.4
PATCH v4 3/3 init: add support to directly boot to a mapped device
In reply to Will DrewryThis change adds a dm= kernel parameter modeled after the md= parameter from do_mounts_md. It allows for simple device-mapper targets to be configured at boot time for use early in the boot process (as the root device or otherwise).
The format is as follows:
dm="name uuid|none ro|rw, table line 1, table line 2, ..."
It relies on the ability to create a device mapper device programmatically and bind that device to the ioctl-style name/uuid. In addition, any /dev/... devices specified in the target parameters will attempt to be early-resolved with name_to_dev_t.
v4:
- introduces early device resolving with name_to_dev_t,
- moves to 'ro' and 'rw' from 0 and non-zero for read-only
--- Documentation/device-mapper/boot.txt | 42 ++++ Documentation/kernel-parameters.txt | 4 + init/Makefile | 1 + init/do_mounts.c | 1 + init/do_mounts.h | 10 + init/do_mounts_dm.c | 414 ++++++++++++++++++++++++++++++++++ 6 files changed, 472 insertions(+), 0 deletions(-) create mode 100644 Documentation/device-mapper/boot.txt create mode 100644 init/do_mounts_dm.c
Documentation/device-mapper/boot.txt new file +42 -0
@@ -0,0 +1,42 @@ +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.
Documentation/kernel-parameters.txt +4 -0
@@ -43,6 +43,7 @@ parameter is applicable: AVR32 AVR32 architecture is enabled. AX25 Appropriate AX.25 support is enabled. BLACKFIN Blackfin architecture is enabled. + DM Device mapper support is enabled. DRM Direct Rendering Management support is enabled. EDD BIOS Enhanced Disk Drive Services (EDD) is enabled EFI EFI Partitioning (GPT) is enabled
@@ -655,6 +656,9 @@ and is between 256 and 4096 characters. It is defined in the file Disable PIN 1 of APIC timer Can be useful to work around chipset bugs. + dm= [DM] Allows early creation of a device-mapper device. + See Documentation/device-mapper/boot.txt. + dmasound= [HW,OSS] Sound subsystem buffers dma_debug=off If the kernel is compiled with DMA_API_DEBUG support,
init/Makefile +1 -0
@@ -14,6 +14,7 @@ mounts-y := do_mounts.o mounts-$(CONFIG_BLK_DEV_RAM) += do_mounts_rd.o mounts-$(CONFIG_BLK_DEV_INITRD) += do_mounts_initrd.o mounts-$(CONFIG_BLK_DEV_MD) += do_mounts_md.o +mounts-$(CONFIG_BLK_DEV_DM) += do_mounts_dm.o # dependencies on generated files need to be listed explicitly $(obj)/version.o: include/generated/compile.h
init/do_mounts.c +1 -0
@@ -383,6 +383,7 @@ void __init prepare_namespace(void)wait_for_device_probe ();md_run_setup (); +dm_run_setup ();if (saved_root_name[0 ]) { root_device_name = saved_root_name;
init/do_mounts.h +10 -0
@@ -74,3 +74,13 @@ void md_run_setup(void);static inline void md_run_setup (void ) {}#endif + +#ifdef CONFIG_BLK_DEV_DM + +void dm_run_setup (void ); + +#else + +static inline void dm_run_setup (void ) {} + +#endif
init/do_mounts_dm.c new file +414 -0
414 lines not on this page · raw message
Signature · 1 line
1.7.0.4