提交 77cfcccf 编写于 作者: D Daniel P. Berrange

Locking of the qemuMonitorPtr object

In preparation of the monitor I/O process becoming fully asynchronous,
it is neccessary to ensure all access to internals of the qemuMonitorPtr
object is protected by a mutex lock.

* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Add mutex for locking
  monitor.
* src/qemu/qemu_driver.c: Add locking around all monitor commands
上级 41d8968d
此差异已折叠。
......@@ -39,6 +39,8 @@
#define VIR_FROM_THIS VIR_FROM_QEMU
struct _qemuMonitor {
virMutex lock;
int fd;
int watch;
int hasSendFD;
......@@ -49,6 +51,16 @@ struct _qemuMonitor {
qemuMonitorDiskSecretLookup secretCB;
};
void qemuMonitorLock(qemuMonitorPtr mon)
{
virMutexLock(&mon->lock);
}
void qemuMonitorUnlock(qemuMonitorPtr mon)
{
virMutexUnlock(&mon->lock);
}
/* Return -1 for error, 1 to continue reading and 0 for success */
typedef int qemuMonitorHandleOutput(virDomainObjPtr vm,
const char *output);
......@@ -292,6 +304,12 @@ qemuMonitorOpen(virDomainObjPtr vm,
return NULL;
}
if (virMutexInit(&mon->lock) < 0) {
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s",
_("cannot initialize monitor mutex"));
VIR_FREE(mon);
return NULL;
}
mon->fd = -1;
mon->vm = vm;
mon->eofCB = eofCB;
......@@ -343,6 +361,7 @@ void qemuMonitorClose(qemuMonitorPtr mon)
if (mon->fd != -1)
close(mon->fd);
virMutexDestroy(&mon->lock);
VIR_FREE(mon);
}
......
......@@ -54,6 +54,9 @@ qemuMonitorPtr qemuMonitorOpen(virDomainObjPtr vm,
void qemuMonitorClose(qemuMonitorPtr mon);
void qemuMonitorLock(qemuMonitorPtr mon);
void qemuMonitorUnlock(qemuMonitorPtr mon);
void qemuMonitorRegisterDiskSecretLookup(qemuMonitorPtr mon,
qemuMonitorDiskSecretLookup secretCB);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册