This patch introduces a new <source> element <name>, which is distinct
from the pool name.  <name> is used only by the logical storage
backend, and represents the volume group name.  For convenience and
back-compatibility, <source> <name> defaults to the pool name if not
specified when the pool is defined, and <pool> <name> defaults to the
source name if not specified.  There is no requirement that pool and
source name be the same, though.

Signed-off-by: David Lively <dlively@virtualiron.com>

diff --git a/src/storage_backend.h b/src/storage_backend.h
index 797ca01..422f26c 100644
--- a/src/storage_backend.h
+++ b/src/storage_backend.h
@@ -53,6 +53,7 @@ enum {
     VIR_STORAGE_BACKEND_POOL_SOURCE_DEVICE  = (1<<1),
     VIR_STORAGE_BACKEND_POOL_SOURCE_DIR     = (1<<2),
     VIR_STORAGE_BACKEND_POOL_SOURCE_ADAPTER = (1<<3),
+    VIR_STORAGE_BACKEND_POOL_SOURCE_NAME    = (1<<4),
 };
 
 typedef struct _virStorageBackendPoolOptions virStorageBackendPoolOptions;
diff --git a/src/storage_backend_logical.c b/src/storage_backend_logical.c
index 0c4f6a5..382078b 100644
--- a/src/storage_backend_logical.c
+++ b/src/storage_backend_logical.c
@@ -80,7 +80,7 @@ virStorageBackendLogicalSetActive(virConnectPtr conn,
 
     cmdargv[0] = VGCHANGE;
     cmdargv[1] = on ? "-ay" : "-an";
-    cmdargv[2] = pool->def->name;
+    cmdargv[2] = pool->def->source.name;
     cmdargv[3] = NULL;
 
     if (virRun(conn, cmdargv, NULL) < 0)
@@ -213,7 +213,7 @@ virStorageBackendLogicalFindLVs(virConnectPtr conn,
         LVS, "--separator", ":", "--noheadings", "--units", "b",
         "--unbuffered", "--nosuffix", "--options",
         "lv_name,uuid,devices,seg_size,vg_extent_size",
-        pool->def->name, NULL
+        pool->def->source.name, NULL
     };
 
     int exitstatus;
@@ -288,7 +288,7 @@ virStorageBackendLogicalBuildPool(virConnectPtr conn,
     }
 
     vgargv[n++] = VGCREATE;
-    vgargv[n++] = pool->def->name;
+    vgargv[n++] = pool->def->source.name;
 
     pvargv[0] = PVCREATE;
     pvargv[2] = NULL;
@@ -365,7 +365,7 @@ virStorageBackendLogicalRefreshPool(virConnectPtr conn,
     const char *prog[] = {
         VGS, "--separator", ":", "--noheadings", "--units", "b", "--unbuffered",
         "--nosuffix", "--options", "vg_size,vg_free",
-        pool->def->name, NULL
+        pool->def->source.name, NULL
     };
     int exitstatus;
 
@@ -419,7 +419,7 @@ virStorageBackendLogicalDeletePool(virConnectPtr conn,
                                    unsigned int flags ATTRIBUTE_UNUSED)
 {
     const char *cmdargv[] = {
-        VGREMOVE, "-f", pool->def->name, NULL
+        VGREMOVE, "-f", pool->def->source.name, NULL
     };
 
     if (virRun(conn, cmdargv, NULL) < 0)
@@ -535,6 +535,7 @@ virStorageBackend virStorageBackendLogical = {
     .deleteVol = virStorageBackendLogicalDeleteVol,
 
     .poolOptions = {
+        .flags = VIR_STORAGE_BACKEND_POOL_SOURCE_NAME,
         .formatFromString = virStorageBackendLogicalPoolFormatFromString,
         .formatToString = virStorageBackendLogicalPoolFormatToString,
     },
diff --git a/src/storage_conf.c b/src/storage_conf.c
index 05b68af..e49f684 100644
--- a/src/storage_conf.c
+++ b/src/storage_conf.c
@@ -96,6 +96,7 @@ virStoragePoolDefFree(virStoragePoolDefPtr def) {
     }
     VIR_FREE(def->source.devices);
     VIR_FREE(def->source.dir);
+    VIR_FREE(def->source.name);
 
     if (def->source.authType == VIR_STORAGE_POOL_AUTH_CHAP) {
         VIR_FREE(def->source.auth.chap.login);
@@ -248,7 +249,11 @@ virStoragePoolDefParseDoc(virConnectPtr conn,
         goto cleanup;
     }
 
-    if ((ret->name = virXPathString(conn, "string(/pool/name)", ctxt)) == NULL) {
+    ret->name = virXPathString(conn, "string(/pool/name)", ctxt);
+    if (ret->name == NULL &&
+        options->flags & VIR_STORAGE_BACKEND_POOL_SOURCE_NAME)
+        ret->name = virXPathString(conn, "string(/pool/source/name)", ctxt);
+    if (ret->name == NULL) {
         virStorageReportError(conn, VIR_ERR_XML_ERROR,
                               "%s", _("missing name element"));
         goto cleanup;
@@ -320,6 +325,15 @@ virStoragePoolDefParseDoc(virConnectPtr conn,
             goto cleanup;
         }
     }
+    if (options->flags & VIR_STORAGE_BACKEND_POOL_SOURCE_NAME) {
+        ret->source.name = virXPathString(conn, "string(/pool/source/name)", ctxt);
+        if (ret->source.name == NULL) {
+            /* source name defaults to pool name */
+            ret->source.name = strdup(ret->name);
+            if (ret->source.name == NULL)
+                virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("pool name"));
+        }
+    }
 
 
     authType = virXPathString(conn, "string(/pool/source/auth/@type)", ctxt);
@@ -499,6 +513,9 @@ virStoragePoolDefFormat(virConnectPtr conn,
     if ((options->flags & VIR_STORAGE_BACKEND_POOL_SOURCE_ADAPTER) &&
         def->source.adapter)
         virBufferVSprintf(&buf,"    <adapter name='%s'/>\n", def->source.adapter);
+    if ((options->flags & VIR_STORAGE_BACKEND_POOL_SOURCE_NAME) &&
+        def->source.name)
+        virBufferVSprintf(&buf,"    <name>%s</name>\n", def->source.name);
 
     if (options->formatToString) {
         const char *format = (options->formatToString)(conn, def->source.format);
diff --git a/src/storage_conf.h b/src/storage_conf.h
index e3577b5..3500039 100644
--- a/src/storage_conf.h
+++ b/src/storage_conf.h
@@ -174,6 +174,9 @@ struct _virStoragePoolSource {
     /* Or an adapter */
     char *adapter;
 
+    /* Or a name */
+    char *name;
+
     int authType;       /* virStoragePoolAuthType */
     union {
         virStoragePoolAuthChap chap;
