From: Mike Anderson <[email-masked]>

This patch adds functions to copy name and uuid from the dm hash cell
structure.

Signed-off-by: Mike Anderson <[email-masked]>
---

 drivers/md/dm-ioctl.c         |   60 ++++++++++++++++++++++++++++++++++++++++++
 include/linux/device-mapper.h |    2 +
 2 files changed, 62 insertions(+)

Index: linux-2.6.23/drivers/md/dm-ioctl.c
===================================================================
--- linux-2.6.23.orig/drivers/md/dm-ioctl.c	2007-10-11 13:18:16.000000000 +0100
+++ linux-2.6.23/drivers/md/dm-ioctl.c	2007-10-11 15:50:43.000000000 +0100
@@ -1515,3 +1515,63 @@ void dm_interface_exit(void)
 
 	dm_hash_exit();
 }
+
+enum dm_hc_field {
+	DM_HC_FIELD_NAME,
+	DM_HC_FIELD_UUID,
+};
+
+static int dm_copy_md_field(struct mapped_device *md, enum dm_hc_field field,
+			    char *buf, size_t len)
+{
+	int r = 0;
+	struct hash_cell *hc;
+	char *value;
+
+	if (!md)
+		return -ENXIO;
+
+	dm_get(md);
+	down_read(&_hash_lock);
+	hc = dm_get_mdptr(md);
+	if (!hc || hc->md != md) {
+		r = -ENXIO;
+		goto out;
+	}
+
+	if (field == DM_HC_FIELD_NAME)
+		value = hc->name;
+	else /* DM_HC_FIELD_UUID */
+		value = hc->uuid;
+
+	strncpy(buf, value ? : "", len);
+
+out:
+	up_read(&_hash_lock);
+	dm_put(md);
+
+	return r;
+}
+
+/*
+ * dm_copy_md_name - Copy a mapped device name into a buffer
+ * @md: Pointer to mapped_device
+ * @buf: Existing buffer to place the result into
+ * @len: The size of the buffer, including the trailing null space
+ */
+int dm_copy_md_name(struct mapped_device *md, char *buf, size_t len)
+{
+	return dm_copy_md_field(md, DM_HC_FIELD_NAME, buf, len);
+}
+
+/*
+ * dm_copy_md_uuid - Copy a mapped device uuid into a buffer
+ * @md: Pointer to mapped_device
+ * @buf: Existing buffer to copy the uuid into
+ * @len: The size of the buffer, including the trailing null space
+ */
+int dm_copy_md_uuid(struct mapped_device *md, char *buf, size_t len)
+{
+	return dm_copy_md_field(md, DM_HC_FIELD_UUID, buf, len);
+}
+
Index: linux-2.6.23/include/linux/device-mapper.h
===================================================================
--- linux-2.6.23.orig/include/linux/device-mapper.h	2007-10-11 13:18:16.000000000 +0100
+++ linux-2.6.23/include/linux/device-mapper.h	2007-10-11 15:17:45.000000000 +0100
@@ -194,6 +194,8 @@ int dm_wait_event(struct mapped_device *
  * Info functions.
  */
 const char *dm_device_name(struct mapped_device *md);
+int dm_copy_md_name(struct mapped_device *md, char *buf, size_t size);
+int dm_copy_md_uuid(struct mapped_device *md, char *buf, size_t size);
 struct gendisk *dm_disk(struct mapped_device *md);
 int dm_suspended(struct mapped_device *md);
 int dm_noflush_suspending(struct dm_target *ti);