提交 449e6b1b 编写于 作者: D Daniel P. Berrange

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
上级 03a60036
......@@ -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;
}
......
......@@ -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);
......
......@@ -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,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册