Re: [PATCH 07/10] qemu: Refresh the actual size of virtio-mem on monitor reconnect

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

 



On Fri, Jan 22, 2021 at 13:50:29 +0100, Michal Privoznik wrote:
> If the QEMU driver restarts it loses the track of the actual size
> of virtio-mem (because it's runtime type of information and thus
> not stored in XML) and therefore, we have to refresh it when
> reconnecting to the domain monitor.
> 
> Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
> ---
>  src/qemu/qemu_domain.c       | 37 ++++++++++++++++++++----
>  src/qemu/qemu_monitor.h      |  3 ++
>  src/qemu/qemu_monitor_json.c | 55 +++++++++++++++++++++---------------
>  src/qemu/qemu_process.c      |  3 ++
>  4 files changed, 70 insertions(+), 28 deletions(-)
> 
> diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
> index 783756b191..5c40c02180 100644
> --- a/src/qemu/qemu_domain.c
> +++ b/src/qemu/qemu_domain.c

[...]

> diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
> index 00428c14d2..9668e287a1 100644
> --- a/src/qemu/qemu_monitor.h
> +++ b/src/qemu/qemu_monitor.h
> @@ -1391,10 +1391,13 @@ typedef struct _qemuMonitorMemoryDeviceInfo qemuMonitorMemoryDeviceInfo;
>  typedef qemuMonitorMemoryDeviceInfo *qemuMonitorMemoryDeviceInfoPtr;
>  
>  struct _qemuMonitorMemoryDeviceInfo {
> +    /* For pc-dimm */
>      unsigned long long address;
>      unsigned int slot;
>      bool hotplugged;
>      bool hotpluggable;
> +    /* For virtio-mem */
> +    unsigned long long size;

Menion the unit here.

[...]

> diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
> index b1dc527e8b..1922f84a5e 100644
> --- a/src/qemu/qemu_monitor_json.c
> +++ b/src/qemu/qemu_monitor_json.c
> @@ -8228,7 +8228,6 @@ qemuMonitorJSONGetMemoryDeviceInfo(qemuMonitorPtr mon,
>      virJSONValuePtr cmd;
>      virJSONValuePtr reply = NULL;
>      virJSONValuePtr data = NULL;
> -    qemuMonitorMemoryDeviceInfoPtr meminfo = NULL;
>      size_t i;
>  
>      if (!(cmd = qemuMonitorJSONMakeCommand("query-memory-devices", NULL)))
> @@ -8249,6 +8248,9 @@ qemuMonitorJSONGetMemoryDeviceInfo(qemuMonitorPtr mon,
>  
>      for (i = 0; i < virJSONValueArraySize(data); i++) {
>          virJSONValuePtr elem = virJSONValueArrayGet(data, i);
> +        g_autofree qemuMonitorMemoryDeviceInfoPtr meminfo = NULL;
> +        virJSONValuePtr dimminfo;
> +        const char *devalias;
>          const char *type;
>  
>          if (!(type = virJSONValueObjectGetString(elem, "type"))) {
> @@ -8258,26 +8260,23 @@ qemuMonitorJSONGetMemoryDeviceInfo(qemuMonitorPtr mon,
>              goto cleanup;
>          }
>  
> +        if (!(dimminfo = virJSONValueObjectGetObject(elem, "data"))) {
> +            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
> +                           _("query-memory-devices reply data doesn't "
> +                             "contain enum data"));
> +            goto cleanup;
> +        }
> +
> +        if (!(devalias = virJSONValueObjectGetString(dimminfo, "id"))) {
> +            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
> +                           _("dimm memory info data is missing 'id'"));
> +            goto cleanup;
> +        }

This isn't future proof. The 'MemoryDeviceInfo' QAPI type which is the
return value of 'query-memory-devices' doesn't have any permanent
members, it's just an union of distinct sub types.

The fields you are querying are re-defined for every type, but are not
guaranteed to be present for any new type.

Thus our code must not require them to be present, only when we are
certain that we've got the correct discriminator.

> +
> +        meminfo = g_new0(qemuMonitorMemoryDeviceInfo, 1);
> +
>          /* dimm memory devices */
>          if (STREQ(type, "dimm")) {

[...]




[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