Re: [PATCH] virQEMUDriverGetDomainCapabilities: Validate machine type

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

 



On 12/22/22 10:48, Michal Privoznik wrote:
> When calling virConnectGetDomainCapabilities() (exposed as virsh
> domcapabilities) users have option to specify whatever sub-set of
> { emulatorbin, arch, machine, virttype } they want. Then we have
> a logic (hidden in virQEMUCapsCacheLookupDefault()) that picks
> qemuCaps that satisfy values passed by user. And whatever was not
> specified is then set to the default value as specified by picked
> qemuCaps. For instance: if no machine type was provided but
> emulatorbin was, then the machine type is set to the default one
> as defined by the emulatorbin.
> 
> Or, when just virttype was set then the remaining three values
> are set to their respective defaults. Except, we have a crasher
> in this case:
> 
>   # virsh domcapabilities --virttype hvf
>   error: Disconnected from qemu:///system due to end of file
>   error: failed to get emulator capabilities
>   error: End of file while reading data: Input/output error
> 
> This is because for 'hvf' virttype (at least my) QEMU does not
> have any machine type. Therefore, @machine is set to NULL and the
> rest of the code does not expect that.
> 
> Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
> ---
>  src/qemu/qemu_conf.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
> index ae5bbcd138..cbd339f594 100644
> --- a/src/qemu/qemu_conf.c
> +++ b/src/qemu/qemu_conf.c
> @@ -1454,6 +1454,13 @@ virQEMUDriverGetDomainCapabilities(virQEMUDriver *driver,
>      g_autoptr(virDomainCaps) domCaps = NULL;
>      const char *path = virQEMUCapsGetBinary(qemuCaps);
>  
> +    if (!virQEMUCapsIsMachineSupported(qemuCaps, virttype, machine)) {
> +        virReportError(VIR_ERR_INVALID_ARG,
> +                       _("the machine '%s' is not supported by emulator '%s'"),
> +                       NULLSTR(machine), path);
> +        return NULL;
> +    }
> +
>      if (!(domCaps = virDomainCapsNew(path, machine, arch, virttype)))
>          return NULL;
>  

Self-NAK. We can do even better and validate the @arch and @virttype
too. V2 coming shortly.

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