[libvirt] [PATCH 3/5] conf: track when storage type is still undetermined

Eric Blake eblake at redhat.com
Fri Apr 4 04:32:53 UTC 2014


Right now, virStorageFileMetadata tracks bool backingStoreIsFile
for whether the backing string specified in metadata can be
resolved as a file (covering both block and regular file
resources) or is treated as a network protocol.  But when
merging this struct with virStorageSource, it will be easier
to just actually track which type of resource it is, as well
as have a reserved value for the case where the resource type
is unknown (or had an error during probing).

* src/util/virstoragefile.h (virStorageType): Add a placeholder
value, swap order to match similar public enum.
* src/util/virstoragefile.c (virStorage): Update string mapping.
* src/conf/domain_conf.c (virDomainDiskSourceParse)
(virDomainDiskDefParseXML, virDomainDiskDefFormat)
(virDomainDiskSourceFormat): Adjust clients.
* src/conf/snapshot_conf.c (virDomainSnapshotDiskDefParseXML):
Likewise.
* src/qemu/qemu_driver.c
(qemuDomainSnapshotPrepareDiskExternalBackingInactive)
(qemuDomainSnapshotPrepareDiskExternalOverlayActive)
(qemuDomainSnapshotPrepareDiskExternalOverlayInactive)
(qemuDomainSnapshotPrepareDiskInternal)
(qemuDomainSnapshotCreateSingleDiskActive): Likewise.
* src/qemu/qemu_command.c (qemuGetDriveSourceString): Likewise.

Signed-off-by: Eric Blake <eblake at redhat.com>
---
 src/conf/domain_conf.c    | 10 ++++++----
 src/conf/snapshot_conf.c  |  2 +-
 src/qemu/qemu_command.c   |  1 +
 src/qemu/qemu_driver.c    | 11 +++++++++--
 src/util/virstoragefile.c |  3 ++-
 src/util/virstoragefile.h |  8 ++++++--
 6 files changed, 25 insertions(+), 10 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 465bf84..0c5c7ab 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -4965,7 +4965,7 @@ virDomainDiskSourceParse(xmlNodePtr node,

     memset(&host, 0, sizeof(host));

-    switch (src->type) {
+    switch ((enum virStorageType)src->type) {
     case VIR_STORAGE_TYPE_FILE:
         src->path = virXMLPropString(node, "file");
         break;
@@ -5053,7 +5053,8 @@ virDomainDiskSourceParse(xmlNodePtr node,
         if (virDomainDiskSourcePoolDefParse(node, &src->srcpool) < 0)
             goto cleanup;
         break;
-    default:
+    case VIR_STORAGE_TYPE_NONE:
+    case VIR_STORAGE_TYPE_LAST:
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("unexpected disk type %s"),
                        virStorageTypeToString(src->type));
@@ -5150,7 +5151,7 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,

     type = virXMLPropString(node, "type");
     if (type) {
-        if ((def->src.type = virStorageTypeFromString(type)) < 0) {
+        if ((def->src.type = virStorageTypeFromString(type)) <= 0) {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                            _("unknown disk type '%s'"), type);
             goto error;
@@ -14836,6 +14837,7 @@ virDomainDiskSourceFormat(virBufferPtr buf,
                                                  src->seclabels, flags);
             break;

+        case VIR_STORAGE_TYPE_NONE:
         case VIR_STORAGE_TYPE_LAST:
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("unexpected disk type %d"), src->type);
@@ -14867,7 +14869,7 @@ virDomainDiskDefFormat(virBufferPtr buf,

     char uuidstr[VIR_UUID_STRING_BUFLEN];

-    if (!type) {
+    if (!type || !def->src.type) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("unexpected disk type %d"), def->src.type);
         return -1;
diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c
index 374a104..852a286 100644
--- a/src/conf/snapshot_conf.c
+++ b/src/conf/snapshot_conf.c
@@ -132,7 +132,7 @@ virDomainSnapshotDiskDefParseXML(xmlNodePtr node,
     }

     if ((type = virXMLPropString(node, "type"))) {
-        if ((def->src.type = virStorageTypeFromString(type)) < 0 ||
+        if ((def->src.type = virStorageTypeFromString(type)) <= 0 ||
             def->src.type == VIR_STORAGE_TYPE_VOLUME ||
             def->src.type == VIR_STORAGE_TYPE_DIR) {
             virReportError(VIR_ERR_XML_ERROR,
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 099a777..37841d1 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3856,6 +3856,7 @@ qemuGetDriveSourceString(int type,
         break;

     case VIR_STORAGE_TYPE_VOLUME:
+    case VIR_STORAGE_TYPE_NONE:
     case VIR_STORAGE_TYPE_LAST:
         break;
     }
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 1d08951..4bb4819 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -12356,6 +12356,7 @@ qemuDomainSnapshotPrepareDiskExternalBackingInactive(virDomainDiskDefPtr disk)

     case VIR_STORAGE_TYPE_DIR:
     case VIR_STORAGE_TYPE_VOLUME:
+    case VIR_STORAGE_TYPE_NONE:
     case VIR_STORAGE_TYPE_LAST:
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("external inactive snapshots are not supported on "
@@ -12420,6 +12421,7 @@ qemuDomainSnapshotPrepareDiskExternalOverlayActive(virDomainSnapshotDiskDefPtr d

     case VIR_STORAGE_TYPE_DIR:
     case VIR_STORAGE_TYPE_VOLUME:
+    case VIR_STORAGE_TYPE_NONE:
     case VIR_STORAGE_TYPE_LAST:
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("external active snapshots are not supported on "
@@ -12444,6 +12446,7 @@ qemuDomainSnapshotPrepareDiskExternalOverlayInactive(virDomainSnapshotDiskDefPtr
     case VIR_STORAGE_TYPE_NETWORK:
     case VIR_STORAGE_TYPE_DIR:
     case VIR_STORAGE_TYPE_VOLUME:
+    case VIR_STORAGE_TYPE_NONE:
     case VIR_STORAGE_TYPE_LAST:
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("external inactive snapshots are not supported on "
@@ -12561,6 +12564,7 @@ qemuDomainSnapshotPrepareDiskInternal(virConnectPtr conn,

     case VIR_STORAGE_TYPE_DIR:
     case VIR_STORAGE_TYPE_VOLUME:
+    case VIR_STORAGE_TYPE_NONE:
     case VIR_STORAGE_TYPE_LAST:
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("internal inactive snapshots are not supported on "
@@ -12766,7 +12770,7 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver,
         VIR_STRDUP(persistSource, snap->src.path) < 0)
         goto cleanup;

-    switch (snap->src.type) {
+    switch ((enum virStorageType)snap->src.type) {
     case VIR_STORAGE_TYPE_BLOCK:
         reuse = true;
         /* fallthrough */
@@ -12813,7 +12817,10 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver,
         }
         break;

-    default:
+    case VIR_STORAGE_TYPE_DIR:
+    case VIR_STORAGE_TYPE_VOLUME:
+    case VIR_STORAGE_TYPE_NONE:
+    case VIR_STORAGE_TYPE_LAST:
         virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
                        _("snapshots are not supported on '%s' volumes"),
                        virStorageTypeToString(snap->src.type));
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index e6a985d..0e1461d 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -48,8 +48,9 @@
 VIR_LOG_INIT("util.storagefile");

 VIR_ENUM_IMPL(virStorage, VIR_STORAGE_TYPE_LAST,
-              "block",
+              "none",
               "file",
+              "block",
               "dir",
               "network",
               "volume")
diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h
index 56105d0..3807285 100644
--- a/src/util/virstoragefile.h
+++ b/src/util/virstoragefile.h
@@ -38,10 +38,14 @@
 # define VIR_STORAGE_MAX_HEADER 0x8200


-/* Types of disk backends (host resource) */
+/* Types of disk backends (host resource).  Comparable to the public
+ * virStorageVolType, except we have an undetermined state, don't have
+ * a netdir type, and add a volume type for reference through a
+ * storage pool.  */
 enum virStorageType {
-    VIR_STORAGE_TYPE_BLOCK,
+    VIR_STORAGE_TYPE_NONE,
     VIR_STORAGE_TYPE_FILE,
+    VIR_STORAGE_TYPE_BLOCK,
     VIR_STORAGE_TYPE_DIR,
     VIR_STORAGE_TYPE_NETWORK,
     VIR_STORAGE_TYPE_VOLUME,
-- 
1.9.0




More information about the libvir-list mailing list