Skip to contentSkip to conversation

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

RFC PATCH Superseded Will Drewry 4 participants 10 messages May 14, 2010 – May 18, 2010

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 dm: allow a dm-fs-style device to be shared via dm-ioctl

Following on the discussion of booting directly to a device-mapper device, two things were made clear:
1. The ioctl interface's name and uuid are mandatory for udev to work
2. There is a functional gap between the dm(-fs) and dm-ioctl

This change adds one function which is used for binding a given mapped device to a name+uuid in the dm-ioctl hash table. In addition, it ensures that public functions are available that allow mapped devices and tables to be created and associated with shared code paths in dm-ioctl:
- suspend flags and block integrity registration are now exposed
- dm_table_complete() now prepares a table for use completely (builds the btree; sets the type; allocates md pools)

Ideally, this lays the groundwork for any kernel code to create fully functional mapped devices, but I'd appreciate feedback on if this approach makes sense/is safe, preferred function names, and if it integrates with the current direction.

(I can also pair this with the init code patch if it makes sense to show consumer code.)

---
 drivers/md/dm-ioctl.c         |   66 ++++++++++++++++++++++++-----------------
 drivers/md/dm-table.c         |   44 ++++++++++++++++++++++++++-
 include/linux/device-mapper.h |   17 ++++++++++
 3 files changed, 99 insertions(+), 28 deletions(-)
drivers/md/dm-ioctl.c +39 -27
index d7500e1..8dc5fd8 100644
@@ -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,7 +1136,7 @@ static int table_load(struct dm_ioctl *param, size_t param_size)
 		goto out;
 	}
 
-	r = table_prealloc_integrity(t, md);
+	r = dm_table_prealloc_integrity(t, md);
 	if (r) {
 		DMERR("%s: could not register integrity profile.",
 		      dm_device_name(md));
@@ -1163,13 +1144,6 @@ static int table_load(struct dm_ioctl *param, size_t param_size)
 		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 +1611,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 export as '%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 +43 -1

56 lines not on this page · raw message

include/linux/device-mapper.h +17 -0
index 1381cd9..95fea4c 100644
@@ -215,6 +215,18 @@ 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
+ */
+int dm_ioctl_export(struct mapped_device *md, const char *name,
+		    const char *uuid);
+
+/*
+ * Suspend feature flags
+ */
+#define DM_SUSPEND_LOCKFS_FLAG		(1 << 0)
+#define DM_SUSPEND_NOFLUSH_FLAG		(1 << 1)
+
+/*
  * A device can still be used while suspended, but I/O is deferred.
  */
 int dm_suspend(struct mapped_device *md, unsigned suspend_flags);
@@ -268,6 +280,11 @@ int dm_table_add_target(struct dm_table *t, const char *type,
 int dm_table_complete(struct dm_table *t);
 
 /*
+ * Optionally add support for block integrity.
+ */
+int dm_table_prealloc_integrity(struct dm_table *t, struct mapped_device *md);
+
+/*
  * Unplug all devices in a table.
  */
 void dm_table_unplug_all(struct dm_table *t);
Signature · 1 line
1.6.6.1
#1 lore raw

Hi Will,

Quoted 5 lines · Will Drewry

Following on the discussion of booting directly to a device-mapper device, two things were made clear:
1. The ioctl interface's name and uuid are mandatory for udev to work
2. There is a functional gap between the dm(-fs) and dm-ioctl

Quoted 8 lines

This change adds one function which is used for binding a given mapped device to a name+uuid in the dm-ioctl hash table. In addition, it ensures that public functions are available that allow mapped devices and tables to be created and associated with shared code paths in dm-ioctl:
- suspend flags and block integrity registration are now exposed
- dm_table_complete() now prepares a table for use completely (builds the btree; sets the type; allocates md pools)

I have done a preliminary review and have some comments inlined below.

Quoted 7 lines

Ideally, this lays the groundwork for any kernel code to create fully functional mapped devices, but I'd appreciate feedback on if this approach makes sense/is safe, preferred function names, and if it integrates with the current direction.

(I can also pair this with the init code patch if it makes sense to show consumer code.)

It would certainly help follow-on reviews as we take a closer look. For the next version of your work I'd recommend sharing all related code in a series (e.g.: core DM patch 1/2, init patch 2/2).

Quoted 32 lines
drivers/md/dm-table.c +16 -1
index 9924ea2..66726d1 100644
@@ -900,7 +900,7 @@ static int setup_indexes(struct dm_table *t)
 /*
  * Builds the btree to index the map.
  */
-int dm_table_complete(struct dm_table *t)
+int dm_table_build_index(struct dm_table *t)
 {
 	int r = 0;
 	unsigned int leaf_nodes;
@@ -919,6 +919,48 @@ int dm_table_complete(struct dm_table *t)
 	return r;
 }
 
+
+/*
+ * Prepares the table for use by building the indices,
+ * setting the type, and allocating mempools.
+ */
+int dm_table_complete(struct dm_table *t)
+{
+	int r = 0;
+	
+	r = dm_table_build_index(t);
+	if (r) {
+		DMWARN("unable to build btrees");
+		return r;
+	}
+	r = dm_table_set_type(t);

drivers/md/dm-table.c int dm_table_complete(struct dm_table *t) · line 946

Quoted 10 lines
drivers/md/dm-table.c +10 -0
+	if (r) {
+		DMWARN("unable to set table type");
+		return r;
+	}
+	r = dm_table_alloc_md_mempools(t);
+	if (r)
+		DMWARN("unable to allocate mempools");
+
+	return r;
+}

Please have dm_table_set_type() come before dm_table_build_index() to preserve the existing call sequence. It is better to check the type related constraints before going on to build the indices.

Quoted 6 lines
drivers/md/dm-table.c +6 -0
+
+/*
+ * Register the mapped device for blk_integrity support if
+ * the underlying devices support it.
+ */
+int dm_table_prealloc_integrity(struct dm_table *t, struct mapped_device *md)

drivers/md/dm-table.c int dm_table_complete(struct dm_table *t) · line 962

Quoted 10 lines
drivers/md/dm-table.c +10 -0
+{
+	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;
+}

I think we need more justification for why you'd want to expose dm_table_prealloc_integrity() as a public interface. Makes DM a bit more brittle with unknown gain at the moment. Why not just move the dm_table_prealloc_integrity() call to dm_table_complete() -- just before dm_table_alloc_md_mempools()?

Quoted 11 lines
drivers/md/dm-table.c +0 -0
 static DEFINE_MUTEX(_event_lock);
 void dm_table_event_callback(struct dm_table *t,
 			     void (*fn)(void *), void *context)
include/linux/device-mapper.h +0 -0
index 1381cd9..95fea4c 100644
@@ -215,6 +215,18 @@ void dm_set_mdptr(struct mapped_device *md, void *ptr);
 void *dm_get_mdptr(struct mapped_device *md);
 
 /*

include/linux/device-mapper.h void dm_set_mdptr(struct mapped_device *md, void *ptr); · line 227

Quoted 10 lines
include/linux/device-mapper.h +10 -0
+ * Export the device via the ioctl interface
+ */
+int dm_ioctl_export(struct mapped_device *md, const char *name,
+		    const char *uuid);
+
+/*
+ * Suspend feature flags
+ */
+#define DM_SUSPEND_LOCKFS_FLAG		(1 << 0)
+#define DM_SUSPEND_NOFLUSH_FLAG		(1 << 1)

You're missing the matching removal of these flags from drivers/md/dm.h

Regards,
Mike

#2 lore raw

Hi Mike,

Quoted 19 lines · Mike Snitzer

Hi Will,

Quoted 5 lines · Will Drewry

Following on the discussion of booting directly to a device-mapper device, two things were made clear:
1. The ioctl interface's name and uuid are mandatory for udev to work
2. There is a functional gap between the dm(-fs) and dm-ioctl

Quoted 8 lines

This change adds one function which is used for binding a given mapped device to a name+uuid in the dm-ioctl hash table.  In addition, it ensures that public functions are available that allow mapped devices and tables to be created and associated with shared code paths in dm-ioctl:
- suspend flags and block integrity registration are now exposed
- dm_table_complete() now prepares a table for use completely (builds the btree; sets the type; allocates md pools)

Quoted 1 line

I have done a preliminary review and have some comments inlined below.

Thanks for the review and comments!

Quoted 11 lines
Quoted 7 lines

Ideally, this lays the groundwork for any kernel code to create fully functional mapped devices, but I'd appreciate feedback on if this approach makes sense/is safe, preferred function names, and if it integrates with the current direction.

(I can also pair this with the init code patch if it makes sense to show consumer code.)

It would certainly help follow-on reviews as we take a closer look.  For the next version of your work I'd recommend sharing all related code in a series (e.g.: core DM patch 1/2, init patch 2/2).

Will do - just finishing up integrating comments from Alasdair and wanted to see if the direction for core DM changes would be reasonable.

Quoted 38 lines
Quoted 38 lines
drivers/md/dm-table.c +22 -1
index 9924ea2..66726d1 100644
@@ -900,7 +900,7 @@ static int setup_indexes(struct dm_table *t)
  /*
   * Builds the btree to index the map.
   */
-int dm_table_complete(struct dm_table *t)
+int dm_table_build_index(struct dm_table *t)
  {
       int r = 0;
       unsigned int leaf_nodes;
@@ -919,6 +919,48 @@ int dm_table_complete(struct dm_table *t)
       return r;
  }
 
+
+/*
+ * Prepares the table for use by building the indices,
+ * setting the type, and allocating mempools.
+ */
+int dm_table_complete(struct dm_table *t)
+{
+     int r = 0;
+
+     r = dm_table_build_index(t);
+     if (r) {
+             DMWARN("unable to build btrees");
+             return r;
+     }
+     r = dm_table_set_type(t);
+     if (r) {
+             DMWARN("unable to set table type");
+             return r;
+     }
+     r = dm_table_alloc_md_mempools(t);
+     if (r)
Quoted 8 lines

drivers/md/dm-table.c int dm_table_complete(struct dm_table *t) · line 946

Quoted 4 lines
drivers/md/dm-table.c +4 -0
+             DMWARN("unable to allocate mempools");
+
+     return r;
+}

Please have dm_table_set_type() come before dm_table_build_index() to preserve the existing call sequence.  It is better to check the type related constraints before going on to build the indices.

Nice catch! I had meant to preserve the order.

Quoted 14 lines
Quoted 14 lines
drivers/md/dm-table.c +14 -0
+
+/*
+ * Register the mapped device for blk_integrity support if
+ * the underlying devices support it.
+ */
+int dm_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);
+
Quoted 8 lines

drivers/md/dm-table.c int dm_table_complete(struct dm_table *t) · line 962

Quoted 2 lines
drivers/md/dm-table.c +2 -0
+     return 0;
+}

I think we need more justification for why you'd want to expose dm_table_prealloc_integrity() as a public interface.  Makes DM a bit more brittle with unknown gain at the moment.  Why not just move the dm_table_prealloc_integrity() call to dm_table_complete() -- just before dm_table_alloc_md_mempools()?

For some reason I special cased it, but I have no idea why. I'll fold it in to dm_table_complete().

Quoted 11 lines
Quoted 11 lines
drivers/md/dm-table.c +0 -0
  static DEFINE_MUTEX(_event_lock);
  void dm_table_event_callback(struct dm_table *t,
                            void (*fn)(void *), void *context)
include/linux/device-mapper.h +0 -0
index 1381cd9..95fea4c 100644
@@ -215,6 +215,18 @@ void dm_set_mdptr(struct mapped_device *md, void *ptr);
  void *dm_get_mdptr(struct mapped_device *md);
 
Quoted 13 lines

include/linux/device-mapper.h void dm_set_mdptr(struct mapped_device *md, void *ptr); · line 227

Quoted 11 lines
include/linux/device-mapper.h +10 -0
  /*
+ * Export the device via the ioctl interface
+ */
+int dm_ioctl_export(struct mapped_device *md, const char *name,
+                 const char *uuid);
+
+/*
+ * Suspend feature flags
+ */
+#define DM_SUSPEND_LOCKFS_FLAG               (1 << 0)
+#define DM_SUSPEND_NOFLUSH_FLAG              (1 << 1)

You're missing the matching removal of these flags from drivers/md/dm.h

I'll pull that into the next mail as well once I get the init changes in better shape.

Thanks again!
will

#3 lore raw

RFC PATCH v2 1/2 dm: allow a dm-fs-style device to be shared via dm-ioctl

In reply to Mike Snitzer

This change adds one function which is used for binding a given mapped device to a name+uuid in the dm-ioctl hash table. In addition, it ensures that public functions are available that allow mapped devices and tables to be created and associated with the shared code paths with dm-ioctl:
- suspend flags are available
- dm_table_complete() now prepares a table for use completely

---
 drivers/md/dm-ioctl.c         |   72 +++++++++++++++++++++-------------------
 drivers/md/dm-table.c         |   50 ++++++++++++++++++++++++++++-
 drivers/md/dm.h               |    6 ---
 include/linux/device-mapper.h |   12 +++++++
 4 files changed, 99 insertions(+), 41 deletions(-)
drivers/md/dm-ioctl.c +38 -34
index d7500e1..006be9d 100644
@@ -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

drivers/md/dm.h +0 -6
index bad1724..782d867 100644
@@ -17,12 +17,6 @@
 #include <linux/hdreg.h>
 
 /*
- * Suspend feature flags
- */
-#define DM_SUSPEND_LOCKFS_FLAG		(1 << 0)
-#define DM_SUSPEND_NOFLUSH_FLAG		(1 << 1)
-
-/*
  * Type of table and mapped_device's mempool
  */
 #define DM_TYPE_NONE		0
include/linux/device-mapper.h +12 -0
index 1381cd9..6c1c230 100644
@@ -215,6 +215,18 @@ 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);
+
+/*
+ * Suspend feature flags
+ */
+#define DM_SUSPEND_LOCKFS_FLAG		(1 << 0)
+#define DM_SUSPEND_NOFLUSH_FLAG		(1 << 1)
+
+/*
  * 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
#4 lore raw

Hi Will,

Quoted 4 lines · Will Drewry

In addition, it ensures that public functions are available that allow mapped devices and tables to be created and associated with the shared code paths with dm-ioctl:
- suspend flags are available

snip

Quoted 30 lines
drivers/md/dm.h +0 -6
index bad1724..782d867 100644
@@ -17,12 +17,6 @@
 #include <linux/hdreg.h>
 
 /*
- * Suspend feature flags
- */
-#define DM_SUSPEND_LOCKFS_FLAG		(1 << 0)
-#define DM_SUSPEND_NOFLUSH_FLAG		(1 << 1)
-
-/*
  * Type of table and mapped_device's mempool
  */
 #define DM_TYPE_NONE		0
include/linux/device-mapper.h +5 -0
index 1381cd9..6c1c230 100644
@@ -215,6 +215,18 @@ 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);
+

include/linux/device-mapper.h void dm_set_mdptr(struct mapped_device *md, void *ptr); · line 232

Quoted 10 lines
include/linux/device-mapper.h +7 -0
+/*
+ * Suspend feature flags
+ */
+#define DM_SUSPEND_LOCKFS_FLAG		(1 << 0)
+#define DM_SUSPEND_NOFLUSH_FLAG		(1 << 1)
+
+/*
  * A device can still be used while suspended, but I/O is deferred.
  */
 int dm_suspend(struct mapped_device *md, unsigned suspend_flags);

Why do you need suspend feature flags?
I think no feature is needed (specifying '0' is enough) to make/suspend a dm device at boot time (although I have looked at only this flag part). Am I missing something?

Thanks,
Kiyoshi Ueda

#5 lore raw
Quoted 45 lines · Kiyoshi Ueda

Hi Will,

Quoted 4 lines · Will Drewry

In addition, it ensures that public functions are available that allow mapped devices and tables to be created and associated with the shared code paths with dm-ioctl:
- suspend flags are available

snip

Quoted 37 lines
drivers/md/dm.h +0 -6
index bad1724..782d867 100644
@@ -17,12 +17,6 @@
  #include <linux/hdreg.h>
 
  /*
- * Suspend feature flags
- */
-#define DM_SUSPEND_LOCKFS_FLAG               (1 << 0)
-#define DM_SUSPEND_NOFLUSH_FLAG              (1 << 1)
-
-/*
   * Type of table and mapped_device's mempool
   */
  #define DM_TYPE_NONE         0
include/linux/device-mapper.h +12 -0
index 1381cd9..6c1c230 100644
@@ -215,6 +215,18 @@ 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);
+
+/*
+ * Suspend feature flags
+ */
+#define DM_SUSPEND_LOCKFS_FLAG               (1 << 0)
+#define DM_SUSPEND_NOFLUSH_FLAG              (1 << 1)
+
+/*
Quoted 8 lines

include/linux/device-mapper.h void dm_set_mdptr(struct mapped_device *md, void *ptr); · line 232

Quoted 3 lines
include/linux/device-mapper.h +0 -0
   * A device can still be used while suspended, but I/O is deferred.
   */
  int dm_suspend(struct mapped_device *md, unsigned suspend_flags);

Why do you need suspend feature flags?
I think no feature is needed (specifying '0' is enough) to make/suspend a dm device at boot time (although I have looked at only this flag part). Am I missing something?

Not at all! I hadn't thoroughly reviewed the code path for flush/noflush and was hoping to avoid additional code paths. However, looking at effect, I don't see any tangible benefit to doing so with a brand new device.

I'll switch it over to 0, and I can take exposing the flags out of this patch.

Any additional comments are appreciated - thanks! will

#6 lore raw

RFC PATCH v2 2/2 init: boot to device-mapper targets without an initr*

In reply to Mike Snitzer

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 98:16 0, 4096 4096 linear 98:32 0"

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

---
 init/Makefile       |    1 +
 init/do_mounts.c    |    1 +
 init/do_mounts.h    |   10 ++
 init/do_mounts_dm.c |  353 +++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 365 insertions(+), 0 deletions(-)
 create mode 100644 init/do_mounts_dm.c
init/Makefile +1 -0
index 0bf677a..1677baa 100644
@@ -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
index 02e3ca4..0848a5b 100644
@@ -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
index f5b978a..09d2286 100644
@@ -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
#7 lore raw

Re: [RFC PATCH v2 2/2] init: boot to device-mapper targets without an initr*

Quoted 4 lines · On Fri, 14 May 2010 20:41:41 -0500 Will Drewry wrote:

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).

dm=<blah>
documentation needs to be added to Documentation/kernel-parameters.txt and/or Documentation/md.txt.

Quoted 4 lines

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()).

This "space in the arg string" has been tested, right?
It seems a bit odd to me. Most kernel parameter strings that I am familiar with use punctuation for separating parameter parts.

Quoted 9 lines

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 98:16 0, 4096 4096 linear 98:32 0"

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

Quoted 8 lines
---
 init/Makefile       |    1 +
 init/do_mounts.c    |    1 +
 init/do_mounts.h    |   10 ++
 init/do_mounts_dm.c |  353 +++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 365 insertions(+), 0 deletions(-)
 create mode 100644 init/do_mounts_dm.c

---
~Randy
*** Remember to use Documentation/SubmitChecklist when testing your code ***

#8 lore raw

Re: [RFC PATCH v2 2/2] init: boot to device-mapper targets without an initr*

Quoted 10 lines · Randy Dunlap
Quoted 4 lines · On Fri, 14 May 2010 20:41:41 -0500 Will Drewry wrote:

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).

dm=<blah>
documentation needs to be added to Documentation/kernel-parameters.txt and/or Documentation/md.txt.

Absolutely -- I've appended a proposed version below which I'll include in the next round. I'm not a lkml veteran, so if it makes sense to resend the full patchset
again with it, I can. Otherwise, I'll wait for comments on the code too.

Quoted 6 lines
Quoted 4 lines

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()).

This "space in the arg string" has been tested, right?

Works for me so far. I've tested this on a user mode linux instance and a real x86 machine with the dm-linear target and a custom dm target (which I'll be
mailing to dm-devel@ for feedback later this week).

Quoted 2 lines

It seems a bit odd to me.  Most kernel parameter strings that I am familiar with use punctuation for separating parameter parts.

Yup - I agree. My first cut I used commas with an empty ,, delimiter as a new line. Then I ran across this in the source:

kernel/params.c
76 /* You can use " around spaces, but can't escape ". */ 77 /* Hyphens and underscores equivalent in parameter names. */ 78 static char *next_arg(char *args, char **param, char **val)

I will need to cross-check all the known dm targets to make sure that they don't expect quoted internal strings. In my first look, I didn't see any.

However, I'm perfectly content with either approach so if there's a preference, I'll rework it to make it happen. This approach just maps more cleanly to the existing experience of configuring a mapped device.

thanks!
will

documentation: dm= parameter documentation

Add documentation for early mapped device creation without an initial rd.

---
 Documentation/device-mapper/boot.txt |   36 ++++++++++++++++++++++++++++++++++
 Documentation/kernel-parameters.txt  |    4 +++
 2 files changed, 40 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/device-mapper/boot.txt
(quoted diff) +0 -0

b/Documentation/device-mapper/boot.txt
new file mode 100644
index 0000000..00fb557

Documentation/device-mapper/boot.txt new file +36 -0
@@ -0,0 +1,36 @@
+Boot time creation of mapped devices
+===================================
+
+You can boot directly to a dm device using the following kernel command
+line:
+
+dm="<name> <uuid> <ro>,table line 1,...,table line n"
+
+name = the name to associated 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.
(quoted diff) +0 -0

b/Documentation/kernel-parameters.txt
index 839b21b..9e22f8e 100644

Documentation/kernel-parameters.txt +1 -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,

Signature · 1 line
1.7.0.4
#9 lore raw

Re: [RFC PATCH v2 2/2] init: boot to device-mapper targets without an initr*

Quoted 8 lines · On Mon, 17 May 2010 13:13:48 -0500 Will Drewry wrote:
Quoted 7 lines · Randy Dunlap
Quoted 4 lines · On Fri, 14 May 2010 20:41:41 -0500 Will Drewry wrote:

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).

Quoted 8 lines
Quoted 3 lines

dm=<blah>
documentation needs to be added to Documentation/kernel-parameters.txt and/or Documentation/md.txt.

Absolutely -- I've appended a proposed version below which I'll include in the next round. I'm not a lkml veteran, so if it makes sense to resend the full patchset
again with it, I can. Otherwise, I'll wait for comments on the code too.

OK, thanks for the doc update. One typo noted below.

Quoted 52 lines
Quoted 6 lines
Quoted 4 lines

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()).

This "space in the arg string" has been tested, right?

Works for me so far. I've tested this on a user mode linux instance and a real x86 machine with the dm-linear target and a custom dm target (which I'll be
mailing to dm-devel@ for feedback later this week).

Quoted 2 lines

It seems a bit odd to me.  Most kernel parameter strings that I am familiar with use punctuation for separating parameter parts.

Yup - I agree. My first cut I used commas with an empty ,, delimiter as a new line. Then I ran across this in the source:

kernel/params.c
76 /* You can use " around spaces, but can't escape ". */ 77 /* Hyphens and underscores equivalent in parameter names. */ 78 static char *next_arg(char *args, char **param, char **val)

I will need to cross-check all the known dm targets to make sure that they don't expect quoted internal strings. In my first look, I didn't see any.

However, I'm perfectly content with either approach so if there's a preference, I'll rework it to make it happen. This approach just maps more cleanly to the existing experience of configuring a mapped device.

thanks!
will

documentation: dm= parameter documentation

Add documentation for early mapped device creation without an initial rd.

---
 Documentation/device-mapper/boot.txt |   36 ++++++++++++++++++++++++++++++++++
 Documentation/kernel-parameters.txt  |    4 +++
 2 files changed, 40 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/device-mapper/boot.txt
Documentation/device-mapper/boot.txt new file +0 -0
new file mode 100644
index 0000000..00fb557

Documentation/device-mapper/boot.txt line 9

Quoted 9 lines
Documentation/device-mapper/boot.txt new file +9 -0
@@ -0,0 +1,36 @@
+Boot time creation of mapped devices
+===================================
+
+You can boot directly to a dm device using the following kernel command
+line:
+
+dm="<name> <uuid> <ro>,table line 1,...,table line n"
+
+name = the name to associated with the device

associate

Quoted 17 lines
Documentation/device-mapper/boot.txt new file +17 -0
+	 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
+=======

Documentation/device-mapper/boot.txt line 36

Quoted 10 lines
Documentation/device-mapper/boot.txt new file +10 -0
+
+- 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.

---
~Randy
*** Remember to use Documentation/SubmitChecklist when testing your code ***