提交 9b73290f 编写于 作者: C Christophe Fergeau

conf: Always use VIR_ERR_CONFIG_UNSUPPORTED on enumFromString() failures

Currently, during XML parsing, when a call to a FromString() function to
get an enum value fails, the error which is reported is either
VIR_ERR_CONFIG_UNSUPPORTED, VIR_ERR_INTERNAL_ERROR or VIR_ERR_XML_ERROR.

This commit makes such conversion failures consistently return
VIR_ERR_CONFIG_UNSUPPORTED.
上级 f902734b
...@@ -221,7 +221,7 @@ virCPUDefParseXML(xmlNodePtr node, ...@@ -221,7 +221,7 @@ virCPUDefParseXML(xmlNodePtr node,
def->mode = virCPUModeTypeFromString(cpuMode); def->mode = virCPUModeTypeFromString(cpuMode);
if (def->mode < 0) { if (def->mode < 0) {
virReportError(VIR_ERR_XML_ERROR, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Invalid mode attribute '%s'"), _("Invalid mode attribute '%s'"),
cpuMode); cpuMode);
VIR_FREE(cpuMode); VIR_FREE(cpuMode);
...@@ -249,7 +249,7 @@ virCPUDefParseXML(xmlNodePtr node, ...@@ -249,7 +249,7 @@ virCPUDefParseXML(xmlNodePtr node,
VIR_FREE(match); VIR_FREE(match);
if (def->match < 0) { if (def->match < 0) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Invalid match attribute for CPU " _("Invalid match attribute for CPU "
"specification")); "specification"));
goto error; goto error;
...@@ -265,7 +265,7 @@ virCPUDefParseXML(xmlNodePtr node, ...@@ -265,7 +265,7 @@ virCPUDefParseXML(xmlNodePtr node,
goto error; goto error;
} }
if ((def->arch = virArchFromString(arch)) == VIR_ARCH_NONE) { if ((def->arch = virArchFromString(arch)) == VIR_ARCH_NONE) {
virReportError(VIR_ERR_XML_ERROR, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Unknown architecture %s"), arch); _("Unknown architecture %s"), arch);
VIR_FREE(arch); VIR_FREE(arch);
goto error; goto error;
...@@ -285,7 +285,7 @@ virCPUDefParseXML(xmlNodePtr node, ...@@ -285,7 +285,7 @@ virCPUDefParseXML(xmlNodePtr node,
if ((fallback = virXPathString("string(./model[1]/@fallback)", ctxt))) { if ((fallback = virXPathString("string(./model[1]/@fallback)", ctxt))) {
if ((def->fallback = virCPUFallbackTypeFromString(fallback)) < 0) { if ((def->fallback = virCPUFallbackTypeFromString(fallback)) < 0) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Invalid fallback attribute")); _("Invalid fallback attribute"));
goto error; goto error;
} }
...@@ -391,7 +391,7 @@ virCPUDefParseXML(xmlNodePtr node, ...@@ -391,7 +391,7 @@ virCPUDefParseXML(xmlNodePtr node,
VIR_FREE(strpolicy); VIR_FREE(strpolicy);
if (policy < 0) { if (policy < 0) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Invalid CPU feature policy")); _("Invalid CPU feature policy"));
goto error; goto error;
} }
......
此差异已折叠。
...@@ -662,7 +662,7 @@ virInterfaceDefParseXML(xmlXPathContextPtr ctxt, int parentIfType) { ...@@ -662,7 +662,7 @@ virInterfaceDefParseXML(xmlXPathContextPtr ctxt, int parentIfType) {
} }
type = virInterfaceTypeFromString(tmp); type = virInterfaceTypeFromString(tmp);
if (type == -1) { if (type == -1) {
virReportError(VIR_ERR_XML_ERROR, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown interface type %s"), tmp); _("unknown interface type %s"), tmp);
VIR_FREE(tmp); VIR_FREE(tmp);
return NULL; return NULL;
......
...@@ -82,7 +82,7 @@ virNetDevVlanParse(xmlNodePtr node, xmlXPathContextPtr ctxt, virNetDevVlanPtr de ...@@ -82,7 +82,7 @@ virNetDevVlanParse(xmlNodePtr node, xmlXPathContextPtr ctxt, virNetDevVlanPtr de
} }
if ((def->nativeMode if ((def->nativeMode
= virNativeVlanModeTypeFromString(nativeMode)) <= 0) { = virNativeVlanModeTypeFromString(nativeMode)) <= 0) {
virReportError(VIR_ERR_XML_ERROR, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Invalid \"nativeMode='%s'\" " _("Invalid \"nativeMode='%s'\" "
"in vlan <tag> element"), "in vlan <tag> element"),
nativeMode); nativeMode);
......
...@@ -48,7 +48,7 @@ virNetDevVPortProfileParse(xmlNodePtr node, unsigned int flags) ...@@ -48,7 +48,7 @@ virNetDevVPortProfileParse(xmlNodePtr node, unsigned int flags)
if ((virtPortType = virXMLPropString(node, "type")) && if ((virtPortType = virXMLPropString(node, "type")) &&
(virtPort->virtPortType = virNetDevVPortTypeFromString(virtPortType)) <= 0) { (virtPort->virtPortType = virNetDevVPortTypeFromString(virtPortType)) <= 0) {
virReportError(VIR_ERR_XML_ERROR, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown virtualport type %s"), virtPortType); _("unknown virtualport type %s"), virtPortType);
goto error; goto error;
} }
......
...@@ -1728,7 +1728,7 @@ virNetworkForwardDefParseXML(const char *networkName, ...@@ -1728,7 +1728,7 @@ virNetworkForwardDefParseXML(const char *networkName,
def->type = VIR_NETWORK_FORWARD_NAT; def->type = VIR_NETWORK_FORWARD_NAT;
} else { } else {
if ((def->type = virNetworkForwardTypeFromString(type)) < 0) { if ((def->type = virNetworkForwardTypeFromString(type)) < 0) {
virReportError(VIR_ERR_XML_ERROR, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown forwarding type '%s'"), type); _("unknown forwarding type '%s'"), type);
goto cleanup; goto cleanup;
} }
...@@ -1747,7 +1747,7 @@ virNetworkForwardDefParseXML(const char *networkName, ...@@ -1747,7 +1747,7 @@ virNetworkForwardDefParseXML(const char *networkName,
= virNetworkForwardDriverNameTypeFromString(forwardDriverName); = virNetworkForwardDriverNameTypeFromString(forwardDriverName);
if (driverName <= 0) { if (driverName <= 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Unknown forward <driver name='%s'/> " _("Unknown forward <driver name='%s'/> "
"in network %s"), "in network %s"),
forwardDriverName, networkName); forwardDriverName, networkName);
...@@ -1873,7 +1873,7 @@ virNetworkForwardDefParseXML(const char *networkName, ...@@ -1873,7 +1873,7 @@ virNetworkForwardDefParseXML(const char *networkName,
} }
if ((def->ifs[i].type = virNetworkForwardHostdevDeviceTypeFromString(type)) < 0) { if ((def->ifs[i].type = virNetworkForwardHostdevDeviceTypeFromString(type)) < 0) {
virReportError(VIR_ERR_XML_ERROR, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown address type '%s' in network %s"), _("unknown address type '%s' in network %s"),
type, networkName); type, networkName);
goto cleanup; goto cleanup;
......
...@@ -854,7 +854,7 @@ virNodeDevCapNetParseXML(xmlXPathContextPtr ctxt, ...@@ -854,7 +854,7 @@ virNodeDevCapNetParseXML(xmlXPathContextPtr ctxt,
int val = virNodeDevNetCapTypeFromString(tmp); int val = virNodeDevNetCapTypeFromString(tmp);
VIR_FREE(tmp); VIR_FREE(tmp);
if (val < 0) { if (val < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("invalid network type supplied for '%s'"), _("invalid network type supplied for '%s'"),
def->name); def->name);
goto out; goto out;
...@@ -1166,7 +1166,7 @@ virNodeDevCapsDefParseXML(xmlXPathContextPtr ctxt, ...@@ -1166,7 +1166,7 @@ virNodeDevCapsDefParseXML(xmlXPathContextPtr ctxt,
} }
if ((val = virNodeDevCapTypeFromString(tmp)) < 0) { if ((val = virNodeDevCapTypeFromString(tmp)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown capability type '%s'"), tmp); _("unknown capability type '%s'"), tmp);
VIR_FREE(tmp); VIR_FREE(tmp);
goto error; goto error;
......
...@@ -2319,7 +2319,7 @@ virNWFilterRuleParse(xmlNodePtr node) ...@@ -2319,7 +2319,7 @@ virNWFilterRuleParse(xmlNodePtr node)
} }
if ((ret->action = virNWFilterRuleActionTypeFromString(action)) < 0) { if ((ret->action = virNWFilterRuleActionTypeFromString(action)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
"%s", "%s",
_("unknown rule action attribute value")); _("unknown rule action attribute value"));
goto err_exit; goto err_exit;
...@@ -2333,7 +2333,7 @@ virNWFilterRuleParse(xmlNodePtr node) ...@@ -2333,7 +2333,7 @@ virNWFilterRuleParse(xmlNodePtr node)
} }
if ((ret->tt = virNWFilterRuleDirectionTypeFromString(direction)) < 0) { if ((ret->tt = virNWFilterRuleDirectionTypeFromString(direction)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
"%s", "%s",
_("unknown rule direction attribute value")); _("unknown rule direction attribute value"));
goto err_exit; goto err_exit;
......
...@@ -82,7 +82,7 @@ virSecretDefParseUsage(xmlXPathContextPtr ctxt, ...@@ -82,7 +82,7 @@ virSecretDefParseUsage(xmlXPathContextPtr ctxt,
} }
type = virSecretUsageTypeTypeFromString(type_str); type = virSecretUsageTypeTypeFromString(type_str);
if (type < 0) { if (type < 0) {
virReportError(VIR_ERR_XML_ERROR, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown secret usage type %s"), type_str); _("unknown secret usage type %s"), type_str);
VIR_FREE(type_str); VIR_FREE(type_str);
return -1; return -1;
......
...@@ -121,7 +121,7 @@ virDomainSnapshotDiskDefParseXML(xmlNodePtr node, ...@@ -121,7 +121,7 @@ virDomainSnapshotDiskDefParseXML(xmlNodePtr node,
if (snapshot) { if (snapshot) {
def->snapshot = virDomainSnapshotLocationTypeFromString(snapshot); def->snapshot = virDomainSnapshotLocationTypeFromString(snapshot);
if (def->snapshot <= 0) { if (def->snapshot <= 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown disk snapshot setting '%s'"), _("unknown disk snapshot setting '%s'"),
snapshot); snapshot);
goto cleanup; goto cleanup;
...@@ -157,7 +157,7 @@ virDomainSnapshotDiskDefParseXML(xmlNodePtr node, ...@@ -157,7 +157,7 @@ virDomainSnapshotDiskDefParseXML(xmlNodePtr node,
if (driver) { if (driver) {
def->format = virStorageFileFormatTypeFromString(driver); def->format = virStorageFileFormatTypeFromString(driver);
if (def->format <= 0) { if (def->format <= 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown disk snapshot driver '%s'"), _("unknown disk snapshot driver '%s'"),
driver); driver);
VIR_FREE(driver); VIR_FREE(driver);
...@@ -242,7 +242,7 @@ virDomainSnapshotDefParse(xmlXPathContextPtr ctxt, ...@@ -242,7 +242,7 @@ virDomainSnapshotDefParse(xmlXPathContextPtr ctxt,
} }
def->state = virDomainSnapshotStateTypeFromString(state); def->state = virDomainSnapshotStateTypeFromString(state);
if (def->state < 0) { if (def->state < 0) {
virReportError(VIR_ERR_XML_ERROR, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Invalid state '%s' in domain snapshot XML"), _("Invalid state '%s' in domain snapshot XML"),
state); state);
goto cleanup; goto cleanup;
...@@ -282,7 +282,7 @@ virDomainSnapshotDefParse(xmlXPathContextPtr ctxt, ...@@ -282,7 +282,7 @@ virDomainSnapshotDefParse(xmlXPathContextPtr ctxt,
if (memorySnapshot) { if (memorySnapshot) {
def->memory = virDomainSnapshotLocationTypeFromString(memorySnapshot); def->memory = virDomainSnapshotLocationTypeFromString(memorySnapshot);
if (def->memory <= 0) { if (def->memory <= 0) {
virReportError(VIR_ERR_XML_ERROR, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown memory snapshot setting '%s'"), _("unknown memory snapshot setting '%s'"),
memorySnapshot); memorySnapshot);
goto cleanup; goto cleanup;
......
...@@ -527,7 +527,7 @@ virStoragePoolDefParseAuth(xmlXPathContextPtr ctxt, ...@@ -527,7 +527,7 @@ virStoragePoolDefParseAuth(xmlXPathContextPtr ctxt,
if ((source->authType = if ((source->authType =
virStoragePoolAuthTypeTypeFromString(authType)) < 0) { virStoragePoolAuthTypeTypeFromString(authType)) < 0) {
virReportError(VIR_ERR_XML_ERROR, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown auth type '%s'"), _("unknown auth type '%s'"),
authType); authType);
goto cleanup; goto cleanup;
...@@ -601,7 +601,7 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt, ...@@ -601,7 +601,7 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt,
source->format = options->formatFromString(format); source->format = options->formatFromString(format);
if (source->format < 0) { if (source->format < 0) {
virReportError(VIR_ERR_XML_ERROR, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown pool format type %s"), format); _("unknown pool format type %s"), format);
VIR_FREE(format); VIR_FREE(format);
goto cleanup; goto cleanup;
...@@ -673,7 +673,7 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt, ...@@ -673,7 +673,7 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt,
if ((adapter_type = virXPathString("string(./adapter/@type)", ctxt))) { if ((adapter_type = virXPathString("string(./adapter/@type)", ctxt))) {
if ((source->adapter.type = if ((source->adapter.type =
virStoragePoolSourceAdapterTypeTypeFromString(adapter_type)) <= 0) { virStoragePoolSourceAdapterTypeTypeFromString(adapter_type)) <= 0) {
virReportError(VIR_ERR_XML_ERROR, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Unknown pool adapter type '%s'"), _("Unknown pool adapter type '%s'"),
adapter_type); adapter_type);
goto cleanup; goto cleanup;
...@@ -871,7 +871,7 @@ virStoragePoolDefParseXML(xmlXPathContextPtr ctxt) ...@@ -871,7 +871,7 @@ virStoragePoolDefParseXML(xmlXPathContextPtr ctxt)
} }
if ((ret->type = virStoragePoolTypeFromString(type)) < 0) { if ((ret->type = virStoragePoolTypeFromString(type)) < 0) {
virReportError(VIR_ERR_XML_ERROR, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown storage pool type %s"), type); _("unknown storage pool type %s"), type);
goto error; goto error;
} }
...@@ -1305,7 +1305,7 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool, ...@@ -1305,7 +1305,7 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
type = virXPathString("string(./@type)", ctxt); type = virXPathString("string(./@type)", ctxt);
if (type) { if (type) {
if ((ret->type = virStorageVolTypeFromString(type)) < 0) { if ((ret->type = virStorageVolTypeFromString(type)) < 0) {
virReportError(VIR_ERR_XML_ERROR, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown volume type '%s'"), type); _("unknown volume type '%s'"), type);
goto error; goto error;
} }
...@@ -1340,7 +1340,7 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool, ...@@ -1340,7 +1340,7 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
ret->target.format = (options->formatFromString)(format); ret->target.format = (options->formatFromString)(format);
if (ret->target.format < 0) { if (ret->target.format < 0) {
virReportError(VIR_ERR_XML_ERROR, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown volume format type %s"), format); _("unknown volume format type %s"), format);
VIR_FREE(format); VIR_FREE(format);
goto error; goto error;
...@@ -1370,7 +1370,7 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool, ...@@ -1370,7 +1370,7 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
ret->backingStore.format = (options->formatFromString)(format); ret->backingStore.format = (options->formatFromString)(format);
if (ret->backingStore.format < 0) { if (ret->backingStore.format < 0) {
virReportError(VIR_ERR_XML_ERROR, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown volume format type %s"), format); _("unknown volume format type %s"), format);
VIR_FREE(format); VIR_FREE(format);
goto error; goto error;
...@@ -1408,7 +1408,7 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool, ...@@ -1408,7 +1408,7 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
int f = options->featureFromString((const char*)nodes[i]->name); int f = options->featureFromString((const char*)nodes[i]->name);
if (f < 0) { if (f < 0) {
virReportError(VIR_ERR_XML_ERROR, _("unsupported feature %s"), virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unsupported feature %s"),
(const char*)nodes[i]->name); (const char*)nodes[i]->name);
goto error; goto error;
} }
......
...@@ -91,7 +91,7 @@ virStorageEncryptionSecretParse(xmlXPathContextPtr ctxt, ...@@ -91,7 +91,7 @@ virStorageEncryptionSecretParse(xmlXPathContextPtr ctxt,
} }
type = virStorageEncryptionSecretTypeTypeFromString(type_str); type = virStorageEncryptionSecretTypeTypeFromString(type_str);
if (type < 0) { if (type < 0) {
virReportError(VIR_ERR_XML_ERROR, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown volume encryption secret type %s"), _("unknown volume encryption secret type %s"),
type_str); type_str);
VIR_FREE(type_str); VIR_FREE(type_str);
...@@ -144,7 +144,7 @@ virStorageEncryptionParseXML(xmlXPathContextPtr ctxt) ...@@ -144,7 +144,7 @@ virStorageEncryptionParseXML(xmlXPathContextPtr ctxt)
} }
format = virStorageEncryptionFormatTypeFromString(format_str); format = virStorageEncryptionFormatTypeFromString(format_str);
if (format < 0) { if (format < 0) {
virReportError(VIR_ERR_XML_ERROR, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown volume encryption format type %s"), _("unknown volume encryption format type %s"),
format_str); format_str);
VIR_FREE(format_str); VIR_FREE(format_str);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册