Re: [libvirt PATCH v2 5/7] qemu: convert monitor to use the per-VM event loop

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
> ---
>  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





[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux