]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Adds storage source element for pools
authorDaniel Veillard <veillard@redhat.com>
Tue, 2 Sep 2008 14:15:42 +0000 (14:15 +0000)
committerDaniel Veillard <veillard@redhat.com>
Tue, 2 Sep 2008 14:15:42 +0000 (14:15 +0000)
* src/storage_backend.h src/storage_backend_logical.c
src/storage_conf.c src/storage_conf.h src/virsh.c:
Applied patches from David Lively to add storage source
elements needed for storage pool
* docs/formatstorage.html docs/formatstorage.html.in: associated
documentation
Daniel

ChangeLog
docs/formatstorage.html
docs/formatstorage.html.in
src/storage_backend.h
src/storage_backend_logical.c
src/storage_conf.c
src/storage_conf.h
src/virsh.c

index 87c3c684bc2e1a4a48d2790b13339dbd999b61c3..3ef2c64ab2ba610181b63adef2ad6d64cac3f6c2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Tue Sep  2 16:12:20 CEST 2008 Daniel Veillard <veillard@redhat.com>
+
+       * src/storage_backend.h src/storage_backend_logical.c
+         src/storage_conf.c src/storage_conf.h src/virsh.c:
+         Applied patches from David Lively to add storage source
+         elements needed for storage pool
+       * docs/formatstorage.html docs/formatstorage.html.in: associated
+         documentation
+
 Tue Sep  2 12:28:54 CEST 2008 Jim Meyering <meyering@redhat.com>
 
        qemu_conf.c: use new function, virFileReadLimFD
index 4f0027bcd2653026bd096b035a363e382861863e..9d92b4cfef78849b6b89d2be6b4db4ddf67b828d 100644 (file)
        or <code>device</code> element. Contains an attribute <code>name</code>
        which is the hostname or IP address of the server. May optionally
        contain a <code>port</code> attribute for the protocol specific
-       port number. <span class="since">Since 0.4.1</span></dd><dt><code>format</code></dt><dd>Provides information about the format of the pool. This
+       port number. <span class="since">Since 0.4.1</span></dd><dt><code>name</code></dt><dd>Provides the source for pools backed by storage from a
+       named element (e.g., a logical volume group name).
+       remote server. Contains a string identifier.
+       <span class="since">Since 0.4.5</span></dd><dt><code>format</code></dt><dd>Provides information about the format of the pool. This
        contains a single attribute <code>type</code> whose value is
        backend specific. This is typically used to indicate filesystem
        type, or network filesystem type, or partition table type, or
index 7ee7bb8669b8b570ec8561524a4726f1d9624e7b..7cd4731da91807e7732b0de01aa35455861c9853 100644 (file)
        which is the hostname or IP address of the server. May optionally
        contain a <code>port</code> attribute for the protocol specific
        port number. <span class="since">Since 0.4.1</span></dd>
+      <dt><code>name</code></dt>
+      <dd>Provides the source for pools backed by storage from a
+       named element (e.g., a logical volume group name).
+       remote server. Contains a string identifier.
+       <span class="since">Since 0.4.5</span></dd>
       <dt><code>format</code></dt>
       <dd>Provides information about the format of the pool. This
        contains a single attribute <code>type</code> whose value is
index a06746b396afa6e3cba8e7794a6a48764917a6f0..5ca5d27b53533a3fa29ac942630d98946e0681fb 100644 (file)
@@ -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;
index c30323acbf916bb7f0bf4c69821a4e0bce6498d5..d182b5e36dd131f147f3b380f593c9dc2958dbc5 100644 (file)
@@ -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;
@@ -357,7 +357,7 @@ virStorageBackendLogicalBuildPool(virConnectPtr conn,
     }
 
     vgargv[n++] = VGCREATE;
-    vgargv[n++] = pool->def->name;
+    vgargv[n++] = pool->def->source.name;
 
     pvargv[0] = PVCREATE;
     pvargv[2] = NULL;
@@ -434,7 +434,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;
 
@@ -488,7 +488,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)
@@ -618,6 +618,7 @@ virStorageBackend virStorageBackendLogical = {
     .deleteVol = virStorageBackendLogicalDeleteVol,
 
     .poolOptions = {
+        .flags = VIR_STORAGE_BACKEND_POOL_SOURCE_NAME,
         .formatFromString = virStorageBackendLogicalPoolFormatFromString,
         .formatToString = virStorageBackendLogicalPoolFormatToString,
     },
index 05b68af15b99a74a379f8dd8f463bf31ad11bbf7..2f6093beb661314ccf71f576188a03db645edb0f 100644 (file)
@@ -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);
@@ -234,7 +235,7 @@ virStoragePoolDefParseDoc(virConnectPtr conn,
 
     if (STRNEQ((const char *)root->name, "pool")) {
         virStorageReportError(conn, VIR_ERR_XML_ERROR,
-                              "%s", _("unknown root element"));
+                          "%s", _("unknown root elementi for storage pool"));
         goto cleanup;
     }
 
@@ -248,9 +249,13 @@ 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"));
+                              "%s", _("missing pool source name element"));
         goto cleanup;
     }
 
@@ -282,7 +287,7 @@ virStoragePoolDefParseDoc(virConnectPtr conn,
     if (options->flags & VIR_STORAGE_BACKEND_POOL_SOURCE_HOST) {
         if ((ret->source.host.name = virXPathString(conn, "string(/pool/source/host/@name)", ctxt)) == NULL) {
             virStorageReportError(conn, VIR_ERR_XML_ERROR,
-                                  "%s", _("missing source host name"));
+                             "%s", _("missing storage pool source host name"));
             goto cleanup;
         }
     }
@@ -292,7 +297,7 @@ virStoragePoolDefParseDoc(virConnectPtr conn,
 
         if ((nsource = virXPathNodeSet(conn, "/pool/source/device", ctxt, &nodeset)) <= 0) {
             virStorageReportError(conn, VIR_ERR_XML_ERROR,
-                                  "%s", _("cannot extract source devices"));
+                        "%s", _("cannot extract storage pool source devices"));
             goto cleanup;
         }
         if (VIR_ALLOC_N(ret->source.devices, nsource) < 0) {
@@ -305,7 +310,7 @@ virStoragePoolDefParseDoc(virConnectPtr conn,
             if (path == NULL) {
                 VIR_FREE(nodeset);
                 virStorageReportError(conn, VIR_ERR_XML_ERROR,
-                                      "%s", _("missing source device path"));
+                        "%s", _("missing storage pool source device path"));
                 goto cleanup;
             }
             ret->source.devices[i].path = (char *)path;
@@ -316,10 +321,18 @@ virStoragePoolDefParseDoc(virConnectPtr conn,
     if (options->flags & VIR_STORAGE_BACKEND_POOL_SOURCE_DIR) {
         if ((ret->source.dir = virXPathString(conn, "string(/pool/source/dir/@path)", ctxt)) == NULL) {
             virStorageReportError(conn, VIR_ERR_XML_ERROR,
-                                  "%s", _("missing source path"));
+                                "%s", _("missing storage pool source path"));
             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);
+        }
+    }
 
 
     authType = virXPathString(conn, "string(/pool/source/auth/@type)", ctxt);
@@ -345,7 +358,7 @@ virStoragePoolDefParseDoc(virConnectPtr conn,
 
     if ((ret->target.path = virXPathString(conn, "string(/pool/target/path)", ctxt)) == NULL) {
         virStorageReportError(conn, VIR_ERR_XML_ERROR,
-                              "%s", _("missing target path"));
+                              "%s", _("missing storage pool target path"));
         goto cleanup;
     }
 
@@ -499,6 +512,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);
@@ -698,7 +714,7 @@ virStorageVolDefParseDoc(virConnectPtr conn,
     ret->name = virXPathString(conn, "string(/volume/name)", ctxt);
     if (ret->name == NULL) {
         virStorageReportError(conn, VIR_ERR_XML_ERROR,
-                              "%s", _("missing name element"));
+                              "%s", _("missing volume name element"));
         goto cleanup;
     }
 
index e3577b59caee8e582124bd3f4af725d02c8c0406..3500039dffde8485da393e26b73ee013dd92884e 100644 (file)
@@ -174,6 +174,9 @@ struct _virStoragePoolSource {
     /* Or an adapter */
     char *adapter;
 
+    /* Or a name */
+    char *name;
+
     int authType;       /* virStoragePoolAuthType */
     union {
         virStoragePoolAuthChap chap;
index eb5c65932301c0cf1522103d003e03407a9f30b9..1fb07ad8a2be0da4ddb389d052420ee922afd3b3 100644 (file)
@@ -3024,6 +3024,7 @@ static const vshCmdOptDef opts_pool_define_as[] = {
     {"source-host", VSH_OT_DATA, 0, gettext_noop("source-host for underlying storage")},
     {"source-path", VSH_OT_DATA, 0, gettext_noop("source path for underlying storage")},
     {"source-dev", VSH_OT_DATA, 0, gettext_noop("source device for underlying storage")},
+    {"source-name", VSH_OT_DATA, 0, gettext_noop("source name for underlying storage")},
     {"target", VSH_OT_DATA, 0, gettext_noop("target for underlying storage")},
     {NULL, 0, 0, NULL}
 };
@@ -3035,7 +3036,7 @@ cmdPoolDefineAs(vshControl *ctl, const vshCmd *cmd)
     virStoragePoolPtr pool;
     int found;
     char *xml;
-    char *name, *type, *srcHost, *srcPath, *srcDev, *target;
+    char *name, *type, *srcHost, *srcPath, *srcDev, *srcName, *target;
     virBuffer buf = VIR_BUFFER_INITIALIZER;
 
     if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
@@ -3051,11 +3052,12 @@ cmdPoolDefineAs(vshControl *ctl, const vshCmd *cmd)
     srcHost = vshCommandOptString(cmd, "source-host", &found);
     srcPath = vshCommandOptString(cmd, "source-path", &found);
     srcDev = vshCommandOptString(cmd, "source-dev", &found);
+    srcName = vshCommandOptString(cmd, "source-name", &found);
     target = vshCommandOptString(cmd, "target", &found);
 
     virBufferVSprintf(&buf, "<pool type='%s'>\n", type);
     virBufferVSprintf(&buf, "  <name>%s</name>\n", name);
-    if (srcHost || srcPath || srcDev) {
+    if (srcHost || srcPath || srcDev || srcName) {
         virBufferAddLit(&buf, "  <source>\n");
         if (srcHost)
             virBufferVSprintf(&buf, "    <host>%s</host>\n", srcHost);
@@ -3063,6 +3065,8 @@ cmdPoolDefineAs(vshControl *ctl, const vshCmd *cmd)
             virBufferVSprintf(&buf, "    <path>%s</path>\n", srcPath);
         if (srcDev)
             virBufferVSprintf(&buf, "    <device>%s</device>\n", srcDev);
+        if (srcName)
+            virBufferVSprintf(&buf, "    <name>%s</name>\n", srcName);
 
         virBufferAddLit(&buf, "  </source>\n");
     }