From: Will Drewry <[email-masked]>

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

N.B. Standard in-kernel device names will now take precedence over what
the /dev inodes say if the two don't match.

Signed-off-by: Will Drewry <[email-masked]>
Signed-off-by: Alasdair G Kergon <[email-masked]>

[Missing EXPORT_SYMBOL and const.]

---
drivers/md/dm-table.c |   16 ++++++++--------
 drivers/md/dm-table.c    |   13 +++++--------
 include/linux/dm-ioctl.h |    6 +++---
 2 files changed, 8 insertions(+), 11 deletions(-)

Index: linux-2.6.37/drivers/md/dm-table.c
===================================================================
--- linux-2.6.37.orig/drivers/md/dm-table.c
+++ linux-2.6.37/drivers/md/dm-table.c
@@ -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>
@@ -442,17 +443,13 @@ static int __table_get_device(struct dm_
 	int r;
 	dev_t uninitialized_var(dev);
 	struct dm_dev_internal *dd;
-	unsigned int major, minor;
 
 	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 */
+	/* lookup by major:minor or registered device name */
+	dev = name_to_dev_t(path);
+	if (!dev) {
+		/* convert the path to a device by finding its inode */
 		struct block_device *bdev = lookup_bdev(path);
 
 		if (IS_ERR(bdev))
Index: linux-2.6.37/include/linux/dm-ioctl.h
===================================================================
--- linux-2.6.37.orig/include/linux/dm-ioctl.h
+++ linux-2.6.37/include/linux/dm-ioctl.h
@@ -267,9 +267,9 @@ enum {
 #define DM_DEV_SET_GEOMETRY	_IOWR(DM_IOCTL, DM_DEV_SET_GEOMETRY_CMD, struct dm_ioctl)
 
 #define DM_VERSION_MAJOR	4
-#define DM_VERSION_MINOR	19
-#define DM_VERSION_PATCHLEVEL	1
-#define DM_VERSION_EXTRA	"-ioctl (2011-01-07)"
+#define DM_VERSION_MINOR	20
+#define DM_VERSION_PATCHLEVEL	0
+#define DM_VERSION_EXTRA	"-ioctl (2011-01-18)"
 
 /* Status bits */
 #define DM_READONLY_FLAG	(1 << 0) /* In/Out */