From c9ee46569cea8cac4d32677c4fde7d979f1e36ee Mon Sep 17 00:00:00 2001
From: Alasdair Kergon <agk@redhat.com>
Date: Wed, 3 Jun 2009 11:40:23 +0000
Subject: [PATCH] Make mempool optional in dm_split_lvm_name()

---
 WHATS_NEW_DM         | 1 +
 libdm/libdevmapper.h | 2 ++
 libdm/libdm-string.c | 2 +-
 3 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM
index 4ab72bb99..d307cd17e 100644
--- a/WHATS_NEW_DM
+++ b/WHATS_NEW_DM
@@ -1,5 +1,6 @@
 Version 1.02.33 - 
 ===============================
+  Make mempool optional in dm_split_lvm_name().
 
 Version 1.02.32 - 21st May 2009
 ===============================
diff --git a/libdm/libdevmapper.h b/libdm/libdevmapper.h
index a6e253008..c8ce21f64 100644
--- a/libdm/libdevmapper.h
+++ b/libdm/libdevmapper.h
@@ -819,6 +819,8 @@ int dm_set_selinux_context(const char *path, mode_t mode);
 /*
  * Break up the name of a mapped device into its constituent
  * Volume Group, Logical Volume and Layer (if present).
+ * If mem is supplied, the result is allocated from the mempool.
+ * Otherwise the strings are changed in situ.
  */
 int dm_split_lvm_name(struct dm_pool *mem, const char *dmname,
 		      char **vgname, char **lvname, char **layer);
diff --git a/libdm/libdm-string.c b/libdm/libdm-string.c
index 0e41f9d9d..c6f101bcc 100644
--- a/libdm/libdm-string.c
+++ b/libdm/libdm-string.c
@@ -93,7 +93,7 @@ static char *_unquote(char *component)
 int dm_split_lvm_name(struct dm_pool *mem, const char *dmname,
 		      char **vgname, char **lvname, char **layer)
 {
-	if (!(*vgname = dm_pool_strdup(mem, dmname)))
+	if (mem && !(*vgname = dm_pool_strdup(mem, dmname)))
 		return 0;
 
 	_unquote(*layer = _unquote(*lvname = _unquote(*vgname)));