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
(cherry picked from commit 95e41fdf0d)

Signed-off-by: Animesh Chaturvedi <animesh@apache.org>
This commit is contained in:
Harikrishna Patnala 2014-02-07 16:44:11 +05:30 committed by Wei Zhou
parent 63fbd16dd1
commit 0b31732bb1
3 changed files with 51 additions and 13 deletions

View File

@ -62,6 +62,7 @@ public class VirtualMachineTO {
DiskTO[] disks;
NicTO[] nics;
GPUDeviceTO gpuDevice;
Integer vcpuMaxLimit;
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) {
@ -284,4 +285,12 @@ public class VirtualMachineTO {
this.platformEmulator = platformEmulator;
}
public Integer getVcpuMaxLimit() {
return vcpuMaxLimit;
}
public void setVcpuMaxLimit(Integer vcpuMaxLimit) {
this.vcpuMaxLimit = vcpuMaxLimit;
}
}

View File

@ -26,11 +26,13 @@ import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector;
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory;
import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
import org.apache.cloudstack.framework.config.Configurable;
import org.apache.cloudstack.hypervisor.xenserver.XenserverConfigs;
import org.apache.cloudstack.storage.command.CopyCommand;
import org.apache.cloudstack.storage.command.DettachCommand;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
import org.apache.cloudstack.framework.config.ConfigKey;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.to.DataObjectType;
@ -50,11 +52,14 @@ import com.cloud.storage.dao.GuestOSHypervisorDao;
import com.cloud.storage.dao.VolumeDao;
import com.cloud.template.VirtualMachineTemplate.BootloaderType;
import com.cloud.utils.Pair;
import com.cloud.vm.UserVmVO;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineProfile;
import com.cloud.vm.dao.UserVmDao;
@Local(value = HypervisorGuru.class)
public class XenServerGuru extends HypervisorGuruBase implements HypervisorGuru {
public class XenServerGuru extends HypervisorGuruBase implements HypervisorGuru, Configurable{
@Inject
GuestOSDao _guestOsDao;
@Inject
@ -69,6 +74,11 @@ public class XenServerGuru extends HypervisorGuruBase implements HypervisorGuru
PrimaryDataStoreDao _storagePoolDao;
@Inject
VolumeDataFactory _volFactory;
@Inject
UserVmDao _userVmDao;
static final ConfigKey<Integer> MaxNumberOfVCPUSPerVM = new ConfigKey<Integer>("Advanced", Integer.class, "xen.vm.vcpu.max", "16",
"Maximum number of VCPUs that VM can get in XenServer.", true, ConfigKey.Scope.Cluster);
protected XenServerGuru() {
super();
@ -86,6 +96,14 @@ public class XenServerGuru extends HypervisorGuruBase implements HypervisorGuru
bt = vm.getBootLoaderType();
}
VirtualMachineTO to = toVirtualMachineTO(vm);
UserVmVO userVmVO = _userVmDao.findById(vm.getId());
if (userVmVO != null) {
HostVO host = hostDao.findById(userVmVO.getHostId());
if (host != null) {
to.setVcpuMaxLimit(MaxNumberOfVCPUSPerVM.valueIn(host.getClusterId()));
}
}
to.setBootloader(bt);
// Determine the VM's OS description
@ -171,4 +189,14 @@ public class XenServerGuru extends HypervisorGuruBase implements HypervisorGuru
}
return new Pair<Boolean, Long>(Boolean.FALSE, new Long(hostId));
}
@Override
public String getConfigComponentName() {
return XenServerGuru.class.getSimpleName();
}
@Override
public ConfigKey<?>[] getConfigKeys() {
return new ConfigKey<?>[] {MaxNumberOfVCPUSPerVM};
}
}

View File

@ -1314,6 +1314,8 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
vmr.nameLabel = vmSpec.getName();
vmr.actionsAfterCrash = Types.OnCrashBehaviour.DESTROY;
vmr.actionsAfterShutdown = Types.OnNormalExit.DESTROY;
vmr.VCPUsMax = (long) vmSpec.getCpus(); // FIX ME: In case of dynamic scaling this VCPU max should be the minumum of
// recommended value for that template and capacity remaining on host
if (isDmcEnabled(conn, host) && vmSpec.isEnableDynamicallyScaleVm()) {
//scaling is allowed
@ -1321,6 +1323,14 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
vmr.memoryStaticMax = getStaticMax(vmSpec.getOs(), vmSpec.getBootloader() == BootloaderType.CD, vmSpec.getMinRam(), vmSpec.getMaxRam());
vmr.memoryDynamicMin = vmSpec.getMinRam();
vmr.memoryDynamicMax = vmSpec.getMaxRam();
if (guestOsTypeName.toLowerCase().contains("windows")) {
vmr.VCPUsMax = (long) vmSpec.getCpus();
} else {
if (vmSpec.getVcpuMaxLimit() != null) {
vmr.VCPUsMax = (long) vmSpec.getVcpuMaxLimit();
}
}
} else {
//scaling disallowed, set static memory target
if (vmSpec.isEnableDynamicallyScaleVm() && !isDmcEnabled(conn, host)) {
@ -1330,20 +1340,11 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
vmr.memoryStaticMax = vmSpec.getMaxRam();
vmr.memoryDynamicMin = vmSpec.getMinRam();
vmr.memoryDynamicMax = vmSpec.getMaxRam();
vmr.VCPUsMax = (long) vmSpec.getCpus();
}
if (guestOsTypeName.toLowerCase().contains("windows")) {
vmr.VCPUsMax = (long)vmSpec.getCpus();
} else {
// XenServer has a documented limit of 16 vcpus per vm
vmr.VCPUsMax = 2L * vmSpec.getCpus();
if (vmr.VCPUsMax > 16)
{
vmr.VCPUsMax = 16L;
}
}
vmr.VCPUsAtStartup = (long)vmSpec.getCpus();
vmr.VCPUsAtStartup = (long) vmSpec.getCpus();
vmr.consoles.clear();
VM vm = VM.create(conn, vmr);