Re: [PREPOST 05/17] src/xenxs:Refactor PCI parsing code

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

 



David Kiarie wrote:
> From: Kiarie Kahurani <davidkiarie4@xxxxxxxxx>
>
> Introduce the function
>  xenParseXMPCI(.........);
> which parses PCI config
>
> signed-off-by:David Kiarie <davidkiarie4@xxxxxxxxx>
> ---
>  src/xenxs/xen_xm.c | 192 +++++++++++++++++++++++++++--------------------------
>  1 file changed, 99 insertions(+), 93 deletions(-)
>
> diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c
> index e30ab9c..7a5b47c 100644
> --- a/src/xenxs/xen_xm.c
> +++ b/src/xenxs/xen_xm.c
> @@ -529,6 +529,102 @@ static int xenParseXMEventsActions(virConfPtr conf, virDomainDefPtr def)
>      return 0;
>  
>  }
> +static int
> +xenParseXMPCI(virConfPtr conf, virDomainDefPtr def)
> +{
> +    virConfValuePtr list = virConfGetValue(conf, "pci");
> +    virDomainHostdevDefPtr hostdev = NULL;
>   

Blank line after local variables.

> +    if (list && list->type == VIR_CONF_LIST) {
> +        list = list->list;
> +        while (list) {
> +            char domain[5];
> +            char bus[3];
> +            char slot[3];
> +            char func[2];
> +            char *key, *nextkey;
> +            int domainID;
> +            int busID;
> +            int slotID;
> +            int funcID;
> +
> +            domain[0] = bus[0] = slot[0] = func[0] = '\0';
> +
> +            if ((list->type != VIR_CONF_STRING) || (list->str == NULL))
> +                goto skippci;
> +
> +            /* pci=['0000:00:1b.0','0000:00:13.0'] */
> +            if (!(key = list->str))
> +                goto skippci;
> +            if (!(nextkey = strchr(key, ':')))
> +                goto skippci;
> +
> +            if (virStrncpy(domain, key, (nextkey - key), sizeof(domain)) == NULL) {
> +                virReportError(VIR_ERR_INTERNAL_ERROR,
> +                               _("Domain %s too big for destination"), key);
>   

Pre-existing, but while we are touching the code, I wonder if the use of
virReportError here is correct?  The device is skipped if there is a
problem parsing it.  I think these errors should be logged via VIR_WARN,
but would like confirmation from another libvirt dev before asking you
to change them.  At the very least, the error should be changed to
VIR_ERR_CONF_SYNTAX.

Regards,
Jim

> +                goto skippci;
> +            }
> +
> +            key = nextkey + 1;
> +            if (!(nextkey = strchr(key, ':')))
> +                goto skippci;
> +
> +            if (virStrncpy(bus, key, (nextkey - key), sizeof(bus)) == NULL) {
> +                virReportError(VIR_ERR_INTERNAL_ERROR,
> +                               _("Bus %s too big for destination"), key);
> +                goto skippci;
> +            }
> +
> +            key = nextkey + 1;
> +            if (!(nextkey = strchr(key, '.')))
> +                goto skippci;
> +
> +            if (virStrncpy(slot, key, (nextkey - key), sizeof(slot)) == NULL) {
> +                virReportError(VIR_ERR_INTERNAL_ERROR,
> +                               _("Slot %s too big for destination"), key);
> +                goto skippci;
> +            }
> +
> +            key = nextkey + 1;
> +            if (strlen(key) != 1)
> +                goto skippci;
> +
> +            if (virStrncpy(func, key, 1, sizeof(func)) == NULL) {
> +                virReportError(VIR_ERR_INTERNAL_ERROR,
> +                               _("Function %s too big for destination"), key);
> +                goto skippci;
> +            }
> +
> +            if (virStrToLong_i(domain, NULL, 16, &domainID) < 0)
> +                goto skippci;
> +            if (virStrToLong_i(bus, NULL, 16, &busID) < 0)
> +                goto skippci;
> +            if (virStrToLong_i(slot, NULL, 16, &slotID) < 0)
> +                goto skippci;
> +            if (virStrToLong_i(func, NULL, 16, &funcID) < 0)
> +                goto skippci;
> +
> +            if (!(hostdev = virDomainHostdevDefAlloc()))
> +               return -1;
> +
> +            hostdev->managed = false;
> +            hostdev->source.subsys.type = VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI;
> +            hostdev->source.subsys.u.pci.addr.domain = domainID;
> +            hostdev->source.subsys.u.pci.addr.bus = busID;
> +            hostdev->source.subsys.u.pci.addr.slot = slotID;
> +            hostdev->source.subsys.u.pci.addr.function = funcID;
> +
> +            if (VIR_APPEND_ELEMENT(def->hostdevs, def->nhostdevs, hostdev) < 0) {
> +                virDomainHostdevDefFree(hostdev);
> +                return -1;
> +            }
> +
> +        skippci:
> +            list = list->next;
> +        }
> +    }
> +
> +    return 0;
> +}
>  virDomainDefPtr
>  xenParseXM(virConfPtr conf, int xendConfigVersion,
>                         virCapsPtr caps)
> @@ -541,7 +637,6 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
>      virDomainDiskDefPtr disk = NULL;
>      virDomainNetDefPtr net = NULL;
>      virDomainGraphicsDefPtr graphics = NULL;
> -    virDomainHostdevDefPtr hostdev = NULL;
>      size_t i;
>      unsigned long count;
>      char *script = NULL;
> @@ -848,98 +943,9 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
>         goto cleanup;
>     if (xenParseXMEventsActions(conf, def) < 0)
>         goto cleanup;
> -
> -    list = virConfGetValue(conf, "pci");
> -    if (list && list->type == VIR_CONF_LIST) {
> -        list = list->list;
> -        while (list) {
> -            char domain[5];
> -            char bus[3];
> -            char slot[3];
> -            char func[2];
> -            char *key, *nextkey;
> -            int domainID;
> -            int busID;
> -            int slotID;
> -            int funcID;
> -
> -            domain[0] = bus[0] = slot[0] = func[0] = '\0';
> -
> -            if ((list->type != VIR_CONF_STRING) || (list->str == NULL))
> -                goto skippci;
> -
> -            /* pci=['0000:00:1b.0','0000:00:13.0'] */
> -            if (!(key = list->str))
> -                goto skippci;
> -            if (!(nextkey = strchr(key, ':')))
> -                goto skippci;
> -
> -            if (virStrncpy(domain, key, (nextkey - key), sizeof(domain)) == NULL) {
> -                virReportError(VIR_ERR_INTERNAL_ERROR,
> -                               _("Domain %s too big for destination"), key);
> -                goto skippci;
> -            }
> -
> -            key = nextkey + 1;
> -            if (!(nextkey = strchr(key, ':')))
> -                goto skippci;
> -
> -            if (virStrncpy(bus, key, (nextkey - key), sizeof(bus)) == NULL) {
> -                virReportError(VIR_ERR_INTERNAL_ERROR,
> -                               _("Bus %s too big for destination"), key);
> -                goto skippci;
> -            }
> -
> -            key = nextkey + 1;
> -            if (!(nextkey = strchr(key, '.')))
> -                goto skippci;
> -
> -            if (virStrncpy(slot, key, (nextkey - key), sizeof(slot)) == NULL) {
> -                virReportError(VIR_ERR_INTERNAL_ERROR,
> -                               _("Slot %s too big for destination"), key);
> -                goto skippci;
> -            }
> -
> -            key = nextkey + 1;
> -            if (strlen(key) != 1)
> -                goto skippci;
> -
> -            if (virStrncpy(func, key, 1, sizeof(func)) == NULL) {
> -                virReportError(VIR_ERR_INTERNAL_ERROR,
> -                               _("Function %s too big for destination"), key);
> -                goto skippci;
> -            }
> -
> -            if (virStrToLong_i(domain, NULL, 16, &domainID) < 0)
> -                goto skippci;
> -            if (virStrToLong_i(bus, NULL, 16, &busID) < 0)
> -                goto skippci;
> -            if (virStrToLong_i(slot, NULL, 16, &slotID) < 0)
> -                goto skippci;
> -            if (virStrToLong_i(func, NULL, 16, &funcID) < 0)
> -                goto skippci;
> -
> -            if (!(hostdev = virDomainHostdevDefAlloc()))
> -               goto cleanup;
> -
> -            hostdev->managed = false;
> -            hostdev->source.subsys.type = VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI;
> -            hostdev->source.subsys.u.pci.addr.domain = domainID;
> -            hostdev->source.subsys.u.pci.addr.bus = busID;
> -            hostdev->source.subsys.u.pci.addr.slot = slotID;
> -            hostdev->source.subsys.u.pci.addr.function = funcID;
> -
> -            if (VIR_APPEND_ELEMENT(def->hostdevs, def->nhostdevs, hostdev) < 0) {
> -                virDomainHostdevDefFree(hostdev);
> -                goto cleanup;
> -            }
> -
> -        skippci:
> -            list = list->next;
> -        }
> -    }
> -
> -    if (hvm) {
> +   if (xenParseXMPCI(conf, def) < 0)
> +       goto cleanup;
> +   if (hvm) {
>          if (xenXMConfigGetString(conf, "usbdevice", &str, NULL) < 0)
>              goto cleanup;
>          if (str &&
>   

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[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]