From: Mike Anderson <[email-masked]>

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

[Use of snprintf in function name is confusing and not documented
- find an existing in-tree example of this or else seriously consider 
alternatives.]
[Why can't we handle both name and uuid within a single call?]
[Replace _MAX - do we need the enum at all, in fact?  Else export it?]

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

 drivers/md/dm-ioctl.c         |   75 ++++++++++++++++++++++++++++++++++++++++++
 include/linux/device-mapper.h |    5 ++
 2 files changed, 79 insertions(+), 1 deletion(-)

Index: linux-2.6.23/drivers/md/dm-ioctl.c
===================================================================
--- linux-2.6.23.orig/drivers/md/dm-ioctl.c	2007-10-10 17:20:22.000000000 +0100
+++ linux-2.6.23/drivers/md/dm-ioctl.c	2007-10-10 18:12:09.000000000 +0100
@@ -1515,3 +1515,78 @@ void dm_interface_exit(void)
 
 	dm_hash_exit();
 }
+
+enum dm_hc_field {
+	DM_HC_FIELD_NAME,
+	DM_HC_FIELD_UUID,
+	DM_HC_FIELD_MAX
+};
+
+/**
+ * dm_snprintf_hc_field - Format a hash cell field and place it in a buffer
+ * @md: Pointer to mapped_device
+ * @buf: The buffer to place the result into
+ * @size: The size of the buffer, including the trailing null space
+ * @fmt: The format string to use
+ *
+ */
+static int dm_snprintf_hc_field(struct mapped_device *md,
+				enum dm_hc_field field, char *buf,
+				size_t size, const char *format)
+{
+	int r = 0;
+	struct hash_cell *hc;
+
+	if (!md || (field >= DM_HC_FIELD_MAX))
+		return -ENXIO;
+
+	dm_get(md);
+	down_write(&_hash_lock);
+	hc = dm_get_mdptr(md);
+	if (!hc || hc->md != md) {
+		r = -ENXIO;
+		goto out;
+	}
+
+	if (field == DM_HC_FIELD_NAME) {
+		if (hc->name)
+			r = snprintf(buf, size, format, hc->name);
+	} else if (field == DM_HC_FIELD_UUID) {
+		if (hc->uuid)
+			r = snprintf(buf, size, format, hc->uuid);
+	}
+
+out:
+	up_write(&_hash_lock);
+	dm_put(md);
+	return r;
+}
+
+/**
+ * dm_snprintf_hc_name - Format a hash cell name and place it in a buffer
+ * @md: Pointer to mapped_device
+ * @buf: The buffer to place the result into
+ * @size: The size of the buffer, including the trailing null space
+ * @fmt: The format string to use
+ *
+ */
+int dm_snprintf_hc_name(struct mapped_device *md, char *buf,
+				size_t size, const char *format)
+{
+	return dm_snprintf_hc_field(md, DM_HC_FIELD_NAME, buf, size, format);
+}
+
+/**
+ * dm_snprintf_hc_uuid - Format a hash cell uuid and place it in a buffer
+ * @md: Pointer to mapped_device
+ * @buf: The buffer to place the result into
+ * @size: The size of the buffer, including the trailing null space
+ * @fmt: The format string to use
+ *
+ */
+int dm_snprintf_hc_uuid(struct mapped_device *md, char *buf,
+				size_t size, const char *format)
+{
+	return dm_snprintf_hc_field(md, DM_HC_FIELD_UUID, buf, size, format);
+}
+
Index: linux-2.6.23/include/linux/device-mapper.h
===================================================================
--- linux-2.6.23.orig/include/linux/device-mapper.h	2007-10-10 18:11:52.000000000 +0100
+++ linux-2.6.23/include/linux/device-mapper.h	2007-10-10 18:12:09.000000000 +0100
@@ -189,7 +189,10 @@ int dm_resume(struct mapped_device *md);
  */
 uint32_t dm_get_event_nr(struct mapped_device *md);
 int dm_wait_event(struct mapped_device *md, int event_nr);
-
+int dm_snprintf_hc_name(struct mapped_device *md, char *buf, size_t size,
+			const char *format);
+int dm_snprintf_hc_uuid(struct mapped_device *md, char *buf, size_t size,
+			const char *format);
 /*
  * Info functions.
  */