[libvirt PATCH v2 7/7] qemu: convert agent to use the per-VM event loop
Michal Prívozník
mprivozn at redhat.com
Fri Mar 6 13:42:49 UTC 2020
On 5. 3. 2020 13:51, Daniel P. Berrangé wrote:
> This converts the QEMU agent 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 at redhat.com>
> ---
> src/qemu/qemu_agent.c | 146 +++++++++++++++++++----------------
> src/qemu/qemu_agent.h | 1 +
> src/qemu/qemu_process.c | 1 +
> tests/qemumonitortestutils.c | 1 +
> 4 files changed, 84 insertions(+), 65 deletions(-)
>
> @@ -498,28 +496,62 @@ qemuAgentIORead(qemuAgentPtr agent)
> }
>
>
> -static void qemuAgentUpdateWatch(qemuAgentPtr agent)
> -{
> - int events =
> - VIR_EVENT_HANDLE_HANGUP |
> - VIR_EVENT_HANDLE_ERROR;
> +static gboolean
> +qemuAgentIO(GSocket *socket,
> + GIOCondition cond,
> + gpointer opaque);
>
> - if (!agent->watch)
> - return;
> +
> +static void
> +qemuAgentRegister(qemuAgentPtr agent)
> +{
> + GIOCondition cond = 0;
>
> if (agent->lastError.code == VIR_ERR_OK) {
> - events |= VIR_EVENT_HANDLE_READABLE;
> + cond |= G_IO_IN;
>
> if (agent->msg && agent->msg->txOffset < agent->msg->txLength)
> - events |= VIR_EVENT_HANDLE_WRITABLE;
> + cond |= G_IO_OUT;
> }
>
> - virEventUpdateHandle(agent->watch, events);
> + agent->watch = g_socket_create_source(agent->socket,
> + cond,
> + NULL);
> +
> + virObjectRef(agent);
> + g_source_set_callback(agent->watch,
> + (GSourceFunc)qemuAgentIO,
> + agent,
> + NULL);
And again, this needs to be "(GDestroyNotify) virObjectUnref" instead of
NULL.
Michal
More information about the libvir-list
mailing list