conf: track when storage type is still undetermined

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@redhat.com>
This commit is contained in:
Eric Blake 2014-04-02 13:01:46 -06:00
parent d1a1d841db
commit 9673418ce5
6 changed files with 25 additions and 10 deletions

View File

@ -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;

View File

@ -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,

View File

@ -3856,6 +3856,7 @@ qemuGetDriveSourceString(int type,
break;
case VIR_STORAGE_TYPE_VOLUME:
case VIR_STORAGE_TYPE_NONE:
case VIR_STORAGE_TYPE_LAST:
break;
}

View File

@ -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));

View File

@ -48,8 +48,9 @@
VIR_LOG_INIT("util.storagefile");
VIR_ENUM_IMPL(virStorage, VIR_STORAGE_TYPE_LAST,
"block",
"none",
"file",
"block",
"dir",
"network",
"volume")

View File

@ -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,