mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 21:55:25 +00:00
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.
This commit is contained in:
parent
19a863c435
commit
5982168290
@ -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;
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user