From: "Daniel P. Berrange" <berrange(a)redhat.com>
Currently the parsing of XML is pushed down into the various
migration helper APIs. This makes it difficult to insert the
correct access control checks, since one helper API services
many public APIs. Pull the parsing of XML up to the top level
of the QEMU driver APIs
---
src/qemu/qemu_driver.c | 92 ++++++++++++++++++++++++++++++++++++++++++++---
src/qemu/qemu_migration.c | 35 +++++-------------
src/qemu/qemu_migration.h | 6 ++--
3 files changed, 99 insertions(+), 34 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index a23bc6c..9abf6cb 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -9235,6 +9235,8 @@ qemuDomainMigratePrepareTunnel(virConnectPtr dconn,
const char *dom_xml)
{
virQEMUDriverPtr driver = dconn->privateData;
+ virCapsPtr caps = NULL;
+ virDomainDefPtr def = NULL;
int ret = -1;
virCheckFlags(QEMU_MIGRATION_FLAGS, -1);
@@ -9262,11 +9264,30 @@ qemuDomainMigratePrepareTunnel(virConnectPtr dconn,
goto cleanup;
}
+ if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
+ goto cleanup;
+
+ if (!(def = virDomainDefParseString(dom_xml, caps, driver->xmlopt,
+ QEMU_EXPECTED_VIRT_TYPES,
+ VIR_DOMAIN_XML_INACTIVE)))
+ goto cleanup;
+
+ if (dname) {
+ VIR_FREE(def->name);
+ if (!(def->name = strdup(dname))) {
+ virReportOOMError();
+ goto cleanup;
+ }
+ }
+
ret = qemuMigrationPrepareTunnel(driver, dconn,
NULL, 0, NULL, NULL, /* No cookies in v2 */
- st, dname, dom_xml, flags);
+ st, def, flags);
+ def = NULL;
cleanup:
+ virDomainDefFree(def);
+ virObjectUnref(caps);
return ret;
}
@@ -9286,6 +9307,8 @@ qemuDomainMigratePrepare2(virConnectPtr dconn,
const char *dom_xml)
{
virQEMUDriverPtr driver = dconn->privateData;
+ virCapsPtr caps = NULL;
+ virDomainDefPtr def = NULL;
int ret = -1;
virCheckFlags(QEMU_MIGRATION_FLAGS, -1);
@@ -9314,6 +9337,22 @@ qemuDomainMigratePrepare2(virConnectPtr dconn,
goto cleanup;
}
+ if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
+ goto cleanup;
+
+ if (!(def = virDomainDefParseString(dom_xml, caps, driver->xmlopt,
+ QEMU_EXPECTED_VIRT_TYPES,
+ VIR_DOMAIN_XML_INACTIVE)))
+ goto cleanup;
+
+ if (dname) {
+ VIR_FREE(def->name);
+ if (!(def->name = strdup(dname))) {
+ virReportOOMError();
+ goto cleanup;
+ }
+ }
+
/* Do not use cookies in v2 protocol, since the cookie
* length was not sufficiently large, causing failures
* migrating between old & new libvirtd
@@ -9321,9 +9360,12 @@ qemuDomainMigratePrepare2(virConnectPtr dconn,
ret = qemuMigrationPrepareDirect(driver, dconn,
NULL, 0, NULL, NULL, /* No cookies */
uri_in, uri_out,
- dname, dom_xml, flags);
+ def, flags);
+ def = NULL;
cleanup:
+ virDomainDefFree(def);
+ virObjectUnref(caps);
return ret;
}
@@ -9513,6 +9555,8 @@ qemuDomainMigratePrepare3(virConnectPtr dconn,
const char *dom_xml)
{
virQEMUDriverPtr driver = dconn->privateData;
+ virCapsPtr caps = NULL;
+ virDomainDefPtr def = NULL;
int ret = -1;
virCheckFlags(QEMU_MIGRATION_FLAGS, -1);
@@ -9534,13 +9578,32 @@ qemuDomainMigratePrepare3(virConnectPtr dconn,
goto cleanup;
}
+ if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
+ goto cleanup;
+
+ if (!(def = virDomainDefParseString(dom_xml, caps, driver->xmlopt,
+ QEMU_EXPECTED_VIRT_TYPES,
+ VIR_DOMAIN_XML_INACTIVE)))
+ goto cleanup;
+
+ if (dname) {
+ VIR_FREE(def->name);
+ if (!(def->name = strdup(dname))) {
+ virReportOOMError();
+ goto cleanup;
+ }
+ }
+
ret = qemuMigrationPrepareDirect(driver, dconn,
cookiein, cookieinlen,
cookieout, cookieoutlen,
uri_in, uri_out,
- dname, dom_xml, flags);
+ def, flags);
+ def = NULL;
cleanup:
+ virDomainDefFree(def);
+ virObjectUnref(caps);
return ret;
}
@@ -9558,6 +9621,8 @@ qemuDomainMigratePrepareTunnel3(virConnectPtr dconn,
const char *dom_xml)
{
virQEMUDriverPtr driver = dconn->privateData;
+ virCapsPtr caps = NULL;
+ virDomainDefPtr def = NULL;
int ret = -1;
virCheckFlags(QEMU_MIGRATION_FLAGS, -1);
@@ -9578,12 +9643,31 @@ qemuDomainMigratePrepareTunnel3(virConnectPtr dconn,
goto cleanup;
}
+ if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
+ goto cleanup;
+
+ if (!(def = virDomainDefParseString(dom_xml, caps, driver->xmlopt,
+ QEMU_EXPECTED_VIRT_TYPES,
+ VIR_DOMAIN_XML_INACTIVE)))
+ goto cleanup;
+
+ if (dname) {
+ VIR_FREE(def->name);
+ if (!(def->name = strdup(dname))) {
+ virReportOOMError();
+ goto cleanup;
+ }
+ }
+
ret = qemuMigrationPrepareTunnel(driver, dconn,
cookiein, cookieinlen,
cookieout, cookieoutlen,
- st, dname, dom_xml, flags);
+ st, def, flags);
+ def = NULL;
cleanup:
+ virDomainDefFree(def);
+ virObjectUnref(caps);
return ret;
}
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index ebd0382..8753c0d 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -1984,13 +1984,11 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
int cookieinlen,
char **cookieout,
int *cookieoutlen,
- const char *dname,
- const char *dom_xml,
+ virDomainDefPtr def,
virStreamPtr st,
unsigned int port,
unsigned long flags)
{
- virDomainDefPtr def = NULL;
virDomainObjPtr vm = NULL;
virDomainEventPtr event = NULL;
int ret = -1;
@@ -2034,22 +2032,9 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
goto cleanup;
- if (!(def = virDomainDefParseString(dom_xml, caps, driver->xmlopt,
- QEMU_EXPECTED_VIRT_TYPES,
- VIR_DOMAIN_XML_INACTIVE)))
- goto cleanup;
-
if (!qemuMigrationIsAllowed(driver, NULL, def, true))
goto cleanup;
- /* Target domain name, maybe renamed. */
- if (dname) {
- origname = def->name;
- def->name = strdup(dname);
- if (def->name == NULL)
- goto cleanup;
- }
-
/* Let migration hook filter domain XML */
if (virHookPresent(VIR_HOOK_DRIVER_QEMU)) {
char *xml;
@@ -2305,20 +2290,19 @@ qemuMigrationPrepareTunnel(virQEMUDriverPtr driver,
char **cookieout,
int *cookieoutlen,
virStreamPtr st,
- const char *dname,
- const char *dom_xml,
+ virDomainDefPtr def,
unsigned long flags)
{
int ret;
VIR_DEBUG("driver=%p, dconn=%p, cookiein=%s, cookieinlen=%d, "
- "cookieout=%p, cookieoutlen=%p, st=%p, dname=%s, dom_xml=%s "
+ "cookieout=%p, cookieoutlen=%p, st=%p, def=%p, "
"flags=%lx",
driver, dconn, NULLSTR(cookiein), cookieinlen,
- cookieout, cookieoutlen, st, NULLSTR(dname), dom_xml, flags);
+ cookieout, cookieoutlen, st, def, flags);
ret = qemuMigrationPrepareAny(driver, dconn, cookiein, cookieinlen,
- cookieout, cookieoutlen, dname, dom_xml,
+ cookieout, cookieoutlen, def,
st, 0, flags);
return ret;
}
@@ -2333,8 +2317,7 @@ qemuMigrationPrepareDirect(virQEMUDriverPtr driver,
int *cookieoutlen,
const char *uri_in,
char **uri_out,
- const char *dname,
- const char *dom_xml,
+ virDomainDefPtr def,
unsigned long flags)
{
static int port = 0;
@@ -2347,10 +2330,10 @@ qemuMigrationPrepareDirect(virQEMUDriverPtr driver,
VIR_DEBUG("driver=%p, dconn=%p, cookiein=%s, cookieinlen=%d, "
"cookieout=%p, cookieoutlen=%p, uri_in=%s, uri_out=%p, "
- "dname=%s, dom_xml=%s flags=%lx",
+ "def=%p, flags=%lx",
driver, dconn, NULLSTR(cookiein), cookieinlen,
cookieout, cookieoutlen, NULLSTR(uri_in), uri_out,
- NULLSTR(dname), dom_xml, flags);
+ def, flags);
/* The URI passed in may be NULL or a string "tcp://somehostname:port".
*
@@ -2445,7 +2428,7 @@ qemuMigrationPrepareDirect(virQEMUDriverPtr driver,
VIR_DEBUG("Generated uri_out=%s", *uri_out);
ret = qemuMigrationPrepareAny(driver, dconn, cookiein, cookieinlen,
- cookieout, cookieoutlen, dname, dom_xml,
+ cookieout, cookieoutlen, def,
NULL, this_port, flags);
cleanup:
VIR_FREE(hostname);
diff --git a/src/qemu/qemu_migration.h b/src/qemu/qemu_migration.h
index 505e911..b42fe4e 100644
--- a/src/qemu/qemu_migration.h
+++ b/src/qemu/qemu_migration.h
@@ -98,8 +98,7 @@ int qemuMigrationPrepareTunnel(virQEMUDriverPtr driver,
char **cookieout,
int *cookieoutlen,
virStreamPtr st,
- const char *dname,
- const char *dom_xml,
+ virDomainDefPtr def,
unsigned long flags);
int qemuMigrationPrepareDirect(virQEMUDriverPtr driver,
@@ -110,8 +109,7 @@ int qemuMigrationPrepareDirect(virQEMUDriverPtr driver,
int *cookieoutlen,
const char *uri_in,
char **uri_out,
- const char *dname,
- const char *dom_xml,
+ virDomainDefPtr def,
unsigned long flags);
int qemuMigrationPerform(virQEMUDriverPtr driver,
--
1.8.1.4