From: Dave Wysochanski <dwysocha@redhat.com>
Date: Thu, 30 Sep 2010 14:07:33 +0000 (+0000)
Subject: Add id_format_and_copy() common function and call from _uuid_disp.
X-Git-Tag: v2_02_91~1524
X-Git-Url: https://sourceware.org/git/?a=commitdiff_plain;h=f4fd41552d79eb7a681c687b1d00872300c5c29e;p=lvm2.git

Add id_format_and_copy() common function and call from _uuid_disp.

Add supporting uuid function to allocate memory and call id_write_format.
Call id_format_and_copy from _uuid_disp.
---

diff --git a/lib/report/report.c b/lib/report/report.c
index d0901a5ba..b8c5d1adc 100644
--- a/lib/report/report.c
+++ b/lib/report/report.c
@@ -677,12 +677,7 @@ static int _uuid_disp(struct dm_report *rh __attribute__((unused)), struct dm_po
 {
 	char *repstr = NULL;
 
-	if (!(repstr = dm_pool_alloc(mem, 40))) {
-		log_error("dm_pool_alloc failed");
-		return 0;
-	}
-
-	if (!id_write_format((const struct id *) data, repstr, 40))
+	if (!(repstr = id_format_and_copy(mem, (struct id *)data)))
 		return_0;
 
 	dm_report_field_set_value(field, repstr, NULL);
diff --git a/lib/uuid/uuid.c b/lib/uuid/uuid.c
index de3f0cd01..e85e852c4 100644
--- a/lib/uuid/uuid.c
+++ b/lib/uuid/uuid.c
@@ -206,3 +206,18 @@ int id_read_format(struct id *id, const char *buffer)
 
 	return id_valid(id);
 }
+
+char *id_format_and_copy(struct dm_pool *mem, const struct id *id)
+{
+	char *repstr = NULL;
+
+	if (!(repstr = dm_pool_alloc(mem, 40))) {
+		log_error("dm_pool_alloc failed");
+		return NULL;
+	}
+
+	if (!id_write_format(id, repstr, 40))
+		return_NULL;
+
+	return repstr;
+}
diff --git a/lib/uuid/uuid.h b/lib/uuid/uuid.h
index 00296393c..5c8382d75 100644
--- a/lib/uuid/uuid.h
+++ b/lib/uuid/uuid.h
@@ -54,4 +54,6 @@ int id_write_format(const struct id *id, char *buffer, size_t size);
  */
 int id_read_format(struct id *id, const char *buffer);
 
+char *id_format_and_copy(struct dm_pool *mem, const struct id *id);
+
 #endif