Re: [libvirt PATCH 2/5] libvirt: Introduce virDomainGraphicsReload API

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

 



On 2/29/24 16:23, Ján Tomko wrote:
> From: Zheng Yan <yanzheng759@xxxxxxxxxx>
> 
> The new virDomainGraphicsReload API is used to make the domain reload
> its certificates without restart, and avoid service interruption.
> 
> Currently, only QEMU VNC TLS certificates are supported, but parameters and
> flags are also reserved for subsequent scenarios.
> 
> To reload QEMU VNC TLS certificates as an example, we can call:
> 
>   virDomainGraphicsReload(domain, 0, 0);
> 
> Then the specified QMP message would be send to QEMU:
> {"execute": "display-reload", "arguments":{"type": "vnc", "tls-certs": true}}
> 
> Signed-off-by: Zheng Yan <yanzheng759@xxxxxxxxxx>
> Signed-off-by: Ján Tomko <jtomko@xxxxxxxxxx>
> ---
>  include/libvirt/libvirt-domain.h | 18 ++++++++++++
>  src/driver-hypervisor.h          |  6 ++++
>  src/libvirt-domain.c             | 50 ++++++++++++++++++++++++++++++++
>  src/libvirt_public.syms          |  5 ++++
>  4 files changed, 79 insertions(+)
> 
> diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h
> index 30cce85b29..2f5b01bbfe 100644
> --- a/include/libvirt/libvirt-domain.h
> +++ b/include/libvirt/libvirt-domain.h
> @@ -6507,4 +6507,22 @@ int virDomainFDAssociate(virDomainPtr domain,
>                           int *fds,
>                           unsigned int flags);
>  
> +/**
> + * virDomainGraphicsReloadType:
> + *
> + * Since: 10.2.0
> + */
> +typedef enum {
> +    VIR_DOMAIN_GRAPHICS_RELOAD_TYPE_ANY = 0, /* reload any graphics known to libvirt (Since: 10.2.0) */
> +    VIR_DOMAIN_GRAPHICS_RELOAD_TYPE_VNC = 1, /* reload vnc graphics (Since: 10.2.0) */
> +# ifdef VIR_ENUM_SENTINELS
> +    VIR_DOMAIN_GRAPHICS_RELOAD_TYPE_LAST /* (Since: 10.2.0) */
> +# endif
> +} virDomainGraphicsReloadType;
> +
> +int
> +virDomainGraphicsReload(virDomainPtr domain,
> +                        unsigned int type,
> +                        unsigned int flags);
> +
>  #endif /* LIBVIRT_DOMAIN_H */
> diff --git a/src/driver-hypervisor.h b/src/driver-hypervisor.h
> index 5219344b72..4ce8da078d 100644
> --- a/src/driver-hypervisor.h
> +++ b/src/driver-hypervisor.h
> @@ -1448,6 +1448,11 @@ typedef int
>                             int *fds,
>                             unsigned int flags);
>  
> +typedef int
> +(*virDrvDomainGraphicsReload)(virDomainPtr domain,
> +                              unsigned int type,
> +                              unsigned int flags);
> +
>  typedef struct _virHypervisorDriver virHypervisorDriver;
>  
>  /**
> @@ -1720,4 +1725,5 @@ struct _virHypervisorDriver {
>      virDrvDomainGetMessages domainGetMessages;
>      virDrvDomainStartDirtyRateCalc domainStartDirtyRateCalc;
>      virDrvDomainFDAssociate domainFDAssociate;
> +    virDrvDomainGraphicsReload domainGraphicsReload;
>  };
> diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c
> index 83abad251e..5a45b16275 100644
> --- a/src/libvirt-domain.c
> +++ b/src/libvirt-domain.c
> @@ -14118,3 +14118,53 @@ virDomainFDAssociate(virDomainPtr domain,
>      virDispatchError(conn);
>      return -1;
>  }
> +
> +
> +/**
> + * virDomainGraphicsReload:
> + * @domain: a domain object
> + * @type: graphics type; from the virDomainGraphicsReloadType enum
> + * @flags: extra flags; not used yet, so callers should always pass 0
> + *
> + * Reload domain's graphics.
> + *

I'd put parts of the commit message here, because this one line
description alone did not help me to understand what the API does. The
commit message did.

> + * Returns 0 in case of success, -1 otherwise.
> + *
> + * Since: 10.2.0
> + */
> +int
> +virDomainGraphicsReload(virDomainPtr domain,
> +                        unsigned int type,
> +                        unsigned int flags)
> +{
> +    virConnectPtr conn;
> +
> +    VIR_DOMAIN_DEBUG(domain, "type=%u, flags=0x%x", type, flags);
> +
> +    virResetLastError();
> +
> +    virCheckDomainReturn(domain, -1);
> +    conn = domain->conn;
> +    virCheckReadOnlyGoto(conn->flags, error);
> +
> +    if (type >= VIR_DOMAIN_GRAPHICS_RELOAD_TYPE_LAST) {
> +        virReportInvalidArg(type,
> +                            _("type must be less than %1$d"),
> +                            VIR_DOMAIN_GRAPHICS_RELOAD_TYPE_LAST);
> +        goto error;
> +    }

I'm not entirely sure why this needs to be here. I mean, if a client is
stuck with older client library they can't just pass the new value, the
API errors out even before any RPC is attempted. IOW, if I'd call:

  virDomainGraphicsReload(dom, 2, 0);

I'd expect to see an error from driver impl rather than client side. But
apparently we do that for other enums too. Interesting.

> +
> +    if (conn->driver->domainGraphicsReload) {
> +        int ret;
> +        ret = conn->driver->domainGraphicsReload(domain, type, flags);
> +        if (ret < 0)
> +            goto error;
> +        return ret;
> +    }
> +
> +    virReportUnsupportedError();
> +
> + error:
> +    virDispatchError(domain->conn);
> +    return -1;
> +}

Michal
_______________________________________________
Devel mailing list -- devel@xxxxxxxxxxxxxxxxx
To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxx




[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