Skip to content

Commit 95e41fd

Browse files
Harikrishna Patnalanitinmeh
authored andcommitted
CLOUDSTACK-6023: Non windows instances are created on XenServer with a vcpu-max above supported xenserver limits
Changed the VCPU max limit to 16 and provided a cluster level configuration parameter for this max limit named xen.vm.vcpu.max
1 parent f0b861f commit 95e41fd

3 files changed

Lines changed: 48 additions & 5 deletions

File tree

‎api/src/com/cloud/agent/api/to/VirtualMachineTO.java‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public class VirtualMachineTO {
6060

6161
DiskTO[] disks;
6262
NicTO[] nics;
63+
Integer vcpuMaxLimit;
6364

6465
public VirtualMachineTO(long id, String instanceName, VirtualMachine.Type type, int cpus, Integer speed, long minRam, long maxRam, BootloaderType bootloader, String os, boolean enableHA, boolean limitCpuUse, String vncPassword) {
6566
this.id = id;
@@ -263,5 +264,13 @@ public void setUuid(String uuid) {
263264
this.uuid = uuid;
264265
}
265266

267+
public Integer getVcpuMaxLimit() {
268+
return vcpuMaxLimit;
269+
}
270+
271+
public void setVcpuMaxLimit(Integer vcpuMaxLimit) {
272+
this.vcpuMaxLimit = vcpuMaxLimit;
273+
}
274+
266275

267276
}

‎plugins/hypervisors/xen/src/com/cloud/hypervisor/XenServerGuru.java‎

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,24 @@
3535
import com.cloud.storage.dao.VolumeDao;
3636
import com.cloud.template.VirtualMachineTemplate.BootloaderType;
3737
import com.cloud.utils.Pair;
38+
import com.cloud.vm.UserVmVO;
3839
import com.cloud.vm.VirtualMachine;
3940
import com.cloud.vm.VirtualMachineProfile;
41+
import com.cloud.vm.dao.UserVmDao;
4042
import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
4143
import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector;
4244
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory;
4345
import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
46+
import org.apache.cloudstack.framework.config.Configurable;
4447
import org.apache.cloudstack.storage.command.CopyCommand;
4548
import org.apache.cloudstack.storage.command.DettachCommand;
4649
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
4750
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
51+
import org.apache.cloudstack.framework.config.ConfigKey;
52+
4853

4954
@Local(value=HypervisorGuru.class)
50-
public class XenServerGuru extends HypervisorGuruBase implements HypervisorGuru {
55+
public class XenServerGuru extends HypervisorGuruBase implements HypervisorGuru, Configurable{
5156
@Inject GuestOSDao _guestOsDao;
5257
@Inject
5358
EndPointSelector endPointSelector;
@@ -59,6 +64,11 @@ public class XenServerGuru extends HypervisorGuruBase implements HypervisorGuru
5964
PrimaryDataStoreDao _storagePoolDao;
6065
@Inject
6166
VolumeDataFactory _volFactory;
67+
@Inject
68+
UserVmDao _userVmDao;
69+
70+
static final ConfigKey<Integer> MaxNumberOfVCPUSPerVM = new ConfigKey<Integer>("Advanced", Integer.class, "xen.vm.vcpu.max", "16",
71+
"Maximum number of VCPUs that VM can get in XenServer.", true, ConfigKey.Scope.Cluster);
6272

6373
protected XenServerGuru() {
6474
super();
@@ -76,6 +86,14 @@ public VirtualMachineTO implement(VirtualMachineProfile vm) {
7686
bt = vm.getBootLoaderType();
7787
}
7888
VirtualMachineTO to = toVirtualMachineTO(vm);
89+
UserVmVO userVmVO = _userVmDao.findById(vm.getId());
90+
if (userVmVO != null) {
91+
HostVO host = hostDao.findById(userVmVO.getHostId());
92+
if (host != null) {
93+
to.setVcpuMaxLimit(MaxNumberOfVCPUSPerVM.valueIn(host.getClusterId()));
94+
}
95+
}
96+
7997
to.setBootloader(bt);
8098

8199
// Determine the VM's OS description
@@ -151,4 +169,14 @@ public Pair<Boolean, Long> getCommandHostDelegation(long hostId, Command cmd) {
151169
}
152170
return new Pair<Boolean, Long>(Boolean.FALSE, new Long(hostId));
153171
}
172+
173+
@Override
174+
public String getConfigComponentName() {
175+
return XenServerGuru.class.getSimpleName();
176+
}
177+
178+
@Override
179+
public ConfigKey<?>[] getConfigKeys() {
180+
return new ConfigKey<?>[] {MaxNumberOfVCPUSPerVM};
181+
}
154182
}

‎plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,13 +1265,23 @@ protected VM createVmFromTemplate(Connection conn, VirtualMachineTO vmSpec, Host
12651265
vmr.nameLabel = vmSpec.getName();
12661266
vmr.actionsAfterCrash = Types.OnCrashBehaviour.DESTROY;
12671267
vmr.actionsAfterShutdown = Types.OnNormalExit.DESTROY;
1268+
vmr.VCPUsMax = (long) vmSpec.getCpus(); // FIX ME: In case of dynamic scaling this VCPU max should be the minumum of
1269+
// recommended value for that template and capacity remaining on host
12681270

12691271
if (isDmcEnabled(conn, host) && vmSpec.isEnableDynamicallyScaleVm()) {
12701272
//scaling is allowed
12711273
vmr.memoryStaticMin = getStaticMin(vmSpec.getOs(), vmSpec.getBootloader() == BootloaderType.CD, vmSpec.getMinRam(), vmSpec.getMaxRam());
12721274
vmr.memoryStaticMax = getStaticMax(vmSpec.getOs(), vmSpec.getBootloader() == BootloaderType.CD, vmSpec.getMinRam(), vmSpec.getMaxRam());
12731275
vmr.memoryDynamicMin = vmSpec.getMinRam();
12741276
vmr.memoryDynamicMax = vmSpec.getMaxRam();
1277+
1278+
if (guestOsTypeName.toLowerCase().contains("windows")) {
1279+
vmr.VCPUsMax = (long) vmSpec.getCpus();
1280+
} else {
1281+
if (vmSpec.getVcpuMaxLimit() != null) {
1282+
vmr.VCPUsMax = (long) vmSpec.getVcpuMaxLimit();
1283+
}
1284+
}
12751285
} else {
12761286
//scaling disallowed, set static memory target
12771287
if (vmSpec.isEnableDynamicallyScaleVm() && !isDmcEnabled(conn, host)) {
@@ -1281,12 +1291,8 @@ protected VM createVmFromTemplate(Connection conn, VirtualMachineTO vmSpec, Host
12811291
vmr.memoryStaticMax = vmSpec.getMaxRam();
12821292
vmr.memoryDynamicMin = vmSpec.getMinRam();
12831293
vmr.memoryDynamicMax = vmSpec.getMaxRam();
1284-
}
12851294

1286-
if (guestOsTypeName.toLowerCase().contains("windows")) {
12871295
vmr.VCPUsMax = (long) vmSpec.getCpus();
1288-
} else {
1289-
vmr.VCPUsMax = 32L;
12901296
}
12911297

12921298
vmr.VCPUsAtStartup = (long) vmSpec.getCpus();

0 commit comments

Comments
 (0)