From 0085fabfc81c097d0307b307ac0441c2448fbb16 Mon Sep 17 00:00:00 2001 Message-Id: <0085fabfc81c097d0307b307ac0441c2448fbb16@dist-git> From: Jiri Denemark Date: Wed, 14 Jun 2017 13:42:16 +0200 Subject: [PATCH] qemu: Introduce qemuDomainDefFromXML helper The main goal of this function is to enable reusing the parsing code from qemuDomainDefCopy. Signed-off-by: Jiri Denemark Reviewed-by: Pavel Hrdina (cherry picked from commit 0810d4f5e0d77354cdf7ad56e1e8b7748bdb1501) https://bugzilla.redhat.com/show_bug.cgi?id=1460952 Signed-off-by: Jiri Denemark --- src/qemu/qemu_domain.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 82dacb3c9c..ce75105afa 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -4146,6 +4146,25 @@ void qemuDomainObjExitRemote(virDomainObjPtr obj) } +static virDomainDefPtr +qemuDomainDefFromXML(virQEMUDriverPtr driver, + const char *xml) +{ + virCapsPtr caps; + virDomainDefPtr def; + + if (!(caps = virQEMUDriverGetCapabilities(driver, false))) + return NULL; + + def = virDomainDefParseString(xml, caps, driver->xmlopt, NULL, + VIR_DOMAIN_DEF_PARSE_INACTIVE | + VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE); + + virObjectUnref(caps); + return def; +} + + virDomainDefPtr qemuDomainDefCopy(virQEMUDriverPtr driver, virDomainDefPtr src, @@ -4153,25 +4172,15 @@ qemuDomainDefCopy(virQEMUDriverPtr driver, { virBuffer buf = VIR_BUFFER_INITIALIZER; virDomainDefPtr ret = NULL; - virCapsPtr caps = NULL; char *xml = NULL; if (qemuDomainDefFormatBuf(driver, src, flags, &buf) < 0) - goto cleanup; + return NULL; xml = virBufferContentAndReset(&buf); + ret = qemuDomainDefFromXML(driver, xml); - if (!(caps = virQEMUDriverGetCapabilities(driver, false))) - goto cleanup; - - if (!(ret = virDomainDefParseString(xml, caps, driver->xmlopt, NULL, - VIR_DOMAIN_DEF_PARSE_INACTIVE | - VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE))) - goto cleanup; - - cleanup: VIR_FREE(xml); - virObjectUnref(caps); return ret; } -- 2.13.1