xen_common: Split per-PCI logic from xenParsePCI()

xenParsePCI() does a lot of stuff and, in order to make things cleaner,
let's split it in two new functions:
- xenParsePCI(): it's a new function that keeps the old name. It's
responsible for the whole per-PCI logic from the old xenParsePCI();
- xenParsePCIList(): it's basically the old xenParsePCI(), but now it
just iterates over the list of PCIs, calling xenParsePCI() per each PCI.

This patch is basically preparing the ground for the future when
typesafe virConf acessors will be used.

Signed-off-by: Fabiano Fidêncio <fabiano@fidencio.org>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Fabiano Fidêncio 2018-05-28 00:28:23 +02:00 committed by Ján Tomko
parent 9c89500ec0
commit cb9868b521

View File

@ -389,15 +389,10 @@ xenParseEventsActions(virConfPtr conf, virDomainDefPtr def)
} }
static int static virDomainHostdevDefPtr
xenParsePCI(virConfPtr conf, virDomainDefPtr def) xenParsePCI(char *entry)
{ {
virConfValuePtr list = virConfGetValue(conf, "pci");
virDomainHostdevDefPtr hostdev = NULL; virDomainHostdevDefPtr hostdev = NULL;
if (list && list->type == VIR_CONF_LIST) {
list = list->list;
while (list) {
char domain[5]; char domain[5];
char bus[3]; char bus[3];
char slot[3]; char slot[3];
@ -410,56 +405,55 @@ xenParsePCI(virConfPtr conf, virDomainDefPtr def)
domain[0] = bus[0] = slot[0] = func[0] = '\0'; 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'] */ /* pci=['0000:00:1b.0','0000:00:13.0'] */
if (!(key = list->str)) if (!(key = entry))
goto skippci; return NULL;
if (!(nextkey = strchr(key, ':'))) if (!(nextkey = strchr(key, ':')))
goto skippci; return NULL;
if (virStrncpy(domain, key, (nextkey - key), sizeof(domain)) == NULL) { if (virStrncpy(domain, key, (nextkey - key), sizeof(domain)) == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Domain %s too big for destination"), key); _("Domain %s too big for destination"), key);
goto skippci; return NULL;
} }
key = nextkey + 1; key = nextkey + 1;
if (!(nextkey = strchr(key, ':'))) if (!(nextkey = strchr(key, ':')))
goto skippci; return NULL;
if (virStrncpy(bus, key, (nextkey - key), sizeof(bus)) == NULL) { if (virStrncpy(bus, key, (nextkey - key), sizeof(bus)) == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Bus %s too big for destination"), key); _("Bus %s too big for destination"), key);
goto skippci; return NULL;
} }
key = nextkey + 1; key = nextkey + 1;
if (!(nextkey = strchr(key, '.'))) if (!(nextkey = strchr(key, '.')))
goto skippci; return NULL;
if (virStrncpy(slot, key, (nextkey - key), sizeof(slot)) == NULL) { if (virStrncpy(slot, key, (nextkey - key), sizeof(slot)) == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Slot %s too big for destination"), key); _("Slot %s too big for destination"), key);
goto skippci; return NULL;
} }
key = nextkey + 1; key = nextkey + 1;
if (strlen(key) != 1) if (strlen(key) != 1)
goto skippci; return NULL;
if (virStrncpy(func, key, 1, sizeof(func)) == NULL) { if (virStrncpy(func, key, 1, sizeof(func)) == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Function %s too big for destination"), key); _("Function %s too big for destination"), key);
goto skippci; return NULL;
} }
if (virStrToLong_i(domain, NULL, 16, &domainID) < 0) if (virStrToLong_i(domain, NULL, 16, &domainID) < 0)
goto skippci; return NULL;
if (virStrToLong_i(bus, NULL, 16, &busID) < 0) if (virStrToLong_i(bus, NULL, 16, &busID) < 0)
goto skippci; return NULL;
if (virStrToLong_i(slot, NULL, 16, &slotID) < 0) if (virStrToLong_i(slot, NULL, 16, &slotID) < 0)
goto skippci; return NULL;
if (virStrToLong_i(func, NULL, 16, &funcID) < 0) if (virStrToLong_i(func, NULL, 16, &funcID) < 0)
goto skippci; return NULL;
if (!(hostdev = virDomainHostdevDefNew())) if (!(hostdev = virDomainHostdevDefNew()))
return -1; return NULL;
hostdev->managed = false; hostdev->managed = false;
hostdev->source.subsys.type = VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI; hostdev->source.subsys.type = VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI;
@ -468,14 +462,31 @@ xenParsePCI(virConfPtr conf, virDomainDefPtr def)
hostdev->source.subsys.u.pci.addr.slot = slotID; hostdev->source.subsys.u.pci.addr.slot = slotID;
hostdev->source.subsys.u.pci.addr.function = funcID; hostdev->source.subsys.u.pci.addr.function = funcID;
return hostdev;
}
static int
xenParsePCIList(virConfPtr conf, virDomainDefPtr def)
{
virConfValuePtr list = virConfGetValue(conf, "pci");
if (!list || list->type != VIR_CONF_LIST)
return 0;
for (list = list->list; list; list = list->next) {
virDomainHostdevDefPtr hostdev;
if ((list->type != VIR_CONF_STRING) || (list->str == NULL))
continue;
if (!(hostdev = xenParsePCI(list->str)))
return -1;
if (VIR_APPEND_ELEMENT(def->hostdevs, def->nhostdevs, hostdev) < 0) { if (VIR_APPEND_ELEMENT(def->hostdevs, def->nhostdevs, hostdev) < 0) {
virDomainHostdevDefFree(hostdev); virDomainHostdevDefFree(hostdev);
return -1; return -1;
} }
skippci:
list = list->next;
}
} }
return 0; return 0;
@ -1126,7 +1137,7 @@ xenParseConfigCommon(virConfPtr conf,
return -1; return -1;
} }
if (xenParsePCI(conf, def) < 0) if (xenParsePCIList(conf, def) < 0)
return -1; return -1;
if (xenParseEmulatedDevices(conf, def) < 0) if (xenParseEmulatedDevices(conf, def) < 0)