提交 8e2982b5 编写于 作者: C Cole Robinson

conf: Clean up virDomainDefParseCaps

- Convert to 'cleanup' label naming
- Use more than one 'tmp' string and do all freeing at the end
- Make the code easier to follow
Acked-by: NMichal Privoznik <mprivozn@redhat.com>
Signed-off-by: NCole Robinson <crobinso@redhat.com>
上级 bd884c56
...@@ -19121,43 +19121,45 @@ virDomainDefParseCaps(virDomainDefPtr def, ...@@ -19121,43 +19121,45 @@ virDomainDefParseCaps(virDomainDefPtr def,
unsigned int flags) unsigned int flags)
{ {
int ret = -1; int ret = -1;
int virtType; char *virttype = NULL;
char *tmp = NULL; char *arch = NULL;
char *ostype = NULL;
virCapsDomainDataPtr capsdata = NULL;
/* Find out what type of virtualization to use */ virttype = virXPathString("string(./@type)", ctxt);
if (!(tmp = virXMLPropString(ctxt->node, "type"))) { ostype = virXPathString("string(./os/type[1])", ctxt);
arch = virXPathString("string(./os/type[1]/@arch)", ctxt);
def->os.bootloader = virXPathString("string(./bootloader)", ctxt);
def->os.bootloaderArgs = virXPathString("string(./bootloader_args)", ctxt);
def->os.machine = virXPathString("string(./os/type[1]/@machine)", ctxt);
def->emulator = virXPathString("string(./devices/emulator[1])", ctxt);
if (!virttype) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("missing domain type attribute")); "%s", _("missing domain type attribute"));
goto error; goto cleanup;
} }
if ((def->virtType = virDomainVirtTypeFromString(virttype)) < 0) {
if ((virtType = virDomainVirtTypeFromString(tmp)) < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("invalid domain type %s"), tmp); _("invalid domain type %s"), virttype);
goto error; goto cleanup;
} }
def->virtType = virtType;
VIR_FREE(tmp);
def->os.bootloader = virXPathString("string(./bootloader)", ctxt);
def->os.bootloaderArgs = virXPathString("string(./bootloader_args)", ctxt);
tmp = virXPathString("string(./os/type[1])", ctxt); if (!ostype) {
if (!tmp) {
if (def->os.bootloader) { if (def->os.bootloader) {
def->os.type = VIR_DOMAIN_OSTYPE_XEN; def->os.type = VIR_DOMAIN_OSTYPE_XEN;
} else { } else {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("an os <type> must be specified")); _("an os <type> must be specified"));
goto error; goto cleanup;
} }
} else { } else {
if ((def->os.type = virDomainOSTypeFromString(tmp)) < 0) { if ((def->os.type = virDomainOSTypeFromString(ostype)) < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown OS type '%s'"), tmp); _("unknown OS type '%s'"), ostype);
goto error; goto cleanup;
} }
VIR_FREE(tmp);
} }
/* /*
...@@ -19170,17 +19172,11 @@ virDomainDefParseCaps(virDomainDefPtr def, ...@@ -19170,17 +19172,11 @@ virDomainDefParseCaps(virDomainDefPtr def,
def->os.type = VIR_DOMAIN_OSTYPE_XEN; def->os.type = VIR_DOMAIN_OSTYPE_XEN;
} }
tmp = virXPathString("string(./os/type[1]/@arch)", ctxt); if (arch && !(def->os.arch = virArchFromString(arch))) {
if (tmp && !(def->os.arch = virArchFromString(tmp))) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Unknown architecture %s"), _("Unknown architecture %s"), arch);
tmp); goto cleanup;
goto error;
} }
VIR_FREE(tmp);
def->os.machine = virXPathString("string(./os/type[1]/@machine)", ctxt);
def->emulator = virXPathString("string(./devices/emulator[1])", ctxt);
if ((!def->os.arch || !def->os.machine) && if ((!def->os.arch || !def->os.machine) &&
!(flags & VIR_DOMAIN_DEF_PARSE_SKIP_OSTYPE_CHECKS)) { !(flags & VIR_DOMAIN_DEF_PARSE_SKIP_OSTYPE_CHECKS)) {
...@@ -19191,26 +19187,28 @@ virDomainDefParseCaps(virDomainDefPtr def, ...@@ -19191,26 +19187,28 @@ virDomainDefParseCaps(virDomainDefPtr def,
* in numerous minor ways. */ * in numerous minor ways. */
bool use_virttype = ((def->os.arch == VIR_ARCH_NONE) || bool use_virttype = ((def->os.arch == VIR_ARCH_NONE) ||
!def->os.machine); !def->os.machine);
virCapsDomainDataPtr capsdata = NULL;
if (!(capsdata = virCapabilitiesDomainDataLookup(caps, def->os.type, if (!(capsdata = virCapabilitiesDomainDataLookup(caps,
def->os.arch, use_virttype ? def->virtType : VIR_DOMAIN_VIRT_NONE, def->os.type,
def->os.arch,
use_virttype ? def->virtType : VIR_DOMAIN_VIRT_NONE,
NULL, NULL))) NULL, NULL)))
goto error; goto cleanup;
if (!def->os.arch) if (!def->os.arch)
def->os.arch = capsdata->arch; def->os.arch = capsdata->arch;
if ((!def->os.machine && if ((!def->os.machine &&
VIR_STRDUP(def->os.machine, capsdata->machinetype) < 0)) { VIR_STRDUP(def->os.machine, capsdata->machinetype) < 0)) {
VIR_FREE(capsdata); goto cleanup;
goto error;
} }
VIR_FREE(capsdata);
} }
ret = 0; ret = 0;
error: cleanup:
VIR_FREE(tmp); VIR_FREE(virttype);
VIR_FREE(ostype);
VIR_FREE(arch);
VIR_FREE(capsdata);
return ret; return ret;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册