dm_get_by_dev()
--- diff/drivers/md/dm.c	2004-09-28 22:48:16.000000000 +0100
+++ source/drivers/md/dm.c	2004-09-28 22:48:07.000000000 +0100
@@ -643,7 +643,7 @@
 /*
  * See if the device with a specific minor # is free.
  */
-static int specific_minor(unsigned int minor)
+static int specific_minor(struct mapped_device *md, unsigned int minor)
 {
 	int r, m;
 
@@ -663,7 +663,7 @@
 		goto out;
 	}
 
-	r = idr_get_new_above(&_minor_idr, specific_minor, minor, &m);
+	r = idr_get_new_above(&_minor_idr, md, minor, &m);
 	if (r) {
 		goto out;
 	}
@@ -679,7 +679,7 @@
 	return r;
 }
 
-static int next_free_minor(unsigned int *minor)
+static int next_free_minor(struct mapped_device *md, unsigned int *minor)
 {
 	int r;
 	unsigned int m;
@@ -692,7 +692,7 @@
 		goto out;
 	}
 
-	r = idr_get_new(&_minor_idr, next_free_minor, &m);
+	r = idr_get_new(&_minor_idr, md, &m);
 	if (r) {
 		goto out;
 	}
@@ -726,7 +726,7 @@
 	}
 
 	/* get a minor number for the dev */
-	r = persistent ? specific_minor(minor) : next_free_minor(&minor);
+	r = persistent ? specific_minor(md, minor) : next_free_minor(md, &minor);
 	if (r < 0)
 		goto bad1;
 
@@ -888,6 +888,30 @@
 	atomic_inc(&md->holders);
 }
 
+struct mapped_device *dm_get_by_dev(unsigned minor)
+{
+	struct mapped_device *md;
+
+	if (minor >= (1 << MINORBITS))
+		return NULL;
+
+	down(&_minor_lock);
+	md = idr_find(&_minor_idr, minor);
+	up(&_minor_lock);
+
+	if (!md)
+		return NULL;
+
+	dm_get(md);
+
+	if (dm_disk(md)->first_minor == minor) {
+		dm_put(md);
+		md = NULL;
+	}
+
+	return md;
+}
+
 void dm_put(struct mapped_device *md)
 {
 	struct dm_table *map = dm_get_table(md);
--- diff/drivers/md/dm.h	2004-09-28 22:48:16.000000000 +0100
+++ source/drivers/md/dm.h	2004-09-28 22:47:52.000000000 +0100
@@ -59,6 +59,7 @@
  * Reference counting for md.
  */
 void dm_get(struct mapped_device *md);
+struct mapped_device *dm_get_by_dev(unsigned minor);
 void dm_put(struct mapped_device *md);
 
 /*
