def uuid(): host_UUID = None try: if os.path.exists(constants.P_VDSM_NODE_ID): with open(constants.P_VDSM_NODE_ID) as f: host_UUID = f.readline().replace("\n", "") else: arch = cpuarch.real() if cpuarch.is_x86(arch): ret, out, err = execCmd( [constants.EXT_DMIDECODE, "-s", "system-uuid"], raw=True, sudo=True) out = '\n'.join(line for line in out.splitlines() if not line.startswith('#')) if ret == 0 and 'Not' not in out: # Avoid error string - 'Not Settable' or 'Not Present' host_UUID = out.strip() else: logging.warning('Could not find host UUID.') elif cpuarch.is_ppc(arch): # eg. output IBM,03061C14A try: with open('/proc/device-tree/system-id') as f: systemId = f.readline() host_UUID = systemId.rstrip('\0').replace(',', '') except IOError: logging.warning('Could not find host UUID.') except: logging.error("Error retrieving host UUID", exc_info=True) return host_UUID
def _fake_caps_arch(caps, arch): ''' Mutate 'caps' to act as an architecture set by fake_kvm_architecture configuration option. Arguments: caps The host capabilities as returned by hooking.read_json. ''' arch = arch caps['kvmEnabled'] = True if cpuarch.is_x86(arch): caps['emulatedMachines'] = _X86_64_MACHINES caps['cpuModel'] = 'Intel(Fake) CPU' flag_list = ['vmx', 'sse2', 'nx'] if cpuarch.real() == cpuarch.X86_64: flag_list += cpuinfo.flags() flags = set(flag_list) caps['cpuFlags'] = ','.join(flags) + ',model_486,model_pentium,' \ 'model_pentium2,model_pentium3,model_pentiumpro,' \ 'model_qemu32,model_coreduo,model_core2duo,model_n270,' \ 'model_Conroe,model_Penryn,model_Nehalem,model_Opteron_G1' elif cpuarch.is_ppc(arch): caps['emulatedMachines'] = _PPC64LE_MACHINES caps['cpuModel'] = 'POWER 8(fake)' caps['cpuFlags'] = 'powernv,model_POWER8' else: raise cpuarch.UnsupportedArchitecture(arch)
def _is_hugetlbfs_1g_mounted(mtab_path='/etc/mtab'): if cpuarch.is_ppc(cpuarch.real()) or 'pdpe1gb' not in cpuinfo.flags(): return True with open(mtab_path, 'r') as f: for line in f: if '/dev/hugepages1G' in line: return True return False
def getHardwareInfo(*args, **kwargs): arch = cpuarch.real() if cpuarch.is_x86(arch): from vdsm.dmidecodeUtil import getHardwareInfoStructure return getHardwareInfoStructure() elif cpuarch.is_ppc(arch): from vdsm.ppc64HardwareInfo import getHardwareInfoStructure return getHardwareInfoStructure() else: # not implemented over other architecture return {}
def nested_virtualization(): if cpuarch.is_ppc(cpuarch.real()): return NestedVirtualization(False, None) for kvm_module in ("kvm_intel", "kvm_amd"): kvm_module_path = "/sys/module/%s/parameters/nested" % kvm_module try: with open(kvm_module_path) as f: if f.readline().strip() in ("Y", "1"): return NestedVirtualization(True, kvm_module) except IOError: logging.debug('Could not determine status of nested ' 'virtualization', exc_info=True) return NestedVirtualization(False, None)
def nested_virtualization(): if cpuarch.is_ppc(cpuarch.real()): return NestedVirtualization(False, None) for kvm_module in ("kvm_intel", "kvm_amd"): kvm_module_path = "/sys/module/%s/parameters/nested" % kvm_module try: with open(kvm_module_path) as f: if f.readline().strip() in ("Y", "1"): return NestedVirtualization(True, kvm_module) except IOError: logging.debug( 'Could not determine status of nested ' 'virtualization', exc_info=True) return NestedVirtualization(False, None)
class Tap(Interface): _IFF_TAP = 0x0002 _IFF_NO_PI = 0x1000 arch = cpuarch.real() if arch in (cpuarch.X86_64, cpuarch.S390X): _TUNSETIFF = 0x400454ca elif cpuarch.is_ppc(arch): _TUNSETIFF = 0x800454ca else: raise SkipTest("Unsupported Architecture %s" % arch) _deviceListener = None def addDevice(self): self._cloneDevice = open('/dev/net/tun', 'r+b') ifr = struct.pack('16sH', self.devName, self._IFF_TAP | self._IFF_NO_PI) fcntl.ioctl(self._cloneDevice, self._TUNSETIFF, ifr) self.up() def delDevice(self): self._down() self._cloneDevice.close() def startListener(self, icmp): self._deviceListener = Process(target=_listenOnDevice, args=(self._cloneDevice.fileno(), icmp)) self._deviceListener.start() def isListenerAlive(self): if self._deviceListener: return self._deviceListener.is_alive() else: return False def stopListener(self): if self._deviceListener: os.kill(self._deviceListener.pid, signal.SIGKILL) self._deviceListener.join() def writeToDevice(self, icmp): os.write(self._cloneDevice.fileno(), icmp)
def uuid(): host_UUID = None try: if os.path.exists(constants.P_VDSM_NODE_ID): with open(constants.P_VDSM_NODE_ID) as f: host_UUID = f.readline().replace("\n", "") else: arch = cpuarch.real() if cpuarch.is_x86(arch): ret, out, err = execCmd([constants.EXT_DMIDECODE, "-s", "system-uuid"], raw=True, sudo=True) out = '\n'.join(line for line in out.splitlines() if not line.startswith('#')) if ret == 0 and 'Not' not in out: # Avoid error string - 'Not Settable' or 'Not Present' host_UUID = out.strip() else: logging.warning('Could not find host UUID.') elif cpuarch.is_ppc(arch): # eg. output IBM,03061C14A try: with open('/proc/device-tree/system-id') as f: systemId = f.readline() host_UUID = systemId.rstrip('\0').replace(',', '') except IOError: logging.warning('Could not find host UUID.') except: logging.error("Error retrieving host UUID", exc_info=True) return host_UUID
def appendCpu(self): """ Add guest CPU definition. <cpu match="exact"> <model>qemu64</model> <topology sockets="S" cores="C" threads="T"/> <feature policy="require" name="sse2"/> <feature policy="disable" name="svm"/> </cpu> For POWER8, there is no point in trying to use baseline CPU for flags since there are only HW features. There are 2 ways of creating a valid POWER8 element that we support: <cpu> <model>POWER{X}</model> </cpu> This translates to -cpu POWER{X} (where {X} is version of the processor - 7 and 8), which tells qemu to emulate the CPU in POWER8 family that it's capable of emulating - in case of hardware virtualization, that will be the host cpu (so an equivalent of -cpu host). Using this option does not limit migration between POWER8 machines - it is still possible to migrate from e.g. POWER8 to POWER8e. The second option is not supported and serves only for reference: <cpu mode="host-model"> <model>power{X}</model> </cpu> where {X} is the binary compatibility version of POWER that we require (6, 7, 8). This translates to qemu's -cpu host,compat=power{X}. Using the second option also does not limit migration between POWER8 machines - it is still possible to migrate from e.g. POWER8 to POWER8e. """ cpu = Element('cpu') if cpuarch.is_x86(self.arch): cpu.setAttrs(match='exact') features = self.conf.get('cpuType', 'qemu64').split(',') model = features[0] if model == 'hostPassthrough': cpu.setAttrs(mode='host-passthrough') elif model == 'hostModel': cpu.setAttrs(mode='host-model') else: cpu.appendChildWithArgs('model', text=model) # This hack is for backward compatibility as the libvirt # does not allow 'qemu64' guest on intel hardware if model == 'qemu64' and '+svm' not in features: features += ['-svm'] for feature in features[1:]: # convert Linux name of feature to libvirt if feature[1:6] == 'sse4_': feature = feature[0] + 'sse4.' + feature[6:] featureAttrs = {'name': feature[1:]} if feature[0] == '+': featureAttrs['policy'] = 'require' elif feature[0] == '-': featureAttrs['policy'] = 'disable' cpu.appendChildWithArgs('feature', **featureAttrs) elif cpuarch.is_ppc(self.arch): features = self.conf.get('cpuType', 'POWER8').split(',') model = features[0] cpu.appendChildWithArgs('model', text=model) if ('smpCoresPerSocket' in self.conf or 'smpThreadsPerCore' in self.conf): maxVCpus = int(self._getMaxVCpus()) cores = int(self.conf.get('smpCoresPerSocket', '1')) threads = int(self.conf.get('smpThreadsPerCore', '1')) cpu.appendChildWithArgs('topology', sockets=str(maxVCpus / cores / threads), cores=str(cores), threads=str(threads)) # CPU-pinning support # see http://www.ovirt.org/wiki/Features/Design/cpu-pinning if 'cpuPinning' in self.conf: cputune = Element('cputune') cpuPinning = self.conf.get('cpuPinning') for cpuPin in cpuPinning.keys(): cputune.appendChildWithArgs('vcpupin', vcpu=cpuPin, cpuset=cpuPinning[cpuPin]) self.dom.appendChild(cputune) # Guest numa topology support # see http://www.ovirt.org/Features/NUMA_and_Virtual_NUMA if 'guestNumaNodes' in self.conf: numa = Element('numa') guestNumaNodes = sorted( self.conf.get('guestNumaNodes'), key=itemgetter('nodeIndex')) for vmCell in guestNumaNodes: nodeMem = int(vmCell['memory']) * 1024 numa.appendChildWithArgs('cell', cpus=vmCell['cpus'], memory=str(nodeMem)) cpu.appendChild(numa) self.dom.appendChild(cpu)