On 02/22/2016 04:38 PM, Jose Ricardo Ziviani wrote:
- Currently it is only possible to perform cold plug of 3D graphic
cards, so this commit blocks hot plug of such device in the backend.
Signed-off-by: Jose Ricardo Ziviani <joserz(a)linux.vnet.ibm.com>
---
i18n.py | 1 +
model/host.py | 15 +++++++++++++++
model/vmhostdevs.py | 5 +++++
3 files changed, 21 insertions(+)
diff --git a/i18n.py b/i18n.py
index 42ee884..4391dff 100644
--- a/i18n.py
+++ b/i18n.py
@@ -142,6 +142,7 @@ messages = {
"For AMD CPU, add 'iommu=pt iommu=1'."),
"KCHVMHDEV0004E": _('"name" should be a device name
string'),
"KCHVMHDEV0005E": _('The device %(name)s is probably in use by the
host. Unable to attach it to the guest.'),
+ "KCHVMHDEV0006E": _('Hot-plug of device %(name)s is not
supported.'),
"KCHVMIF0001E": _("Interface %(iface)s does not exist in virtual
machine %(name)s"),
"KCHVMIF0002E": _("Network %(network)s specified for virtual machine
%(name)s does not exist"),
diff --git a/model/host.py b/model/host.py
index 583accd..53a8692 100644
--- a/model/host.py
+++ b/model/host.py
@@ -18,6 +18,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import libvirt
+import os
from collections import defaultdict
from lxml import objectify
@@ -176,6 +177,7 @@ class DeviceModel(object):
info = hostdev.get_dev_info(dev)
info['multifunction'] = self.is_multifunction_pci(info)
+ info['vga3d'] = self.is_device_3D_controller(info)
return info
As you are adding a new parameter to the API, please, update docs/API.md
accordingly.
def is_multifunction_pci(self, info):
@@ -184,6 +186,19 @@ class DeviceModel(object):
iommu_group_nr = int(info['iommuGroup'])
return len(self.iommu_groups[iommu_group_nr]) > 1
+ def is_device_3D_controller(self, info):
+ try:
+ with open(os.path.join(info['path'], 'class')) as f:
+ pci_class = int(f.readline().strip(), 16)
+
+ except:
+ return False
+
+ if pci_class == 0x030200:
+ return True
+
+ return False
+
@staticmethod
def _toint(num_str):
if num_str.startswith('0x'):
diff --git a/model/vmhostdevs.py b/model/vmhostdevs.py
index de52cd8..2a56f9f 100644
--- a/model/vmhostdevs.py
+++ b/model/vmhostdevs.py
@@ -184,6 +184,11 @@ class VMHostDevsModel(object):
DOM_STATE_MAP[dom.info()[0]] == "shutoff"
pci_infos = sorted(pci_infos, key=itemgetter('name'))
+ if dev_model.is_device_3D_controller(dev_info) and \
+ DOM_STATE_MAP[dom.info()[0]] != "shutoff":
+ raise InvalidOperation('KCHVMHDEV0006E',
+ {'name': dev_info['name']})
+
# all devices in the group that is going to be attached to the vm
# must be detached from the host first
with RollbackContext() as rollback: