From f8964db41c6f86d2fa556f8025af9fb4432ec5c5 Mon Sep 17 00:00:00 2001
From: Alasdair Kergon <agk@redhat.com>
Date: Thu, 28 May 2009 01:59:37 +0000
Subject: [PATCH] When creating new LV, double-check that name is not already
 in use.

---
 WHATS_NEW               | 1 +
 lib/metadata/lv_manip.c | 4 ++++
 2 files changed, 5 insertions(+)

diff --git a/WHATS_NEW b/WHATS_NEW
index fe363efcd..c10ddc45f 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
 Version 2.02.48 - 
 ===============================
+  When creating new LV, double-check that name is not already in use.
   Remove /dev/vgname/lvname symlink automatically if LV is no longer visible.
   Rename internal vorigin LV to match visible LV.
   Suppress 'removed' messages displayed when internal LVs are removed.
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c
index 53e92e0f9..f5fb7d893 100644
--- a/lib/metadata/lv_manip.c
+++ b/lib/metadata/lv_manip.c
@@ -1844,6 +1844,10 @@ struct logical_volume *lv_create_empty(const char *name,
 		log_error("Failed to generate unique name for the new "
 			  "logical volume");
 		return NULL;
+	} else if (find_lv_in_vg(vg, name)) {
+		log_error("Unable to create LV %s in Volume Group %s: "
+			  "name already in use.", name, vg->name);
+		return NULL;
 	}
 
 	log_verbose("Creating logical volume %s", name);