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:
Peter Krempa 2022-03-08 15:02:29 +01:00
parent b150c6cf31
commit 0146d70887
4 changed files with 29 additions and 25 deletions

View File

@ -198,6 +198,7 @@ virCHMonitorBuildDiskJson(virJSONValue *disks, virDomainDiskDef *diskdef)
case VIR_STORAGE_TYPE_VOLUME: case VIR_STORAGE_TYPE_VOLUME:
case VIR_STORAGE_TYPE_NVME: case VIR_STORAGE_TYPE_NVME:
case VIR_STORAGE_TYPE_VHOST_USER: case VIR_STORAGE_TYPE_VHOST_USER:
case VIR_STORAGE_TYPE_LAST:
default: default:
virReportEnumRangeError(virStorageType, diskdef->src->type); virReportEnumRangeError(virStorageType, diskdef->src->type);
return -1; return -1;

View File

@ -8502,11 +8502,15 @@ virDomainStorageSourceParseBase(const char *type,
src = virStorageSourceNew(); src = virStorageSourceNew();
src->type = VIR_STORAGE_TYPE_FILE; src->type = VIR_STORAGE_TYPE_FILE;
if (type && if (type) {
(src->type = virStorageTypeFromString(type)) <= 0) { int tmp;
virReportError(VIR_ERR_XML_ERROR, if ((tmp = virStorageTypeFromString(type)) <= 0) {
_("unknown storage source type '%s'"), type); virReportError(VIR_ERR_XML_ERROR,
return NULL; _("unknown storage source type '%s'"), type);
return NULL;
}
src->type = tmp;
} }
if (format && if (format &&
@ -9055,19 +9059,16 @@ virDomainDiskDefParseSourceXML(virDomainXMLOption *xmlopt,
{ {
g_autoptr(virStorageSource) src = virStorageSourceNew(); g_autoptr(virStorageSource) src = virStorageSourceNew();
VIR_XPATH_NODE_AUTORESTORE(ctxt) VIR_XPATH_NODE_AUTORESTORE(ctxt)
g_autofree char *type = NULL;
xmlNodePtr tmp; xmlNodePtr tmp;
ctxt->node = node; ctxt->node = node;
src->type = VIR_STORAGE_TYPE_FILE; if (virXMLPropEnumDefault(node, "type",
virStorageTypeFromString,
if ((type = virXMLPropString(node, "type")) && VIR_XML_PROP_NONZERO,
(src->type = virStorageTypeFromString(type)) <= 0) { &src->type,
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, VIR_STORAGE_TYPE_FILE) < 0)
_("unknown disk type '%s'"), type);
return NULL; return NULL;
}
if ((tmp = virXPathNode("./source[1]", ctxt))) { if ((tmp = virXPathNode("./source[1]", ctxt))) {
if (virDomainStorageSourceParse(tmp, ctxt, src, flags, xmlopt) < 0) if (virDomainStorageSourceParse(tmp, ctxt, src, flags, xmlopt) < 0)

View File

@ -139,7 +139,6 @@ virDomainSnapshotDiskDefParseXML(xmlNodePtr node,
virDomainXMLOption *xmlopt) virDomainXMLOption *xmlopt)
{ {
g_autofree char *snapshot = NULL; g_autofree char *snapshot = NULL;
g_autofree char *type = NULL;
g_autofree char *driver = NULL; g_autofree char *driver = NULL;
g_autofree char *name = NULL; g_autofree char *name = NULL;
g_autoptr(virStorageSource) src = virStorageSourceNew(); g_autoptr(virStorageSource) src = virStorageSourceNew();
@ -165,16 +164,19 @@ virDomainSnapshotDiskDefParseXML(xmlNodePtr node,
} }
} }
if ((type = virXMLPropString(node, "type"))) { if (virXMLPropEnumDefault(node, "type",
if ((src->type = virStorageTypeFromString(type)) <= 0 || virStorageTypeFromString,
src->type == VIR_STORAGE_TYPE_VOLUME || VIR_XML_PROP_NONZERO,
src->type == VIR_STORAGE_TYPE_DIR) { &src->type,
virReportError(VIR_ERR_XML_ERROR, VIR_STORAGE_TYPE_FILE) < 0)
_("unknown disk snapshot type '%s'"), type); return -1;
return -1;
} if (src->type == VIR_STORAGE_TYPE_VOLUME ||
} else { src->type == VIR_STORAGE_TYPE_DIR) {
src->type = VIR_STORAGE_TYPE_FILE; virReportError(VIR_ERR_XML_ERROR,
_("unsupported disk snapshot type '%s'"),
virStorageTypeToString(src->type));
return -1;
} }
if ((cur = virXPathNode("./source", ctxt)) && if ((cur = virXPathNode("./source", ctxt)) &&

View File

@ -269,7 +269,7 @@ struct _virStorageSource {
virObject parent; virObject parent;
unsigned int id; /* backing chain identifier, 0 is unset */ unsigned int id; /* backing chain identifier, 0 is unset */
int type; /* virStorageType */ virStorageType type;
char *path; char *path;
int protocol; /* virStorageNetProtocol */ int protocol; /* virStorageNetProtocol */
char *volume; /* volume name for remote storage */ char *volume; /* volume name for remote storage */