提交 508b566e 编写于 作者: J Jiri Denemark

virpcimock: Mock /sys/bus/pci/drivers_probe

This file is used by PCI detach and reattach APIs to probe for a driver
that handles a specific device.
Signed-off-by: NJiri Denemark <jdenemar@redhat.com>
上级 124affae
...@@ -91,6 +91,10 @@ char *fakesysfsdir; ...@@ -91,6 +91,10 @@ char *fakesysfsdir;
* Unbind driver from the device. * Unbind driver from the device.
* Data in format "DDDD:BB:DD.F" (Domain:Bus:Device.Function). * Data in format "DDDD:BB:DD.F" (Domain:Bus:Device.Function).
* *
* /sys/bus/pci/drivers_probe
* Probe for a driver that handles the specified device.
* Data in format "DDDD:BB:DD.F" (Domain:Bus:Device.Function).
*
* As a little hack, we are not mocking write to these files, but close() * As a little hack, we are not mocking write to these files, but close()
* instead. The advantage is we don't need any self growing array to hold the * instead. The advantage is we don't need any self growing array to hold the
* partial writes and construct them back. We can let all the writes finish, * partial writes and construct them back. We can let all the writes finish,
...@@ -567,28 +571,40 @@ cleanup: ...@@ -567,28 +571,40 @@ cleanup:
return ret; return ret;
} }
static int
pci_driver_handle_drivers_probe(const char *path)
{
struct pciDevice *dev;
if (!(dev = pci_device_find_by_content(path))) {
errno = ENODEV;
return -1;
}
if (dev->driver)
return 0;
return pci_device_autobind(dev);
}
static int static int
pci_driver_handle_change(int fd ATTRIBUTE_UNUSED, const char *path) pci_driver_handle_change(int fd ATTRIBUTE_UNUSED, const char *path)
{ {
int ret; int ret;
const char *file = last_component(path); const char *file = last_component(path);
if (STREQ(file, "bind")) { if (STREQ(file, "bind"))
/* handle write to bind */
ret = pci_driver_handle_bind(path); ret = pci_driver_handle_bind(path);
} else if (STREQ(file, "unbind")) { else if (STREQ(file, "unbind"))
/* handle write to unbind */
ret = pci_driver_handle_unbind(path); ret = pci_driver_handle_unbind(path);
} else if (STREQ(file, "new_id")) { else if (STREQ(file, "new_id"))
/* handle write to new_id */
ret = pci_driver_handle_new_id(path); ret = pci_driver_handle_new_id(path);
} else if (STREQ(file, "remove_id")) { else if (STREQ(file, "remove_id"))
/* handle write to remove_id */
ret = pci_driver_handle_remove_id(path); ret = pci_driver_handle_remove_id(path);
} else { else if (STREQ(file, "drivers_probe"))
/* yet not handled write */ ret = pci_driver_handle_drivers_probe(path);
else
ABORT("Not handled write to: %s", path); ABORT("Not handled write to: %s", path);
}
return ret; return ret;
} }
...@@ -766,6 +782,8 @@ init_env(void) ...@@ -766,6 +782,8 @@ init_env(void)
if (!(fakesysfsdir = getenv("LIBVIRT_FAKE_SYSFS_DIR"))) if (!(fakesysfsdir = getenv("LIBVIRT_FAKE_SYSFS_DIR")))
ABORT("Missing LIBVIRT_FAKE_SYSFS_DIR env variable\n"); ABORT("Missing LIBVIRT_FAKE_SYSFS_DIR env variable\n");
make_file(fakesysfsdir, "drivers_probe", NULL, -1);
# define MAKE_PCI_DRIVER(name, ...) \ # define MAKE_PCI_DRIVER(name, ...) \
pci_driver_new(name, __VA_ARGS__, -1, -1) pci_driver_new(name, __VA_ARGS__, -1, -1)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册