@@ -2629,7 +2629,8 @@ private CpuModeDef createCpuModeDef(VirtualMachineTO vmTO, int vcpus) {
26292629 if (VirtualMachine .Type .User .equals (vmTO .getType ())) {
26302630 cmd .setFeatures (_cpuFeatures );
26312631 }
2632- setCpuTopology (cmd , vcpus , vmTO .getDetails ());
2632+ int vCpusInDef = vmTO .getVcpuMaxLimit () == null ? vcpus : vmTO .getVcpuMaxLimit ();
2633+ setCpuTopology (cmd , vCpusInDef , vmTO .getDetails ());
26332634 return cmd ;
26342635 }
26352636
@@ -4749,7 +4750,7 @@ public boolean isSecureMode(String bootMode) {
47494750 return false ;
47504751 }
47514752
4752- private void setCpuTopology (CpuModeDef cmd , int vcpus , Map <String , String > details ) {
4753+ private void setCpuTopology (CpuModeDef cmd , int vCpusInDef , Map <String , String > details ) {
47534754 if (!enableManuallySettingCpuTopologyOnKvmVm ) {
47544755 s_logger .debug (String .format ("Skipping manually setting CPU topology on VM's XML due to it is disabled in agent.properties {\" property\" : \" %s\" , \" value\" : %s}." ,
47554756 AgentProperties .ENABLE_MANUALLY_SETTING_CPU_TOPOLOGY_ON_KVM_VM .getName (), enableManuallySettingCpuTopologyOnKvmVm ));
@@ -4760,19 +4761,19 @@ private void setCpuTopology(CpuModeDef cmd, int vcpus, Map<String, String> detai
47604761 if (details != null ) {
47614762 final String coresPerSocket = details .get (VmDetailConstants .CPU_CORE_PER_SOCKET );
47624763 final int intCoresPerSocket = NumbersUtil .parseInt (coresPerSocket , numCoresPerSocket );
4763- if (intCoresPerSocket > 0 && vcpus % intCoresPerSocket == 0 ) {
4764+ if (intCoresPerSocket > 0 && vCpusInDef % intCoresPerSocket == 0 ) {
47644765 numCoresPerSocket = intCoresPerSocket ;
47654766 }
47664767 }
47674768 if (numCoresPerSocket <= 0 ) {
4768- if (vcpus % 6 == 0 ) {
4769+ if (vCpusInDef % 6 == 0 ) {
47694770 numCoresPerSocket = 6 ;
4770- } else if (vcpus % 4 == 0 ) {
4771+ } else if (vCpusInDef % 4 == 0 ) {
47714772 numCoresPerSocket = 4 ;
47724773 }
47734774 }
47744775 if (numCoresPerSocket > 0 ) {
4775- cmd .setTopology (numCoresPerSocket , vcpus / numCoresPerSocket );
4776+ cmd .setTopology (numCoresPerSocket , vCpusInDef / numCoresPerSocket );
47764777 }
47774778 }
47784779
0 commit comments