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_NVME:
case VIR_STORAGE_TYPE_VHOST_USER:
case VIR_STORAGE_TYPE_LAST:
default:
virReportEnumRangeError(virStorageType, diskdef->src->type);
return -1;

View File

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

View File

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

View File

@ -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 */