From: Hannes Reinecke <[email-masked]>

Partitions on device-mapper devices are managed by kpartx (if at
all). So if we send out a 'change' event when BLKRRPART is called,
udev has the ability to trigger kpartx if it wishes.

Signed-off-by: Hannes Reinecke <[email-masked]>
Signed-off-by: Nikanth Karthikesan <[email-masked]>

[AGK - need confirmation this patch works, and block layer doesn't also need changing to pass the ioctls to dm]

---
 drivers/md/dm.c |   22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

Index: linux-2.6.31/drivers/md/dm.c
===================================================================
--- linux-2.6.31.orig/drivers/md/dm.c
+++ linux-2.6.31/drivers/md/dm.c
@@ -395,19 +395,25 @@ static int dm_blk_ioctl(struct block_dev
 	if (!map || !dm_table_get_size(map))
 		goto out;
 
-	/* We only support devices that have a single target */
-	if (dm_table_get_num_targets(map) != 1)
-		goto out;
-
-	tgt = dm_table_get_target(map, 0);
-
 	if (dm_suspended(md)) {
 		r = -EAGAIN;
 		goto out;
 	}
 
-	if (tgt->type->ioctl)
-		r = tgt->type->ioctl(tgt, cmd, arg);
+	if (cmd == BLKRRPART) {
+		/* Emulate Re-read partitions table */
+		kobject_uevent(&disk_to_dev(md->disk)->kobj, KOBJ_CHANGE);
+		r = 0;
+	} else {
+		/* We only support devices that have a single target */
+		if (dm_table_get_num_targets(map) != 1)
+			goto out;
+
+		tgt = dm_table_get_target(map, 0);
+
+		if (tgt->type->ioctl)
+			r = tgt->type->ioctl(tgt, cmd, arg);
+	}
 
 out:
 	dm_table_put(map);