提交 af3ddc13 编写于 作者: M Michal Privoznik

virpcimock: Introduce and use pci_driver_get_path()

Have just one function to generate path to a PCI driver so that
when we change it in near future there's only few of the places
we need to fix.
Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
Tested-by: NDaniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: NDaniel Henrique Barboza <danielhb413@gmail.com>
上级 7f7bd601
...@@ -504,6 +504,29 @@ pci_device_autobind(struct pciDevice *dev) ...@@ -504,6 +504,29 @@ pci_device_autobind(struct pciDevice *dev)
/* /*
* PCI Driver functions * PCI Driver functions
*/ */
static char *
pci_driver_get_path(const struct pciDriver *driver,
const char *file,
bool faked)
{
char *ret = NULL;
const char *prefix = "";
if (faked)
prefix = fakerootdir;
if (file) {
ignore_value(virAsprintfQuiet(&ret, "%s" SYSFS_PCI_PREFIX "drivers/%s/%s",
prefix, driver->name, file));
} else {
ignore_value(virAsprintfQuiet(&ret, "%s" SYSFS_PCI_PREFIX "drivers/%s",
prefix, driver->name));
}
return ret;
}
static void static void
pci_driver_new(const char *name, int fail, ...) pci_driver_new(const char *name, int fail, ...)
{ {
...@@ -514,7 +537,7 @@ pci_driver_new(const char *name, int fail, ...) ...@@ -514,7 +537,7 @@ pci_driver_new(const char *name, int fail, ...)
if (VIR_ALLOC_QUIET(driver) < 0 || if (VIR_ALLOC_QUIET(driver) < 0 ||
VIR_STRDUP_QUIET(driver->name, name) < 0 || VIR_STRDUP_QUIET(driver->name, name) < 0 ||
virAsprintfQuiet(&driverpath, "%s/sys/bus/pci/drivers/%s", fakerootdir, name) < 0) !(driverpath = pci_driver_get_path(driver, NULL, true)))
ABORT_OOM(); ABORT_OOM();
driver->fail = fail; driver->fail = fail;
...@@ -620,8 +643,7 @@ pci_driver_bind(struct pciDriver *driver, ...@@ -620,8 +643,7 @@ pci_driver_bind(struct pciDriver *driver,
/* Make symlink under device tree */ /* Make symlink under device tree */
if (!(devpath = pci_device_get_path(dev, "driver", true)) || if (!(devpath = pci_device_get_path(dev, "driver", true)) ||
virAsprintfQuiet(&driverpath, "%s/sys/bus/pci/drivers/%s", !(driverpath = pci_driver_get_path(driver, NULL, true))) {
fakerootdir, driver->name) < 0) {
errno = ENOMEM; errno = ENOMEM;
return -1; return -1;
} }
...@@ -633,8 +655,7 @@ pci_driver_bind(struct pciDriver *driver, ...@@ -633,8 +655,7 @@ pci_driver_bind(struct pciDriver *driver,
VIR_FREE(devpath); VIR_FREE(devpath);
VIR_FREE(driverpath); VIR_FREE(driverpath);
if (!(devpath = pci_device_get_path(dev, NULL, true)) || if (!(devpath = pci_device_get_path(dev, NULL, true)) ||
virAsprintfQuiet(&driverpath, "%s/sys/bus/pci/drivers/%s/%s", !(driverpath = pci_driver_get_path(driver, dev->id, true))) {
fakerootdir, driver->name, dev->id) < 0) {
errno = ENOMEM; errno = ENOMEM;
return -1; return -1;
} }
...@@ -661,8 +682,7 @@ pci_driver_unbind(struct pciDriver *driver, ...@@ -661,8 +682,7 @@ pci_driver_unbind(struct pciDriver *driver,
/* Make symlink under device tree */ /* Make symlink under device tree */
if (!(devpath = pci_device_get_path(dev, "driver", true)) || if (!(devpath = pci_device_get_path(dev, "driver", true)) ||
virAsprintfQuiet(&driverpath, "%s/sys/bus/pci/drivers/%s/%s", !(driverpath = pci_driver_get_path(driver, dev->id, true))) {
fakerootdir, driver->name, dev->id) < 0) {
errno = ENOMEM; errno = ENOMEM;
return -1; return -1;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册