From 449e6b1b58440917099709be3bba3e0aec60a589 Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Mon, 29 Apr 2013 11:29:02 +0100 Subject: [PATCH] Pull parsing of migration xml up into QEMU driver APIs 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 e593516c41..018f0aecb2 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -9287,6 +9287,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); @@ -9314,11 +9316,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; } @@ -9338,6 +9359,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); @@ -9366,6 +9389,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 @@ -9373,9 +9412,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; } @@ -9565,6 +9607,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); @@ -9586,13 +9630,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; } @@ -9610,6 +9673,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); @@ -9630,12 +9695,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 db7c4f8580..e38d99b586 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -1983,13 +1983,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; @@ -2033,22 +2031,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; @@ -2304,20 +2289,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; } @@ -2332,8 +2316,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; @@ -2346,10 +2329,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". * @@ -2444,7 +2427,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 505e9114d6..b42fe4eec2 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,