mirror of https://gitee.com/openkylin/libvirt.git
cpu: simplify failure cleanup paths
Get rid of the separate 'error:' label, so all code paths jump straight to the 'cleanup:' label. Reviewed-by: Jiri Denemark <jdenemar@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
parent
0815f51978
commit
18cab54c3a
|
@ -288,27 +288,28 @@ ppc64VendorParse(xmlXPathContextPtr ctxt ATTRIBUTE_UNUSED,
|
||||||
{
|
{
|
||||||
struct ppc64_map *map = data;
|
struct ppc64_map *map = data;
|
||||||
struct ppc64_vendor *vendor;
|
struct ppc64_vendor *vendor;
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
if (VIR_ALLOC(vendor) < 0)
|
if (VIR_ALLOC(vendor) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (VIR_STRDUP(vendor->name, name) < 0)
|
if (VIR_STRDUP(vendor->name, name) < 0)
|
||||||
goto error;
|
goto cleanup;
|
||||||
|
|
||||||
if (ppc64VendorFind(map, vendor->name)) {
|
if (ppc64VendorFind(map, vendor->name)) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("CPU vendor %s already defined"), vendor->name);
|
_("CPU vendor %s already defined"), vendor->name);
|
||||||
goto error;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_APPEND_ELEMENT(map->vendors, map->nvendors, vendor) < 0)
|
if (VIR_APPEND_ELEMENT(map->vendors, map->nvendors, vendor) < 0)
|
||||||
goto error;
|
goto cleanup;
|
||||||
|
|
||||||
return 0;
|
ret = 0;
|
||||||
|
|
||||||
error:
|
cleanup:
|
||||||
ppc64VendorFree(vendor);
|
ppc64VendorFree(vendor);
|
||||||
return -1;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -327,15 +328,15 @@ ppc64ModelParse(xmlXPathContextPtr ctxt,
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
if (VIR_ALLOC(model) < 0)
|
if (VIR_ALLOC(model) < 0)
|
||||||
goto error;
|
goto cleanup;
|
||||||
|
|
||||||
if (VIR_STRDUP(model->name, name) < 0)
|
if (VIR_STRDUP(model->name, name) < 0)
|
||||||
goto error;
|
goto cleanup;
|
||||||
|
|
||||||
if (ppc64ModelFind(map, model->name)) {
|
if (ppc64ModelFind(map, model->name)) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("CPU model %s already defined"), model->name);
|
_("CPU model %s already defined"), model->name);
|
||||||
goto error;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virXPathBoolean("boolean(./vendor)", ctxt)) {
|
if (virXPathBoolean("boolean(./vendor)", ctxt)) {
|
||||||
|
@ -344,14 +345,14 @@ ppc64ModelParse(xmlXPathContextPtr ctxt,
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Invalid vendor element in CPU model %s"),
|
_("Invalid vendor element in CPU model %s"),
|
||||||
model->name);
|
model->name);
|
||||||
goto error;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(model->vendor = ppc64VendorFind(map, vendor))) {
|
if (!(model->vendor = ppc64VendorFind(map, vendor))) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Unknown vendor %s referenced by CPU model %s"),
|
_("Unknown vendor %s referenced by CPU model %s"),
|
||||||
vendor, model->name);
|
vendor, model->name);
|
||||||
goto error;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -359,11 +360,11 @@ ppc64ModelParse(xmlXPathContextPtr ctxt,
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Missing PVR information for CPU model %s"),
|
_("Missing PVR information for CPU model %s"),
|
||||||
model->name);
|
model->name);
|
||||||
goto error;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_ALLOC_N(model->data.pvr, n) < 0)
|
if (VIR_ALLOC_N(model->data.pvr, n) < 0)
|
||||||
goto error;
|
goto cleanup;
|
||||||
|
|
||||||
model->data.len = n;
|
model->data.len = n;
|
||||||
|
|
||||||
|
@ -374,7 +375,7 @@ ppc64ModelParse(xmlXPathContextPtr ctxt,
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Missing or invalid PVR value in CPU model %s"),
|
_("Missing or invalid PVR value in CPU model %s"),
|
||||||
model->name);
|
model->name);
|
||||||
goto error;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
model->data.pvr[i].value = pvr;
|
model->data.pvr[i].value = pvr;
|
||||||
|
|
||||||
|
@ -382,24 +383,21 @@ ppc64ModelParse(xmlXPathContextPtr ctxt,
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Missing or invalid PVR mask in CPU model %s"),
|
_("Missing or invalid PVR mask in CPU model %s"),
|
||||||
model->name);
|
model->name);
|
||||||
goto error;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
model->data.pvr[i].mask = pvr;
|
model->data.pvr[i].mask = pvr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_APPEND_ELEMENT(map->models, map->nmodels, model) < 0)
|
if (VIR_APPEND_ELEMENT(map->models, map->nmodels, model) < 0)
|
||||||
goto error;
|
goto cleanup;
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
ppc64ModelFree(model);
|
||||||
VIR_FREE(vendor);
|
VIR_FREE(vendor);
|
||||||
VIR_FREE(nodes);
|
VIR_FREE(nodes);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
error:
|
|
||||||
ppc64ModelFree(model);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -732,15 +732,15 @@ x86VendorParse(xmlXPathContextPtr ctxt,
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
if (VIR_ALLOC(vendor) < 0)
|
if (VIR_ALLOC(vendor) < 0)
|
||||||
goto error;
|
goto cleanup;
|
||||||
|
|
||||||
if (VIR_STRDUP(vendor->name, name) < 0)
|
if (VIR_STRDUP(vendor->name, name) < 0)
|
||||||
goto error;
|
goto cleanup;
|
||||||
|
|
||||||
if (x86VendorFind(map, vendor->name)) {
|
if (x86VendorFind(map, vendor->name)) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("CPU vendor %s already defined"), vendor->name);
|
_("CPU vendor %s already defined"), vendor->name);
|
||||||
goto error;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
string = virXPathString("string(@string)", ctxt);
|
string = virXPathString("string(@string)", ctxt);
|
||||||
|
@ -748,24 +748,21 @@ x86VendorParse(xmlXPathContextPtr ctxt,
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Missing vendor string for CPU vendor %s"),
|
_("Missing vendor string for CPU vendor %s"),
|
||||||
vendor->name);
|
vendor->name);
|
||||||
goto error;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virCPUx86VendorToCPUID(string, &vendor->cpuid) < 0)
|
if (virCPUx86VendorToCPUID(string, &vendor->cpuid) < 0)
|
||||||
goto error;
|
goto cleanup;
|
||||||
|
|
||||||
if (VIR_APPEND_ELEMENT(map->vendors, map->nvendors, vendor) < 0)
|
if (VIR_APPEND_ELEMENT(map->vendors, map->nvendors, vendor) < 0)
|
||||||
goto error;
|
goto cleanup;
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
x86VendorFree(vendor);
|
||||||
VIR_FREE(string);
|
VIR_FREE(string);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
error:
|
|
||||||
x86VendorFree(vendor);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -905,17 +902,17 @@ x86FeatureParse(xmlXPathContextPtr ctxt,
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
if (!(feature = x86FeatureNew()))
|
if (!(feature = x86FeatureNew()))
|
||||||
goto error;
|
goto cleanup;
|
||||||
|
|
||||||
feature->migratable = true;
|
feature->migratable = true;
|
||||||
|
|
||||||
if (VIR_STRDUP(feature->name, name) < 0)
|
if (VIR_STRDUP(feature->name, name) < 0)
|
||||||
goto error;
|
goto cleanup;
|
||||||
|
|
||||||
if (x86FeatureFind(map, feature->name)) {
|
if (x86FeatureFind(map, feature->name)) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("CPU feature %s already defined"), feature->name);
|
_("CPU feature %s already defined"), feature->name);
|
||||||
goto error;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
str = virXPathString("string(@migratable)", ctxt);
|
str = virXPathString("string(@migratable)", ctxt);
|
||||||
|
@ -924,7 +921,7 @@ x86FeatureParse(xmlXPathContextPtr ctxt,
|
||||||
|
|
||||||
n = virXPathNodeSet("./cpuid", ctxt, &nodes);
|
n = virXPathNodeSet("./cpuid", ctxt, &nodes);
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
goto error;
|
goto cleanup;
|
||||||
|
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
ctxt->node = nodes[i];
|
ctxt->node = nodes[i];
|
||||||
|
@ -932,31 +929,28 @@ x86FeatureParse(xmlXPathContextPtr ctxt,
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Invalid cpuid[%zu] in %s feature"),
|
_("Invalid cpuid[%zu] in %s feature"),
|
||||||
i, feature->name);
|
i, feature->name);
|
||||||
goto error;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
if (virCPUx86DataAddCPUIDInt(&feature->data, &cpuid))
|
if (virCPUx86DataAddCPUIDInt(&feature->data, &cpuid))
|
||||||
goto error;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!feature->migratable &&
|
if (!feature->migratable &&
|
||||||
VIR_APPEND_ELEMENT_COPY(map->migrate_blockers,
|
VIR_APPEND_ELEMENT_COPY(map->migrate_blockers,
|
||||||
map->nblockers,
|
map->nblockers,
|
||||||
feature) < 0)
|
feature) < 0)
|
||||||
goto error;
|
goto cleanup;
|
||||||
|
|
||||||
if (VIR_APPEND_ELEMENT(map->features, map->nfeatures, feature) < 0)
|
if (VIR_APPEND_ELEMENT(map->features, map->nfeatures, feature) < 0)
|
||||||
goto error;
|
goto cleanup;
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
x86FeatureFree(feature);
|
||||||
VIR_FREE(nodes);
|
VIR_FREE(nodes);
|
||||||
VIR_FREE(str);
|
VIR_FREE(str);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
error:
|
|
||||||
x86FeatureFree(feature);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1169,10 +1163,10 @@ x86ModelParse(xmlXPathContextPtr ctxt,
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
if (!(model = x86ModelNew()))
|
if (!(model = x86ModelNew()))
|
||||||
goto error;
|
goto cleanup;
|
||||||
|
|
||||||
if (VIR_STRDUP(model->name, name) < 0)
|
if (VIR_STRDUP(model->name, name) < 0)
|
||||||
goto error;
|
goto cleanup;
|
||||||
|
|
||||||
if (virXPathNode("./model", ctxt)) {
|
if (virXPathNode("./model", ctxt)) {
|
||||||
virCPUx86ModelPtr ancestor;
|
virCPUx86ModelPtr ancestor;
|
||||||
|
@ -1183,7 +1177,7 @@ x86ModelParse(xmlXPathContextPtr ctxt,
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Missing ancestor's name in CPU model %s"),
|
_("Missing ancestor's name in CPU model %s"),
|
||||||
model->name);
|
model->name);
|
||||||
goto error;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(ancestor = x86ModelFind(map, anname))) {
|
if (!(ancestor = x86ModelFind(map, anname))) {
|
||||||
|
@ -1191,7 +1185,7 @@ x86ModelParse(xmlXPathContextPtr ctxt,
|
||||||
_("Ancestor model %s not found for CPU model %s"),
|
_("Ancestor model %s not found for CPU model %s"),
|
||||||
anname, model->name);
|
anname, model->name);
|
||||||
VIR_FREE(anname);
|
VIR_FREE(anname);
|
||||||
goto error;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
VIR_FREE(anname);
|
VIR_FREE(anname);
|
||||||
|
@ -1199,7 +1193,7 @@ x86ModelParse(xmlXPathContextPtr ctxt,
|
||||||
model->vendor = ancestor->vendor;
|
model->vendor = ancestor->vendor;
|
||||||
model->signature = ancestor->signature;
|
model->signature = ancestor->signature;
|
||||||
if (x86DataCopy(&model->data, &ancestor->data) < 0)
|
if (x86DataCopy(&model->data, &ancestor->data) < 0)
|
||||||
goto error;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virXPathBoolean("boolean(./signature)", ctxt)) {
|
if (virXPathBoolean("boolean(./signature)", ctxt)) {
|
||||||
|
@ -1212,7 +1206,7 @@ x86ModelParse(xmlXPathContextPtr ctxt,
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Invalid CPU signature family in model %s"),
|
_("Invalid CPU signature family in model %s"),
|
||||||
model->name);
|
model->name);
|
||||||
goto error;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = virXPathUInt("string(./signature/@model)", ctxt, &sigModel);
|
rc = virXPathUInt("string(./signature/@model)", ctxt, &sigModel);
|
||||||
|
@ -1220,7 +1214,7 @@ x86ModelParse(xmlXPathContextPtr ctxt,
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Invalid CPU signature model in model %s"),
|
_("Invalid CPU signature model in model %s"),
|
||||||
model->name);
|
model->name);
|
||||||
goto error;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
model->signature = x86MakeSignature(sigFamily, sigModel, 0);
|
model->signature = x86MakeSignature(sigFamily, sigModel, 0);
|
||||||
|
@ -1232,20 +1226,20 @@ x86ModelParse(xmlXPathContextPtr ctxt,
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Invalid vendor element in CPU model %s"),
|
_("Invalid vendor element in CPU model %s"),
|
||||||
model->name);
|
model->name);
|
||||||
goto error;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(model->vendor = x86VendorFind(map, vendor))) {
|
if (!(model->vendor = x86VendorFind(map, vendor))) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Unknown vendor %s referenced by CPU model %s"),
|
_("Unknown vendor %s referenced by CPU model %s"),
|
||||||
vendor, model->name);
|
vendor, model->name);
|
||||||
goto error;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
n = virXPathNodeSet("./feature", ctxt, &nodes);
|
n = virXPathNodeSet("./feature", ctxt, &nodes);
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
goto error;
|
goto cleanup;
|
||||||
|
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
virCPUx86FeaturePtr feature;
|
virCPUx86FeaturePtr feature;
|
||||||
|
@ -1254,7 +1248,7 @@ x86ModelParse(xmlXPathContextPtr ctxt,
|
||||||
if (!(ftname = virXMLPropString(nodes[i], "name"))) {
|
if (!(ftname = virXMLPropString(nodes[i], "name"))) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Missing feature name for CPU model %s"), model->name);
|
_("Missing feature name for CPU model %s"), model->name);
|
||||||
goto error;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(feature = x86FeatureFind(map, ftname))) {
|
if (!(feature = x86FeatureFind(map, ftname))) {
|
||||||
|
@ -1262,27 +1256,24 @@ x86ModelParse(xmlXPathContextPtr ctxt,
|
||||||
_("Feature %s required by CPU model %s not found"),
|
_("Feature %s required by CPU model %s not found"),
|
||||||
ftname, model->name);
|
ftname, model->name);
|
||||||
VIR_FREE(ftname);
|
VIR_FREE(ftname);
|
||||||
goto error;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
VIR_FREE(ftname);
|
VIR_FREE(ftname);
|
||||||
|
|
||||||
if (x86DataAdd(&model->data, &feature->data))
|
if (x86DataAdd(&model->data, &feature->data))
|
||||||
goto error;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_APPEND_ELEMENT(map->models, map->nmodels, model) < 0)
|
if (VIR_APPEND_ELEMENT(map->models, map->nmodels, model) < 0)
|
||||||
goto error;
|
goto cleanup;
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
x86ModelFree(model);
|
||||||
VIR_FREE(vendor);
|
VIR_FREE(vendor);
|
||||||
VIR_FREE(nodes);
|
VIR_FREE(nodes);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
error:
|
|
||||||
x86ModelFree(model);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue