From 5982168290c9d75441abccbce100306c4e4535d6 Mon Sep 17 00:00:00 2001 From: Jiri Denemark Date: Wed, 24 Mar 2010 15:31:21 +0100 Subject: [PATCH] Don't replace persistent domain config with migrated config When a domain is defined on host1, migrated to host2 and then migrated back to host1, its current configuration would overwrite the libvirtd's in-memory copy of persistent configuration of that domain. This is not desired as we want to preserve the persistent configuration untouched. This patch introduces new 'live' parameter to virDomainAssignDef. Passing 'true' for 'live' means the configuration passed to virDomainAssignDef describes a configuration of live instance of the domain. This applies for saved domains which are being restored or for incoming domains during migration. All callers have been changed to pass the appropriate value. --- src/conf/domain_conf.c | 16 ++++++++++++---- src/conf/domain_conf.h | 5 ++++- src/lxc/lxc_driver.c | 4 ++-- src/opennebula/one_driver.c | 4 ++-- src/openvz/openvz_driver.c | 4 ++-- src/qemu/qemu_driver.c | 10 +++++----- src/test/test_driver.c | 10 +++++----- src/uml/uml_driver.c | 4 ++-- 8 files changed, 34 insertions(+), 23 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index c802a1c558..7be4b11370 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -766,15 +766,23 @@ static virDomainObjPtr virDomainObjNew(virCapsPtr caps) virDomainObjPtr virDomainAssignDef(virCapsPtr caps, virDomainObjListPtr doms, - const virDomainDefPtr def) + const virDomainDefPtr def, + bool live) { virDomainObjPtr domain; char uuidstr[VIR_UUID_STRING_BUFLEN]; if ((domain = virDomainFindByUUID(doms, def->uuid))) { if (!virDomainObjIsActive(domain)) { - virDomainDefFree(domain->def); - domain->def = def; + if (live) { + /* save current configuration to be restored on domain shutdown */ + if (!domain->newDef) + domain->newDef = domain->def; + domain->def = def; + } else { + virDomainDefFree(domain->def); + domain->def = def; + } } else { virDomainDefFree(domain->newDef); domain->newDef = def; @@ -5856,7 +5864,7 @@ virDomainObjPtr virDomainLoadConfig(virCapsPtr caps, newVM = 0; } - if (!(dom = virDomainAssignDef(caps, doms, def))) + if (!(dom = virDomainAssignDef(caps, doms, def, false))) goto error; dom->autostart = autostart; diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 67a68c975a..c72d37dcf7 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -825,9 +825,12 @@ void virDomainObjRef(virDomainObjPtr vm); /* Returns 1 if the object was freed, 0 if more refs exist */ int virDomainObjUnref(virDomainObjPtr vm); +/* live == true means def describes an active domain (being migrated or + * restored) as opposed to a new persistent configuration of the domain */ virDomainObjPtr virDomainAssignDef(virCapsPtr caps, virDomainObjListPtr doms, - const virDomainDefPtr def); + const virDomainDefPtr def, + bool live); void virDomainRemoveInactive(virDomainObjListPtr doms, virDomainObjPtr dom); diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 532cf8b27a..0650dc500a 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -381,7 +381,7 @@ static virDomainPtr lxcDomainDefine(virConnectPtr conn, const char *xml) } if (!(vm = virDomainAssignDef(driver->caps, - &driver->domains, def))) + &driver->domains, def, false))) goto cleanup; def = NULL; vm->persistent = 1; @@ -1378,7 +1378,7 @@ lxcDomainCreateAndStart(virConnectPtr conn, if (!(vm = virDomainAssignDef(driver->caps, - &driver->domains, def))) + &driver->domains, def, false))) goto cleanup; def = NULL; diff --git a/src/opennebula/one_driver.c b/src/opennebula/one_driver.c index d8c5059a8c..e901a03fa3 100644 --- a/src/opennebula/one_driver.c +++ b/src/opennebula/one_driver.c @@ -251,7 +251,7 @@ static virDomainPtr oneDomainDefine(virConnectPtr conn, const char *xml) goto return_point; if (!(vm = virDomainAssignDef(driver->caps, - &driver->domains, def))) { + &driver->domains, def, false))) { virDomainDefFree(def); goto return_point; } @@ -456,7 +456,7 @@ oneDomainCreateAndStart(virConnectPtr conn, } if (!(vm = virDomainAssignDef(driver->caps, - &driver->domains, def))) { + &driver->domains, def, false))) { virDomainDefFree(def); goto return_point; } diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index da094ffec6..61765771f1 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -825,7 +825,7 @@ openvzDomainDefineXML(virConnectPtr conn, const char *xml) goto cleanup; } if (!(vm = virDomainAssignDef(driver->caps, - &driver->domains, vmdef))) + &driver->domains, vmdef, false))) goto cleanup; vmdef = NULL; vm->persistent = 1; @@ -905,7 +905,7 @@ openvzDomainCreateXML(virConnectPtr conn, const char *xml, goto cleanup; } if (!(vm = virDomainAssignDef(driver->caps, - &driver->domains, vmdef))) + &driver->domains, vmdef, false))) goto cleanup; vmdef = NULL; /* All OpenVZ domains seem to be persistent - this is a bit of a violation diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index dfa6ea3e89..6d76de697a 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -3809,7 +3809,7 @@ static virDomainPtr qemudDomainCreate(virConnectPtr conn, const char *xml, if (!(vm = virDomainAssignDef(driver->caps, &driver->domains, - def))) + def, false))) goto cleanup; def = NULL; @@ -5466,7 +5466,7 @@ static int qemudDomainRestore(virConnectPtr conn, if (!(vm = virDomainAssignDef(driver->caps, &driver->domains, - def))) { + def, true))) { qemuReportError(VIR_ERR_OPERATION_FAILED, "%s", _("failed to assign new VM")); goto cleanup; @@ -6007,7 +6007,7 @@ static virDomainPtr qemudDomainDefine(virConnectPtr conn, const char *xml) { if (!(vm = virDomainAssignDef(driver->caps, &driver->domains, - def))) { + def, false))) { goto cleanup; } def = NULL; @@ -8881,7 +8881,7 @@ qemudDomainMigratePrepareTunnel(virConnectPtr dconn, if (!(vm = virDomainAssignDef(driver->caps, &driver->domains, - def))) { + def, true))) { qemuReportError(VIR_ERR_OPERATION_FAILED, "%s", _("failed to assign new VM")); goto cleanup; @@ -9112,7 +9112,7 @@ qemudDomainMigratePrepare2 (virConnectPtr dconn, if (!(vm = virDomainAssignDef(driver->caps, &driver->domains, - def))) { + def, true))) { qemuReportError(VIR_ERR_OPERATION_FAILED, "%s", _("failed to assign new VM")); goto cleanup; diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 4af2d001d2..2931a95b6c 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -554,7 +554,7 @@ static int testOpenDefault(virConnectPtr conn) { if (testDomainGenerateIfnames(conn, domdef) < 0) goto error; if (!(domobj = virDomainAssignDef(privconn->caps, - &privconn->domains, domdef))) + &privconn->domains, domdef, false))) goto error; domdef = NULL; @@ -910,7 +910,7 @@ static int testOpenFromFile(virConnectPtr conn, if (testDomainGenerateIfnames(conn, def) < 0 || !(dom = virDomainAssignDef(privconn->caps, - &privconn->domains, def))) { + &privconn->domains, def, false))) { virDomainDefFree(def); goto error; } @@ -1308,7 +1308,7 @@ testDomainCreateXML(virConnectPtr conn, const char *xml, if (testDomainGenerateIfnames(conn, def) < 0) goto cleanup; if (!(dom = virDomainAssignDef(privconn->caps, - &privconn->domains, def))) + &privconn->domains, def, false))) goto cleanup; def = NULL; @@ -1852,7 +1852,7 @@ static int testDomainRestore(virConnectPtr conn, if (testDomainGenerateIfnames(conn, def) < 0) goto cleanup; if (!(dom = virDomainAssignDef(privconn->caps, - &privconn->domains, def))) + &privconn->domains, def, true))) goto cleanup; def = NULL; @@ -2301,7 +2301,7 @@ static virDomainPtr testDomainDefineXML(virConnectPtr conn, if (testDomainGenerateIfnames(conn, def) < 0) goto cleanup; if (!(dom = virDomainAssignDef(privconn->caps, - &privconn->domains, def))) + &privconn->domains, def, false))) goto cleanup; def = NULL; dom->persistent = 1; diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c index 008eb8d4d3..835e5d4ca3 100644 --- a/src/uml/uml_driver.c +++ b/src/uml/uml_driver.c @@ -1283,7 +1283,7 @@ static virDomainPtr umlDomainCreate(virConnectPtr conn, const char *xml, if (!(vm = virDomainAssignDef(driver->caps, &driver->domains, - def))) + def, false))) goto cleanup; def = NULL; @@ -1619,7 +1619,7 @@ static virDomainPtr umlDomainDefine(virConnectPtr conn, const char *xml) { if (!(vm = virDomainAssignDef(driver->caps, &driver->domains, - def))) + def, false))) goto cleanup; def = NULL; vm->persistent = 1;