conf: Move more PCI functions out of device_conf

Functions that deal with virPCIDeviceAddress exclusively
belong to util/virpci.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Andrea Bolognani 2018-09-13 16:36:25 +02:00
parent 16858439de
commit 679895eb5d
5 changed files with 75 additions and 76 deletions

View File

@ -160,59 +160,6 @@ virDomainDeviceInfoAddressIsEqual(const virDomainDeviceInfo *a,
return true;
}
bool
virPCIDeviceAddressIsValid(virPCIDeviceAddressPtr addr,
bool report)
{
if (addr->domain > 0xFFFF) {
if (report)
virReportError(VIR_ERR_XML_ERROR,
_("Invalid PCI address domain='0x%x', "
"must be <= 0xFFFF"),
addr->domain);
return false;
}
if (addr->bus > 0xFF) {
if (report)
virReportError(VIR_ERR_XML_ERROR,
_("Invalid PCI address bus='0x%x', "
"must be <= 0xFF"),
addr->bus);
return false;
}
if (addr->slot > 0x1F) {
if (report)
virReportError(VIR_ERR_XML_ERROR,
_("Invalid PCI address slot='0x%x', "
"must be <= 0x1F"),
addr->slot);
return false;
}
if (addr->function > 7) {
if (report)
virReportError(VIR_ERR_XML_ERROR,
_("Invalid PCI address function=0x%x, "
"must be <= 7"),
addr->function);
return false;
}
if (virPCIDeviceAddressIsEmpty(addr)) {
if (report)
virReportError(VIR_ERR_XML_ERROR, "%s",
_("Invalid PCI address 0000:00:00, at least "
"one of domain, bus, or slot must be > 0"));
return false;
}
return true;
}
bool
virPCIDeviceAddressIsEmpty(const virPCIDeviceAddress *addr)
{
return !(addr->domain || addr->bus || addr->slot);
}
bool
virDeviceInfoPCIAddressIsWanted(const virDomainDeviceInfo *info)
{
@ -309,19 +256,6 @@ virPCIDeviceAddressFormat(virBufferPtr buf,
return 0;
}
bool
virPCIDeviceAddressEqual(virPCIDeviceAddress *addr1,
virPCIDeviceAddress *addr2)
{
if (addr1->domain == addr2->domain &&
addr1->bus == addr2->bus &&
addr1->slot == addr2->slot &&
addr1->function == addr2->function) {
return true;
}
return false;
}
bool
virDomainDeviceCCWAddressIsValid(virDomainDeviceCCWAddressPtr addr)
{

View File

@ -191,10 +191,6 @@ bool virDomainDeviceInfoAddressIsEqual(const virDomainDeviceInfo *a,
bool virDomainDeviceAddressIsValid(virDomainDeviceInfoPtr info,
int type);
bool virPCIDeviceAddressIsValid(virPCIDeviceAddressPtr addr,
bool report);
bool virPCIDeviceAddressIsEmpty(const virPCIDeviceAddress *addr);
bool virDeviceInfoPCIAddressIsWanted(const virDomainDeviceInfo *info);
bool virDeviceInfoPCIAddressIsPresent(const virDomainDeviceInfo *info);
@ -205,9 +201,6 @@ int virPCIDeviceAddressFormat(virBufferPtr buf,
virPCIDeviceAddress addr,
bool includeTypeInAddr);
bool virPCIDeviceAddressEqual(virPCIDeviceAddress *addr1,
virPCIDeviceAddress *addr2);
bool virDomainDeviceCCWAddressIsValid(virDomainDeviceCCWAddressPtr addr);
int virDomainDeviceCCWAddressParseXML(xmlNodePtr node,
virDomainDeviceCCWAddressPtr addr);

View File

@ -108,10 +108,7 @@ virDomainDeviceUSBAddressParseXML;
virDomainDeviceVirtioSerialAddressParseXML;
virInterfaceLinkFormat;
virInterfaceLinkParseXML;
virPCIDeviceAddressEqual;
virPCIDeviceAddressFormat;
virPCIDeviceAddressIsEmpty;
virPCIDeviceAddressIsValid;
virPCIDeviceAddressParseXML;
@ -2498,10 +2495,13 @@ virObjectUnref;
# util/virpci.h
virPCIDeviceAddressAsString;
virPCIDeviceAddressEqual;
virPCIDeviceAddressGetIOMMUGroupAddresses;
virPCIDeviceAddressGetIOMMUGroupNum;
virPCIDeviceAddressGetSysfsFile;
virPCIDeviceAddressIOMMUGroupIterate;
virPCIDeviceAddressIsEmpty;
virPCIDeviceAddressIsValid;
virPCIDeviceAddressParse;
virPCIDeviceCopy;
virPCIDeviceDetach;

View File

@ -1668,6 +1668,71 @@ virPCIDeviceReadID(virPCIDevicePtr dev, const char *id_name)
return id_str;
}
bool
virPCIDeviceAddressIsValid(virPCIDeviceAddressPtr addr,
bool report)
{
if (addr->domain > 0xFFFF) {
if (report)
virReportError(VIR_ERR_XML_ERROR,
_("Invalid PCI address domain='0x%x', "
"must be <= 0xFFFF"),
addr->domain);
return false;
}
if (addr->bus > 0xFF) {
if (report)
virReportError(VIR_ERR_XML_ERROR,
_("Invalid PCI address bus='0x%x', "
"must be <= 0xFF"),
addr->bus);
return false;
}
if (addr->slot > 0x1F) {
if (report)
virReportError(VIR_ERR_XML_ERROR,
_("Invalid PCI address slot='0x%x', "
"must be <= 0x1F"),
addr->slot);
return false;
}
if (addr->function > 7) {
if (report)
virReportError(VIR_ERR_XML_ERROR,
_("Invalid PCI address function=0x%x, "
"must be <= 7"),
addr->function);
return false;
}
if (virPCIDeviceAddressIsEmpty(addr)) {
if (report)
virReportError(VIR_ERR_XML_ERROR, "%s",
_("Invalid PCI address 0000:00:00, at least "
"one of domain, bus, or slot must be > 0"));
return false;
}
return true;
}
bool
virPCIDeviceAddressIsEmpty(const virPCIDeviceAddress *addr)
{
return !(addr->domain || addr->bus || addr->slot);
}
bool
virPCIDeviceAddressEqual(virPCIDeviceAddress *addr1,
virPCIDeviceAddress *addr2)
{
if (addr1->domain == addr2->domain &&
addr1->bus == addr2->bus &&
addr1->slot == addr2->slot &&
addr1->function == addr2->function) {
return true;
}
return false;
}
char *
virPCIDeviceAddressAsString(virPCIDeviceAddressPtr addr)
{

View File

@ -218,6 +218,13 @@ int virPCIGetSysfsFile(char *virPCIDeviceName,
char **pci_sysfs_device_link)
ATTRIBUTE_RETURN_CHECK;
bool virPCIDeviceAddressIsValid(virPCIDeviceAddressPtr addr,
bool report);
bool virPCIDeviceAddressIsEmpty(const virPCIDeviceAddress *addr);
bool virPCIDeviceAddressEqual(virPCIDeviceAddress *addr1,
virPCIDeviceAddress *addr2);
char *virPCIDeviceAddressAsString(virPCIDeviceAddressPtr addr)
ATTRIBUTE_NONNULL(1);