From ece14d74fe18608fe080427f0bdb3715b0ca88e6 Mon Sep 17 00:00:00 2001
From: Niklas Eiling <niklas.eiling@eonerc.rwth-aachen.de>
Date: Mon, 5 Dec 2022 09:18:26 +0100
Subject: [PATCH] vfio: convert container from singleton to normal class

Signed-off-by: Niklas Eiling <niklas.eiling@eonerc.rwth-aachen.de>
---
 common/include/villas/kernel/vfio_container.hpp | 12 ++----------
 common/include/villas/kernel/vfio_device.hpp    |  4 ++++
 common/include/villas/kernel/vfio_group.hpp     |  4 ++++
 3 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/common/include/villas/kernel/vfio_container.hpp b/common/include/villas/kernel/vfio_container.hpp
index 50d0a5614..90eee666a 100644
--- a/common/include/villas/kernel/vfio_container.hpp
+++ b/common/include/villas/kernel/vfio_container.hpp
@@ -25,19 +25,11 @@ namespace kernel {
 namespace vfio {
 
 class Container {
-private:
-	// This is a singleton: There can only be one container to rule them all.
+public:
 	Container();
 
-public:
-	// The Container instance is lazily initialized and correctly destroyed.
-	static Container* getInstance()
-	{
-		static Container instance;
-		return &instance;
-	}
 
-	// No copying allowed
+	// No copying allowed because we manage the vfio state in constructor and destructors
 	Container(Container const&) = delete;
 	void operator=(Container const&) = delete;
 
diff --git a/common/include/villas/kernel/vfio_device.hpp b/common/include/villas/kernel/vfio_device.hpp
index 6cb717cf2..796223142 100644
--- a/common/include/villas/kernel/vfio_device.hpp
+++ b/common/include/villas/kernel/vfio_device.hpp
@@ -38,6 +38,10 @@ public:
 	Device(const std::string &name, int groupFileDescriptor, const kernel::pci::Device *pci_device = nullptr);
 	~Device();
 
+	// No copying allowed because we manage the vfio state in constructor and destructors
+	Device(Device const&) = delete;
+	void operator=(Device const&) = delete;
+
 	bool reset();
 
 	// Map a device memory region to the application address space (e.g. PCI BARs)
diff --git a/common/include/villas/kernel/vfio_group.hpp b/common/include/villas/kernel/vfio_group.hpp
index af1905519..169aa1e87 100644
--- a/common/include/villas/kernel/vfio_group.hpp
+++ b/common/include/villas/kernel/vfio_group.hpp
@@ -30,6 +30,10 @@ public:
 	Group(int index, bool iommuEnabled);
 	~Group();
 
+	// No copying allowed because we manage the vfio state in constructor and destructors
+	Group(Group const&) = delete;
+	void operator=(Group const&) = delete;
+
 	void setAttachedToContainer()
 	{
 		attachedToContainer = true;