diff --git a/common/include/villas/kernel/devices/pci_device.hpp b/common/include/villas/kernel/devices/pci_device.hpp index d7f457c04..2b6185152 100644 --- a/common/include/villas/kernel/devices/pci_device.hpp +++ b/common/include/villas/kernel/devices/pci_device.hpp @@ -70,8 +70,8 @@ public: bool operator==(const PciDevice &other); - // Get currently loaded driver for device - std::string getDriver() const; + // Implement device interface + std::optional> driver() const override; // Bind a new LKM to the PCI device bool attachDriver(const std::string &driver) const; diff --git a/common/lib/kernel/devices/pci_device.cpp b/common/lib/kernel/devices/pci_device.cpp index ef8a8b5d0..7a218b1a2 100644 --- a/common/lib/kernel/devices/pci_device.cpp +++ b/common/lib/kernel/devices/pci_device.cpp @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -311,8 +312,7 @@ std::list PciDevice::getRegions() const { return regions; } - -std::string PciDevice::getDriver() const { +std::optional> PciDevice::driver() const { int ret; char sysfs[1024], syml[1024]; memset(syml, 0, sizeof(syml)); @@ -323,13 +323,15 @@ std::string PciDevice::getDriver() const { struct stat st; ret = stat(sysfs, &st); if (ret) - return ""; + return std::nullopt; ret = readlink(sysfs, syml, sizeof(syml)); if (ret < 0) throw SystemError("Failed to follow link: {}", sysfs); - return basename(syml); + auto driver = std::make_optional(std::make_unique( + "/sys/bus/pci/drivers/" + std::string(basename(syml)))); + return driver; } bool PciDevice::attachDriver(const std::string &driver) const {