From 8251be558d6824fa1dce37836b7f1d6ec6be6e9f Mon Sep 17 00:00:00 2001
From: jikui <jikui2@huawei.com>
Date: Tue, 30 Nov 2021 10:36:27 +0800
Subject: [PATCH] kata-runtime: check VFIO when create device

Signed-off-by: jikui <jikui2@huawei.com>
---
 src/runtime/virtcontainers/device/manager/manager.go | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/runtime/virtcontainers/device/manager/manager.go b/src/runtime/virtcontainers/device/manager/manager.go
index 4515609..3afc148 100644
--- a/src/runtime/virtcontainers/device/manager/manager.go
+++ b/src/runtime/virtcontainers/device/manager/manager.go
@@ -10,6 +10,7 @@ import (
 	"context"
 	"encoding/hex"
 	"errors"
+	"fmt"
 	"sync"
 
 	"github.com/sirupsen/logrus"
@@ -116,7 +117,11 @@ func (dm *deviceManager) createDevice(devInfo config.DeviceInfo) (dev api.Device
 	}()
 
 	if existingDev := dm.findDeviceByMajorMinor(devInfo.Major, devInfo.Minor); existingDev != nil {
-		return existingDev, nil
+		if isVFIO(devInfo.HostPath) {
+			return nil, fmt.Errorf("device %s is replicated in the same Pod!", devInfo.ContainerPath)
+		} else {
+			return existingDev, nil
+		}
 	}
 
 	// device ID must be generated by manager instead of device itself
-- 
2.25.1

