On Wed, Feb 12, 2025 at 09:46:10AM +0300, Alexander Shursha wrote:
> Sponsored by: Future Crew, LLC
> Signed-off-by: Alexander Shursha <[email protected]>
> ---
> src/bhyve/bhyve_parse_command.c | 59 +++++++++++++++++++++++++++++++++
> 1 file changed, 59 insertions(+)
Should come with additions to bhyveargv2xmltest.c data files
>
> diff --git a/src/bhyve/bhyve_parse_command.c b/src/bhyve/bhyve_parse_command.c
> index 29d3a678bf..14916c401d 100644
> --- a/src/bhyve/bhyve_parse_command.c
> +++ b/src/bhyve/bhyve_parse_command.c
> @@ -639,6 +639,63 @@ bhyveParsePCIFbuf(virDomainDef *def,
> return -1;
> }
>
> +static int
> +bhyveParsePassthru(virDomainDef *def G_GNUC_UNUSED,
> + unsigned pcibus,
> + unsigned pcislot,
> + unsigned pcifunction,
> + char *addr)
> +{
> + /* -s slot,bus/slot/function */
> + /* -s slot,pcibus:slot:function */
> + virDomainHostdevDef *hostdev = NULL;
> + g_auto(GStrv) params = NULL;
> + GStrv param;
> + char *p = NULL;
> +
> + if (!(hostdev = virDomainHostdevDefNew()))
> + return 0;
This method can't fail so don't check for NULL.
> +
> + hostdev->mode = VIR_DOMAIN_HOSTDEV_MODE_SUBSYS;
> + hostdev->source.subsys.type = VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI;
> +
> + hostdev->info->type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI;
> + hostdev->info->addr.pci.bus = pcibus;
> + hostdev->info->addr.pci.slot = pcislot;
> + hostdev->info->addr.pci.function = pcifunction;
> +
> + if (!addr)
> + goto error;
> +
> + if (!(params = g_strsplit(addr, ":", -1))) {
> + virReportError(VIR_ERR_OPERATION_FAILED, _("Failed to parse PCI
> address %1$s"), addr);
> + goto error;
> + }
> + if (g_str_equal(addr, *params))
> + if (!(params = g_strsplit(addr, "/", -1))) {
This overwrites the pointer currently stored in 'params'
without free'ing it. The 'g_auto' will only free data
when it goes out of scope, not when the pointer is
overwritten directly.
> + virReportError(VIR_ERR_OPERATION_FAILED, _("Failed to parse PCI
> address %1$s"), addr);
> + goto error;
> + }
Add {} on the outer if too for clarity.
> + if (g_strv_length(params) != 3) {
> + virReportError(VIR_ERR_OPERATION_FAILED, _("Failed to parse PCI
> address %1$s"), addr);
> + goto error;
> + }
> + param = params;
> + hostdev->source.subsys.u.pci.addr.bus = g_ascii_strtoull(*param++, &p,
> 10);
> + hostdev->source.subsys.u.pci.addr.slot = g_ascii_strtoull(*param++, &p,
> 10);
> + hostdev->source.subsys.u.pci.addr.function = g_ascii_strtoull(*param,
> &p, 10);
> +
> + hostdev->source.subsys.u.pci.addr.domain = 0;
> + hostdev->managed = false;
> +
> + VIR_APPEND_ELEMENT(def->hostdevs, def->nhostdevs, hostdev);
> + return 0;
> +
> + error:
> + virDomainHostdevDefFree(hostdev);
> + return -1;
> +}
> +
> static int
> bhyveParseBhyvePCIArg(virDomainDef *def,
> virDomainXMLOption *xmlopt,
> @@ -703,6 +760,8 @@ bhyveParseBhyvePCIArg(virDomainDef *def,
> VIR_DOMAIN_NET_MODEL_E1000, conf);
> else if (STREQ(emulation, "fbuf"))
> bhyveParsePCIFbuf(def, xmlopt, caps, bus, slot, function, conf);
> + else if (STREQ(emulation, "passthru"))
> + bhyveParsePassthru(def, bus, slot, function, conf);
>
> VIR_FREE(emulation);
> VIR_FREE(slotdef);
> --
> 2.47.1
>
With regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|