mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-22 19:32:19 +00:00
qemu: minor monitor lock cleanups
If virCondInit fails (okay, so that's unlikely), then we end up attempting a virObjectUnlock() on the cleanup path, even though we don't hold a lock. This is not guaranteed to be safe. While at it, I noticed a couple places where we were referencing mon->fd outside locks. * src/qemu/qemu_monitor.c (qemuMonitorOpenInternal): Minimize lock duration. mon->watch doesn't need clean up on error. (qemuMonitorGetBlockExtent, qemuMonitorBlockResize): Don't dereference fd outside of lock.
This commit is contained in:
parent
29424d1acd
commit
6abd5ea124
@ -717,7 +717,6 @@ qemuMonitorOpenInternal(virDomainObjPtr vm,
|
|||||||
if (json)
|
if (json)
|
||||||
mon->wait_greeting = 1;
|
mon->wait_greeting = 1;
|
||||||
mon->cb = cb;
|
mon->cb = cb;
|
||||||
virObjectLock(mon);
|
|
||||||
|
|
||||||
if (virSetCloseExec(mon->fd) < 0) {
|
if (virSetCloseExec(mon->fd) < 0) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
@ -731,6 +730,7 @@ qemuMonitorOpenInternal(virDomainObjPtr vm,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
virObjectLock(mon);
|
||||||
virObjectRef(mon);
|
virObjectRef(mon);
|
||||||
if ((mon->watch = virEventAddHandle(mon->fd,
|
if ((mon->watch = virEventAddHandle(mon->fd,
|
||||||
VIR_EVENT_HANDLE_HANGUP |
|
VIR_EVENT_HANDLE_HANGUP |
|
||||||
@ -740,6 +740,7 @@ qemuMonitorOpenInternal(virDomainObjPtr vm,
|
|||||||
mon,
|
mon,
|
||||||
virObjectFreeCallback)) < 0) {
|
virObjectFreeCallback)) < 0) {
|
||||||
virObjectUnref(mon);
|
virObjectUnref(mon);
|
||||||
|
virObjectUnlock(mon);
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
_("unable to register monitor events"));
|
_("unable to register monitor events"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -759,11 +760,8 @@ cleanup:
|
|||||||
* so kill the callbacks now.
|
* so kill the callbacks now.
|
||||||
*/
|
*/
|
||||||
mon->cb = NULL;
|
mon->cb = NULL;
|
||||||
virObjectUnlock(mon);
|
|
||||||
/* The caller owns 'fd' on failure */
|
/* The caller owns 'fd' on failure */
|
||||||
mon->fd = -1;
|
mon->fd = -1;
|
||||||
if (mon->watch)
|
|
||||||
virEventRemoveHandle(mon->watch);
|
|
||||||
qemuMonitorClose(mon);
|
qemuMonitorClose(mon);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -1508,8 +1506,7 @@ int qemuMonitorGetBlockExtent(qemuMonitorPtr mon,
|
|||||||
unsigned long long *extent)
|
unsigned long long *extent)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
VIR_DEBUG("mon=%p, fd=%d, dev_name=%p",
|
VIR_DEBUG("mon=%p, dev_name=%p", mon, dev_name);
|
||||||
mon, mon->fd, dev_name);
|
|
||||||
|
|
||||||
if (mon->json)
|
if (mon->json)
|
||||||
ret = qemuMonitorJSONGetBlockExtent(mon, dev_name, extent);
|
ret = qemuMonitorJSONGetBlockExtent(mon, dev_name, extent);
|
||||||
@ -1524,8 +1521,7 @@ int qemuMonitorBlockResize(qemuMonitorPtr mon,
|
|||||||
unsigned long long size)
|
unsigned long long size)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
VIR_DEBUG("mon=%p, fd=%d, devname=%p size=%llu",
|
VIR_DEBUG("mon=%p, devname=%p size=%llu", mon, device, size);
|
||||||
mon, mon->fd, device, size);
|
|
||||||
|
|
||||||
if (mon->json)
|
if (mon->json)
|
||||||
ret = qemuMonitorJSONBlockResize(mon, device, size);
|
ret = qemuMonitorJSONBlockResize(mon, device, size);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user