Skip to content

Commit ced775b

Browse files
Add path check for channel buffer cleanup
1 parent a571131 commit ced775b

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

src/Driver.cxx

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,32 +33,34 @@ void freeUnusedChannelBuffers()
3333

3434
try {
3535
std::string pciPath = "/sys/bus/pci/drivers/uio_pci_dma/";
36-
for (auto &entry : boost::make_iterator_range(bfs::directory_iterator(pciPath), {})) {
37-
auto filename = entry.path().filename().string();
38-
if (filename.size() == 12) {
39-
// The PCI directory names are 12 characters long
40-
auto pciAddress = filename.substr(5); // Remove leading '0000:'
36+
if (boost::filesystem::exists(pciPath)) {
37+
for (auto &entry : boost::make_iterator_range(bfs::directory_iterator(pciPath), {})) {
38+
auto filename = entry.path().filename().string();
39+
if (filename.size() == 12) {
40+
// The PCI directory names are 12 characters long
41+
auto pciAddress = filename.substr(5); // Remove leading '0000:'
4142

42-
if (PciAddress::fromString(pciAddress)) {
43-
// This is a valid PCI address
44-
std::string dmaPath("/sys/bus/pci/drivers/uio_pci_dma/" + filename + "/dma");
45-
for (auto &entry : boost::make_iterator_range(bfs::directory_iterator(dmaPath), {})) {
46-
auto bufferId = entry.path().filename().string();
47-
if (bfs::is_directory(entry)) {
48-
std::string mapPath = dmaPath + "/" + bufferId + "/map";
49-
std::string freePath = dmaPath + "/free";
50-
auto fuserResult = AliceO2::Common::System::executeCommand("fuser " + mapPath);
51-
if (fuserResult.empty()) {
52-
// No process is using it, we can free the buffer!
53-
logger << "Freeing PDA buffer '" + mapPath + "'" << InfoLogger::InfoLogger::endm;
54-
auto fuserResult = AliceO2::Common::System::executeCommand("echo " + bufferId + " > " + freePath);
43+
if (PciAddress::fromString(pciAddress)) {
44+
// This is a valid PCI address
45+
std::string dmaPath("/sys/bus/pci/drivers/uio_pci_dma/" + filename + "/dma");
46+
for (auto &entry : boost::make_iterator_range(bfs::directory_iterator(dmaPath), {})) {
47+
auto bufferId = entry.path().filename().string();
48+
if (bfs::is_directory(entry)) {
49+
std::string mapPath = dmaPath + "/" + bufferId + "/map";
50+
std::string freePath = dmaPath + "/free";
51+
auto fuserResult = AliceO2::Common::System::executeCommand("fuser " + mapPath);
52+
if (fuserResult.empty()) {
53+
// No process is using it, we can free the buffer!
54+
logger << "Freeing PDA buffer '" + mapPath + "'" << InfoLogger::InfoLogger::endm;
55+
auto fuserResult = AliceO2::Common::System::executeCommand("echo " + bufferId + " > " + freePath);
56+
}
5557
}
5658
}
5759
}
5860
}
5961
}
6062
}
61-
} catch (const boost::filesystem::filesystem_error& e) {
63+
} catch (const boost::filesystem::filesystem_error &e) {
6264
logger << "Failed to free buffers: " << e.what() << InfoLogger::InfoLogger::endm;
6365
throw;
6466
}

0 commit comments

Comments
 (0)