From: "Daniel P. Berrange" <berrange(a)redhat.com>
Rename all the pciDeviceXXX and pciXXXDevice APIs to have a
fixed virPCIDevice name prefix
---
src/conf/node_device_conf.c | 1 -
src/conf/node_device_conf.h | 5 +-
src/libvirt_private.syms | 74 ++--
src/network/bridge_driver.c | 2 +-
src/node_device/node_device_udev.c | 4 +-
src/qemu/qemu_agent.c | 1 -
src/qemu/qemu_conf.h | 5 +-
src/qemu/qemu_driver.c | 52 +--
src/qemu/qemu_hostdev.c | 244 ++++++-------
src/qemu/qemu_hostdev.h | 2 +-
src/qemu/qemu_hotplug.c | 18 +-
src/security/security_apparmor.c | 17 +-
src/security/security_dac.c | 32 +-
src/security/security_selinux.c | 30 +-
src/security/virt-aa-helper.c | 10 +-
src/util/virnetdev.c | 34 +-
src/util/virnetdev.h | 2 +-
src/util/virpci.c | 676 ++++++++++++++++++-------------------
src/util/virpci.h | 174 +++++-----
src/xen/xen_driver.c | 24 +-
20 files changed, 709 insertions(+), 698 deletions(-)
diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c
index 53b6af2..af89fe3 100644
--- a/src/conf/node_device_conf.c
+++ b/src/conf/node_device_conf.c
@@ -36,7 +36,6 @@
#include "virutil.h"
#include "virbuffer.h"
#include "viruuid.h"
-#include "virpci.h"
#include "virrandom.h"
#define VIR_FROM_THIS VIR_FROM_NODEDEV
diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h
index 12c36d8..03380df 100644
--- a/src/conf/node_device_conf.h
+++ b/src/conf/node_device_conf.h
@@ -28,6 +28,7 @@
# include "internal.h"
# include "virutil.h"
# include "virthread.h"
+# include "virpci.h"
# include <libxml/tree.h>
@@ -111,8 +112,8 @@ struct _virNodeDevCapsDef {
unsigned int class;
char *product_name;
char *vendor_name;
- struct pci_config_address *physical_function;
- struct pci_config_address **virtual_functions;
+ virPCIDeviceAddressPtr physical_function;
+ virPCIDeviceAddressPtr *virtual_functions;
unsigned int num_virtual_functions;
unsigned int flags;
} pci_dev;
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 17c35e1..dc9de46 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -989,43 +989,43 @@ virNWFilterVarValueGetSimple;
# pci.h
-pciConfigAddressToSysfsFile;
-pciDettachDevice;
-pciDeviceFileIterate;
-pciDeviceGetManaged;
-pciDeviceGetName;
-pciDeviceGetRemoveSlot;
-pciDeviceGetReprobe;
-pciDeviceGetUnbindFromStub;
-pciDeviceGetUsedBy;
-pciDeviceGetVirtualFunctionInfo;
-pciDeviceIsAssignable;
-pciDeviceIsVirtualFunction;
-pciDeviceListAdd;
-pciDeviceListCount;
-pciDeviceListDel;
-pciDeviceListFind;
-pciDeviceListFindIndex;
-pciDeviceListFree;
-pciDeviceListGet;
-pciDeviceListNew;
-pciDeviceListSteal;
-pciDeviceListStealIndex;
-pciDeviceNetName;
-pciDeviceReAttachInit;
-pciDeviceSetManaged;
-pciDeviceSetRemoveSlot;
-pciDeviceSetReprobe;
-pciDeviceSetUnbindFromStub;
-pciDeviceSetUsedBy;
-pciFreeDevice;
-pciGetDevice;
-pciGetPhysicalFunction;
-pciGetVirtualFunctionIndex;
-pciGetVirtualFunctions;
-pciReAttachDevice;
-pciResetDevice;
-pciWaitForDeviceCleanup;
+virPCIDeviceAddressGetSysfsFile;
+virPCIDeviceDettach;
+virPCIDeviceFileIterate;
+virPCIDeviceFree;
+virPCIDeviceGetManaged;
+virPCIDeviceGetName;
+virPCIDeviceGetRemoveSlot;
+virPCIDeviceGetReprobe;
+virPCIDeviceGetUnbindFromStub;
+virPCIDeviceGetUsedBy;
+virPCIDeviceIsAssignable;
+virPCIDeviceListAdd;
+virPCIDeviceListCount;
+virPCIDeviceListDel;
+virPCIDeviceListFind;
+virPCIDeviceListFindIndex;
+virPCIDeviceListFree;
+virPCIDeviceListGet;
+virPCIDeviceListNew;
+virPCIDeviceListSteal;
+virPCIDeviceListStealIndex;
+virPCIDeviceNew;
+virPCIDeviceReAttach;
+virPCIDeviceReAttachInit;
+virPCIDeviceReset;
+virPCIDeviceSetManaged;
+virPCIDeviceSetRemoveSlot;
+virPCIDeviceSetReprobe;
+virPCIDeviceSetUnbindFromStub;
+virPCIDeviceSetUsedBy;
+virPCIDeviceWaitForCleanup;
+virPCIGetNetName;
+virPCIGetPhysicalFunction;
+virPCIGetVirtualFunctionIndex;
+virPCIGetVirtualFunctionInfo;
+virPCIGetVirtualFunctions;
+virPCIIsVirtualFunction;
# secret_conf.h
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 268dada..942c17f 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -3621,7 +3621,7 @@ static int
networkCreateInterfacePool(virNetworkDefPtr netdef) {
unsigned int num_virt_fns = 0;
char **vfname = NULL;
- struct pci_config_address **virt_fns;
+ virPCIDeviceAddressPtr *virt_fns;
int ret = -1, ii = 0;
if ((virNetDevGetVirtualFunctions(netdef->forward.pfs->dev,
diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c
index a9b30b2..566e7ab 100644
--- a/src/node_device/node_device_udev.c
+++ b/src/node_device/node_device_udev.c
@@ -481,10 +481,10 @@ static int udevProcessPCI(struct udev_device *device,
goto out;
}
- if (!pciGetPhysicalFunction(syspath, &data->pci_dev.physical_function))
+ if (!virPCIGetPhysicalFunction(syspath, &data->pci_dev.physical_function))
data->pci_dev.flags |= VIR_NODE_DEV_CAP_FLAG_PCI_PHYSICAL_FUNCTION;
- if (!pciGetVirtualFunctions(syspath, &data->pci_dev.virtual_functions,
+ if (!virPCIGetVirtualFunctions(syspath, &data->pci_dev.virtual_functions,
&data->pci_dev.num_virtual_functions) ||
data->pci_dev.num_virtual_functions > 0)
data->pci_dev.flags |= VIR_NODE_DEV_CAP_FLAG_PCI_VIRTUAL_FUNCTION;
diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c
index ae54228..05641da 100644
--- a/src/qemu/qemu_agent.c
+++ b/src/qemu/qemu_agent.c
@@ -33,7 +33,6 @@
#include <sys/time.h>
#include "qemu_agent.h"
-#include "qemu_command.h"
#include "viralloc.h"
#include "virlog.h"
#include "virerror.h"
diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h
index 2b27a3e..be45cf0 100644
--- a/src/qemu/qemu_conf.h
+++ b/src/qemu/qemu_conf.h
@@ -181,11 +181,10 @@ struct _virQEMUDriver {
virSecurityManagerPtr securityManager;
- pciDeviceList *activePciHostdevs;
+ virPCIDeviceListPtr activePciHostdevs;
+ virPCIDeviceListPtr inactivePciHostdevs;
usbDeviceList *activeUsbHostdevs;
- pciDeviceList *inactivePciHostdevs;
-
virHashTablePtr sharedDisks;
virPortAllocatorPtr remotePorts;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index e2c6d07..d36f2c0 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -781,13 +781,13 @@ qemuStartup(bool privileged,
if (!qemu_driver->capsCache)
goto error;
- if ((qemu_driver->activePciHostdevs = pciDeviceListNew()) == NULL)
+ if ((qemu_driver->activePciHostdevs = virPCIDeviceListNew()) == NULL)
goto error;
if ((qemu_driver->activeUsbHostdevs = usbDeviceListNew()) == NULL)
goto error;
- if ((qemu_driver->inactivePciHostdevs = pciDeviceListNew()) == NULL)
+ if ((qemu_driver->inactivePciHostdevs = virPCIDeviceListNew()) == NULL)
goto error;
if (!(qemu_driver->sharedDisks = virHashCreate(30, NULL)))
@@ -1048,8 +1048,8 @@ qemuShutdown(void) {
qemuDriverLock(qemu_driver);
virNWFilterUnRegisterCallbackDriver(&qemuCallbackDriver);
- pciDeviceListFree(qemu_driver->activePciHostdevs);
- pciDeviceListFree(qemu_driver->inactivePciHostdevs);
+ virPCIDeviceListFree(qemu_driver->activePciHostdevs);
+ virPCIDeviceListFree(qemu_driver->inactivePciHostdevs);
usbDeviceListFree(qemu_driver->activeUsbHostdevs);
virHashFree(qemu_driver->sharedDisks);
virCapabilitiesFree(qemu_driver->caps);
@@ -10023,7 +10023,7 @@ static int
qemuNodeDeviceDettach(virNodeDevicePtr dev)
{
virQEMUDriverPtr driver = dev->conn->privateData;
- pciDevice *pci;
+ virPCIDevicePtr pci;
unsigned domain, bus, slot, function;
int ret = -1;
bool in_inactive_list = false;
@@ -10031,22 +10031,22 @@ qemuNodeDeviceDettach(virNodeDevicePtr dev)
if (qemuNodeDeviceGetPciInfo(dev, &domain, &bus, &slot, &function)
< 0)
return -1;
- pci = pciGetDevice(domain, bus, slot, function);
+ pci = virPCIDeviceNew(domain, bus, slot, function);
if (!pci)
return -1;
qemuDriverLock(driver);
- in_inactive_list = pciDeviceListFind(driver->inactivePciHostdevs, pci);
+ in_inactive_list = virPCIDeviceListFind(driver->inactivePciHostdevs, pci);
- if (pciDettachDevice(pci, driver->activePciHostdevs,
- driver->inactivePciHostdevs, "pci-stub") < 0)
+ if (virPCIDeviceDettach(pci, driver->activePciHostdevs,
+ driver->inactivePciHostdevs, "pci-stub") <
0)
goto out;
ret = 0;
out:
qemuDriverUnlock(driver);
if (in_inactive_list)
- pciFreeDevice(pci);
+ virPCIDeviceFree(pci);
return ret;
}
@@ -10054,43 +10054,43 @@ static int
qemuNodeDeviceReAttach(virNodeDevicePtr dev)
{
virQEMUDriverPtr driver = dev->conn->privateData;
- pciDevice *pci;
- pciDevice *other;
+ virPCIDevicePtr pci;
+ virPCIDevicePtr other;
unsigned domain, bus, slot, function;
int ret = -1;
if (qemuNodeDeviceGetPciInfo(dev, &domain, &bus, &slot, &function)
< 0)
return -1;
- pci = pciGetDevice(domain, bus, slot, function);
+ pci = virPCIDeviceNew(domain, bus, slot, function);
if (!pci)
return -1;
- other = pciDeviceListFind(driver->activePciHostdevs, pci);
+ other = virPCIDeviceListFind(driver->activePciHostdevs, pci);
if (other) {
- const char *other_name = pciDeviceGetUsedBy(other);
+ const char *other_name = virPCIDeviceGetUsedBy(other);
if (other_name)
virReportError(VIR_ERR_OPERATION_INVALID,
_("PCI device %s is still in use by domain %s"),
- pciDeviceGetName(pci), other_name);
+ virPCIDeviceGetName(pci), other_name);
else
virReportError(VIR_ERR_OPERATION_INVALID,
_("PCI device %s is still in use"),
- pciDeviceGetName(pci));
+ virPCIDeviceGetName(pci));
}
- pciDeviceReAttachInit(pci);
+ virPCIDeviceReAttachInit(pci);
qemuDriverLock(driver);
- if (pciReAttachDevice(pci, driver->activePciHostdevs,
- driver->inactivePciHostdevs, "pci-stub") < 0)
+ if (virPCIDeviceReAttach(pci, driver->activePciHostdevs,
+ driver->inactivePciHostdevs, "pci-stub") <
0)
goto out;
ret = 0;
out:
qemuDriverUnlock(driver);
- pciFreeDevice(pci);
+ virPCIDeviceFree(pci);
return ret;
}
@@ -10098,27 +10098,27 @@ static int
qemuNodeDeviceReset(virNodeDevicePtr dev)
{
virQEMUDriverPtr driver = dev->conn->privateData;
- pciDevice *pci;
+ virPCIDevicePtr pci;
unsigned domain, bus, slot, function;
int ret = -1;
if (qemuNodeDeviceGetPciInfo(dev, &domain, &bus, &slot, &function)
< 0)
return -1;
- pci = pciGetDevice(domain, bus, slot, function);
+ pci = virPCIDeviceNew(domain, bus, slot, function);
if (!pci)
return -1;
qemuDriverLock(driver);
- if (pciResetDevice(pci, driver->activePciHostdevs,
- driver->inactivePciHostdevs) < 0)
+ if (virPCIDeviceReset(pci, driver->activePciHostdevs,
+ driver->inactivePciHostdevs) < 0)
goto out;
ret = 0;
out:
qemuDriverUnlock(driver);
- pciFreeDevice(pci);
+ virPCIDeviceFree(pci);
return ret;
}
diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c
index 1b8a9cd..b5d7c5e 100644
--- a/src/qemu/qemu_hostdev.c
+++ b/src/qemu/qemu_hostdev.c
@@ -33,84 +33,84 @@
#define VIR_FROM_THIS VIR_FROM_QEMU
-static pciDeviceList *
+static virPCIDeviceListPtr
qemuGetPciHostDeviceList(virDomainHostdevDefPtr *hostdevs, int nhostdevs)
{
- pciDeviceList *list;
+ virPCIDeviceListPtr list;
int i;
- if (!(list = pciDeviceListNew()))
+ if (!(list = virPCIDeviceListNew()))
return NULL;
for (i = 0 ; i < nhostdevs ; i++) {
virDomainHostdevDefPtr hostdev = hostdevs[i];
- pciDevice *dev;
+ virPCIDevicePtr dev;
if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
continue;
if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI)
continue;
- dev = pciGetDevice(hostdev->source.subsys.u.pci.domain,
- hostdev->source.subsys.u.pci.bus,
- hostdev->source.subsys.u.pci.slot,
- hostdev->source.subsys.u.pci.function);
+ dev = virPCIDeviceNew(hostdev->source.subsys.u.pci.domain,
+ hostdev->source.subsys.u.pci.bus,
+ hostdev->source.subsys.u.pci.slot,
+ hostdev->source.subsys.u.pci.function);
if (!dev) {
- pciDeviceListFree(list);
+ virPCIDeviceListFree(list);
return NULL;
}
- if (pciDeviceListAdd(list, dev) < 0) {
- pciFreeDevice(dev);
- pciDeviceListFree(list);
+ if (virPCIDeviceListAdd(list, dev) < 0) {
+ virPCIDeviceFree(dev);
+ virPCIDeviceListFree(list);
return NULL;
}
- pciDeviceSetManaged(dev, hostdev->managed);
+ virPCIDeviceSetManaged(dev, hostdev->managed);
}
return list;
}
-static pciDeviceList *
+static virPCIDeviceListPtr
qemuGetActivePciHostDeviceList(virQEMUDriverPtr driver,
virDomainHostdevDefPtr *hostdevs,
int nhostdevs)
{
- pciDeviceList *list;
+ virPCIDeviceListPtr list;
int i;
- if (!(list = pciDeviceListNew()))
+ if (!(list = virPCIDeviceListNew()))
return NULL;
for (i = 0 ; i < nhostdevs ; i++) {
virDomainHostdevDefPtr hostdev = hostdevs[i];
- pciDevice *dev;
- pciDevice *activeDev;
+ virPCIDevicePtr dev;
+ virPCIDevicePtr activeDev;
if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
continue;
if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI)
continue;
- dev = pciGetDevice(hostdev->source.subsys.u.pci.domain,
- hostdev->source.subsys.u.pci.bus,
- hostdev->source.subsys.u.pci.slot,
- hostdev->source.subsys.u.pci.function);
+ dev = virPCIDeviceNew(hostdev->source.subsys.u.pci.domain,
+ hostdev->source.subsys.u.pci.bus,
+ hostdev->source.subsys.u.pci.slot,
+ hostdev->source.subsys.u.pci.function);
if (!dev) {
- pciDeviceListFree(list);
+ virPCIDeviceListFree(list);
return NULL;
}
- if ((activeDev = pciDeviceListFind(driver->activePciHostdevs, dev))) {
- if (pciDeviceListAdd(list, activeDev) < 0) {
- pciFreeDevice(dev);
- pciDeviceListFree(list);
+ if ((activeDev = virPCIDeviceListFind(driver->activePciHostdevs, dev))) {
+ if (virPCIDeviceListAdd(list, activeDev) < 0) {
+ virPCIDeviceFree(dev);
+ virPCIDeviceListFree(list);
return NULL;
}
}
- pciFreeDevice(dev);
+ virPCIDeviceFree(dev);
}
return list;
@@ -126,7 +126,7 @@ int qemuUpdateActivePciHostdevs(virQEMUDriverPtr driver,
return 0;
for (i = 0; i < def->nhostdevs; i++) {
- pciDevice *dev = NULL;
+ virPCIDevicePtr dev = NULL;
hostdev = def->hostdevs[i];
if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
@@ -134,24 +134,24 @@ int qemuUpdateActivePciHostdevs(virQEMUDriverPtr driver,
if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI)
continue;
- dev = pciGetDevice(hostdev->source.subsys.u.pci.domain,
- hostdev->source.subsys.u.pci.bus,
- hostdev->source.subsys.u.pci.slot,
- hostdev->source.subsys.u.pci.function);
+ dev = virPCIDeviceNew(hostdev->source.subsys.u.pci.domain,
+ hostdev->source.subsys.u.pci.bus,
+ hostdev->source.subsys.u.pci.slot,
+ hostdev->source.subsys.u.pci.function);
if (!dev)
return -1;
- pciDeviceSetManaged(dev, hostdev->managed);
- pciDeviceSetUsedBy(dev, def->name);
+ virPCIDeviceSetManaged(dev, hostdev->managed);
+ virPCIDeviceSetUsedBy(dev, def->name);
/* Setup the original states for the PCI device */
- pciDeviceSetUnbindFromStub(dev,
hostdev->origstates.states.pci.unbind_from_stub);
- pciDeviceSetRemoveSlot(dev, hostdev->origstates.states.pci.remove_slot);
- pciDeviceSetReprobe(dev, hostdev->origstates.states.pci.reprobe);
+ virPCIDeviceSetUnbindFromStub(dev,
hostdev->origstates.states.pci.unbind_from_stub);
+ virPCIDeviceSetRemoveSlot(dev, hostdev->origstates.states.pci.remove_slot);
+ virPCIDeviceSetReprobe(dev, hostdev->origstates.states.pci.reprobe);
- if (pciDeviceListAdd(driver->activePciHostdevs, dev) < 0) {
- pciFreeDevice(dev);
+ if (virPCIDeviceListAdd(driver->activePciHostdevs, dev) < 0) {
+ virPCIDeviceFree(dev);
return -1;
}
}
@@ -203,14 +203,14 @@ qemuUpdateActiveUsbHostdevs(virQEMUDriverPtr driver,
static int
qemuDomainHostdevPciSysfsPath(virDomainHostdevDefPtr hostdev, char **sysfs_path)
{
- struct pci_config_address config_address;
+ virPCIDeviceAddress config_address;
config_address.domain = hostdev->source.subsys.u.pci.domain;
config_address.bus = hostdev->source.subsys.u.pci.bus;
config_address.slot = hostdev->source.subsys.u.pci.slot;
config_address.function = hostdev->source.subsys.u.pci.function;
- return pciConfigAddressToSysfsFile(&config_address, sysfs_path);
+ return virPCIDeviceAddressGetSysfsFile(&config_address, sysfs_path);
}
int
@@ -222,7 +222,7 @@ qemuDomainHostdevIsVirtualFunction(virDomainHostdevDefPtr hostdev)
if (qemuDomainHostdevPciSysfsPath(hostdev, &sysfs_path) < 0)
return ret;
- ret = pciDeviceIsVirtualFunction(sysfs_path);
+ ret = virPCIIsVirtualFunction(sysfs_path);
VIR_FREE(sysfs_path);
@@ -239,12 +239,12 @@ qemuDomainHostdevNetDevice(virDomainHostdevDefPtr hostdev, char
**linkdev,
if (qemuDomainHostdevPciSysfsPath(hostdev, &sysfs_path) < 0)
return ret;
- if (pciDeviceIsVirtualFunction(sysfs_path) == 1) {
- if (pciDeviceGetVirtualFunctionInfo(sysfs_path, linkdev,
- vf) < 0)
+ if (virPCIIsVirtualFunction(sysfs_path) == 1) {
+ if (virPCIGetVirtualFunctionInfo(sysfs_path, linkdev,
+ vf) < 0)
goto cleanup;
} else {
- if (pciDeviceNetName(sysfs_path, linkdev) < 0)
+ if (virPCIGetNetName(sysfs_path, linkdev) < 0)
goto cleanup;
*vf = -1;
}
@@ -406,7 +406,7 @@ int qemuPrepareHostdevPCIDevices(virQEMUDriverPtr driver,
virDomainHostdevDefPtr *hostdevs,
int nhostdevs)
{
- pciDeviceList *pcidevs;
+ virPCIDeviceListPtr pcidevs;
int last_processed_hostdev_vf = -1;
int i;
int ret = -1;
@@ -427,48 +427,48 @@ int qemuPrepareHostdevPCIDevices(virQEMUDriverPtr driver,
* to pci-stub.ko
*/
- for (i = 0; i < pciDeviceListCount(pcidevs); i++) {
- pciDevice *dev = pciDeviceListGet(pcidevs, i);
- pciDevice *other;
+ for (i = 0; i < virPCIDeviceListCount(pcidevs); i++) {
+ virPCIDevicePtr dev = virPCIDeviceListGet(pcidevs, i);
+ virPCIDevicePtr other;
- if (!pciDeviceIsAssignable(dev, !cfg->relaxedACS)) {
+ if (!virPCIDeviceIsAssignable(dev, !cfg->relaxedACS)) {
virReportError(VIR_ERR_OPERATION_INVALID,
_("PCI device %s is not assignable"),
- pciDeviceGetName(dev));
+ virPCIDeviceGetName(dev));
goto cleanup;
}
/* The device is in use by other active domain if
* the dev is in list driver->activePciHostdevs.
*/
- if ((other = pciDeviceListFind(driver->activePciHostdevs, dev))) {
- const char *other_name = pciDeviceGetUsedBy(other);
+ if ((other = virPCIDeviceListFind(driver->activePciHostdevs, dev))) {
+ const char *other_name = virPCIDeviceGetUsedBy(other);
if (other_name)
virReportError(VIR_ERR_OPERATION_INVALID,
_("PCI device %s is in use by domain %s"),
- pciDeviceGetName(dev), other_name);
+ virPCIDeviceGetName(dev), other_name);
else
virReportError(VIR_ERR_OPERATION_INVALID,
_("PCI device %s is already in use"),
- pciDeviceGetName(dev));
+ virPCIDeviceGetName(dev));
goto cleanup;
}
}
/* Loop 2: detach managed devices */
- for (i = 0; i < pciDeviceListCount(pcidevs); i++) {
- pciDevice *dev = pciDeviceListGet(pcidevs, i);
- if (pciDeviceGetManaged(dev) &&
- pciDettachDevice(dev, driver->activePciHostdevs, NULL,
"pci-stub") < 0)
+ for (i = 0; i < virPCIDeviceListCount(pcidevs); i++) {
+ virPCIDevicePtr dev = virPCIDeviceListGet(pcidevs, i);
+ if (virPCIDeviceGetManaged(dev) &&
+ virPCIDeviceDettach(dev, driver->activePciHostdevs, NULL,
"pci-stub") < 0)
goto reattachdevs;
}
/* Loop 3: Now that all the PCI hostdevs have been detached, we
* can safely reset them */
- for (i = 0; i < pciDeviceListCount(pcidevs); i++) {
- pciDevice *dev = pciDeviceListGet(pcidevs, i);
- if (pciResetDevice(dev, driver->activePciHostdevs,
- driver->inactivePciHostdevs) < 0)
+ for (i = 0; i < virPCIDeviceListCount(pcidevs); i++) {
+ virPCIDevicePtr dev = virPCIDeviceListGet(pcidevs, i);
+ if (virPCIDeviceReset(dev, driver->activePciHostdevs,
+ driver->inactivePciHostdevs) < 0)
goto reattachdevs;
}
@@ -491,35 +491,35 @@ int qemuPrepareHostdevPCIDevices(virQEMUDriverPtr driver,
}
/* Loop 5: Now mark all the devices as active */
- for (i = 0; i < pciDeviceListCount(pcidevs); i++) {
- pciDevice *dev = pciDeviceListGet(pcidevs, i);
- if (pciDeviceListAdd(driver->activePciHostdevs, dev) < 0)
+ for (i = 0; i < virPCIDeviceListCount(pcidevs); i++) {
+ virPCIDevicePtr dev = virPCIDeviceListGet(pcidevs, i);
+ if (virPCIDeviceListAdd(driver->activePciHostdevs, dev) < 0)
goto inactivedevs;
}
/* Loop 6: Now remove the devices from inactive list. */
- for (i = 0; i < pciDeviceListCount(pcidevs); i++) {
- pciDevice *dev = pciDeviceListGet(pcidevs, i);
- pciDeviceListDel(driver->inactivePciHostdevs, dev);
+ for (i = 0; i < virPCIDeviceListCount(pcidevs); i++) {
+ virPCIDevicePtr dev = virPCIDeviceListGet(pcidevs, i);
+ virPCIDeviceListDel(driver->inactivePciHostdevs, dev);
}
/* Loop 7: Now set the used_by_domain of the device in
* driver->activePciHostdevs as domain name.
*/
- for (i = 0; i < pciDeviceListCount(pcidevs); i++) {
- pciDevice *dev, *activeDev;
+ for (i = 0; i < virPCIDeviceListCount(pcidevs); i++) {
+ virPCIDevicePtr dev, activeDev;
- dev = pciDeviceListGet(pcidevs, i);
- activeDev = pciDeviceListFind(driver->activePciHostdevs, dev);
+ dev = virPCIDeviceListGet(pcidevs, i);
+ activeDev = virPCIDeviceListFind(driver->activePciHostdevs, dev);
if (activeDev)
- pciDeviceSetUsedBy(activeDev, name);
+ virPCIDeviceSetUsedBy(activeDev, name);
}
/* Loop 8: Now set the original states for hostdev def */
for (i = 0; i < nhostdevs; i++) {
- pciDevice *dev;
- pciDevice *pcidev;
+ virPCIDevicePtr dev;
+ virPCIDevicePtr pcidev;
virDomainHostdevDefPtr hostdev = hostdevs[i];
if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
@@ -527,41 +527,41 @@ int qemuPrepareHostdevPCIDevices(virQEMUDriverPtr driver,
if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI)
continue;
- dev = pciGetDevice(hostdev->source.subsys.u.pci.domain,
- hostdev->source.subsys.u.pci.bus,
- hostdev->source.subsys.u.pci.slot,
- hostdev->source.subsys.u.pci.function);
+ dev = virPCIDeviceNew(hostdev->source.subsys.u.pci.domain,
+ hostdev->source.subsys.u.pci.bus,
+ hostdev->source.subsys.u.pci.slot,
+ hostdev->source.subsys.u.pci.function);
/* original states "unbind_from_stub", "remove_slot",
* "reprobe" were already set by pciDettachDevice in
* loop 2.
*/
- if ((pcidev = pciDeviceListFind(pcidevs, dev))) {
+ if ((pcidev = virPCIDeviceListFind(pcidevs, dev))) {
hostdev->origstates.states.pci.unbind_from_stub =
- pciDeviceGetUnbindFromStub(pcidev);
+ virPCIDeviceGetUnbindFromStub(pcidev);
hostdev->origstates.states.pci.remove_slot =
- pciDeviceGetRemoveSlot(pcidev);
+ virPCIDeviceGetRemoveSlot(pcidev);
hostdev->origstates.states.pci.reprobe =
- pciDeviceGetReprobe(pcidev);
+ virPCIDeviceGetReprobe(pcidev);
}
- pciFreeDevice(dev);
+ virPCIDeviceFree(dev);
}
/* Loop 9: Now steal all the devices from pcidevs */
- while (pciDeviceListCount(pcidevs) > 0)
- pciDeviceListStealIndex(pcidevs, 0);
+ while (virPCIDeviceListCount(pcidevs) > 0)
+ virPCIDeviceListStealIndex(pcidevs, 0);
ret = 0;
goto cleanup;
inactivedevs:
/* Only steal all the devices from driver->activePciHostdevs. We will
- * free them in pciDeviceListFree().
+ * free them in virPCIDeviceListFree().
*/
- while (pciDeviceListCount(pcidevs) > 0) {
- pciDevice *dev = pciDeviceListGet(pcidevs, 0);
- pciDeviceListSteal(driver->activePciHostdevs, dev);
+ while (virPCIDeviceListCount(pcidevs) > 0) {
+ virPCIDevicePtr dev = virPCIDeviceListGet(pcidevs, 0);
+ virPCIDeviceListSteal(driver->activePciHostdevs, dev);
}
resetvfnetconfig:
@@ -574,13 +574,13 @@ resetvfnetconfig:
}
reattachdevs:
- for (i = 0; i < pciDeviceListCount(pcidevs); i++) {
- pciDevice *dev = pciDeviceListGet(pcidevs, i);
- pciReAttachDevice(dev, driver->activePciHostdevs, NULL,
"pci-stub");
+ for (i = 0; i < virPCIDeviceListCount(pcidevs); i++) {
+ virPCIDevicePtr dev = virPCIDeviceListGet(pcidevs, i);
+ virPCIDeviceReAttach(dev, driver->activePciHostdevs, NULL,
"pci-stub");
}
cleanup:
- pciDeviceListFree(pcidevs);
+ virPCIDeviceListFree(pcidevs);
virObjectUnref(cfg);
return ret;
}
@@ -813,33 +813,33 @@ int qemuPrepareHostDevices(virQEMUDriverPtr driver,
}
-void qemuReattachPciDevice(pciDevice *dev, virQEMUDriverPtr driver)
+void qemuReattachPciDevice(virPCIDevicePtr dev, virQEMUDriverPtr driver)
{
int retries = 100;
/* If the device is not managed and was attached to guest
* successfully, it must have been inactive.
*/
- if (!pciDeviceGetManaged(dev)) {
- if (pciDeviceListAdd(driver->inactivePciHostdevs, dev) < 0)
- pciFreeDevice(dev);
+ if (!virPCIDeviceGetManaged(dev)) {
+ if (virPCIDeviceListAdd(driver->inactivePciHostdevs, dev) < 0)
+ virPCIDeviceFree(dev);
return;
}
- while (pciWaitForDeviceCleanup(dev, "kvm_assigned_device")
+ while (virPCIDeviceWaitForCleanup(dev, "kvm_assigned_device")
&& retries) {
usleep(100*1000);
retries--;
}
- if (pciReAttachDevice(dev, driver->activePciHostdevs,
- driver->inactivePciHostdevs, "pci-stub") < 0)
{
+ if (virPCIDeviceReAttach(dev, driver->activePciHostdevs,
+ driver->inactivePciHostdevs, "pci-stub") <
0) {
virErrorPtr err = virGetLastError();
VIR_ERROR(_("Failed to re-attach PCI device: %s"),
err ? err->message : _("unknown error"));
virResetError(err);
}
- pciFreeDevice(dev);
+ virPCIDeviceFree(dev);
}
@@ -848,7 +848,7 @@ void qemuDomainReAttachHostdevDevices(virQEMUDriverPtr driver,
virDomainHostdevDefPtr *hostdevs,
int nhostdevs)
{
- pciDeviceList *pcidevs;
+ virPCIDeviceListPtr pcidevs;
int i;
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
@@ -856,7 +856,7 @@ void qemuDomainReAttachHostdevDevices(virQEMUDriverPtr driver,
hostdevs,
nhostdevs))) {
virErrorPtr err = virGetLastError();
- VIR_ERROR(_("Failed to allocate pciDeviceList: %s"),
+ VIR_ERROR(_("Failed to allocate virPCIDeviceList: %s"),
err ? err->message : _("unknown error"));
virResetError(err);
goto cleanup;
@@ -866,22 +866,22 @@ void qemuDomainReAttachHostdevDevices(virQEMUDriverPtr driver,
* them and reset all the devices before re-attach.
* Attach mac and port profile parameters to devices
*/
- for (i = 0; i < pciDeviceListCount(pcidevs); i++) {
- pciDevice *dev = pciDeviceListGet(pcidevs, i);
- pciDevice *activeDev = NULL;
+ for (i = 0; i < virPCIDeviceListCount(pcidevs); i++) {
+ virPCIDevicePtr dev = virPCIDeviceListGet(pcidevs, i);
+ virPCIDevicePtr activeDev = NULL;
/* Never delete the dev from list driver->activePciHostdevs
* if it's used by other domain.
*/
- activeDev = pciDeviceListFind(driver->activePciHostdevs, dev);
+ activeDev = virPCIDeviceListFind(driver->activePciHostdevs, dev);
if (activeDev &&
- STRNEQ_NULLABLE(name, pciDeviceGetUsedBy(activeDev))) {
- pciDeviceListSteal(pcidevs, dev);
+ STRNEQ_NULLABLE(name, virPCIDeviceGetUsedBy(activeDev))) {
+ virPCIDeviceListSteal(pcidevs, dev);
continue;
}
- /* pciDeviceListFree() will take care of freeing the dev. */
- pciDeviceListSteal(driver->activePciHostdevs, dev);
+ /* virPCIDeviceListFree() will take care of freeing the dev. */
+ virPCIDeviceListSteal(driver->activePciHostdevs, dev);
}
/*
@@ -900,10 +900,10 @@ void qemuDomainReAttachHostdevDevices(virQEMUDriverPtr driver,
}
}
- for (i = 0; i < pciDeviceListCount(pcidevs); i++) {
- pciDevice *dev = pciDeviceListGet(pcidevs, i);
- if (pciResetDevice(dev, driver->activePciHostdevs,
- driver->inactivePciHostdevs) < 0) {
+ for (i = 0; i < virPCIDeviceListCount(pcidevs); i++) {
+ virPCIDevicePtr dev = virPCIDeviceListGet(pcidevs, i);
+ if (virPCIDeviceReset(dev, driver->activePciHostdevs,
+ driver->inactivePciHostdevs) < 0) {
virErrorPtr err = virGetLastError();
VIR_ERROR(_("Failed to reset PCI device: %s"),
err ? err->message : _("unknown error"));
@@ -911,12 +911,12 @@ void qemuDomainReAttachHostdevDevices(virQEMUDriverPtr driver,
}
}
- while (pciDeviceListCount(pcidevs) > 0) {
- pciDevice *dev = pciDeviceListStealIndex(pcidevs, 0);
+ while (virPCIDeviceListCount(pcidevs) > 0) {
+ virPCIDevicePtr dev = virPCIDeviceListStealIndex(pcidevs, 0);
qemuReattachPciDevice(dev, driver);
}
- pciDeviceListFree(pcidevs);
+ virPCIDeviceListFree(pcidevs);
cleanup:
virObjectUnref(cfg);
}
diff --git a/src/qemu/qemu_hostdev.h b/src/qemu/qemu_hostdev.h
index 9ef2385..8bfd36f 100644
--- a/src/qemu/qemu_hostdev.h
+++ b/src/qemu/qemu_hostdev.h
@@ -45,7 +45,7 @@ int qemuPrepareHostdevUSBDevices(virQEMUDriverPtr driver,
int qemuPrepareHostDevices(virQEMUDriverPtr driver,
virDomainDefPtr def,
bool coldBoot);
-void qemuReattachPciDevice(pciDevice *dev, virQEMUDriverPtr driver);
+void qemuReattachPciDevice(virPCIDevicePtr dev, virQEMUDriverPtr driver);
void qemuDomainReAttachHostdevDevices(virQEMUDriverPtr driver,
const char *name,
virDomainHostdevDefPtr *hostdevs,
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 77e9745..2fc8b00 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -2307,8 +2307,8 @@ qemuDomainDetachHostPciDevice(virQEMUDriverPtr driver,
qemuDomainObjPrivatePtr priv = vm->privateData;
virDomainHostdevSubsysPtr subsys = &detach->source.subsys;
int ret = -1, rv;
- pciDevice *pci;
- pciDevice *activePci;
+ virPCIDevicePtr pci;
+ virPCIDevicePtr activePci;
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
if (qemuIsMultiFunctionDevice(vm->def, detach->info)) {
@@ -2344,20 +2344,20 @@ qemuDomainDetachHostPciDevice(virQEMUDriverPtr driver,
if (
detach->parent.data.net)
qemuDomainHostdevNetConfigRestore(detach, cfg->stateDir);
- pci = pciGetDevice(subsys->u.pci.domain, subsys->u.pci.bus,
- subsys->u.pci.slot, subsys->u.pci.function);
+ pci = virPCIDeviceNew(subsys->u.pci.domain, subsys->u.pci.bus,
+ subsys->u.pci.slot, subsys->u.pci.function);
if (pci) {
- activePci = pciDeviceListSteal(driver->activePciHostdevs, pci);
+ activePci = virPCIDeviceListSteal(driver->activePciHostdevs, pci);
if (activePci &&
- pciResetDevice(activePci, driver->activePciHostdevs,
- driver->inactivePciHostdevs) == 0) {
+ virPCIDeviceReset(activePci, driver->activePciHostdevs,
+ driver->inactivePciHostdevs) == 0) {
qemuReattachPciDevice(activePci, driver);
ret = 0;
} else {
/* reset of the device failed, treat it as if it was returned */
- pciFreeDevice(activePci);
+ virPCIDeviceFree(activePci);
}
- pciFreeDevice(pci);
+ virPCIDeviceFree(pci);
}
if (qemuCapsGet(priv->caps, QEMU_CAPS_DEVICE) &&
diff --git a/src/security/security_apparmor.c b/src/security/security_apparmor.c
index 7331c91..a635a1b 100644
--- a/src/security/security_apparmor.c
+++ b/src/security/security_apparmor.c
@@ -327,8 +327,8 @@ AppArmorSetSecurityUSBLabel(usbDevice *dev ATTRIBUTE_UNUSED,
}
static int
-AppArmorSetSecurityPCILabel(pciDevice *dev ATTRIBUTE_UNUSED,
- const char *file, void *opaque)
+AppArmorSetSecurityPCILabel(virPCIDevicePtr dev ATTRIBUTE_UNUSED,
+ const char *file, void *opaque)
{
struct SDPDOP *ptr = opaque;
virDomainDefPtr def = ptr->def;
@@ -782,16 +782,17 @@ AppArmorSetSecurityHostdevLabel(virSecurityManagerPtr mgr,
}
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: {
- pciDevice *pci = pciGetDevice(dev->source.subsys.u.pci.domain,
- dev->source.subsys.u.pci.bus,
- dev->source.subsys.u.pci.slot,
- dev->source.subsys.u.pci.function);
+ virPCIDevicePtr pci =
+ virPCIDeviceNew(dev->source.subsys.u.pci.domain,
+ dev->source.subsys.u.pci.bus,
+ dev->source.subsys.u.pci.slot,
+ dev->source.subsys.u.pci.function);
if (!pci)
goto done;
- ret = pciDeviceFileIterate(pci, AppArmorSetSecurityPCILabel, ptr);
- pciFreeDevice(pci);
+ ret = virPCIDeviceFileIterate(pci, AppArmorSetSecurityPCILabel, ptr);
+ virPCIDeviceFree(pci);
break;
}
diff --git a/src/security/security_dac.c b/src/security/security_dac.c
index deff024..e42d049 100644
--- a/src/security/security_dac.c
+++ b/src/security/security_dac.c
@@ -434,7 +434,7 @@ virSecurityDACRestoreSecurityImageLabel(virSecurityManagerPtr mgr,
static int
-virSecurityDACSetSecurityPCILabel(pciDevice *dev ATTRIBUTE_UNUSED,
+virSecurityDACSetSecurityPCILabel(virPCIDevicePtr dev ATTRIBUTE_UNUSED,
const char *file,
void *opaque)
{
@@ -507,17 +507,18 @@ virSecurityDACSetSecurityHostdevLabel(virSecurityManagerPtr mgr,
}
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: {
- pciDevice *pci = pciGetDevice(dev->source.subsys.u.pci.domain,
- dev->source.subsys.u.pci.bus,
- dev->source.subsys.u.pci.slot,
- dev->source.subsys.u.pci.function);
+ virPCIDevicePtr pci =
+ virPCIDeviceNew(dev->source.subsys.u.pci.domain,
+ dev->source.subsys.u.pci.bus,
+ dev->source.subsys.u.pci.slot,
+ dev->source.subsys.u.pci.function);
if (!pci)
goto done;
- ret = pciDeviceFileIterate(pci, virSecurityDACSetSecurityPCILabel,
- params);
- pciFreeDevice(pci);
+ ret = virPCIDeviceFileIterate(pci, virSecurityDACSetSecurityPCILabel,
+ params);
+ virPCIDeviceFree(pci);
break;
}
@@ -533,7 +534,7 @@ done:
static int
-virSecurityDACRestoreSecurityPCILabel(pciDevice *dev ATTRIBUTE_UNUSED,
+virSecurityDACRestoreSecurityPCILabel(virPCIDevicePtr dev ATTRIBUTE_UNUSED,
const char *file,
void *opaque ATTRIBUTE_UNUSED)
{
@@ -586,16 +587,17 @@ virSecurityDACRestoreSecurityHostdevLabel(virSecurityManagerPtr
mgr,
}
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: {
- pciDevice *pci = pciGetDevice(dev->source.subsys.u.pci.domain,
- dev->source.subsys.u.pci.bus,
- dev->source.subsys.u.pci.slot,
- dev->source.subsys.u.pci.function);
+ virPCIDevicePtr pci =
+ virPCIDeviceNew(dev->source.subsys.u.pci.domain,
+ dev->source.subsys.u.pci.bus,
+ dev->source.subsys.u.pci.slot,
+ dev->source.subsys.u.pci.function);
if (!pci)
goto done;
- ret = pciDeviceFileIterate(pci, virSecurityDACRestoreSecurityPCILabel, mgr);
- pciFreeDevice(pci);
+ ret = virPCIDeviceFileIterate(pci, virSecurityDACRestoreSecurityPCILabel, mgr);
+ virPCIDeviceFree(pci);
break;
}
diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c
index b5e1a9a..8b1692c 100644
--- a/src/security/security_selinux.c
+++ b/src/security/security_selinux.c
@@ -1132,7 +1132,7 @@ virSecuritySELinuxSetSecurityImageLabel(virSecurityManagerPtr mgr,
static int
-virSecuritySELinuxSetSecurityPCILabel(pciDevice *dev ATTRIBUTE_UNUSED,
+virSecuritySELinuxSetSecurityPCILabel(virPCIDevicePtr dev ATTRIBUTE_UNUSED,
const char *file, void *opaque)
{
virSecurityLabelDefPtr secdef;
@@ -1186,16 +1186,17 @@ virSecuritySELinuxSetSecurityHostdevSubsysLabel(virDomainDefPtr
def,
}
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: {
- pciDevice *pci = pciGetDevice(dev->source.subsys.u.pci.domain,
- dev->source.subsys.u.pci.bus,
- dev->source.subsys.u.pci.slot,
- dev->source.subsys.u.pci.function);
+ virPCIDevicePtr pci =
+ virPCIDeviceNew(dev->source.subsys.u.pci.domain,
+ dev->source.subsys.u.pci.bus,
+ dev->source.subsys.u.pci.slot,
+ dev->source.subsys.u.pci.function);
if (!pci)
goto done;
- ret = pciDeviceFileIterate(pci, virSecuritySELinuxSetSecurityPCILabel, def);
- pciFreeDevice(pci);
+ ret = virPCIDeviceFileIterate(pci, virSecuritySELinuxSetSecurityPCILabel, def);
+ virPCIDeviceFree(pci);
break;
}
@@ -1299,7 +1300,7 @@ virSecuritySELinuxSetSecurityHostdevLabel(virSecurityManagerPtr mgr
ATTRIBUTE_UN
static int
-virSecuritySELinuxRestoreSecurityPCILabel(pciDevice *dev ATTRIBUTE_UNUSED,
+virSecuritySELinuxRestoreSecurityPCILabel(virPCIDevicePtr dev ATTRIBUTE_UNUSED,
const char *file,
void *opaque ATTRIBUTE_UNUSED)
{
@@ -1342,16 +1343,17 @@
virSecuritySELinuxRestoreSecurityHostdevSubsysLabel(virDomainHostdevDefPtr dev,
}
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: {
- pciDevice *pci = pciGetDevice(dev->source.subsys.u.pci.domain,
- dev->source.subsys.u.pci.bus,
- dev->source.subsys.u.pci.slot,
- dev->source.subsys.u.pci.function);
+ virPCIDevicePtr pci =
+ virPCIDeviceNew(dev->source.subsys.u.pci.domain,
+ dev->source.subsys.u.pci.bus,
+ dev->source.subsys.u.pci.slot,
+ dev->source.subsys.u.pci.function);
if (!pci)
goto done;
- ret = pciDeviceFileIterate(pci, virSecuritySELinuxRestoreSecurityPCILabel,
NULL);
- pciFreeDevice(pci);
+ ret = virPCIDeviceFileIterate(pci, virSecuritySELinuxRestoreSecurityPCILabel,
NULL);
+ virPCIDeviceFree(pci);
break;
}
diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c
index 0aa978e..227d0f1 100644
--- a/src/security/virt-aa-helper.c
+++ b/src/security/virt-aa-helper.c
@@ -853,8 +853,8 @@ file_iterate_hostdev_cb(usbDevice *dev ATTRIBUTE_UNUSED,
}
static int
-file_iterate_pci_cb(pciDevice *dev ATTRIBUTE_UNUSED,
- const char *file, void *opaque)
+file_iterate_pci_cb(virPCIDevicePtr dev ATTRIBUTE_UNUSED,
+ const char *file, void *opaque)
{
virBufferPtr buf = opaque;
return vah_add_file(buf, file, "rw");
@@ -1022,7 +1022,7 @@ get_files(vahControl * ctl)
}
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: {
- pciDevice *pci = pciGetDevice(
+ virPCIDevicePtr pci = virPCIDeviceNew(
dev->source.subsys.u.pci.domain,
dev->source.subsys.u.pci.bus,
dev->source.subsys.u.pci.slot,
@@ -1031,8 +1031,8 @@ get_files(vahControl * ctl)
if (pci == NULL)
continue;
- rc = pciDeviceFileIterate(pci, file_iterate_pci_cb, &buf);
- pciFreeDevice(pci);
+ rc = virPCIDeviceFileIterate(pci, file_iterate_pci_cb, &buf);
+ virPCIDeviceFree(pci);
break;
}
diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c
index 7ffd3c2..72fe257 100644
--- a/src/util/virnetdev.c
+++ b/src/util/virnetdev.c
@@ -980,7 +980,7 @@ virNetDevSysfsDeviceFile(char **pf_sysfs_device_link, const char
*ifname,
int
virNetDevGetVirtualFunctions(const char *pfname,
char ***vfname,
- struct pci_config_address ***virt_fns,
+ virPCIDeviceAddressPtr **virt_fns,
unsigned int *n_vfname)
{
int ret = -1, i;
@@ -991,8 +991,8 @@ virNetDevGetVirtualFunctions(const char *pfname,
if (virNetDevSysfsFile(&pf_sysfs_device_link, pfname, "device") <
0)
return ret;
- if (pciGetVirtualFunctions(pf_sysfs_device_link, virt_fns,
- n_vfname) < 0)
+ if (virPCIGetVirtualFunctions(pf_sysfs_device_link, virt_fns,
+ n_vfname) < 0)
goto cleanup;
if (VIR_ALLOC_N(*vfname, *n_vfname) < 0) {
@@ -1002,22 +1002,22 @@ virNetDevGetVirtualFunctions(const char *pfname,
for (i = 0; i < *n_vfname; i++)
{
- if (pciGetDeviceAddrString((*virt_fns)[i]->domain,
- (*virt_fns)[i]->bus,
- (*virt_fns)[i]->slot,
- (*virt_fns)[i]->function,
- &pciConfigAddr) < 0) {
+ if (virPCIGetAddrString((*virt_fns)[i]->domain,
+ (*virt_fns)[i]->bus,
+ (*virt_fns)[i]->slot,
+ (*virt_fns)[i]->function,
+ &pciConfigAddr) < 0) {
virReportSystemError(ENOSYS, "%s",
_("Failed to get PCI Config Address
String"));
goto cleanup;
}
- if (pciSysfsFile(pciConfigAddr, &pci_sysfs_device_link) < 0) {
+ if (virPCIGetSysfsFile(pciConfigAddr, &pci_sysfs_device_link) < 0) {
virReportSystemError(ENOSYS, "%s",
_("Failed to get PCI SYSFS file"));
goto cleanup;
}
- if (pciDeviceNetName(pci_sysfs_device_link, &((*vfname)[i])) < 0) {
+ if (virPCIGetNetName(pci_sysfs_device_link, &((*vfname)[i])) < 0) {
VIR_INFO("VF does not have an interface name");
}
}
@@ -1053,7 +1053,7 @@ virNetDevIsVirtualFunction(const char *ifname)
if (virNetDevSysfsFile(&if_sysfs_device_link, ifname, "device") <
0)
return ret;
- ret = pciDeviceIsVirtualFunction(if_sysfs_device_link);
+ ret = virPCIIsVirtualFunction(if_sysfs_device_link);
VIR_FREE(if_sysfs_device_link);
@@ -1086,9 +1086,9 @@ virNetDevGetVirtualFunctionIndex(const char *pfname, const char
*vfname,
return ret;
}
- ret = pciGetVirtualFunctionIndex(pf_sysfs_device_link,
- vf_sysfs_device_link,
- vf_index);
+ ret = virPCIGetVirtualFunctionIndex(pf_sysfs_device_link,
+ vf_sysfs_device_link,
+ vf_index);
VIR_FREE(pf_sysfs_device_link);
VIR_FREE(vf_sysfs_device_link);
@@ -1115,7 +1115,7 @@ virNetDevGetPhysicalFunction(const char *ifname, char **pfname)
if (virNetDevSysfsDeviceFile(&physfn_sysfs_path, ifname, "physfn") <
0)
return ret;
- ret = pciDeviceNetName(physfn_sysfs_path, pfname);
+ ret = virPCIGetNetName(physfn_sysfs_path, pfname);
VIR_FREE(physfn_sysfs_path);
@@ -1149,7 +1149,7 @@ virNetDevGetVirtualFunctionInfo(const char *vfname, char **pfname,
if (virNetDevSysfsFile(&vf_sysfs_path, vfname, "device") < 0)
goto cleanup;
- ret = pciGetVirtualFunctionIndex(pf_sysfs_path, vf_sysfs_path, vf);
+ ret = virPCIGetVirtualFunctionIndex(pf_sysfs_path, vf_sysfs_path, vf);
cleanup:
if (ret < 0)
@@ -1165,7 +1165,7 @@ cleanup:
int
virNetDevGetVirtualFunctions(const char *pfname ATTRIBUTE_UNUSED,
char ***vfname ATTRIBUTE_UNUSED,
- struct pci_config_address ***virt_fns ATTRIBUTE_UNUSED,
+ virPCIDeviceAddressPtr **virt_fns ATTRIBUTE_UNUSED,
unsigned int *n_vfname ATTRIBUTE_UNUSED)
{
virReportSystemError(ENOSYS, "%s",
diff --git a/src/util/virnetdev.h b/src/util/virnetdev.h
index d588e89..06d0650 100644
--- a/src/util/virnetdev.h
+++ b/src/util/virnetdev.h
@@ -104,7 +104,7 @@ int virNetDevGetPhysicalFunction(const char *ifname, char **pfname)
int virNetDevGetVirtualFunctions(const char *pfname,
char ***vfname,
- struct pci_config_address ***virt_fns,
+ virPCIDeviceAddressPtr **virt_fns,
unsigned int *n_vfname)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3)
ATTRIBUTE_NONNULL(4) ATTRIBUTE_RETURN_CHECK;
diff --git a/src/util/virpci.c b/src/util/virpci.c
index 0fb9923..695f372 100644
--- a/src/util/virpci.c
+++ b/src/util/virpci.c
@@ -50,7 +50,7 @@
#define SRIOV_NOT_FOUND 1
#define SRIOV_ERROR -1
-struct _pciDevice {
+struct _virPCIDevice {
unsigned domain;
unsigned bus;
unsigned slot;
@@ -73,9 +73,9 @@ struct _pciDevice {
unsigned reprobe : 1;
};
-struct _pciDeviceList {
+struct _virPCIDeviceList {
unsigned count;
- pciDevice **devs;
+ virPCIDevicePtr *devs;
};
@@ -160,13 +160,13 @@ struct _pciDeviceList {
#define PCI_EXT_CAP_ACS_RR 0x04
#define PCI_EXT_CAP_ACS_CR 0x08
#define PCI_EXT_CAP_ACS_UF 0x10
-#define PCI_EXT_CAP_ACS_ENABLED (PCI_EXT_CAP_ACS_SV | \
- PCI_EXT_CAP_ACS_RR | \
- PCI_EXT_CAP_ACS_CR | \
+#define PCI_EXT_CAP_ACS_ENABLED (PCI_EXT_CAP_ACS_SV | \
+ PCI_EXT_CAP_ACS_RR | \
+ PCI_EXT_CAP_ACS_CR | \
PCI_EXT_CAP_ACS_UF)
static int
-pciConfigOpen(pciDevice *dev, bool fatal)
+virPCIDeviceConfigOpen(virPCIDevicePtr dev, bool fatal)
{
int fd;
@@ -190,7 +190,7 @@ pciConfigOpen(pciDevice *dev, bool fatal)
}
static void
-pciConfigClose(pciDevice *dev, int cfgfd)
+virPCIDeviceConfigClose(virPCIDevicePtr dev, int cfgfd)
{
if (VIR_CLOSE(cfgfd) < 0) {
char ebuf[1024];
@@ -201,11 +201,11 @@ pciConfigClose(pciDevice *dev, int cfgfd)
static int
-pciRead(pciDevice *dev,
- int cfgfd,
- unsigned pos,
- uint8_t *buf,
- unsigned buflen)
+virPCIDeviceRead(virPCIDevicePtr dev,
+ int cfgfd,
+ unsigned pos,
+ uint8_t *buf,
+ unsigned buflen)
{
memset(buf, 0, buflen);
@@ -220,35 +220,35 @@ pciRead(pciDevice *dev,
}
static uint8_t
-pciRead8(pciDevice *dev, int cfgfd, unsigned pos)
+virPCIDeviceRead8(virPCIDevicePtr dev, int cfgfd, unsigned pos)
{
uint8_t buf;
- pciRead(dev, cfgfd, pos, &buf, sizeof(buf));
+ virPCIDeviceRead(dev, cfgfd, pos, &buf, sizeof(buf));
return buf;
}
static uint16_t
-pciRead16(pciDevice *dev, int cfgfd, unsigned pos)
+virPCIDeviceRead16(virPCIDevicePtr dev, int cfgfd, unsigned pos)
{
uint8_t buf[2];
- pciRead(dev, cfgfd, pos, &buf[0], sizeof(buf));
+ virPCIDeviceRead(dev, cfgfd, pos, &buf[0], sizeof(buf));
return (buf[0] << 0) | (buf[1] << 8);
}
static uint32_t
-pciRead32(pciDevice *dev, int cfgfd, unsigned pos)
+virPCIDeviceRead32(virPCIDevicePtr dev, int cfgfd, unsigned pos)
{
uint8_t buf[4];
- pciRead(dev, cfgfd, pos, &buf[0], sizeof(buf));
+ virPCIDeviceRead(dev, cfgfd, pos, &buf[0], sizeof(buf));
return (buf[0] << 0) | (buf[1] << 8) | (buf[2] << 16) | (buf[3]
<< 24);
}
static int
-pciWrite(pciDevice *dev,
- int cfgfd,
- unsigned pos,
- uint8_t *buf,
- unsigned buflen)
+virPCIDeviceWrite(virPCIDevicePtr dev,
+ int cfgfd,
+ unsigned pos,
+ uint8_t *buf,
+ unsigned buflen)
{
if (lseek(cfgfd, pos, SEEK_SET) != pos ||
safewrite(cfgfd, buf, buflen) != buflen) {
@@ -261,20 +261,20 @@ pciWrite(pciDevice *dev,
}
static void
-pciWrite16(pciDevice *dev, int cfgfd, unsigned pos, uint16_t val)
+virPCIDeviceWrite16(virPCIDevicePtr dev, int cfgfd, unsigned pos, uint16_t val)
{
uint8_t buf[2] = { (val >> 0), (val >> 8) };
- pciWrite(dev, cfgfd, pos, &buf[0], sizeof(buf));
+ virPCIDeviceWrite(dev, cfgfd, pos, &buf[0], sizeof(buf));
}
static void
-pciWrite32(pciDevice *dev, int cfgfd, unsigned pos, uint32_t val)
+virPCIDeviceWrite32(virPCIDevicePtr dev, int cfgfd, unsigned pos, uint32_t val)
{
uint8_t buf[4] = { (val >> 0), (val >> 8), (val >> 16), (val
>> 24) };
- pciWrite(dev, cfgfd, pos, &buf[0], sizeof(buf));
+ virPCIDeviceWrite(dev, cfgfd, pos, &buf[0], sizeof(buf));
}
-typedef int (*pciIterPredicate)(pciDevice *, pciDevice *, void *);
+typedef int (*virPCIDeviceIterPredicate)(virPCIDevicePtr , virPCIDevicePtr , void *);
/* Iterate over available PCI devices calling @predicate
* to compare each one to @dev.
@@ -282,10 +282,10 @@ typedef int (*pciIterPredicate)(pciDevice *, pciDevice *, void *);
* safe to reset if there is an error.
*/
static int
-pciIterDevices(pciIterPredicate predicate,
- pciDevice *dev,
- pciDevice **matched,
- void *data)
+virPCIDeviceIterDevices(virPCIDeviceIterPredicate predicate,
+ virPCIDevicePtr dev,
+ virPCIDevicePtr *matched,
+ void *data)
{
DIR *dir;
struct dirent *entry;
@@ -304,7 +304,7 @@ pciIterDevices(pciIterPredicate predicate,
while ((entry = readdir(dir))) {
unsigned int domain, bus, slot, function;
- pciDevice *check;
+ virPCIDevicePtr check;
char *tmp;
/* Ignore '.' and '..' */
@@ -324,7 +324,7 @@ pciIterDevices(pciIterPredicate predicate,
continue;
}
- check = pciGetDevice(domain, bus, slot, function);
+ check = virPCIDeviceNew(domain, bus, slot, function);
if (!check) {
ret = -1;
break;
@@ -333,7 +333,7 @@ pciIterDevices(pciIterPredicate predicate,
rc = predicate(dev, check, data);
if (rc < 0) {
/* the predicate returned an error, bail */
- pciFreeDevice(check);
+ virPCIDeviceFree(check);
ret = -1;
break;
}
@@ -344,23 +344,23 @@ pciIterDevices(pciIterPredicate predicate,
break;
}
- pciFreeDevice(check);
+ virPCIDeviceFree(check);
}
closedir(dir);
return ret;
}
static uint8_t
-pciFindCapabilityOffset(pciDevice *dev, int cfgfd, unsigned capability)
+virPCIDeviceFindCapabilityOffset(virPCIDevicePtr dev, int cfgfd, unsigned capability)
{
uint16_t status;
uint8_t pos;
- status = pciRead16(dev, cfgfd, PCI_STATUS);
+ status = virPCIDeviceRead16(dev, cfgfd, PCI_STATUS);
if (!(status & PCI_STATUS_CAP_LIST))
return 0;
- pos = pciRead8(dev, cfgfd, PCI_CAPABILITY_LIST);
+ pos = virPCIDeviceRead8(dev, cfgfd, PCI_CAPABILITY_LIST);
/* Zero indicates last capability, capabilities can't
* be in the config space header and 0xff is returned
@@ -370,14 +370,14 @@ pciFindCapabilityOffset(pciDevice *dev, int cfgfd, unsigned
capability)
* capabilities here.
*/
while (pos >= PCI_CONF_HEADER_LEN && pos != 0xff) {
- uint8_t capid = pciRead8(dev, cfgfd, pos);
+ uint8_t capid = virPCIDeviceRead8(dev, cfgfd, pos);
if (capid == capability) {
VIR_DEBUG("%s %s: found cap 0x%.2x at 0x%.2x",
dev->id, dev->name, capability, pos);
return pos;
}
- pos = pciRead8(dev, cfgfd, pos + 1);
+ pos = virPCIDeviceRead8(dev, cfgfd, pos + 1);
}
VIR_DEBUG("%s %s: failed to find cap 0x%.2x", dev->id, dev->name,
capability);
@@ -386,9 +386,9 @@ pciFindCapabilityOffset(pciDevice *dev, int cfgfd, unsigned
capability)
}
static unsigned int
-pciFindExtendedCapabilityOffset(pciDevice *dev,
- int cfgfd,
- unsigned capability)
+virPCIDeviceFindExtendedCapabilityOffset(virPCIDevicePtr dev,
+ int cfgfd,
+ unsigned capability)
{
int ttl;
unsigned int pos;
@@ -399,7 +399,7 @@ pciFindExtendedCapabilityOffset(pciDevice *dev,
pos = PCI_EXT_CAP_BASE;
while (ttl > 0 && pos >= PCI_EXT_CAP_BASE) {
- header = pciRead32(dev, cfgfd, pos);
+ header = virPCIDeviceRead32(dev, cfgfd, pos);
if ((header & PCI_EXT_CAP_ID_MASK) == capability)
return pos;
@@ -415,7 +415,7 @@ pciFindExtendedCapabilityOffset(pciDevice *dev,
* not have FLR, 1 if it does, and -1 on error
*/
static int
-pciDetectFunctionLevelReset(pciDevice *dev, int cfgfd)
+virPCIDeviceDetectFunctionLevelReset(virPCIDevicePtr dev, int cfgfd)
{
uint32_t caps;
uint8_t pos;
@@ -429,7 +429,7 @@ pciDetectFunctionLevelReset(pciDevice *dev, int cfgfd)
* on SR-IOV NICs at the moment.
*/
if (dev->pcie_cap_pos) {
- caps = pciRead32(dev, cfgfd, dev->pcie_cap_pos + PCI_EXP_DEVCAP);
+ caps = virPCIDeviceRead32(dev, cfgfd, dev->pcie_cap_pos + PCI_EXP_DEVCAP);
if (caps & PCI_EXP_DEVCAP_FLR) {
VIR_DEBUG("%s %s: detected PCIe FLR capability", dev->id,
dev->name);
return 1;
@@ -440,9 +440,9 @@ pciDetectFunctionLevelReset(pciDevice *dev, int cfgfd)
* the same thing, except for conventional PCI
* devices. This is not common yet.
*/
- pos = pciFindCapabilityOffset(dev, cfgfd, PCI_CAP_ID_AF);
+ pos = virPCIDeviceFindCapabilityOffset(dev, cfgfd, PCI_CAP_ID_AF);
if (pos) {
- caps = pciRead16(dev, cfgfd, pos + PCI_AF_CAP);
+ caps = virPCIDeviceRead16(dev, cfgfd, pos + PCI_AF_CAP);
if (caps & PCI_AF_CAP_FLR) {
VIR_DEBUG("%s %s: detected PCI FLR capability", dev->id,
dev->name);
return 1;
@@ -478,13 +478,13 @@ pciDetectFunctionLevelReset(pciDevice *dev, int cfgfd)
* internal reset, not just a soft reset.
*/
static unsigned
-pciDetectPowerManagementReset(pciDevice *dev, int cfgfd)
+virPCIDeviceDetectPowerManagementReset(virPCIDevicePtr dev, int cfgfd)
{
if (dev->pci_pm_cap_pos) {
uint32_t ctl;
/* require the NO_SOFT_RESET bit is clear */
- ctl = pciRead32(dev, cfgfd, dev->pci_pm_cap_pos + PCI_PM_CTRL);
+ ctl = virPCIDeviceRead32(dev, cfgfd, dev->pci_pm_cap_pos + PCI_PM_CTRL);
if (!(ctl & PCI_PM_CTRL_NO_SOFT_RESET)) {
VIR_DEBUG("%s %s: detected PM reset capability", dev->id,
dev->name);
return 1;
@@ -498,9 +498,9 @@ pciDetectPowerManagementReset(pciDevice *dev, int cfgfd)
/* Any active devices on the same domain/bus ? */
static int
-pciSharesBusWithActive(pciDevice *dev, pciDevice *check, void *data)
+virPCIDeviceSharesBusWithActive(virPCIDevicePtr dev, virPCIDevicePtr check, void *data)
{
- pciDeviceList *inactiveDevs = data;
+ virPCIDeviceList *inactiveDevs = data;
/* Different domain, different bus, or simply identical device */
if (dev->domain != check->domain ||
@@ -510,51 +510,51 @@ pciSharesBusWithActive(pciDevice *dev, pciDevice *check, void
*data)
return 0;
/* same bus, but inactive, i.e. about to be assigned to guest */
- if (inactiveDevs && pciDeviceListFind(inactiveDevs, check))
+ if (inactiveDevs && virPCIDeviceListFind(inactiveDevs, check))
return 0;
return 1;
}
-static pciDevice *
-pciBusContainsActiveDevices(pciDevice *dev,
- pciDeviceList *inactiveDevs)
+static virPCIDevicePtr
+virPCIDeviceBusContainsActiveDevices(virPCIDevicePtr dev,
+ virPCIDeviceList *inactiveDevs)
{
- pciDevice *active = NULL;
- if (pciIterDevices(pciSharesBusWithActive,
- dev, &active, inactiveDevs) < 0)
+ virPCIDevicePtr active = NULL;
+ if (virPCIDeviceIterDevices(virPCIDeviceSharesBusWithActive,
+ dev, &active, inactiveDevs) < 0)
return NULL;
return active;
}
/* Is @check the parent of @dev ? */
static int
-pciIsParent(pciDevice *dev, pciDevice *check, void *data)
+virPCIDeviceIsParent(virPCIDevicePtr dev, virPCIDevicePtr check, void *data)
{
uint16_t device_class;
uint8_t header_type, secondary, subordinate;
- pciDevice **best = data;
+ virPCIDevicePtr *best = data;
int ret = 0;
int fd;
if (dev->domain != check->domain)
return 0;
- if ((fd = pciConfigOpen(check, false)) < 0)
+ if ((fd = virPCIDeviceConfigOpen(check, false)) < 0)
return 0;
/* Is it a bridge? */
- device_class = pciRead16(check, fd, PCI_CLASS_DEVICE);
+ device_class = virPCIDeviceRead16(check, fd, PCI_CLASS_DEVICE);
if (device_class != PCI_CLASS_BRIDGE_PCI)
goto cleanup;
/* Is it a plane? */
- header_type = pciRead8(check, fd, PCI_HEADER_TYPE);
+ header_type = virPCIDeviceRead8(check, fd, PCI_HEADER_TYPE);
if ((header_type & PCI_HEADER_TYPE_MASK) != PCI_HEADER_TYPE_BRIDGE)
goto cleanup;
- secondary = pciRead8(check, fd, PCI_SECONDARY_BUS);
- subordinate = pciRead8(check, fd, PCI_SUBORDINATE_BUS);
+ secondary = virPCIDeviceRead8(check, fd, PCI_SECONDARY_BUS);
+ subordinate = virPCIDeviceRead8(check, fd, PCI_SUBORDINATE_BUS);
VIR_DEBUG("%s %s: found parent device %s", dev->id, dev->name,
check->name);
@@ -572,8 +572,8 @@ pciIsParent(pciDevice *dev, pciDevice *check, void *data)
*/
if (dev->bus > secondary && dev->bus <= subordinate) {
if (*best == NULL) {
- *best = pciGetDevice(check->domain, check->bus, check->slot,
- check->function);
+ *best = virPCIDeviceNew(check->domain, check->bus, check->slot,
+ check->function);
if (*best == NULL) {
ret = -1;
goto cleanup;
@@ -586,15 +586,15 @@ pciIsParent(pciDevice *dev, pciDevice *check, void *data)
int bestfd;
uint8_t best_secondary;
- if ((bestfd = pciConfigOpen(*best, false)) < 0)
+ if ((bestfd = virPCIDeviceConfigOpen(*best, false)) < 0)
goto cleanup;
- best_secondary = pciRead8(*best, bestfd, PCI_SECONDARY_BUS);
- pciConfigClose(*best, bestfd);
+ best_secondary = virPCIDeviceRead8(*best, bestfd, PCI_SECONDARY_BUS);
+ virPCIDeviceConfigClose(*best, bestfd);
if (secondary > best_secondary) {
- pciFreeDevice(*best);
- *best = pciGetDevice(check->domain, check->bus, check->slot,
- check->function);
+ virPCIDeviceFree(*best);
+ *best = virPCIDeviceNew(check->domain, check->bus, check->slot,
+ check->function);
if (*best == NULL) {
ret = -1;
goto cleanup;
@@ -604,20 +604,20 @@ pciIsParent(pciDevice *dev, pciDevice *check, void *data)
}
cleanup:
- pciConfigClose(check, fd);
+ virPCIDeviceConfigClose(check, fd);
return ret;
}
static int
-pciGetParentDevice(pciDevice *dev, pciDevice **parent)
+virPCIDeviceGetParentDevice(virPCIDevicePtr dev, virPCIDevicePtr *parent)
{
- pciDevice *best = NULL;
+ virPCIDevicePtr best = NULL;
int ret;
*parent = NULL;
- ret = pciIterDevices(pciIsParent, dev, parent, &best);
+ ret = virPCIDeviceIterDevices(virPCIDeviceIsParent, dev, parent, &best);
if (ret == 1)
- pciFreeDevice(best);
+ virPCIDeviceFree(best);
else if (ret == 0)
*parent = best;
return ret;
@@ -627,11 +627,11 @@ pciGetParentDevice(pciDevice *dev, pciDevice **parent)
* devices behind a bus.
*/
static int
-pciTrySecondaryBusReset(pciDevice *dev,
- int cfgfd,
- pciDeviceList *inactiveDevs)
+virPCIDeviceTrySecondaryBusReset(virPCIDevicePtr dev,
+ int cfgfd,
+ virPCIDeviceList *inactiveDevs)
{
- pciDevice *parent, *conflict;
+ virPCIDevicePtr parent, conflict;
uint8_t config_space[PCI_CONF_LEN];
uint16_t ctl;
int ret = -1;
@@ -641,7 +641,7 @@ pciTrySecondaryBusReset(pciDevice *dev,
* devices/functions behind the bus are used by the host
* or other guests.
*/
- if ((conflict = pciBusContainsActiveDevices(dev, inactiveDevs))) {
+ if ((conflict = virPCIDeviceBusContainsActiveDevices(dev, inactiveDevs))) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Active %s devices on bus with %s, not doing bus
reset"),
conflict->name, dev->name);
@@ -649,7 +649,7 @@ pciTrySecondaryBusReset(pciDevice *dev,
}
/* Find the parent bus */
- if (pciGetParentDevice(dev, &parent) < 0)
+ if (virPCIDeviceGetParentDevice(dev, &parent) < 0)
return -1;
if (!parent) {
virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -657,7 +657,7 @@ pciTrySecondaryBusReset(pciDevice *dev,
dev->name);
return -1;
}
- if ((parentfd = pciConfigOpen(parent, true)) < 0)
+ if ((parentfd = virPCIDeviceConfigOpen(parent, true)) < 0)
goto out;
VIR_DEBUG("%s %s: doing a secondary bus reset", dev->id, dev->name);
@@ -666,7 +666,7 @@ pciTrySecondaryBusReset(pciDevice *dev,
* for the supplied device since we refuse to do a reset if there
* are multiple devices/functions
*/
- if (pciRead(dev, cfgfd, 0, config_space, PCI_CONF_LEN) < 0) {
+ if (virPCIDeviceRead(dev, cfgfd, 0, config_space, PCI_CONF_LEN) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Failed to read PCI config space for %s"),
dev->name);
@@ -676,18 +676,18 @@ pciTrySecondaryBusReset(pciDevice *dev,
/* Read the control register, set the reset flag, wait 200ms,
* unset the reset flag and wait 200ms.
*/
- ctl = pciRead16(dev, cfgfd, PCI_BRIDGE_CONTROL);
+ ctl = virPCIDeviceRead16(dev, cfgfd, PCI_BRIDGE_CONTROL);
- pciWrite16(parent, parentfd, PCI_BRIDGE_CONTROL,
- ctl | PCI_BRIDGE_CTL_RESET);
+ virPCIDeviceWrite16(parent, parentfd, PCI_BRIDGE_CONTROL,
+ ctl | PCI_BRIDGE_CTL_RESET);
usleep(200 * 1000); /* sleep 200ms */
- pciWrite16(parent, parentfd, PCI_BRIDGE_CONTROL, ctl);
+ virPCIDeviceWrite16(parent, parentfd, PCI_BRIDGE_CONTROL, ctl);
usleep(200 * 1000); /* sleep 200ms */
- if (pciWrite(dev, cfgfd, 0, config_space, PCI_CONF_LEN) < 0) {
+ if (virPCIDeviceWrite(dev, cfgfd, 0, config_space, PCI_CONF_LEN) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Failed to restore PCI config space for %s"),
dev->name);
@@ -696,8 +696,8 @@ pciTrySecondaryBusReset(pciDevice *dev,
ret = 0;
out:
- pciConfigClose(parent, parentfd);
- pciFreeDevice(parent);
+ virPCIDeviceConfigClose(parent, parentfd);
+ virPCIDeviceFree(parent);
return ret;
}
@@ -706,7 +706,7 @@ out:
* above we require the device supports a full internal reset.
*/
static int
-pciTryPowerManagementReset(pciDevice *dev, int cfgfd)
+virPCIDeviceTryPowerManagementReset(virPCIDevicePtr dev, int cfgfd)
{
uint8_t config_space[PCI_CONF_LEN];
uint32_t ctl;
@@ -715,7 +715,7 @@ pciTryPowerManagementReset(pciDevice *dev, int cfgfd)
return -1;
/* Save and restore the device's config space. */
- if (pciRead(dev, cfgfd, 0, &config_space[0], PCI_CONF_LEN) < 0) {
+ if (virPCIDeviceRead(dev, cfgfd, 0, &config_space[0], PCI_CONF_LEN) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Failed to read PCI config space for %s"),
dev->name);
@@ -724,20 +724,20 @@ pciTryPowerManagementReset(pciDevice *dev, int cfgfd)
VIR_DEBUG("%s %s: doing a power management reset", dev->id,
dev->name);
- ctl = pciRead32(dev, cfgfd, dev->pci_pm_cap_pos + PCI_PM_CTRL);
+ ctl = virPCIDeviceRead32(dev, cfgfd, dev->pci_pm_cap_pos + PCI_PM_CTRL);
ctl &= ~PCI_PM_CTRL_STATE_MASK;
- pciWrite32(dev, cfgfd, dev->pci_pm_cap_pos + PCI_PM_CTRL,
- ctl | PCI_PM_CTRL_STATE_D3hot);
+ virPCIDeviceWrite32(dev, cfgfd, dev->pci_pm_cap_pos + PCI_PM_CTRL,
+ ctl | PCI_PM_CTRL_STATE_D3hot);
usleep(10 * 1000); /* sleep 10ms */
- pciWrite32(dev, cfgfd, dev->pci_pm_cap_pos + PCI_PM_CTRL,
- ctl | PCI_PM_CTRL_STATE_D0);
+ virPCIDeviceWrite32(dev, cfgfd, dev->pci_pm_cap_pos + PCI_PM_CTRL,
+ ctl | PCI_PM_CTRL_STATE_D0);
usleep(10 * 1000); /* sleep 10ms */
- if (pciWrite(dev, cfgfd, 0, &config_space[0], PCI_CONF_LEN) < 0) {
+ if (virPCIDeviceWrite(dev, cfgfd, 0, &config_space[0], PCI_CONF_LEN) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Failed to restore PCI config space for %s"),
dev->name);
@@ -748,39 +748,39 @@ pciTryPowerManagementReset(pciDevice *dev, int cfgfd)
}
static int
-pciInitDevice(pciDevice *dev, int cfgfd)
+virPCIDeviceInitDevice(virPCIDevicePtr dev, int cfgfd)
{
int flr;
- dev->pcie_cap_pos = pciFindCapabilityOffset(dev, cfgfd, PCI_CAP_ID_EXP);
- dev->pci_pm_cap_pos = pciFindCapabilityOffset(dev, cfgfd, PCI_CAP_ID_PM);
- flr = pciDetectFunctionLevelReset(dev, cfgfd);
+ dev->pcie_cap_pos = virPCIDeviceFindCapabilityOffset(dev, cfgfd,
PCI_CAP_ID_EXP);
+ dev->pci_pm_cap_pos = virPCIDeviceFindCapabilityOffset(dev, cfgfd,
PCI_CAP_ID_PM);
+ flr = virPCIDeviceDetectFunctionLevelReset(dev, cfgfd);
if (flr < 0)
return flr;
dev->has_flr = flr;
- dev->has_pm_reset = pciDetectPowerManagementReset(dev, cfgfd);
+ dev->has_pm_reset = virPCIDeviceDetectPowerManagementReset(dev, cfgfd);
return 0;
}
int
-pciResetDevice(pciDevice *dev,
- pciDeviceList *activeDevs,
- pciDeviceList *inactiveDevs)
+virPCIDeviceReset(virPCIDevicePtr dev,
+ virPCIDeviceList *activeDevs,
+ virPCIDeviceList *inactiveDevs)
{
int ret = -1;
int fd;
- if (activeDevs && pciDeviceListFind(activeDevs, dev)) {
+ if (activeDevs && virPCIDeviceListFind(activeDevs, dev)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Not resetting active device %s"), dev->name);
return -1;
}
- if ((fd = pciConfigOpen(dev, true)) < 0)
+ if ((fd = virPCIDeviceConfigOpen(dev, true)) < 0)
return -1;
- if (pciInitDevice(dev, fd) < 0)
+ if (virPCIDeviceInitDevice(dev, fd) < 0)
goto cleanup;
/* KVM will perform FLR when starting and stopping
@@ -796,11 +796,11 @@ pciResetDevice(pciDevice *dev,
* the function, not the whole device.
*/
if (dev->has_pm_reset)
- ret = pciTryPowerManagementReset(dev, fd);
+ ret = virPCIDeviceTryPowerManagementReset(dev, fd);
/* Bus reset is not an option with the root bus */
if (ret < 0 && dev->bus != 0)
- ret = pciTrySecondaryBusReset(dev, fd, inactiveDevs);
+ ret = virPCIDeviceTrySecondaryBusReset(dev, fd, inactiveDevs);
if (ret < 0) {
virErrorPtr err = virGetLastError();
@@ -811,13 +811,13 @@ pciResetDevice(pciDevice *dev,
}
cleanup:
- pciConfigClose(dev, fd);
+ virPCIDeviceConfigClose(dev, fd);
return ret;
}
static int
-pciDriverDir(char **buffer, const char *driver)
+virPCIDriverDir(char **buffer, const char *driver)
{
VIR_FREE(*buffer);
@@ -830,7 +830,7 @@ pciDriverDir(char **buffer, const char *driver)
}
static int
-pciDriverFile(char **buffer, const char *driver, const char *file)
+virPCIDriverFile(char **buffer, const char *driver, const char *file)
{
VIR_FREE(*buffer);
@@ -843,7 +843,7 @@ pciDriverFile(char **buffer, const char *driver, const char *file)
}
static int
-pciDeviceFile(char **buffer, const char *device, const char *file)
+virPCIFile(char **buffer, const char *device, const char *file)
{
VIR_FREE(*buffer);
@@ -856,13 +856,13 @@ pciDeviceFile(char **buffer, const char *device, const char *file)
}
static int
-pciProbeStubDriver(const char *driver)
+virPCIProbeStubDriver(const char *driver)
{
char *drvpath = NULL;
int probed = 0;
recheck:
- if (pciDriverDir(&drvpath, driver) == 0 && virFileExists(drvpath)) {
+ if (virPCIDriverDir(&drvpath, driver) == 0 && virFileExists(drvpath)) {
/* driver already loaded, return */
VIR_FREE(drvpath);
return 0;
@@ -887,13 +887,13 @@ recheck:
}
static int
-pciUnbindDeviceFromStub(pciDevice *dev, const char *driver)
+virPCIDeviceUnbindDeviceFromStub(virPCIDevicePtr dev, const char *driver)
{
int result = -1;
char *drvdir = NULL;
char *path = NULL;
- if (pciDriverDir(&drvdir, driver) < 0)
+ if (virPCIDriverDir(&drvdir, driver) < 0)
goto cleanup;
if (!dev->unbind_from_stub)
@@ -901,11 +901,11 @@ pciUnbindDeviceFromStub(pciDevice *dev, const char *driver)
/* If the device is bound to stub, unbind it.
*/
- if (pciDeviceFile(&path, dev->name, "driver") < 0)
+ if (virPCIFile(&path, dev->name, "driver") < 0)
goto cleanup;
if (virFileExists(drvdir) && virFileLinkPointsTo(path, drvdir)) {
- if (pciDriverFile(&path, driver, "unbind") < 0) {
+ if (virPCIDriverFile(&path, driver, "unbind") < 0) {
goto cleanup;
}
@@ -923,7 +923,7 @@ remove_slot:
goto reprobe;
/* Xen's pciback.ko wants you to use remove_slot on the specific device */
- if (pciDriverFile(&path, driver, "remove_slot") < 0) {
+ if (virPCIDriverFile(&path, driver, "remove_slot") < 0) {
goto cleanup;
}
@@ -946,7 +946,7 @@ reprobe:
* available, then re-probing would just cause the device to be
* re-bound to the stub.
*/
- if (pciDriverFile(&path, driver, "remove_id") < 0) {
+ if (virPCIDriverFile(&path, driver, "remove_id") < 0) {
goto cleanup;
}
@@ -975,7 +975,7 @@ cleanup:
static int
-pciBindDeviceToStub(pciDevice *dev, const char *driver)
+virPCIDeviceBindDeviceToStub(virPCIDevicePtr dev, const char *driver)
{
int result = -1;
char *drvdir = NULL;
@@ -983,8 +983,8 @@ pciBindDeviceToStub(pciDevice *dev, const char *driver)
int reprobe = 0;
/* check whether the device is already bound to a driver */
- if (pciDriverDir(&drvdir, driver) < 0 ||
- pciDeviceFile(&path, dev->name, "driver") < 0) {
+ if (virPCIDriverDir(&drvdir, driver) < 0 ||
+ virPCIFile(&path, dev->name, "driver") < 0) {
goto cleanup;
}
@@ -1005,7 +1005,7 @@ pciBindDeviceToStub(pciDevice *dev, const char *driver)
* is triggered for such a device, it will also be immediately
* bound by the stub.
*/
- if (pciDriverFile(&path, driver, "new_id") < 0) {
+ if (virPCIDriverFile(&path, driver, "new_id") < 0) {
goto cleanup;
}
@@ -1019,8 +1019,8 @@ pciBindDeviceToStub(pciDevice *dev, const char *driver)
/* check whether the device is bound to pci-stub when we write dev->id to
* new_id.
*/
- if (pciDriverDir(&drvdir, driver) < 0 ||
- pciDeviceFile(&path, dev->name, "driver") < 0) {
+ if (virPCIDriverDir(&drvdir, driver) < 0 ||
+ virPCIFile(&path, dev->name, "driver") < 0) {
goto remove_id;
}
@@ -1035,7 +1035,7 @@ pciBindDeviceToStub(pciDevice *dev, const char *driver)
* PCI device happens to be IDE controller for the disk hosting
* your root filesystem.
*/
- if (pciDeviceFile(&path, dev->name, "driver/unbind") < 0) {
+ if (virPCIFile(&path, dev->name, "driver/unbind") < 0) {
goto cleanup;
}
@@ -1051,14 +1051,14 @@ pciBindDeviceToStub(pciDevice *dev, const char *driver)
/* If the device isn't already bound to pci-stub, try binding it now.
*/
- if (pciDriverDir(&drvdir, driver) < 0 ||
- pciDeviceFile(&path, dev->name, "driver") < 0) {
+ if (virPCIDriverDir(&drvdir, driver) < 0 ||
+ virPCIFile(&path, dev->name, "driver") < 0) {
goto remove_id;
}
if (!virFileLinkPointsTo(path, drvdir)) {
/* Xen's pciback.ko wants you to use new_slot first */
- if (pciDriverFile(&path, driver, "new_slot") < 0) {
+ if (virPCIDriverFile(&path, driver, "new_slot") < 0) {
goto remove_id;
}
@@ -1070,7 +1070,7 @@ pciBindDeviceToStub(pciDevice *dev, const char *driver)
}
dev->remove_slot = 1;
- if (pciDriverFile(&path, driver, "bind") < 0) {
+ if (virPCIDriverFile(&path, driver, "bind") < 0) {
goto remove_id;
}
@@ -1087,7 +1087,7 @@ remove_id:
/* If 'remove_id' exists, remove the device id from pci-stub's dynamic
* ID table so that 'drivers_probe' works below.
*/
- if (pciDriverFile(&path, driver, "remove_id") < 0) {
+ if (virPCIDriverFile(&path, driver, "remove_id") < 0) {
/* We do not remove PCI ID from pci-stub, and we cannot reprobe it */
if (dev->reprobe) {
VIR_WARN("Could not remove PCI ID '%s' from %s, and the device
"
@@ -1118,36 +1118,36 @@ cleanup:
VIR_FREE(path);
if (result < 0) {
- pciUnbindDeviceFromStub(dev, driver);
+ virPCIDeviceUnbindDeviceFromStub(dev, driver);
}
return result;
}
int
-pciDettachDevice(pciDevice *dev,
- pciDeviceList *activeDevs,
- pciDeviceList *inactiveDevs,
- const char *driver)
+virPCIDeviceDettach(virPCIDevicePtr dev,
+ virPCIDeviceList *activeDevs,
+ virPCIDeviceList *inactiveDevs,
+ const char *driver)
{
- if (pciProbeStubDriver(driver) < 0) {
+ if (virPCIProbeStubDriver(driver) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Failed to load PCI stub module %s"), driver);
return -1;
}
- if (activeDevs && pciDeviceListFind(activeDevs, dev)) {
+ if (activeDevs && virPCIDeviceListFind(activeDevs, dev)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Not detaching active device %s"), dev->name);
return -1;
}
- if (pciBindDeviceToStub(dev, driver) < 0)
+ if (virPCIDeviceBindDeviceToStub(dev, driver) < 0)
return -1;
/* Add the dev into list inactiveDevs */
- if (inactiveDevs && !pciDeviceListFind(inactiveDevs, dev)) {
- if (pciDeviceListAdd(inactiveDevs, dev) < 0)
+ if (inactiveDevs && !virPCIDeviceListFind(inactiveDevs, dev)) {
+ if (virPCIDeviceListAdd(inactiveDevs, dev) < 0)
return -1;
}
@@ -1155,29 +1155,29 @@ pciDettachDevice(pciDevice *dev,
}
int
-pciReAttachDevice(pciDevice *dev,
- pciDeviceList *activeDevs,
- pciDeviceList *inactiveDevs,
- const char *driver)
+virPCIDeviceReAttach(virPCIDevicePtr dev,
+ virPCIDeviceListPtr activeDevs,
+ virPCIDeviceListPtr inactiveDevs,
+ const char *driver)
{
- if (pciProbeStubDriver(driver) < 0) {
+ if (virPCIProbeStubDriver(driver) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Failed to load PCI stub module %s"), driver);
return -1;
}
- if (activeDevs && pciDeviceListFind(activeDevs, dev)) {
+ if (activeDevs && virPCIDeviceListFind(activeDevs, dev)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Not reattaching active device %s"), dev->name);
return -1;
}
- if (pciUnbindDeviceFromStub(dev, driver) < 0)
+ if (virPCIDeviceUnbindDeviceFromStub(dev, driver) < 0)
return -1;
/* Steal the dev from list inactiveDevs */
if (inactiveDevs)
- pciDeviceListSteal(inactiveDevs, dev);
+ virPCIDeviceListSteal(inactiveDevs, dev);
return 0;
}
@@ -1212,7 +1212,7 @@ pciReAttachDevice(pciDevice *dev,
* holding onto the resource.
*/
int
-pciWaitForDeviceCleanup(pciDevice *dev, const char *matcher)
+virPCIDeviceWaitForCleanup(virPCIDevicePtr dev, const char *matcher)
{
FILE *fp;
char line[160];
@@ -1292,12 +1292,12 @@ pciWaitForDeviceCleanup(pciDevice *dev, const char *matcher)
}
static char *
-pciReadDeviceID(pciDevice *dev, const char *id_name)
+virPCIDeviceReadDeviceID(virPCIDevicePtr dev, const char *id_name)
{
char *path = NULL;
char *id_str;
- if (pciDeviceFile(&path, dev->name, id_name) < 0) {
+ if (virPCIFile(&path, dev->name, id_name) < 0) {
return NULL;
}
@@ -1322,16 +1322,16 @@ pciReadDeviceID(pciDevice *dev, const char *id_name)
}
int
-pciGetDeviceAddrString(unsigned domain,
- unsigned bus,
- unsigned slot,
- unsigned function,
- char **pciConfigAddr)
+virPCIGetAddrString(unsigned domain,
+ unsigned bus,
+ unsigned slot,
+ unsigned function,
+ char **pciConfigAddr)
{
- pciDevice *dev = NULL;
+ virPCIDevicePtr dev = NULL;
int ret = -1;
- dev = pciGetDevice(domain, bus, slot, function);
+ dev = virPCIDeviceNew(domain, bus, slot, function);
if (dev != NULL) {
if ((*pciConfigAddr = strdup(dev->name)) == NULL) {
virReportOOMError();
@@ -1341,17 +1341,17 @@ pciGetDeviceAddrString(unsigned domain,
}
cleanup:
- pciFreeDevice(dev);
+ virPCIDeviceFree(dev);
return ret;
}
-pciDevice *
-pciGetDevice(unsigned domain,
- unsigned bus,
- unsigned slot,
- unsigned function)
+virPCIDevicePtr
+virPCIDeviceNew(unsigned domain,
+ unsigned bus,
+ unsigned slot,
+ unsigned function)
{
- pciDevice *dev;
+ virPCIDevicePtr dev;
char *vendor = NULL;
char *product = NULL;
@@ -1386,8 +1386,8 @@ pciGetDevice(unsigned domain,
goto error;
}
- vendor = pciReadDeviceID(dev, "vendor");
- product = pciReadDeviceID(dev, "device");
+ vendor = virPCIDeviceReadDeviceID(dev, "vendor");
+ product = virPCIDeviceReadDeviceID(dev, "device");
if (!vendor || !product) {
virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -1413,13 +1413,13 @@ cleanup:
return dev;
error:
- pciFreeDevice(dev);
+ virPCIDeviceFree(dev);
dev = NULL;
goto cleanup;
}
void
-pciFreeDevice(pciDevice *dev)
+virPCIDeviceFree(virPCIDevicePtr dev)
{
if (!dev)
return;
@@ -1429,70 +1429,70 @@ pciFreeDevice(pciDevice *dev)
}
const char *
-pciDeviceGetName(pciDevice *dev)
+virPCIDeviceGetName(virPCIDevicePtr dev)
{
return dev->name;
}
-void pciDeviceSetManaged(pciDevice *dev, unsigned managed)
+void virPCIDeviceSetManaged(virPCIDevicePtr dev, unsigned managed)
{
dev->managed = !!managed;
}
-unsigned pciDeviceGetManaged(pciDevice *dev)
+unsigned virPCIDeviceGetManaged(virPCIDevicePtr dev)
{
return dev->managed;
}
unsigned
-pciDeviceGetUnbindFromStub(pciDevice *dev)
+virPCIDeviceGetUnbindFromStub(virPCIDevicePtr dev)
{
return dev->unbind_from_stub;
}
void
-pciDeviceSetUnbindFromStub(pciDevice *dev, unsigned unbind)
+virPCIDeviceSetUnbindFromStub(virPCIDevicePtr dev, unsigned unbind)
{
dev->unbind_from_stub = !!unbind;
}
unsigned
-pciDeviceGetRemoveSlot(pciDevice *dev)
+virPCIDeviceGetRemoveSlot(virPCIDevicePtr dev)
{
return dev->remove_slot;
}
void
-pciDeviceSetRemoveSlot(pciDevice *dev, unsigned remove_slot)
+virPCIDeviceSetRemoveSlot(virPCIDevicePtr dev, unsigned remove_slot)
{
dev->remove_slot = !!remove_slot;
}
unsigned
-pciDeviceGetReprobe(pciDevice *dev)
+virPCIDeviceGetReprobe(virPCIDevicePtr dev)
{
return dev->reprobe;
}
void
-pciDeviceSetReprobe(pciDevice *dev, unsigned reprobe)
+virPCIDeviceSetReprobe(virPCIDevicePtr dev, unsigned reprobe)
{
dev->reprobe = !!reprobe;
}
void
-pciDeviceSetUsedBy(pciDevice *dev, const char *name)
+virPCIDeviceSetUsedBy(virPCIDevicePtr dev, const char *name)
{
dev->used_by = name;
}
const char *
-pciDeviceGetUsedBy(pciDevice *dev)
+virPCIDeviceGetUsedBy(virPCIDevicePtr dev)
{
return dev->used_by;
}
-void pciDeviceReAttachInit(pciDevice *pci)
+void virPCIDeviceReAttachInit(virPCIDevicePtr pci)
{
pci->unbind_from_stub = 1;
pci->remove_slot = 1;
@@ -1500,10 +1500,10 @@ void pciDeviceReAttachInit(pciDevice *pci)
}
-pciDeviceList *
-pciDeviceListNew(void)
+virPCIDeviceListPtr
+virPCIDeviceListNew(void)
{
- pciDeviceList *list;
+ virPCIDeviceListPtr list;
if (VIR_ALLOC(list) < 0) {
virReportOOMError();
@@ -1514,7 +1514,7 @@ pciDeviceListNew(void)
}
void
-pciDeviceListFree(pciDeviceList *list)
+virPCIDeviceListFree(virPCIDeviceListPtr list)
{
int i;
@@ -1522,7 +1522,7 @@ pciDeviceListFree(pciDeviceList *list)
return;
for (i = 0; i < list->count; i++) {
- pciFreeDevice(list->devs[i]);
+ virPCIDeviceFree(list->devs[i]);
list->devs[i] = NULL;
}
@@ -1532,10 +1532,10 @@ pciDeviceListFree(pciDeviceList *list)
}
int
-pciDeviceListAdd(pciDeviceList *list,
- pciDevice *dev)
+virPCIDeviceListAdd(virPCIDeviceListPtr list,
+ virPCIDevicePtr dev)
{
- if (pciDeviceListFind(list, dev)) {
+ if (virPCIDeviceListFind(list, dev)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Device %s is already in use"), dev->name);
return -1;
@@ -1551,9 +1551,9 @@ pciDeviceListAdd(pciDeviceList *list,
return 0;
}
-pciDevice *
-pciDeviceListGet(pciDeviceList *list,
- int idx)
+virPCIDevicePtr
+virPCIDeviceListGet(virPCIDeviceListPtr list,
+ int idx)
{
if (idx >= list->count)
return NULL;
@@ -1564,16 +1564,16 @@ pciDeviceListGet(pciDeviceList *list,
}
int
-pciDeviceListCount(pciDeviceList *list)
+virPCIDeviceListCount(virPCIDeviceListPtr list)
{
return list->count;
}
-pciDevice *
-pciDeviceListStealIndex(pciDeviceList *list,
- int idx)
+virPCIDevicePtr
+virPCIDeviceListStealIndex(virPCIDeviceListPtr list,
+ int idx)
{
- pciDevice *ret;
+ virPCIDevicePtr ret;
if (idx < 0 || idx >= list->count)
return NULL;
@@ -1593,24 +1593,24 @@ pciDeviceListStealIndex(pciDeviceList *list,
return ret;
}
-pciDevice *
-pciDeviceListSteal(pciDeviceList *list,
- pciDevice *dev)
+virPCIDevicePtr
+virPCIDeviceListSteal(virPCIDeviceListPtr list,
+ virPCIDevicePtr dev)
{
- return pciDeviceListStealIndex(list, pciDeviceListFindIndex(list, dev));
+ return virPCIDeviceListStealIndex(list, virPCIDeviceListFindIndex(list, dev));
}
void
-pciDeviceListDel(pciDeviceList *list,
- pciDevice *dev)
+virPCIDeviceListDel(virPCIDeviceListPtr list,
+ virPCIDevicePtr dev)
{
- pciDevice *ret = pciDeviceListSteal(list, dev);
+ virPCIDevicePtr ret = virPCIDeviceListSteal(list, dev);
if (ret)
- pciFreeDevice(ret);
+ virPCIDeviceFree(ret);
}
int
-pciDeviceListFindIndex(pciDeviceList *list, pciDevice *dev)
+virPCIDeviceListFindIndex(virPCIDeviceListPtr list, virPCIDevicePtr dev)
{
int i;
@@ -1623,21 +1623,21 @@ pciDeviceListFindIndex(pciDeviceList *list, pciDevice *dev)
return -1;
}
-pciDevice *
-pciDeviceListFind(pciDeviceList *list, pciDevice *dev)
+virPCIDevicePtr
+virPCIDeviceListFind(virPCIDeviceListPtr list, virPCIDevicePtr dev)
{
int i;
- if ((i = pciDeviceListFindIndex(list, dev)) >= 0)
+ if ((i = virPCIDeviceListFindIndex(list, dev)) >= 0)
return list->devs[i];
else
return NULL;
}
-int pciDeviceFileIterate(pciDevice *dev,
- pciDeviceFileActor actor,
- void *opaque)
+int virPCIDeviceFileIterate(virPCIDevicePtr dev,
+ virPCIDeviceFileActor actor,
+ void *opaque)
{
char *pcidir = NULL;
char *file = NULL;
@@ -1688,7 +1688,7 @@ cleanup:
}
static int
-pciDeviceDownstreamLacksACS(pciDevice *dev)
+virPCIDeviceDownstreamLacksACS(virPCIDevicePtr dev)
{
uint16_t flags;
uint16_t ctrl;
@@ -1696,30 +1696,30 @@ pciDeviceDownstreamLacksACS(pciDevice *dev)
int fd;
int ret = 0;
- if ((fd = pciConfigOpen(dev, true)) < 0)
+ if ((fd = virPCIDeviceConfigOpen(dev, true)) < 0)
return -1;
- if (pciInitDevice(dev, fd) < 0) {
+ if (virPCIDeviceInitDevice(dev, fd) < 0) {
ret = -1;
goto cleanup;
}
pos = dev->pcie_cap_pos;
- if (!pos || pciRead16(dev, fd, PCI_CLASS_DEVICE) != PCI_CLASS_BRIDGE_PCI)
+ if (!pos || virPCIDeviceRead16(dev, fd, PCI_CLASS_DEVICE) != PCI_CLASS_BRIDGE_PCI)
goto cleanup;
- flags = pciRead16(dev, fd, pos + PCI_EXP_FLAGS);
+ flags = virPCIDeviceRead16(dev, fd, pos + PCI_EXP_FLAGS);
if (((flags & PCI_EXP_FLAGS_TYPE) >> 4) != PCI_EXP_TYPE_DOWNSTREAM)
goto cleanup;
- pos = pciFindExtendedCapabilityOffset(dev, fd, PCI_EXT_CAP_ID_ACS);
+ pos = virPCIDeviceFindExtendedCapabilityOffset(dev, fd, PCI_EXT_CAP_ID_ACS);
if (!pos) {
VIR_DEBUG("%s %s: downstream port lacks ACS", dev->id,
dev->name);
ret = 1;
goto cleanup;
}
- ctrl = pciRead16(dev, fd, pos + PCI_EXT_ACS_CTRL);
+ ctrl = virPCIDeviceRead16(dev, fd, pos + PCI_EXT_ACS_CTRL);
if ((ctrl & PCI_EXT_CAP_ACS_ENABLED) != PCI_EXT_CAP_ACS_ENABLED) {
VIR_DEBUG("%s %s: downstream port has ACS disabled",
dev->id, dev->name);
@@ -1728,16 +1728,16 @@ pciDeviceDownstreamLacksACS(pciDevice *dev)
}
cleanup:
- pciConfigClose(dev, fd);
+ virPCIDeviceConfigClose(dev, fd);
return ret;
}
static int
-pciDeviceIsBehindSwitchLackingACS(pciDevice *dev)
+virPCIDeviceIsBehindSwitchLackingACS(virPCIDevicePtr dev)
{
- pciDevice *parent;
+ virPCIDevicePtr parent;
- if (pciGetParentDevice(dev, &parent) < 0)
+ if (virPCIDeviceGetParentDevice(dev, &parent) < 0)
return -1;
if (!parent) {
/* if we have no parent, and this is the root bus, ACS doesn't come
@@ -1759,14 +1759,14 @@ pciDeviceIsBehindSwitchLackingACS(pciDevice *dev)
* parent can be found
*/
do {
- pciDevice *tmp;
+ virPCIDevicePtr tmp;
int acs;
int ret;
- acs = pciDeviceDownstreamLacksACS(parent);
+ acs = virPCIDeviceDownstreamLacksACS(parent);
if (acs) {
- pciFreeDevice(parent);
+ virPCIDeviceFree(parent);
if (acs < 0)
return -1;
else
@@ -1774,8 +1774,8 @@ pciDeviceIsBehindSwitchLackingACS(pciDevice *dev)
}
tmp = parent;
- ret = pciGetParentDevice(parent, &parent);
- pciFreeDevice(tmp);
+ ret = virPCIDeviceGetParentDevice(parent, &parent);
+ virPCIDeviceFree(tmp);
if (ret < 0)
return -1;
} while (parent);
@@ -1783,8 +1783,8 @@ pciDeviceIsBehindSwitchLackingACS(pciDevice *dev)
return 0;
}
-int pciDeviceIsAssignable(pciDevice *dev,
- int strict_acs_check)
+int virPCIDeviceIsAssignable(virPCIDevicePtr dev,
+ int strict_acs_check)
{
int ret;
@@ -1793,7 +1793,7 @@ int pciDeviceIsAssignable(pciDevice *dev,
* or bound to a stub driver.
*/
- ret = pciDeviceIsBehindSwitchLackingACS(dev);
+ ret = virPCIDeviceIsBehindSwitchLackingACS(dev);
if (ret < 0)
return 0;
@@ -1819,8 +1819,8 @@ int pciDeviceIsAssignable(pciDevice *dev,
* returns true if equal
*/
static bool
-pciConfigAddressEqual(struct pci_config_address *bdf1,
- struct pci_config_address *bdf2)
+virPCIDeviceAddressIsEqual(virPCIDeviceAddressPtr bdf1,
+ virPCIDeviceAddressPtr bdf2)
{
return ((bdf1->domain == bdf2->domain) &&
(bdf1->bus == bdf2->bus) &&
@@ -1847,8 +1847,8 @@ logStrToLong_ui(char const *s,
}
static int
-pciParsePciConfigAddress(char *address,
- struct pci_config_address *bdf)
+virPCIParseDeviceAddress(char *address,
+ virPCIDeviceAddressPtr bdf)
{
char *p = NULL;
int ret = -1;
@@ -1880,8 +1880,8 @@ out:
}
static int
-pciGetPciConfigAddressFromSysfsDeviceLink(const char *device_link,
- struct pci_config_address **bdf)
+virPCIGetDeviceAddressFromSysfsDeviceLink(const char *device_link,
+ virPCIDeviceAddressPtr *bdf)
{
char *config_address = NULL;
char *device_path = NULL;
@@ -1911,7 +1911,7 @@ pciGetPciConfigAddressFromSysfsDeviceLink(const char *device_link,
goto out;
}
- if (pciParsePciConfigAddress(config_address, *bdf) != 0) {
+ if (virPCIParseDeviceAddress(config_address, *bdf) != 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Failed to parse PCI config address '%s'"),
config_address);
@@ -1919,7 +1919,7 @@ pciGetPciConfigAddressFromSysfsDeviceLink(const char *device_link,
goto out;
}
- VIR_DEBUG("pci_config_address %.4x:%.2x:%.2x.%.1x",
+ VIR_DEBUG("virPCIDeviceAddress %.4x:%.2x:%.2x.%.1x",
(*bdf)->domain,
(*bdf)->bus,
(*bdf)->slot,
@@ -1937,8 +1937,8 @@ out:
* Returns Physical function given a virtual function
*/
int
-pciGetPhysicalFunction(const char *vf_sysfs_path,
- struct pci_config_address **physical_function)
+virPCIGetPhysicalFunction(const char *vf_sysfs_path,
+ virPCIDeviceAddressPtr *physical_function)
{
int ret = -1;
char *device_link = NULL;
@@ -1950,7 +1950,7 @@ pciGetPhysicalFunction(const char *vf_sysfs_path,
virReportOOMError();
return ret;
} else {
- ret = pciGetPciConfigAddressFromSysfsDeviceLink(device_link,
+ ret = virPCIGetDeviceAddressFromSysfsDeviceLink(device_link,
physical_function);
}
@@ -1963,9 +1963,9 @@ pciGetPhysicalFunction(const char *vf_sysfs_path,
* Returns virtual functions of a physical function
*/
int
-pciGetVirtualFunctions(const char *sysfs_path,
- struct pci_config_address ***virtual_functions,
- unsigned int *num_virtual_functions)
+virPCIGetVirtualFunctions(const char *sysfs_path,
+ virPCIDeviceAddressPtr **virtual_functions,
+ unsigned int *num_virtual_functions)
{
int ret = -1;
DIR *dir = NULL;
@@ -1998,20 +1998,20 @@ pciGetVirtualFunctions(const char *sysfs_path,
VIR_DEBUG("Number of virtual functions: %d",
*num_virtual_functions);
if (VIR_REALLOC_N(*virtual_functions,
- (*num_virtual_functions) + 1) != 0) {
+ (*num_virtual_functions) + 1) != 0) {
virReportOOMError();
VIR_FREE(device_link);
goto out;
}
- if (pciGetPciConfigAddressFromSysfsDeviceLink(device_link,
- &((*virtual_functions)[*num_virtual_functions])) !=
+ if (virPCIGetDeviceAddressFromSysfsDeviceLink(device_link,
+
&((*virtual_functions)[*num_virtual_functions])) !=
SRIOV_FOUND) {
/* We should not get back SRIOV_NOT_FOUND in this
* case, so if we do, it's an error. */
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Failed to get SR IOV function from device "
- "link '%s'"), device_link);
+ "link '%s'"), device_link);
VIR_FREE(device_link);
goto out;
} else {
@@ -2034,13 +2034,13 @@ out:
* Returns 1 if vf device is a virtual function, 0 if not, -1 on error
*/
int
-pciDeviceIsVirtualFunction(const char *vf_sysfs_device_link)
+virPCIIsVirtualFunction(const char *vf_sysfs_device_link)
{
char *vf_sysfs_physfn_link = NULL;
int ret = -1;
if (virAsprintf(&vf_sysfs_physfn_link, "%s/physfn",
- vf_sysfs_device_link) < 0) {
+ vf_sysfs_device_link) < 0) {
virReportOOMError();
return ret;
}
@@ -2056,40 +2056,40 @@ pciDeviceIsVirtualFunction(const char *vf_sysfs_device_link)
* Returns the sriov virtual function index of vf given its pf
*/
int
-pciGetVirtualFunctionIndex(const char *pf_sysfs_device_link,
- const char *vf_sysfs_device_link,
- int *vf_index)
+virPCIGetVirtualFunctionIndex(const char *pf_sysfs_device_link,
+ const char *vf_sysfs_device_link,
+ int *vf_index)
{
int ret = -1, i;
unsigned int num_virt_fns = 0;
- struct pci_config_address *vf_bdf = NULL;
- struct pci_config_address **virt_fns = NULL;
+ virPCIDeviceAddressPtr vf_bdf = NULL;
+ virPCIDeviceAddressPtr *virt_fns = NULL;
- if (pciGetPciConfigAddressFromSysfsDeviceLink(vf_sysfs_device_link,
- &vf_bdf) < 0)
+ if (virPCIGetDeviceAddressFromSysfsDeviceLink(vf_sysfs_device_link,
+ &vf_bdf) < 0)
return ret;
- if (pciGetVirtualFunctions(pf_sysfs_device_link, &virt_fns,
- &num_virt_fns) < 0) {
+ if (virPCIGetVirtualFunctions(pf_sysfs_device_link, &virt_fns,
+ &num_virt_fns) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Error getting physical function's '%s' "
- "virtual_functions"), pf_sysfs_device_link);
+ "virtual_functions"), pf_sysfs_device_link);
goto out;
}
for (i = 0; i < num_virt_fns; i++) {
- if (pciConfigAddressEqual(vf_bdf, virt_fns[i])) {
- *vf_index = i;
- ret = 0;
- break;
- }
+ if (virPCIDeviceAddressIsEqual(vf_bdf, virt_fns[i])) {
+ *vf_index = i;
+ ret = 0;
+ break;
+ }
}
out:
/* free virtual functions */
for (i = 0; i < num_virt_fns; i++)
- VIR_FREE(virt_fns[i]);
+ VIR_FREE(virt_fns[i]);
VIR_FREE(virt_fns);
VIR_FREE(vf_bdf);
@@ -2102,10 +2102,10 @@ out:
*/
int
-pciSysfsFile(char *pciDeviceName, char **pci_sysfs_device_link)
+virPCIGetSysfsFile(char *virPCIDeviceName, char **pci_sysfs_device_link)
{
if (virAsprintf(pci_sysfs_device_link, PCI_SYSFS "devices/%s",
- pciDeviceName) < 0) {
+ virPCIDeviceName) < 0) {
virReportOOMError();
return -1;
}
@@ -2114,8 +2114,8 @@ pciSysfsFile(char *pciDeviceName, char **pci_sysfs_device_link)
}
int
-pciConfigAddressToSysfsFile(struct pci_config_address *dev,
- char **pci_sysfs_device_link)
+virPCIDeviceAddressGetSysfsFile(virPCIDeviceAddressPtr dev,
+ char **pci_sysfs_device_link)
{
if (virAsprintf(pci_sysfs_device_link,
PCI_SYSFS "devices/%04x:%02x:%02x.%x", dev->domain,
@@ -2131,68 +2131,68 @@ pciConfigAddressToSysfsFile(struct pci_config_address *dev,
* Returns the network device name of a pci device
*/
int
-pciDeviceNetName(char *device_link_sysfs_path, char **netname)
-{
- char *pcidev_sysfs_net_path = NULL;
- int ret = -1;
- DIR *dir = NULL;
- struct dirent *entry = NULL;
-
- if (virBuildPath(&pcidev_sysfs_net_path, device_link_sysfs_path,
- "net") == -1) {
- virReportOOMError();
- return -1;
- }
-
- dir = opendir(pcidev_sysfs_net_path);
- if (dir == NULL)
- goto out;
-
- while ((entry = readdir(dir))) {
- if (STREQ(entry->d_name, ".") ||
- STREQ(entry->d_name, ".."))
- continue;
+virPCIGetNetName(char *device_link_sysfs_path, char **netname)
+{
+ char *pcidev_sysfs_net_path = NULL;
+ int ret = -1;
+ DIR *dir = NULL;
+ struct dirent *entry = NULL;
- /* Assume a single directory entry */
- *netname = strdup(entry->d_name);
- if (!*netname)
- virReportOOMError();
- else
- ret = 0;
- break;
- }
+ if (virBuildPath(&pcidev_sysfs_net_path, device_link_sysfs_path,
+ "net") == -1) {
+ virReportOOMError();
+ return -1;
+ }
+
+ dir = opendir(pcidev_sysfs_net_path);
+ if (dir == NULL)
+ goto out;
- closedir(dir);
+ while ((entry = readdir(dir))) {
+ if (STREQ(entry->d_name, ".") ||
+ STREQ(entry->d_name, ".."))
+ continue;
+
+ /* Assume a single directory entry */
+ *netname = strdup(entry->d_name);
+ if (!*netname)
+ virReportOOMError();
+ else
+ ret = 0;
+ break;
+ }
+
+ closedir(dir);
out:
- VIR_FREE(pcidev_sysfs_net_path);
+ VIR_FREE(pcidev_sysfs_net_path);
- return ret;
+ return ret;
}
int
-pciDeviceGetVirtualFunctionInfo(const char *vf_sysfs_device_path,
- char **pfname, int *vf_index)
+virPCIGetVirtualFunctionInfo(const char *vf_sysfs_device_path,
+ char **pfname, int *vf_index)
{
- struct pci_config_address *pf_config_address = NULL;
+ virPCIDeviceAddressPtr pf_config_address = NULL;
char *pf_sysfs_device_path = NULL;
int ret = -1;
- if (pciGetPhysicalFunction(vf_sysfs_device_path, &pf_config_address) < 0)
+ if (virPCIGetPhysicalFunction(vf_sysfs_device_path, &pf_config_address) < 0)
return ret;
- if (pciConfigAddressToSysfsFile(pf_config_address,
- &pf_sysfs_device_path) < 0) {
+ if (virPCIDeviceAddressGetSysfsFile(pf_config_address,
+ &pf_sysfs_device_path) < 0) {
VIR_FREE(pf_config_address);
return ret;
}
- if (pciGetVirtualFunctionIndex(pf_sysfs_device_path, vf_sysfs_device_path,
- vf_index) < 0)
+ if (virPCIGetVirtualFunctionIndex(pf_sysfs_device_path, vf_sysfs_device_path,
+ vf_index) < 0)
goto cleanup;
- ret = pciDeviceNetName(pf_sysfs_device_path, pfname);
+ ret = virPCIGetNetName(pf_sysfs_device_path, pfname);
cleanup:
VIR_FREE(pf_config_address);
@@ -2205,33 +2205,33 @@ cleanup:
static const char *unsupported = N_("not supported on non-linux platforms");
int
-pciGetPhysicalFunction(const char *vf_sysfs_path ATTRIBUTE_UNUSED,
- struct pci_config_address **physical_function ATTRIBUTE_UNUSED)
+virPCIGetPhysicalFunction(const char *vf_sysfs_path ATTRIBUTE_UNUSED,
+ virPCIDeviceAddressPtr *physical_function ATTRIBUTE_UNUSED)
{
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _(unsupported));
return -1;
}
int
-pciGetVirtualFunctions(const char *sysfs_path ATTRIBUTE_UNUSED,
- struct pci_config_address ***virtual_functions ATTRIBUTE_UNUSED,
- unsigned int *num_virtual_functions ATTRIBUTE_UNUSED)
+virPCIGetVirtualFunctions(const char *sysfs_path ATTRIBUTE_UNUSED,
+ virPCIDeviceAddressPtr **virtual_functions ATTRIBUTE_UNUSED,
+ unsigned int *num_virtual_functions ATTRIBUTE_UNUSED)
{
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _(unsupported));
return -1;
}
int
-pciDeviceIsVirtualFunction(const char *vf_sysfs_device_link ATTRIBUTE_UNUSED)
+virPCIDeviceIsVirtualFunction(const char *vf_sysfs_device_link ATTRIBUTE_UNUSED)
{
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _(unsupported));
return -1;
}
int
-pciGetVirtualFunctionIndex(const char *pf_sysfs_device_link ATTRIBUTE_UNUSED,
- const char *vf_sysfs_device_link ATTRIBUTE_UNUSED,
- int *vf_index ATTRIBUTE_UNUSED)
+virPCIGetVirtualFunctionIndex(const char *pf_sysfs_device_link ATTRIBUTE_UNUSED,
+ const char *vf_sysfs_device_link ATTRIBUTE_UNUSED,
+ int *vf_index ATTRIBUTE_UNUSED)
{
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _(unsupported));
return -1;
@@ -2239,15 +2239,15 @@ pciGetVirtualFunctionIndex(const char *pf_sysfs_device_link
ATTRIBUTE_UNUSED,
}
int
-pciConfigAddressToSysfsFile(struct pci_config_address *dev ATTRIBUTE_UNUSED,
- char **pci_sysfs_device_link ATTRIBUTE_UNUSED)
+virPCIDeviceAddressGetSysfsFile(virPCIDeviceAddressPtr dev ATTRIBUTE_UNUSED,
+ char **pci_sysfs_device_link ATTRIBUTE_UNUSED)
{
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _(unsupported));
return -1;
}
int
-pciDeviceNetName(char *device_link_sysfs_path ATTRIBUTE_UNUSED,
+virPCIGetNetName(char *device_link_sysfs_path ATTRIBUTE_UNUSED,
char **netname ATTRIBUTE_UNUSED)
{
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _(unsupported));
@@ -2255,9 +2255,9 @@ pciDeviceNetName(char *device_link_sysfs_path ATTRIBUTE_UNUSED,
}
int
-pciDeviceGetVirtualFunctionInfo(const char *vf_sysfs_device_path ATTRIBUTE_UNUSED,
- char **pfname ATTRIBUTE_UNUSED,
- int *vf_index ATTRIBUTE_UNUSED)
+virPCIGetVirtualFunctionInfo(const char *vf_sysfs_device_path ATTRIBUTE_UNUSED,
+ char **pfname ATTRIBUTE_UNUSED,
+ int *vf_index ATTRIBUTE_UNUSED)
{
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _(unsupported));
return -1;
diff --git a/src/util/virpci.h b/src/util/virpci.h
index bf7da01..3ca7545 100644
--- a/src/util/virpci.h
+++ b/src/util/virpci.h
@@ -26,67 +26,74 @@
# include "internal.h"
-typedef struct _pciDevice pciDevice;
-typedef struct _pciDeviceList pciDeviceList;
-
-struct pci_config_address {
+typedef struct _virPCIDevice virPCIDevice;
+typedef virPCIDevice *virPCIDevicePtr;
+typedef struct _virPCIDeviceAddress virPCIDeviceAddress;
+typedef virPCIDeviceAddress *virPCIDeviceAddressPtr;
+typedef struct _virPCIDeviceList virPCIDeviceList;
+typedef virPCIDeviceList *virPCIDeviceListPtr;
+
+struct _virPCIDeviceAddress {
unsigned int domain;
unsigned int bus;
unsigned int slot;
unsigned int function;
};
-pciDevice *pciGetDevice (unsigned domain,
- unsigned bus,
- unsigned slot,
- unsigned function);
-void pciFreeDevice (pciDevice *dev);
-const char *pciDeviceGetName (pciDevice *dev);
-int pciDettachDevice (pciDevice *dev,
- pciDeviceList *activeDevs,
- pciDeviceList *inactiveDevs,
- const char *driver);
-int pciReAttachDevice (pciDevice *dev,
- pciDeviceList *activeDevs,
- pciDeviceList *inactiveDevs,
- const char *driver);
-int pciResetDevice (pciDevice *dev,
- pciDeviceList *activeDevs,
- pciDeviceList *inactiveDevs);
-void pciDeviceSetManaged(pciDevice *dev,
- unsigned managed);
-unsigned pciDeviceGetManaged(pciDevice *dev);
-void pciDeviceSetUsedBy(pciDevice *dev,
- const char *used_by);
-const char *pciDeviceGetUsedBy(pciDevice *dev);
-unsigned pciDeviceGetUnbindFromStub(pciDevice *dev);
-void pciDeviceSetUnbindFromStub(pciDevice *dev,
- unsigned unbind);
-unsigned pciDeviceGetRemoveSlot(pciDevice *dev);
-void pciDeviceSetRemoveSlot(pciDevice *dev,
- unsigned remove_slot);
-unsigned pciDeviceGetReprobe(pciDevice *dev);
-void pciDeviceSetReprobe(pciDevice *dev,
- unsigned reprobe);
-void pciDeviceReAttachInit(pciDevice *dev);
-
-pciDeviceList *pciDeviceListNew (void);
-void pciDeviceListFree (pciDeviceList *list);
-int pciDeviceListAdd (pciDeviceList *list,
- pciDevice *dev);
-pciDevice * pciDeviceListGet (pciDeviceList *list,
- int idx);
-int pciDeviceListCount (pciDeviceList *list);
-pciDevice * pciDeviceListSteal (pciDeviceList *list,
- pciDevice *dev);
-pciDevice * pciDeviceListStealIndex(pciDeviceList *list,
- int idx);
-void pciDeviceListDel (pciDeviceList *list,
- pciDevice *dev);
-pciDevice * pciDeviceListFind (pciDeviceList *list,
- pciDevice *dev);
-int pciDeviceListFindIndex(pciDeviceList *list,
- pciDevice *dev);
+virPCIDevicePtr virPCIDeviceNew(unsigned domain,
+ unsigned bus,
+ unsigned slot,
+ unsigned function);
+void virPCIDeviceFree(virPCIDevicePtr dev);
+const char *virPCIDeviceGetName(virPCIDevicePtr dev);
+
+int virPCIDeviceDettach(virPCIDevicePtr dev,
+ virPCIDeviceListPtr activeDevs,
+ virPCIDeviceListPtr inactiveDevs,
+ const char *driver);
+int virPCIDeviceReAttach(virPCIDevicePtr dev,
+ virPCIDeviceListPtr activeDevs,
+ virPCIDeviceListPtr inactiveDevs,
+ const char *driver);
+int virPCIDeviceReset(virPCIDevicePtr dev,
+ virPCIDeviceListPtr activeDevs,
+ virPCIDeviceListPtr inactiveDevs);
+
+void virPCIDeviceSetManaged(virPCIDevice *dev,
+ unsigned managed);
+unsigned virPCIDeviceGetManaged(virPCIDevice *dev);
+void virPCIDeviceSetUsedBy(virPCIDevice *dev,
+ const char *used_by);
+const char *virPCIDeviceGetUsedBy(virPCIDevice *dev);
+unsigned virPCIDeviceGetUnbindFromStub(virPCIDevicePtr dev);
+void virPCIDeviceSetUnbindFromStub(virPCIDevice *dev,
+ unsigned unbind);
+unsigned virPCIDeviceGetRemoveSlot(virPCIDevicePtr dev);
+void virPCIDeviceSetRemoveSlot(virPCIDevice *dev,
+ unsigned remove_slot);
+unsigned virPCIDeviceGetReprobe(virPCIDevicePtr dev);
+void virPCIDeviceSetReprobe(virPCIDevice *dev,
+ unsigned reprobe);
+void virPCIDeviceReAttachInit(virPCIDevice *dev);
+
+
+virPCIDeviceListPtr virPCIDeviceListNew(void);
+void virPCIDeviceListFree(virPCIDeviceListPtr list);
+int virPCIDeviceListAdd(virPCIDeviceListPtr list,
+ virPCIDevicePtr dev);
+virPCIDevicePtr virPCIDeviceListGet(virPCIDeviceListPtr list,
+ int idx);
+int virPCIDeviceListCount(virPCIDeviceListPtr list);
+virPCIDevicePtr virPCIDeviceListSteal(virPCIDeviceListPtr list,
+ virPCIDevicePtr dev);
+virPCIDevicePtr virPCIDeviceListStealIndex(virPCIDeviceListPtr list,
+ int idx);
+void virPCIDeviceListDel(virPCIDeviceListPtr list,
+ virPCIDevicePtr dev);
+virPCIDevicePtr virPCIDeviceListFind(virPCIDeviceListPtr list,
+ virPCIDevicePtr dev);
+int virPCIDeviceListFindIndex(virPCIDeviceListPtr list,
+ virPCIDevicePtr dev);
/*
* Callback that will be invoked once for each file
@@ -95,46 +102,47 @@ int pciDeviceListFindIndex(pciDeviceList *list,
* Should return 0 if successfully processed, or
* -1 to indicate error and abort iteration
*/
-typedef int (*pciDeviceFileActor)(pciDevice *dev,
- const char *path, void *opaque);
+typedef int (*virPCIDeviceFileActor)(virPCIDevicePtr dev,
+ const char *path, void *opaque);
-int pciDeviceFileIterate(pciDevice *dev,
- pciDeviceFileActor actor,
- void *opaque);
+int virPCIDeviceFileIterate(virPCIDevicePtr dev,
+ virPCIDeviceFileActor actor,
+ void *opaque);
-int pciDeviceIsAssignable(pciDevice *dev,
- int strict_acs_check);
-int pciWaitForDeviceCleanup(pciDevice *dev, const char *matcher);
+int virPCIDeviceIsAssignable(virPCIDevicePtr dev,
+ int strict_acs_check);
+int virPCIDeviceWaitForCleanup(virPCIDevicePtr dev, const char *matcher);
-int pciGetPhysicalFunction(const char *sysfs_path,
- struct pci_config_address **phys_fn);
+int virPCIGetPhysicalFunction(const char *sysfs_path,
+ virPCIDeviceAddressPtr *phys_fn);
-int pciGetVirtualFunctions(const char *sysfs_path,
- struct pci_config_address ***virtual_functions,
- unsigned int *num_virtual_functions);
+int virPCIGetVirtualFunctions(const char *sysfs_path,
+ virPCIDeviceAddressPtr **virtual_functions,
+ unsigned int *num_virtual_functions);
-int pciDeviceIsVirtualFunction(const char *vf_sysfs_device_link);
+int virPCIIsVirtualFunction(const char *vf_sysfs_device_link);
-int pciGetVirtualFunctionIndex(const char *pf_sysfs_device_link,
- const char *vf_sysfs_device_link,
- int *vf_index);
+int virPCIGetVirtualFunctionIndex(const char *pf_sysfs_device_link,
+ const char *vf_sysfs_device_link,
+ int *vf_index);
-int pciConfigAddressToSysfsFile(struct pci_config_address *dev,
- char **pci_sysfs_device_link);
+int virPCIDeviceAddressGetSysfsFile(virPCIDeviceAddressPtr dev,
+ char **pci_sysfs_device_link);
-int pciDeviceNetName(char *device_link_sysfs_path, char **netname);
+int virPCIGetNetName(char *device_link_sysfs_path, char **netname);
-int pciSysfsFile(char *pciDeviceName, char **pci_sysfs_device_link)
+int virPCIGetSysfsFile(char *virPCIDeviceName,
+ char **pci_sysfs_device_link)
ATTRIBUTE_RETURN_CHECK;
-int pciGetDeviceAddrString(unsigned domain,
- unsigned bus,
- unsigned slot,
- unsigned function,
- char **pciConfigAddr)
+int virPCIGetAddrString(unsigned domain,
+ unsigned bus,
+ unsigned slot,
+ unsigned function,
+ char **pciConfigAddr)
ATTRIBUTE_NONNULL(5) ATTRIBUTE_RETURN_CHECK;
-int pciDeviceGetVirtualFunctionInfo(const char *vf_sysfs_device_path,
- char **pfname, int *vf_index);
+int virPCIGetVirtualFunctionInfo(const char *vf_sysfs_device_path,
+ char **pfname, int *vf_index);
#endif /* __VIR_PCI_H__ */
diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c
index 2795ebc..2c8b73e 100644
--- a/src/xen/xen_driver.c
+++ b/src/xen/xen_driver.c
@@ -2102,23 +2102,23 @@ out:
static int
xenUnifiedNodeDeviceDettach(virNodeDevicePtr dev)
{
- pciDevice *pci;
+ virPCIDevicePtr pci;
unsigned domain, bus, slot, function;
int ret = -1;
if (xenUnifiedNodeDeviceGetPciInfo(dev, &domain, &bus, &slot,
&function) < 0)
return -1;
- pci = pciGetDevice(domain, bus, slot, function);
+ pci = virPCIDeviceNew(domain, bus, slot, function);
if (!pci)
return -1;
- if (pciDettachDevice(pci, NULL, NULL, "pciback") < 0)
+ if (virPCIDeviceDettach(pci, NULL, NULL, "pciback") < 0)
goto out;
ret = 0;
out:
- pciFreeDevice(pci);
+ virPCIDeviceFree(pci);
return ret;
}
@@ -2183,7 +2183,7 @@ out:
static int
xenUnifiedNodeDeviceReAttach(virNodeDevicePtr dev)
{
- pciDevice *pci;
+ virPCIDevicePtr pci;
unsigned domain, bus, slot, function;
int ret = -1;
int domid;
@@ -2191,7 +2191,7 @@ xenUnifiedNodeDeviceReAttach(virNodeDevicePtr dev)
if (xenUnifiedNodeDeviceGetPciInfo(dev, &domain, &bus, &slot,
&function) < 0)
return -1;
- pci = pciGetDevice(domain, bus, slot, function);
+ pci = virPCIDeviceNew(domain, bus, slot, function);
if (!pci)
return -1;
@@ -2203,35 +2203,35 @@ xenUnifiedNodeDeviceReAttach(virNodeDevicePtr dev)
goto out;
}
- if (pciReAttachDevice(pci, NULL, NULL, "pciback") < 0)
+ if (virPCIDeviceReAttach(pci, NULL, NULL, "pciback") < 0)
goto out;
ret = 0;
out:
- pciFreeDevice(pci);
+ virPCIDeviceFree(pci);
return ret;
}
static int
xenUnifiedNodeDeviceReset(virNodeDevicePtr dev)
{
- pciDevice *pci;
+ virPCIDevicePtr pci;
unsigned domain, bus, slot, function;
int ret = -1;
if (xenUnifiedNodeDeviceGetPciInfo(dev, &domain, &bus, &slot,
&function) < 0)
return -1;
- pci = pciGetDevice(domain, bus, slot, function);
+ pci = virPCIDeviceNew(domain, bus, slot, function);
if (!pci)
return -1;
- if (pciResetDevice(pci, NULL, NULL) < 0)
+ if (virPCIDeviceReset(pci, NULL, NULL) < 0)
goto out;
ret = 0;
out:
- pciFreeDevice(pci);
+ virPCIDeviceFree(pci);
return ret;
}
--
1.8.0.2