Francesco Romani has uploaded a new change for review.

Change subject: hypervisor autodetection for the vdsm capabilities
......................................................................

hypervisor autodetection for the vdsm capabilities

This is a follow up and an extension of the
Change I79f4ab08: add and use hypervisor autodetection in bootstrap.
(see http://gerrit.ovirt.org/#/c/7657 )

The vdsm capability reporting code is enhanced to autonomously
autodetect and report if the vdsm is running under an hypervisor,
thus if the virtualization support has to be emulated.

The hypervisor detection code is the same as the patch mentioned
above, updated following the comment received so far.
The autodetection code is moved in a separate little module
(`cpu_utils.py') which can be shared both by the vdsm and the
vds_bootstrap code.

So far, the two patches are independent and so they use independent
(duplicated) detection code, but a further patch (or an extension
of the current one, if preferred) is planned in order to share
the same module, minimizing the duplication to the point which I believe
is the minimum possible.

With this change and the one mentioned above both applied, there
is no longer need of the `fake_kvm_support' configuration variable.
In the proposed patch it is left as last resort/fallback option,
but it can be removed with a further patch, planned as well.

Change-Id: I565ef639e1f74bdbaef93060f4f25c75085d361b
Signed-off-by: Francesco Romani <[email protected]>
---
M vdsm.spec.in
M vdsm/Makefile.am
M vdsm/caps.py
A vdsm/cpu_utils.py
4 files changed, 82 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/84/7884/1

diff --git a/vdsm.spec.in b/vdsm.spec.in
index bb6730e..fb8bb01 100644
--- a/vdsm.spec.in
+++ b/vdsm.spec.in
@@ -559,6 +559,7 @@
 %{_datadir}/%{vdsm_name}/blkid.py*
 %{_datadir}/%{vdsm_name}/caps.py*
 %{_datadir}/%{vdsm_name}/clientIF.py*
+%{_datadir}/%{vdsm_name}/cpu_utils.py*
 %{_datadir}/%{vdsm_name}/API.py*
 %{_datadir}/%{vdsm_name}/hooking.py*
 %{_datadir}/%{vdsm_name}/hooks.py*
diff --git a/vdsm/Makefile.am b/vdsm/Makefile.am
index 96c8a56..662190d 100644
--- a/vdsm/Makefile.am
+++ b/vdsm/Makefile.am
@@ -31,6 +31,7 @@
        caps.py \
        clientIF.py \
        configNetwork.py \
+       cpu_utils.py \
        debugPluginClient.py \
        guestIF.py \
        hooking.py \
diff --git a/vdsm/caps.py b/vdsm/caps.py
index f1641ff..afc88dd 100644
--- a/vdsm/caps.py
+++ b/vdsm/caps.py
@@ -41,6 +41,7 @@
 from vdsm import utils
 from vdsm import constants
 import storage.hba
+import cpu_utils
 
 # For debian systems we can use python-apt if available
 try:
@@ -228,11 +229,18 @@
     return __osversion
 
 
[email protected]
+def _getHypervisorName():
+    return cpu_utils.findHypervisor()
+
+
 def get():
     caps = {}
 
+    fake_kvm = bool(_getHypervisorName()) or \
+                   config.getboolean('vars', 'fake_kvm_support')
     caps['kvmEnabled'] = \
-                str(config.getboolean('vars', 'fake_kvm_support') or
+                (str(fake_kvm) or
                     os.path.exists('/dev/kvm')).lower()
 
     cpuInfo = CpuInfo()
@@ -243,7 +251,7 @@
 
     caps['cpuSockets'] = str(cpuInfo.sockets())
     caps['cpuSpeed'] = cpuInfo.mhz()
-    if config.getboolean('vars', 'fake_kvm_support'):
+    if fake_kvm:
         caps['cpuModel'] = 'Intel(Fake) CPU'
         flags = set(cpuInfo.flags() + ['vmx', 'sse2', 'nx'])
         caps['cpuFlags'] = ','.join(flags) + 'model_486,model_pentium,' \
@@ -276,6 +284,7 @@
             config.getint('vars', 'host_mem_reserve') +
             config.getint('vars', 'extra_mem_reserve'))
     caps['guestOverhead'] = config.get('vars', 'guest_ram_overhead')
+    caps['hypervisorName'] = _getHypervisorName()
 
     return caps
 
diff --git a/vdsm/cpu_utils.py b/vdsm/cpu_utils.py
new file mode 100644
index 0000000..c3f402e
--- /dev/null
+++ b/vdsm/cpu_utils.py
@@ -0,0 +1,69 @@
+#
+# Copyright 2008-2012 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+# Refer to the README and COPYING files for full details of the license
+#
+
+"""
+A module containing miscellaneous cpu detection functions 
+used by various vdsm components.
+"""
+
+import struct
+import logging
+import traceback
+
+
+def cpuHypervisorID():
+    # we cannot (yet) use _cpuid because of the different
+    # unpack format.
+    HYPERVISOR_CPUID_LEAF = 0x40000000
+    with open('/dev/cpu/0/cpuid') as f:
+        f.seek(HYPERVISOR_CPUID_LEAF)
+        c = struct.unpack('I12s', f.read(16))
+        return c[1].strip('\x00')
+    return ''
+
+def cpuModelName():
+    with open('/proc/cpuinfo') as f:
+        for line in f:
+            if ':' in line:
+                k, v = line.split(':', 1)
+                k = k.strip()
+                if k == 'model name':
+                    return v.strip()
+    return ''
+
+def findHypervisor():
+    name = ''
+    try:
+        hid = cpuHypervisorID()
+        if hid == 'VMwareVMware':
+            name = 'vmware'
+        elif hid == 'Microsoft Hv':
+            name = 'hyperv'
+        elif hid == 'XenVMMXenVMM':
+            name = 'xen'
+        elif hid == 'KVMKVMKVM':
+            name = 'kvm'
+        elif 'QEMU' in cpuModelName():
+            name = 'qemu'
+        logging.debug('detected hypervisor: %s', name)
+    except:
+        logging.error(traceback.format_exc())
+    return name
+


--
To view, visit http://gerrit.ovirt.org/7884
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I565ef639e1f74bdbaef93060f4f25c75085d361b
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Francesco Romani <[email protected]>
_______________________________________________
vdsm-patches mailing list
[email protected]
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches

Reply via email to