Re: [RFC v2: vf-token 6/7] qemu: validate & generate command line

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

 



On Wed, Nov 29, 2023 at 21:07:26 -0700, Vivek Kashyap wrote:
> Introduce a validation function for vf-token support in qemu
> and generate vf-token device attribute in qemu command line
> 
> Signed-off-by: Vivek Kashyap <vivek.kashyap@xxxxxxxxxxxxxxx>
> ---
>  src/qemu/qemu_command.c  | 13 +++++++++++++
>  src/qemu/qemu_validate.c | 20 ++++++++++++++++++++
>  2 files changed, 33 insertions(+)
> 
> diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
> index d54149ed2d..c8b8c37ff9 100644
> --- a/src/qemu/qemu_command.c
> +++ b/src/qemu/qemu_command.c
> @@ -4710,6 +4710,7 @@ qemuBuildPCIHostdevDevProps(const virDomainDef *def,
>                                              pcisrc->addr.slot,
>                                              pcisrc->addr.function);
>      const char *failover_pair_id = NULL;
> +    g_autofree char *token = NULL;
>  
>      /* caller has to assign proper passthrough backend type */
>      switch (pcisrc->backend) {
> @@ -4736,9 +4737,21 @@ qemuBuildPCIHostdevDevProps(const virDomainDef *def,
>          teaming->persistent)
>          failover_pair_id = teaming->persistent;
>  
> +    if ((dev->info->pciAddrExtFlags & VIR_PCI_ADDRESS_EXTENSION_VFTOKEN) &&
> +             pcisrc->addr.token.isSet) {

Broken coding style. I've pointed it out last time:

https://lists.libvirt.org/archives/list/devel@xxxxxxxxxxxxxxxxx/message/RBIWRG5VQMWLHGII5CMPWH6GDFCD44QY/

> +        const unsigned char *uuid = pcisrc->addr.token.uuid;
> +
> +        token = g_strdup_printf(VIR_PCI_DEVICE_TOKEN_FMT,

So VIR_PCI_DEVICE_TOKEN_FMT is:

"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x"

virUUIDFormat uses:

"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x"

Thus the exactly same format string. So use virUUIDFromat here rather
than reimplementing it.

Hint:

 token = g_strdup(virUUIDFormat(pcisrc->addr.token.uuid, uuidstrbuf));


> +                   uuid[0], uuid[1], uuid[2], uuid[3],
> +                   uuid[4], uuid[5], uuid[6], uuid[7],
> +                   uuid[8], uuid[9], uuid[10], uuid[11],
> +                   uuid[12], uuid[13], uuid[14], uuid[15]);
> +    }
> +
>      if (virJSONValueObjectAdd(&props,
>                                "s:driver", "vfio-pci",
>                                "s:host", host,
> +                              "S:vf-token", token,
>                                "s:id", dev->info->alias,
>                                "p:bootindex", dev->info->effectiveBootIndex,
>                                "S:failover_pair_id", failover_pair_id,
> diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c
> index e475ad035e..13114ca3d1 100644
> --- a/src/qemu/qemu_validate.c
> +++ b/src/qemu/qemu_validate.c
> @@ -1364,6 +1364,24 @@ qemuValidateDomainDeviceDefZPCIAddress(virDomainDeviceInfo *info,
>  }
>  
>  
> +static int
> +qemuValidateDomainDeviceDefVFTokenId(virDomainDeviceInfo *info,
> +                                     virQEMUCaps *qemuCaps)
> +{
> +    virPCIDeviceToken *vftoken = &info->addr.pci.token;
> +
> +    if (virPCIVFIOTokenIDIsPresent(vftoken) &&
> +        !virQEMUCapsGet(qemuCaps, QEMU_CAPS_VFIO_VFTOKEN)) {
> +        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
> +                       "%s",
> +                       _("This QEMU binary doesn't support vf token ids"));
> +        return -1;
> +    }
> +
> +    return 0;
> +}
> +
> +
>  static int
>  qemuValidateDomainDeviceDefAddressDrive(virDomainDeviceInfo *info,
>                                          const virDomainDef *def,
> @@ -1483,6 +1501,8 @@ qemuValidateDomainDeviceDefAddress(const virDomainDeviceDef *dev,
>      case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI:
>          if (qemuValidateDomainDeviceDefZPCIAddress(info, qemuCaps) < 0)
>              return -1;
> +         if (qemuValidateDomainDeviceDefVFTokenId(info, qemuCaps) < 0)
> +            return -1;
>          break;
>  
>      case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE:
> -- 
> 2.25.1
> _______________________________________________
> Devel mailing list -- devel@xxxxxxxxxxxxxxxxx
> To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxx
_______________________________________________
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