|
174 | 174 | import com.cloud.hypervisor.kvm.resource.KVMHABase.NfsStoragePool; |
175 | 175 | import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.ClockDef; |
176 | 176 | import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.ConsoleDef; |
| 177 | +import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.CpuModeDef; |
177 | 178 | import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.CpuTuneDef; |
178 | 179 | import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.DevicesDef; |
179 | 180 | import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.DiskDef; |
@@ -332,6 +333,8 @@ protected String getDefaultScriptsDir() { |
332 | 333 | private boolean _can_bridge_firewall; |
333 | 334 | protected String _localStoragePath; |
334 | 335 | protected String _localStorageUUID; |
| 336 | + protected String _guestCpuMode; |
| 337 | + protected String _guestCpuModel; |
335 | 338 | private final Map <String, String> _pifs = new HashMap<String, String>(); |
336 | 339 | private final Map<String, Map<String, String>> hostNetInfo = new HashMap<String, Map<String, String>>(); |
337 | 340 | private final Map<String, vmStats> _vmStats = new ConcurrentHashMap<String, vmStats>(); |
@@ -692,6 +695,18 @@ public boolean configure(String name, Map<String, Object> params) |
692 | 695 |
|
693 | 696 | } |
694 | 697 |
|
| 698 | + _guestCpuMode = (String) params.get("guest.cpu.mode"); |
| 699 | + if (_guestCpuMode != null) { |
| 700 | + _guestCpuModel = (String) params.get("guest.cpu.model"); |
| 701 | + |
| 702 | + if(_hypervisorLibvirtVersion < (9 * 1000 + 10)) { |
| 703 | + s_logger.warn("LibVirt version 0.9.10 required for guest cpu mode, but version " + |
| 704 | + prettyVersion(_hypervisorLibvirtVersion) + " detected, so it will be disabled"); |
| 705 | + _guestCpuMode = null; |
| 706 | + _guestCpuModel = null; |
| 707 | + } |
| 708 | + } |
| 709 | + |
695 | 710 | String[] info = NetUtils.getNetworkParams(_privateNic); |
696 | 711 |
|
697 | 712 | _monitor = new KVMHAMonitor(null, info[0], _heartBeatPath); |
@@ -3043,6 +3058,11 @@ protected LibvirtVMDef createVMFromSpec(VirtualMachineTO vmTO) { |
3043 | 3058 | grd.setVcpuNum(vmTO.getCpus()); |
3044 | 3059 | vm.addComp(grd); |
3045 | 3060 |
|
| 3061 | + CpuModeDef cmd = new CpuModeDef(); |
| 3062 | + cmd.setMode(_guestCpuMode); |
| 3063 | + cmd.setModel(_guestCpuModel); |
| 3064 | + vm.addComp(cmd); |
| 3065 | + |
3046 | 3066 | CpuTuneDef ctd = new CpuTuneDef(); |
3047 | 3067 | ctd.setShares(vmTO.getCpus() * vmTO.getSpeed()); |
3048 | 3068 | vm.addComp(ctd); |
@@ -4671,6 +4691,13 @@ private Answer execute(NetworkRulesSystemVmCommand cmd) { |
4671 | 4691 | return new Answer(cmd, success, ""); |
4672 | 4692 | } |
4673 | 4693 |
|
| 4694 | + private String prettyVersion(long version) { |
| 4695 | + long major = version / 1000000; |
| 4696 | + long minor = version % 1000000 / 1000; |
| 4697 | + long release = version % 1000000 % 1000; |
| 4698 | + return major + "." + minor + "." + release; |
| 4699 | + } |
| 4700 | + |
4674 | 4701 | @Override |
4675 | 4702 | public void setName(String name) { |
4676 | 4703 | // TODO Auto-generated method stub |
|
0 commit comments