提交 45ec297d 编写于 作者: C Cole Robinson

Make state driver device hotplug/update actually transient

The current semantics of non-persistent hotplug/update are confusing: the
changes will persist as long as the in memory domain definition isn't
overwritten. This means hotplug changes stay around until the domain is
redefined or libvirtd is restarted.

Call virDomainObjSetDefTransient at VM startup, so that we properly discard
hotplug changes when the VM is shutdown.
上级 08a72a7d
...@@ -1532,6 +1532,9 @@ static int lxcVmStart(virConnectPtr conn, ...@@ -1532,6 +1532,9 @@ static int lxcVmStart(virConnectPtr conn,
if (virDomainSaveConfig(driver->stateDir, vm->def) < 0) if (virDomainSaveConfig(driver->stateDir, vm->def) < 0)
goto cleanup; goto cleanup;
if (virDomainObjSetDefTransient(driver->caps, vm) < 0)
goto cleanup;
rc = 0; rc = 0;
cleanup: cleanup:
......
...@@ -4235,6 +4235,11 @@ static int qemudStartVMDaemon(virConnectPtr conn, ...@@ -4235,6 +4235,11 @@ static int qemudStartVMDaemon(virConnectPtr conn,
if (virDomainSaveStatus(driver->caps, driver->stateDir, vm) < 0) if (virDomainSaveStatus(driver->caps, driver->stateDir, vm) < 0)
goto cleanup; goto cleanup;
/* Do this last, since it depends on domain being active */
DEBUG0("Setting running domain def as transient");
if (virDomainObjSetDefTransient(driver->caps, vm) < 0)
goto cleanup;
VIR_FORCE_CLOSE(logfile); VIR_FORCE_CLOSE(logfile);
return 0; return 0;
......
...@@ -457,6 +457,22 @@ cleanup: ...@@ -457,6 +457,22 @@ cleanup:
return ret; return ret;
} }
static void
testDomainShutdownState(virDomainPtr domain,
virDomainObjPtr privdom)
{
if (privdom->newDef) {
virDomainDefFree(privdom->def);
privdom->def = privdom->newDef;
privdom->newDef = NULL;
}
privdom->state = VIR_DOMAIN_SHUTOFF;
privdom->def->id = -1;
if (domain)
domain->id = -1;
}
/* Set up domain runtime state */ /* Set up domain runtime state */
static int static int
testDomainStartState(virConnectPtr conn, testDomainStartState(virConnectPtr conn,
...@@ -468,30 +484,20 @@ testDomainStartState(virConnectPtr conn, ...@@ -468,30 +484,20 @@ testDomainStartState(virConnectPtr conn,
if (testDomainUpdateVCPUs(conn, dom, dom->def->vcpus, 1) < 0) if (testDomainUpdateVCPUs(conn, dom, dom->def->vcpus, 1) < 0)
goto cleanup; goto cleanup;
/* Set typical run state */
dom->state = VIR_DOMAIN_RUNNING; dom->state = VIR_DOMAIN_RUNNING;
dom->def->id = privconn->nextDomID++; dom->def->id = privconn->nextDomID++;
if (virDomainObjSetDefTransient(privconn->caps, dom) < 0) {
goto cleanup;
}
ret = 0; ret = 0;
cleanup: cleanup:
if (ret < 0)
testDomainShutdownState(NULL, dom);
return ret; return ret;
} }
static void
testDomainShutdownState(virDomainPtr domain,
virDomainObjPtr privdom)
{
if (privdom->newDef) {
virDomainDefFree(privdom->def);
privdom->def = privdom->newDef;
privdom->newDef = NULL;
}
privdom->state = VIR_DOMAIN_SHUTOFF;
privdom->def->id = -1;
domain->id = -1;
}
static int testOpenDefault(virConnectPtr conn) { static int testOpenDefault(virConnectPtr conn) {
int u; int u;
struct timeval tv; struct timeval tv;
...@@ -558,12 +564,12 @@ static int testOpenDefault(virConnectPtr conn) { ...@@ -558,12 +564,12 @@ static int testOpenDefault(virConnectPtr conn) {
goto error; goto error;
domdef = NULL; domdef = NULL;
domobj->persistent = 1;
if (testDomainStartState(conn, domobj) < 0) { if (testDomainStartState(conn, domobj) < 0) {
virDomainObjUnlock(domobj); virDomainObjUnlock(domobj);
goto error; goto error;
} }
domobj->persistent = 1;
virDomainObjUnlock(domobj); virDomainObjUnlock(domobj);
if (!(netdef = virNetworkDefParseString(defaultNetworkXML))) if (!(netdef = virNetworkDefParseString(defaultNetworkXML)))
...@@ -918,12 +924,12 @@ static int testOpenFromFile(virConnectPtr conn, ...@@ -918,12 +924,12 @@ static int testOpenFromFile(virConnectPtr conn,
goto error; goto error;
} }
dom->persistent = 1;
if (testDomainStartState(conn, dom) < 0) { if (testDomainStartState(conn, dom) < 0) {
virDomainObjUnlock(dom); virDomainObjUnlock(dom);
goto error; goto error;
} }
dom->persistent = 1;
virDomainObjUnlock(dom); virDomainObjUnlock(dom);
} }
VIR_FREE(domains); VIR_FREE(domains);
......
...@@ -916,7 +916,11 @@ static int umlStartVMDaemon(virConnectPtr conn, ...@@ -916,7 +916,11 @@ static int umlStartVMDaemon(virConnectPtr conn,
VIR_EXEC_CLEAR_CAPS, VIR_EXEC_CLEAR_CAPS,
NULL, NULL, NULL); NULL, NULL, NULL);
VIR_FORCE_CLOSE(logfd); VIR_FORCE_CLOSE(logfd);
if (ret < 0)
goto cleanup;
ret = virDomainObjSetDefTransient(driver->caps, vm);
cleanup:
/* /*
* At the moment, the only thing that populates keepfd is * At the moment, the only thing that populates keepfd is
* umlBuildCommandLineChr. We want to close every fd it opens. * umlBuildCommandLineChr. We want to close every fd it opens.
...@@ -940,7 +944,6 @@ static int umlStartVMDaemon(virConnectPtr conn, ...@@ -940,7 +944,6 @@ static int umlStartVMDaemon(virConnectPtr conn,
umlCleanupTapDevices(conn, vm); umlCleanupTapDevices(conn, vm);
} }
/* NB we don't mark it running here - we do that async /* NB we don't mark it running here - we do that async
with inotify */ with inotify */
/* XXX what if someone else tries to start it again /* XXX what if someone else tries to start it again
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册