On 5. 3. 2020 13:51, Daniel P. Berrangé wrote:
This converts the QEMU monitor APIs to use the per-VM
event loop, which involves switching from virEvent APIs
to GMainContext / GSource APIs.
A GSocket is used as a convenient way to create a GSource
for a socket, but is not yet used for actual I/O.
Signed-off-by: Daniel P. Berrangé <berrange(a)redhat.com>
---
src/qemu/qemu_monitor.c | 145 ++++++++++++++++-------------------
src/qemu/qemu_monitor.h | 3 +-
src/qemu/qemu_process.c | 6 +-
tests/qemumonitortestutils.c | 1 +
4 files changed, 71 insertions(+), 84 deletions(-)
@@ -831,25 +804,32 @@ qemuMonitorOpen(virDomainObjPtr vm,
*
* Registers the monitor in the event loop. The caller has to hold the
* lock for @mon.
- *
- * Returns true in case of success, false otherwise
*/
-bool
+void
qemuMonitorRegister(qemuMonitorPtr mon)
{
- virObjectRef(mon);
- if ((mon->watch = virEventAddHandle(mon->fd,
- VIR_EVENT_HANDLE_HANGUP |
- VIR_EVENT_HANDLE_ERROR |
- VIR_EVENT_HANDLE_READABLE,
- qemuMonitorIO,
- mon,
- virObjectFreeCallback)) < 0) {
- virObjectUnref(mon);
- return false;
+ GIOCondition cond = 0;
+
+ if (mon->lastError.code == VIR_ERR_OK) {
+ cond |= G_IO_IN;
+
+ if ((mon->msg && mon->msg->txOffset <
mon->msg->txLength) &&
+ !mon->waitGreeting)
+ cond |= G_IO_OUT;
}
- return true;
+ mon->watch = g_socket_create_source(mon->socket,
+ cond,
+ NULL);
+
+ virObjectRef(mon);
+ g_source_set_callback(mon->watch,
+ (GSourceFunc)qemuMonitorIO,
+ mon,
+ NULL);
So previously, we passed virObjectFreeCallback, so that @mon is unrefed
when removing the watch. But now you're passing NULL which will lead to
a memleak. Replace it with "(GDestroyNotify) virObjectUnref".
Michal