diff --git a/common/include/villas/graph/directed.hpp b/common/include/villas/graph/directed.hpp index cd75102dd..506d87012 100644 --- a/common/include/villas/graph/directed.hpp +++ b/common/include/villas/graph/directed.hpp @@ -42,7 +42,7 @@ public: std::shared_ptr getVertex(VertexIdentifier vertexId) const { - if (vertexId >= lastVertexId) + if (vertexId >= vertices.size()) throw std::invalid_argument("vertex doesn't exist"); // cannot use [] operator, because creates non-existing elements @@ -154,6 +154,7 @@ public: auto startVertex = getVertex(edge->from); startVertex->edges.remove(edge->id); + } if ((edge->from == vertexId) or removeEdge) { @@ -167,6 +168,7 @@ public: logger->debug("Remove vertex {}", vertexId); vertices.erase(vertexId); + lastVertexId--; } const std::list& diff --git a/common/lib/kernel/vfio_container.cpp b/common/lib/kernel/vfio_container.cpp index e0c36421b..6c301eb77 100644 --- a/common/lib/kernel/vfio_container.cpp +++ b/common/lib/kernel/vfio_container.cpp @@ -93,11 +93,10 @@ Container::Container() : Container::~Container() { - log->debug("Clean up container with fd {}", fd); - /* Release memory and close fds */ groups.clear(); + log->debug("Cleaning up container with fd {}", fd); /* Close container */ int ret = close(fd); if (ret < 0) diff --git a/common/lib/kernel/vfio_device.cpp b/common/lib/kernel/vfio_device.cpp index 568921759..a5f59564f 100644 --- a/common/lib/kernel/vfio_device.cpp +++ b/common/lib/kernel/vfio_device.cpp @@ -125,11 +125,14 @@ Device::Device(const std::string &name, int groupFileDescriptor, const kernel::p Device::~Device() { - log->debug("Clean up device {} with fd {}", this->name, this->fd); + log->debug("Cleaning up device {} with fd {}", this->name, this->fd); for (auto ®ion : regions) { regionUnmap(region.index); } + if (isVfioPciDevice()) { + pciHotReset(); + } reset(); int ret = close(fd); @@ -412,6 +415,7 @@ bool Device::pciHotReset() if (!isVfioPciDevice()) return false; + log->debug("Performing hot reset."); const size_t reset_info_len = sizeof(struct vfio_pci_hot_reset_info) + sizeof(struct vfio_pci_dependent_device) * 64; @@ -461,7 +465,7 @@ bool Device::pciHotReset() delete[] reset_buf; if (!success) { - log->warn("PCI hot reset failed, maybe not IOMMU available?"); + log->warn("PCI hot reset failed, maybe no IOMMU available?"); return true; } diff --git a/common/lib/kernel/vfio_group.cpp b/common/lib/kernel/vfio_group.cpp index bac909768..b17b4a25e 100644 --- a/common/lib/kernel/vfio_group.cpp +++ b/common/lib/kernel/vfio_group.cpp @@ -118,11 +118,11 @@ void Group::dump() Group::~Group() { - log->debug("Clean up group {} with fd {}", this->index, this->fd); - /* Release memory and close fds */ devices.clear(); + log->debug("Cleaning up group {} with fd {}", index, fd); + if (fd < 0) log->debug("Destructing group that has not been attached"); else {