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

Re: [libvirt] [PATCH v2 09/12] qemu_process: separate graphics socket and address generation



On Wed, May 11, 2016 at 5:08 PM, Pavel Hrdina <phrdina redhat com> wrote:
> Signed-off-by: Pavel Hrdina <phrdina redhat com>
> ---
>  src/qemu/qemu_process.c | 123 ++++++++++++++++++++++++++++++------------------
>  1 file changed, 77 insertions(+), 46 deletions(-)
>

Reviewed-by: Marc-André Lureau <marcandre lureau redhat com>


> diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
> index 3d78455..21c2db2 100644
> --- a/src/qemu/qemu_process.c
> +++ b/src/qemu/qemu_process.c
> @@ -4418,14 +4418,87 @@ qemuProcessGraphicsReservePorts(virQEMUDriverPtr driver,
>
>
>  static int
> +qemuProcessGraphicsListenGenerate(virDomainObjPtr vm,
> +                                  virQEMUDriverConfigPtr cfg,
> +                                  virDomainGraphicsDefPtr graphics)
> +{
> +    qemuDomainObjPrivatePtr priv = vm->privateData;
> +    const char *type = virDomainGraphicsTypeToString(graphics->type);
> +    char *listenAddr = NULL;
> +    bool autoSocket = false;
> +    size_t i;
> +
> +    switch (graphics->type) {
> +    case VIR_DOMAIN_GRAPHICS_TYPE_VNC:
> +        if (cfg->vncAutoUnixSocket) {
> +            autoSocket = true;
> +        } else {
> +            listenAddr = cfg->vncListen;
> +        }
> +        break;
> +
> +    case VIR_DOMAIN_GRAPHICS_TYPE_SPICE:
> +            listenAddr = cfg->spiceListen;
> +        break;
> +
> +    case VIR_DOMAIN_GRAPHICS_TYPE_SDL:
> +    case VIR_DOMAIN_GRAPHICS_TYPE_RDP:
> +    case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP:
> +    case VIR_DOMAIN_GRAPHICS_TYPE_LAST:
> +        break;
> +    }
> +
> +    for (i = 0; i < graphics->nListens; i++) {
> +        virDomainGraphicsListenDefPtr glisten = &graphics->listens[i];
> +
> +        switch (glisten->type) {
> +        case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS:
> +            /* If there is no address specified we will use address from
> +             * qemu.conf from '*Listen'.  If '*_auto_unix_socket' is set it has
> +             * higher priority and we will use unix socket as a default listen
> +             * type. */
> +            if (!glisten->address) {
> +                if (autoSocket) {
> +                    memset(glisten, 0, sizeof(virDomainGraphicsListenDef));
> +                    if (virAsprintf(&glisten->socket, "%s/%s.sock",
> +                                    priv->libDir, type) < 0)
> +                        return -1;
> +                    glisten->fromConfig = true;
> +                    glisten->type = VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_SOCKET;
> +                } else if (listenAddr) {
> +                    if (VIR_STRDUP(glisten->address, listenAddr) < 0)
> +                        return -1;
> +                    glisten->fromConfig = true;
> +                }
> +            }
> +            break;
> +        case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_SOCKET:
> +            if (!glisten->socket) {
> +                if (virAsprintf(&glisten->socket, "%s/%s.sock",
> +                                priv->libDir, type) < 0)
> +                    return -1;
> +                glisten->autogenerated = true;
> +            }
> +            break;
> +        case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NONE:
> +        case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK:
> +        case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_LAST:
> +            break;
> +        }
> +    }
> +
> +    return 0;
> +}
> +
> +
> +static int
>  qemuProcessSetupGraphics(virQEMUDriverPtr driver,
>                           virDomainObjPtr vm,
>                           unsigned int flags)
>  {
>      virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
> -    qemuDomainObjPrivatePtr priv = vm->privateData;
>      bool allocate = !(flags & VIR_QEMU_PROCESS_START_PRETEND);
> -    size_t i, j;
> +    size_t i;
>      int ret = -1;
>
>      if (allocate && qemuProcessGraphicsReservePorts(driver, vm) < 0)
> @@ -4433,22 +4506,16 @@ qemuProcessSetupGraphics(virQEMUDriverPtr driver,
>
>      for (i = 0; i < vm->def->ngraphics; ++i) {
>          virDomainGraphicsDefPtr graphics = vm->def->graphics[i];
> -        const char *type = virDomainGraphicsTypeToString(graphics->type);
> -        char *listenAddr = NULL;
>
>          switch (graphics->type) {
>          case VIR_DOMAIN_GRAPHICS_TYPE_VNC:
>              if (qemuProcessVNCAllocatePorts(driver, graphics, allocate) < 0)
>                  goto cleanup;
> -
> -            listenAddr = cfg->vncListen;
>              break;
>
>          case VIR_DOMAIN_GRAPHICS_TYPE_SPICE:
>              if (qemuProcessSPICEAllocatePorts(driver, cfg, graphics, allocate) < 0)
>                  goto cleanup;
> -
> -            listenAddr = cfg->spiceListen;
>              break;
>
>          case VIR_DOMAIN_GRAPHICS_TYPE_SDL:
> @@ -4458,44 +4525,8 @@ qemuProcessSetupGraphics(virQEMUDriverPtr driver,
>              break;
>          }
>
> -        for (j = 0; j < graphics->nListens; j++) {
> -            virDomainGraphicsListenDefPtr glisten = &graphics->listens[j];
> -
> -            switch (glisten->type) {
> -            case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS:
> -                if (!glisten->address) {
> -                    /* If there is no address specified and qemu.conf has
> -                     * vnc_auto_unix_socket set we should use unix socket as
> -                     * default instead of tcp listen. */
> -                    if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC &&
> -                        cfg->vncAutoUnixSocket) {
> -                        memset(glisten, 0, sizeof(virDomainGraphicsListenDef));
> -                        if (virAsprintf(&glisten->socket, "%s/%s.sock",
> -                                        priv->libDir, type) < 0)
> -                            goto cleanup;
> -                        glisten->fromConfig = true;
> -                        glisten->type = VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_SOCKET;
> -                    } else if (listenAddr) {
> -                        if (VIR_STRDUP(glisten->address, listenAddr) < 0)
> -                            goto cleanup;
> -                        glisten->fromConfig = true;
> -                    }
> -                }
> -                break;
> -            case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_SOCKET:
> -                if (!glisten->socket) {
> -                    if (virAsprintf(&glisten->socket, "%s/%s.sock",
> -                                    priv->libDir, type) < 0)
> -                        goto cleanup;
> -                    glisten->autogenerated = true;
> -                }
> -                break;
> -            case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NONE:
> -            case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK:
> -            case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_LAST:
> -                break;
> -            }
> -        }
> +        if (qemuProcessGraphicsListenGenerate(vm, cfg, graphics) < 0)
> +            goto cleanup;
>      }
>
>      ret = 0;
> --
> 2.8.2
>
> --
> libvir-list mailing list
> libvir-list redhat com
> https://www.redhat.com/mailman/listinfo/libvir-list



-- 
Marc-André Lureau


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