提交 b999ce97 编写于 作者: N Nikolay Shirokovskiy 提交者: Maxim Nestratov

vz: handle gracefully races on undefining domain

Undefine procedure drops domain lock while waiting for detaching
disks vz sdk call. Meanwhile vz sdk event domain-config-changed
arrives, its handler finds domain and is blocked waiting for job
condition. After undefine API call finishes event processing procedes
and tries to refreshes domain config thru existing vz sdk domain handle.
Domain does not exists anymore and event processing fails. Everything
is fine we just don't want to see error message in log for this
particular case.

Fortunately domain has flag that domain is removed from list. This
also imply that vz sdk domain is also undefined. Thus if we check
for this flag right after domain is locked again on accuiring
job condition we gracefully handle this situation.

Actually the race can happen in other situations too. Any
time we wait for job condition in mutualy exclusive job in
time when we acquire it vz sdk domain can cease to exist.
So instead of general internal error we can return domain
not found which is easier to handle. We don't need to patch
other places in mutually exclusive jobs where domain lock
is dropped as if job is started domain can't be undefine
by mutually exclusive undefine job.

The code of this patch is quite similar to qemu driver checks
for is domain is active after acquiring a job. The difference
only while qemu domain is operational while process is active
vz domain is operational while domain exists.
上级 84299235
...@@ -714,6 +714,22 @@ vzDomainGetAutostart(virDomainPtr domain, int *autostart) ...@@ -714,6 +714,22 @@ vzDomainGetAutostart(virDomainPtr domain, int *autostart)
return 0; return 0;
} }
static int
vzEnsureDomainExists(virDomainObjPtr dom)
{
char uuidstr[VIR_UUID_STRING_BUFLEN];
if (!dom->removing)
return 0;
virUUIDFormat(dom->def->uuid, uuidstr);
virReportError(VIR_ERR_NO_DOMAIN,
_("no domain with matching uuid '%s' (%s)"),
uuidstr, dom->def->name);
return -1;
}
static virDomainPtr static virDomainPtr
vzDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags) vzDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags)
{ {
...@@ -780,6 +796,9 @@ vzDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags) ...@@ -780,6 +796,9 @@ vzDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags)
goto cleanup; goto cleanup;
job = true; job = true;
if (vzEnsureDomainExists(dom) < 0)
goto cleanup;
if (prlsdkApplyConfig(driver, dom, def)) if (prlsdkApplyConfig(driver, dom, def))
goto cleanup; goto cleanup;
...@@ -1010,6 +1029,9 @@ vzDomainUndefineFlags(virDomainPtr domain, ...@@ -1010,6 +1029,9 @@ vzDomainUndefineFlags(virDomainPtr domain,
goto cleanup; goto cleanup;
job = true; job = true;
if (vzEnsureDomainExists(dom) < 0)
goto cleanup;
ret = prlsdkUnregisterDomain(privconn->driver, dom, flags); ret = prlsdkUnregisterDomain(privconn->driver, dom, flags);
cleanup: cleanup:
...@@ -1066,6 +1088,9 @@ vzDomainManagedSave(virDomainPtr domain, unsigned int flags) ...@@ -1066,6 +1088,9 @@ vzDomainManagedSave(virDomainPtr domain, unsigned int flags)
goto cleanup; goto cleanup;
job = true; job = true;
if (vzEnsureDomainExists(dom) < 0)
goto cleanup;
state = virDomainObjGetState(dom, &reason); state = virDomainObjGetState(dom, &reason);
if (state == VIR_DOMAIN_RUNNING && (flags & VIR_DOMAIN_SAVE_PAUSED)) { if (state == VIR_DOMAIN_RUNNING && (flags & VIR_DOMAIN_SAVE_PAUSED)) {
...@@ -1157,6 +1182,9 @@ static int vzDomainAttachDeviceFlags(virDomainPtr domain, const char *xml, ...@@ -1157,6 +1182,9 @@ static int vzDomainAttachDeviceFlags(virDomainPtr domain, const char *xml,
goto cleanup; goto cleanup;
job = true; job = true;
if (vzEnsureDomainExists(dom) < 0)
goto cleanup;
if (prlsdkAttachDevice(driver, dom, dev) < 0) if (prlsdkAttachDevice(driver, dom, dev) < 0)
goto cleanup; goto cleanup;
...@@ -1206,6 +1234,9 @@ static int vzDomainDetachDeviceFlags(virDomainPtr domain, const char *xml, ...@@ -1206,6 +1234,9 @@ static int vzDomainDetachDeviceFlags(virDomainPtr domain, const char *xml,
goto cleanup; goto cleanup;
job = true; job = true;
if (vzEnsureDomainExists(dom) < 0)
goto cleanup;
if (prlsdkDetachDevice(driver, dom, dev) < 0) if (prlsdkDetachDevice(driver, dom, dev) < 0)
goto cleanup; goto cleanup;
...@@ -1243,6 +1274,9 @@ vzDomainSetUserPassword(virDomainPtr domain, ...@@ -1243,6 +1274,9 @@ vzDomainSetUserPassword(virDomainPtr domain,
goto cleanup; goto cleanup;
job = true; job = true;
if (vzEnsureDomainExists(dom) < 0)
goto cleanup;
ret = prlsdkDomainSetUserPassword(dom, user, password); ret = prlsdkDomainSetUserPassword(dom, user, password);
cleanup: cleanup:
...@@ -1281,6 +1315,9 @@ static int vzDomainUpdateDeviceFlags(virDomainPtr domain, ...@@ -1281,6 +1315,9 @@ static int vzDomainUpdateDeviceFlags(virDomainPtr domain,
goto cleanup; goto cleanup;
job = true; job = true;
if (vzEnsureDomainExists(dom) < 0)
goto cleanup;
if (prlsdkUpdateDevice(driver, dom, dev) < 0) if (prlsdkUpdateDevice(driver, dom, dev) < 0)
goto cleanup; goto cleanup;
...@@ -1619,6 +1656,9 @@ static int vzDomainSetMemoryFlagsImpl(virDomainPtr domain, unsigned long memory, ...@@ -1619,6 +1656,9 @@ static int vzDomainSetMemoryFlagsImpl(virDomainPtr domain, unsigned long memory,
goto cleanup; goto cleanup;
job = true; job = true;
if (vzEnsureDomainExists(dom) < 0)
goto cleanup;
ret = prlsdkSetMemsize(dom, memory >> 10); ret = prlsdkSetMemsize(dom, memory >> 10);
cleanup: cleanup:
...@@ -2103,6 +2143,9 @@ vzDomainSnapshotCreateXML(virDomainPtr domain, ...@@ -2103,6 +2143,9 @@ vzDomainSnapshotCreateXML(virDomainPtr domain,
goto cleanup; goto cleanup;
job = true; job = true;
if (vzEnsureDomainExists(dom) < 0)
goto cleanup;
/* snaphot name is ignored, it will be set to auto generated by sdk uuid */ /* snaphot name is ignored, it will be set to auto generated by sdk uuid */
if (prlsdkCreateSnapshot(dom, def->description) < 0) if (prlsdkCreateSnapshot(dom, def->description) < 0)
goto cleanup; goto cleanup;
...@@ -2164,6 +2207,9 @@ vzDomainRevertToSnapshot(virDomainSnapshotPtr snapshot, unsigned int flags) ...@@ -2164,6 +2207,9 @@ vzDomainRevertToSnapshot(virDomainSnapshotPtr snapshot, unsigned int flags)
goto cleanup; goto cleanup;
job = true; job = true;
if (vzEnsureDomainExists(dom) < 0)
goto cleanup;
ret = prlsdkSwitchToSnapshot(dom, snapshot->name, ret = prlsdkSwitchToSnapshot(dom, snapshot->name,
flags & VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED); flags & VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED);
cleanup: cleanup:
...@@ -2534,6 +2580,9 @@ vzDomainMigratePerformStep(virDomainPtr domain, ...@@ -2534,6 +2580,9 @@ vzDomainMigratePerformStep(virDomainPtr domain,
goto cleanup; goto cleanup;
job = true; job = true;
if (vzEnsureDomainExists(dom) < 0)
goto cleanup;
if (!(vzuri = vzParseVzURI(miguri))) if (!(vzuri = vzParseVzURI(miguri)))
goto cleanup; goto cleanup;
......
...@@ -2067,6 +2067,9 @@ prlsdkHandleVmConfigEvent(vzDriverPtr driver, ...@@ -2067,6 +2067,9 @@ prlsdkHandleVmConfigEvent(vzDriverPtr driver,
goto cleanup; goto cleanup;
job = true; job = true;
if (dom->removing)
goto cleanup;
if (prlsdkUpdateDomain(driver, dom) < 0) if (prlsdkUpdateDomain(driver, dom) < 0)
goto cleanup; goto cleanup;
...@@ -2333,6 +2336,16 @@ prlsdkDomainChangeState(virDomainPtr domain, ...@@ -2333,6 +2336,16 @@ prlsdkDomainChangeState(virDomainPtr domain,
goto cleanup; goto cleanup;
job = true; job = true;
if (dom->removing) {
char uuidstr[VIR_UUID_STRING_BUFLEN];
virUUIDFormat(dom->def->uuid, uuidstr);
virReportError(VIR_ERR_NO_DOMAIN,
_("no domain with matching uuid '%s' (%s)"),
uuidstr, dom->def->name);
goto cleanup;
}
ret = prlsdkDomainChangeStateLocked(privconn->driver, dom, chstate); ret = prlsdkDomainChangeStateLocked(privconn->driver, dom, chstate);
cleanup: cleanup:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册