Possible access method for a singleton target:

tgt = dm_get_singleton_target(md)
confirm tgt->type is as expected
then access tgt->private
dm_put_singleton_target(tgt)

Alternatively, we could require the type as a second parameter on the get,
validate it internally, put the target and return just 'private'.

It's designed for targets to gain access to their own private data on
a different (related) mapped device.

---
 drivers/md/dm-table.c         |   31 +++++++++++++++++++++++++++++++
 include/linux/device-mapper.h |    3 +++
 2 files changed, 34 insertions(+)

Index: linux-3.1-rc7/drivers/md/dm-table.c
===================================================================
--- linux-3.1-rc7.orig/drivers/md/dm-table.c
+++ linux-3.1-rc7/drivers/md/dm-table.c
@@ -1190,6 +1190,37 @@ struct dm_target *dm_table_find_target(s
 	return &t->targets[(KEYS_PER_NODE * n) + k];
 }
 
+static struct dm_target *dm_table_get_singleton_target(struct dm_table *t)
+{
+	if (!t->singleton)
+		return NULL;
+
+	return t->targets;
+}
+
+struct dm_target *dm_get_singleton_target(struct mapped_device *md)
+{
+	struct dm_table *t;
+	struct dm_target *tgt;
+
+	t = dm_get_live_table(md);
+	if (!t)
+		return NULL;
+
+	tgt = dm_table_get_singleton_target(t);
+	if (!tgt)
+		dm_table_put(t);
+
+	return tgt;
+}
+EXPORT_SYMBOL_GPL(dm_get_singleton_target);
+
+void dm_put_singleton_target(struct dm_target *tgt)
+{
+	dm_table_put(tgt->table);
+}
+EXPORT_SYMBOL_GPL(dm_put_singleton_target);
+
 /*
  * Establish the new table's queue_limits and validate them.
  */
Index: linux-3.1-rc7/include/linux/device-mapper.h
===================================================================
--- linux-3.1-rc7.orig/include/linux/device-mapper.h
+++ linux-3.1-rc7/include/linux/device-mapper.h
@@ -364,6 +364,9 @@ unsigned int dm_table_get_num_targets(st
 fmode_t dm_table_get_mode(struct dm_table *t);
 struct mapped_device *dm_table_get_md(struct dm_table *t);
 
+struct dm_target *dm_get_singleton_target(struct mapped_device *md);
+void dm_put_singleton_target(struct dm_target *tgt);
+
 /*
  * Trigger an event.
  */