提交 49608417 编写于 作者: E Eric Blake

qemu: respect locking rules

THREADS.txt states that the contents of vm should not be read or
modified while the vm lock is not held, but that the lock must not
be held while performing a monitor command.  This fixes all the
offenders that I could find.

* src/qemu/qemu_process.c (qemuProcessStartCPUs)
(qemuProcessInitPasswords, qemuProcessStart): Don't modify or
refer to vm state outside lock.
* src/qemu/qemu_driver.c (qemudDomainHotplugVcpus): Likewise.
* src/qemu/qemu_hotplug.c (qemuDomainChangeGraphicsPasswords):
Likewise.
上级 b538cdd5
...@@ -2553,14 +2553,15 @@ static int qemudDomainHotplugVcpus(virDomainObjPtr vm, unsigned int nvcpus) ...@@ -2553,14 +2553,15 @@ static int qemudDomainHotplugVcpus(virDomainObjPtr vm, unsigned int nvcpus)
int i, rc = 1; int i, rc = 1;
int ret = -1; int ret = -1;
int oldvcpus = vm->def->vcpus; int oldvcpus = vm->def->vcpus;
int vcpus = oldvcpus;
qemuDomainObjEnterMonitor(vm); qemuDomainObjEnterMonitor(vm);
/* We need different branches here, because we want to offline /* We need different branches here, because we want to offline
* in reverse order to onlining, so any partial fail leaves us in a * in reverse order to onlining, so any partial fail leaves us in a
* reasonably sensible state */ * reasonably sensible state */
if (nvcpus > vm->def->vcpus) { if (nvcpus > vcpus) {
for (i = vm->def->vcpus ; i < nvcpus ; i++) { for (i = vcpus ; i < nvcpus ; i++) {
/* Online new CPU */ /* Online new CPU */
rc = qemuMonitorSetCPU(priv->mon, i, 1); rc = qemuMonitorSetCPU(priv->mon, i, 1);
if (rc == 0) if (rc == 0)
...@@ -2568,10 +2569,10 @@ static int qemudDomainHotplugVcpus(virDomainObjPtr vm, unsigned int nvcpus) ...@@ -2568,10 +2569,10 @@ static int qemudDomainHotplugVcpus(virDomainObjPtr vm, unsigned int nvcpus)
if (rc < 0) if (rc < 0)
goto cleanup; goto cleanup;
vm->def->vcpus++; vcpus++;
} }
} else { } else {
for (i = vm->def->vcpus - 1 ; i >= nvcpus ; i--) { for (i = vcpus - 1 ; i >= nvcpus ; i--) {
/* Offline old CPU */ /* Offline old CPU */
rc = qemuMonitorSetCPU(priv->mon, i, 0); rc = qemuMonitorSetCPU(priv->mon, i, 0);
if (rc == 0) if (rc == 0)
...@@ -2579,7 +2580,7 @@ static int qemudDomainHotplugVcpus(virDomainObjPtr vm, unsigned int nvcpus) ...@@ -2579,7 +2580,7 @@ static int qemudDomainHotplugVcpus(virDomainObjPtr vm, unsigned int nvcpus)
if (rc < 0) if (rc < 0)
goto cleanup; goto cleanup;
vm->def->vcpus--; vcpus--;
} }
} }
...@@ -2587,6 +2588,7 @@ static int qemudDomainHotplugVcpus(virDomainObjPtr vm, unsigned int nvcpus) ...@@ -2587,6 +2588,7 @@ static int qemudDomainHotplugVcpus(virDomainObjPtr vm, unsigned int nvcpus)
cleanup: cleanup:
qemuDomainObjExitMonitor(vm); qemuDomainObjExitMonitor(vm);
vm->def->vcpus = vcpus;
qemuAuditVcpu(vm, oldvcpus, nvcpus, "update", rc == 1); qemuAuditVcpu(vm, oldvcpus, nvcpus, "update", rc == 1);
return ret; return ret;
......
...@@ -1836,13 +1836,6 @@ qemuDomainChangeGraphicsPasswords(struct qemud_driver *driver, ...@@ -1836,13 +1836,6 @@ qemuDomainChangeGraphicsPasswords(struct qemud_driver *driver,
if (ret != 0) if (ret != 0)
goto cleanup; goto cleanup;
if (!virDomainObjIsActive(vm)) {
ret = -1;
qemuReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("guest unexpectedly quit"));
goto cleanup;
}
if (auth->expires) { if (auth->expires) {
time_t lifetime = auth->validTo - now; time_t lifetime = auth->validTo - now;
if (lifetime <= 0) if (lifetime <= 0)
......
...@@ -1008,8 +1008,8 @@ qemuProcessWaitForMonitor(struct qemud_driver* driver, ...@@ -1008,8 +1008,8 @@ qemuProcessWaitForMonitor(struct qemud_driver* driver,
if (paths == NULL) if (paths == NULL)
goto cleanup; goto cleanup;
qemuDomainObjEnterMonitorWithDriver(driver, vm);
qemuDomainObjPrivatePtr priv = vm->privateData; qemuDomainObjPrivatePtr priv = vm->privateData;
qemuDomainObjEnterMonitorWithDriver(driver, vm);
ret = qemuMonitorGetPtyPaths(priv->mon, paths); ret = qemuMonitorGetPtyPaths(priv->mon, paths);
qemuDomainObjExitMonitorWithDriver(driver, vm); qemuDomainObjExitMonitorWithDriver(driver, vm);
...@@ -1175,6 +1175,7 @@ qemuProcessInitPasswords(virConnectPtr conn, ...@@ -1175,6 +1175,7 @@ qemuProcessInitPasswords(virConnectPtr conn,
for (i = 0 ; i < vm->def->ndisks ; i++) { for (i = 0 ; i < vm->def->ndisks ; i++) {
char *secret; char *secret;
size_t secretLen; size_t secretLen;
const char *alias;
if (!vm->def->disks[i]->encryption || if (!vm->def->disks[i]->encryption ||
!vm->def->disks[i]->src) !vm->def->disks[i]->src)
...@@ -1185,10 +1186,9 @@ qemuProcessInitPasswords(virConnectPtr conn, ...@@ -1185,10 +1186,9 @@ qemuProcessInitPasswords(virConnectPtr conn,
&secret, &secretLen) < 0) &secret, &secretLen) < 0)
goto cleanup; goto cleanup;
alias = vm->def->disks[i]->info.alias;
qemuDomainObjEnterMonitorWithDriver(driver, vm); qemuDomainObjEnterMonitorWithDriver(driver, vm);
ret = qemuMonitorSetDrivePassphrase(priv->mon, ret = qemuMonitorSetDrivePassphrase(priv->mon, alias, secret);
vm->def->disks[i]->info.alias,
secret);
VIR_FREE(secret); VIR_FREE(secret);
qemuDomainObjExitMonitorWithDriver(driver, vm); qemuDomainObjExitMonitorWithDriver(driver, vm);
if (ret < 0) if (ret < 0)
...@@ -1727,17 +1727,19 @@ qemuProcessPrepareMonitorChr(struct qemud_driver *driver, ...@@ -1727,17 +1727,19 @@ qemuProcessPrepareMonitorChr(struct qemud_driver *driver,
} }
int qemuProcessStartCPUs(struct qemud_driver *driver, virDomainObjPtr vm, virConnectPtr conn) int
qemuProcessStartCPUs(struct qemud_driver *driver, virDomainObjPtr vm,
virConnectPtr conn)
{ {
int ret; int ret;
qemuDomainObjPrivatePtr priv = vm->privateData; qemuDomainObjPrivatePtr priv = vm->privateData;
qemuDomainObjEnterMonitorWithDriver(driver, vm); qemuDomainObjEnterMonitorWithDriver(driver, vm);
ret = qemuMonitorStartCPUs(priv->mon, conn); ret = qemuMonitorStartCPUs(priv->mon, conn);
qemuDomainObjExitMonitorWithDriver(driver, vm);
if (ret == 0) { if (ret == 0) {
vm->state = VIR_DOMAIN_RUNNING; vm->state = VIR_DOMAIN_RUNNING;
} }
qemuDomainObjExitMonitorWithDriver(driver, vm);
return ret; return ret;
} }
...@@ -1901,6 +1903,7 @@ int qemuProcessStart(virConnectPtr conn, ...@@ -1901,6 +1903,7 @@ int qemuProcessStart(virConnectPtr conn,
qemuDomainObjPrivatePtr priv = vm->privateData; qemuDomainObjPrivatePtr priv = vm->privateData;
virCommandPtr cmd = NULL; virCommandPtr cmd = NULL;
struct qemuProcessHookData hookData; struct qemuProcessHookData hookData;
unsigned long cur_balloon;
hookData.conn = conn; hookData.conn = conn;
hookData.vm = vm; hookData.vm = vm;
...@@ -2210,8 +2213,9 @@ int qemuProcessStart(virConnectPtr conn, ...@@ -2210,8 +2213,9 @@ int qemuProcessStart(virConnectPtr conn,
} }
VIR_DEBUG0("Setting initial memory amount"); VIR_DEBUG0("Setting initial memory amount");
cur_balloon = vm->def->mem.cur_balloon;
qemuDomainObjEnterMonitorWithDriver(driver, vm); qemuDomainObjEnterMonitorWithDriver(driver, vm);
if (qemuMonitorSetBalloon(priv->mon, vm->def->mem.cur_balloon) < 0) { if (qemuMonitorSetBalloon(priv->mon, cur_balloon) < 0) {
qemuDomainObjExitMonitorWithDriver(driver, vm); qemuDomainObjExitMonitorWithDriver(driver, vm);
goto cleanup; goto cleanup;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册