From 326e90f97cf5ace73dff95257f7b4faa43c56f99 Mon Sep 17 00:00:00 2001
From: holyfei <yangfeiyu20092010@163.com>
Date: Mon, 17 Aug 2020 16:11:35 +0800
Subject: [PATCH 31/50] device_mangaer: check VFIO when create device

reason: check VFIO when create device, block device can be
reused and VFIO device can not

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

diff --git a/virtcontainers/device/manager/manager.go b/virtcontainers/device/manager/manager.go
index 6a2b665a..d24a29ab 100644
--- a/virtcontainers/device/manager/manager.go
+++ b/virtcontainers/device/manager/manager.go
@@ -9,6 +9,7 @@ package manager
 import (
 	"encoding/hex"
 	"errors"
+	"fmt"
 	"sync"
 
 	"github.com/sirupsen/logrus"
@@ -115,7 +116,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.14.3 (Apple Git-98)

