mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 17:34:18 +03:00
virStorageSource: Convert 'type' to proper enum
Use 'virStorageType' as type for the 'type' member and convert the code to work properly. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
b150c6cf31
commit
0146d70887
@ -198,6 +198,7 @@ virCHMonitorBuildDiskJson(virJSONValue *disks, virDomainDiskDef *diskdef)
|
||||
case VIR_STORAGE_TYPE_VOLUME:
|
||||
case VIR_STORAGE_TYPE_NVME:
|
||||
case VIR_STORAGE_TYPE_VHOST_USER:
|
||||
case VIR_STORAGE_TYPE_LAST:
|
||||
default:
|
||||
virReportEnumRangeError(virStorageType, diskdef->src->type);
|
||||
return -1;
|
||||
|
@ -8502,11 +8502,15 @@ virDomainStorageSourceParseBase(const char *type,
|
||||
src = virStorageSourceNew();
|
||||
src->type = VIR_STORAGE_TYPE_FILE;
|
||||
|
||||
if (type &&
|
||||
(src->type = virStorageTypeFromString(type)) <= 0) {
|
||||
virReportError(VIR_ERR_XML_ERROR,
|
||||
_("unknown storage source type '%s'"), type);
|
||||
return NULL;
|
||||
if (type) {
|
||||
int tmp;
|
||||
if ((tmp = virStorageTypeFromString(type)) <= 0) {
|
||||
virReportError(VIR_ERR_XML_ERROR,
|
||||
_("unknown storage source type '%s'"), type);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
src->type = tmp;
|
||||
}
|
||||
|
||||
if (format &&
|
||||
@ -9055,19 +9059,16 @@ virDomainDiskDefParseSourceXML(virDomainXMLOption *xmlopt,
|
||||
{
|
||||
g_autoptr(virStorageSource) src = virStorageSourceNew();
|
||||
VIR_XPATH_NODE_AUTORESTORE(ctxt)
|
||||
g_autofree char *type = NULL;
|
||||
xmlNodePtr tmp;
|
||||
|
||||
ctxt->node = node;
|
||||
|
||||
src->type = VIR_STORAGE_TYPE_FILE;
|
||||
|
||||
if ((type = virXMLPropString(node, "type")) &&
|
||||
(src->type = virStorageTypeFromString(type)) <= 0) {
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||
_("unknown disk type '%s'"), type);
|
||||
if (virXMLPropEnumDefault(node, "type",
|
||||
virStorageTypeFromString,
|
||||
VIR_XML_PROP_NONZERO,
|
||||
&src->type,
|
||||
VIR_STORAGE_TYPE_FILE) < 0)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((tmp = virXPathNode("./source[1]", ctxt))) {
|
||||
if (virDomainStorageSourceParse(tmp, ctxt, src, flags, xmlopt) < 0)
|
||||
|
@ -139,7 +139,6 @@ virDomainSnapshotDiskDefParseXML(xmlNodePtr node,
|
||||
virDomainXMLOption *xmlopt)
|
||||
{
|
||||
g_autofree char *snapshot = NULL;
|
||||
g_autofree char *type = NULL;
|
||||
g_autofree char *driver = NULL;
|
||||
g_autofree char *name = NULL;
|
||||
g_autoptr(virStorageSource) src = virStorageSourceNew();
|
||||
@ -165,16 +164,19 @@ virDomainSnapshotDiskDefParseXML(xmlNodePtr node,
|
||||
}
|
||||
}
|
||||
|
||||
if ((type = virXMLPropString(node, "type"))) {
|
||||
if ((src->type = virStorageTypeFromString(type)) <= 0 ||
|
||||
src->type == VIR_STORAGE_TYPE_VOLUME ||
|
||||
src->type == VIR_STORAGE_TYPE_DIR) {
|
||||
virReportError(VIR_ERR_XML_ERROR,
|
||||
_("unknown disk snapshot type '%s'"), type);
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
src->type = VIR_STORAGE_TYPE_FILE;
|
||||
if (virXMLPropEnumDefault(node, "type",
|
||||
virStorageTypeFromString,
|
||||
VIR_XML_PROP_NONZERO,
|
||||
&src->type,
|
||||
VIR_STORAGE_TYPE_FILE) < 0)
|
||||
return -1;
|
||||
|
||||
if (src->type == VIR_STORAGE_TYPE_VOLUME ||
|
||||
src->type == VIR_STORAGE_TYPE_DIR) {
|
||||
virReportError(VIR_ERR_XML_ERROR,
|
||||
_("unsupported disk snapshot type '%s'"),
|
||||
virStorageTypeToString(src->type));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((cur = virXPathNode("./source", ctxt)) &&
|
||||
|
@ -269,7 +269,7 @@ struct _virStorageSource {
|
||||
virObject parent;
|
||||
|
||||
unsigned int id; /* backing chain identifier, 0 is unset */
|
||||
int type; /* virStorageType */
|
||||
virStorageType type;
|
||||
char *path;
|
||||
int protocol; /* virStorageNetProtocol */
|
||||
char *volume; /* volume name for remote storage */
|
||||
|
Loading…
Reference in New Issue
Block a user