From f526a92b084392d73db38d0a269e1de2730dc90d Mon Sep 17 00:00:00 2001 From: edison Date: Fri, 29 Oct 2010 15:46:13 -0700 Subject: [PATCH] Only allow to attach a volume to a vm, when they are created by the same hypervisor. --- server/src/com/cloud/vm/UserVmManagerImpl.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index 08d72a0d2e6..dc3d8561cf8 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -462,6 +462,8 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM rootVolumeOfVm = rootVolumesOfVm.get(0); } + HypervisorType rootDiskHyperType = _volsDao.getHypervisorType(rootVolumeOfVm.getId()); + if (volume.getState().equals(Volume.State.Allocated)) { /*Need to create the volume*/ VMTemplateVO rootDiskTmplt = _templateDao.findById(vm.getTemplateId()); @@ -470,8 +472,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM StoragePoolVO rootDiskPool = _storagePoolDao.findById(rootVolumeOfVm.getPoolId()); ServiceOfferingVO svo = _serviceOfferingDao.findById(vm.getServiceOfferingId()); DiskOfferingVO diskVO = _diskOfferingDao.findById(volume.getDiskOfferingId()); - HypervisorType rootDiskHyperType = _volsDao.getHypervisorType(rootVolumeOfVm.getId()); - + volume = _storageMgr.createVolume(volume, vm, rootDiskTmplt, dcVO, pod, rootDiskPool.getClusterId(), svo, diskVO, new ArrayList(), volume.getSize(), rootDiskHyperType); if (volume == null) { @@ -479,6 +480,11 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM } } + HypervisorType dataDiskHyperType = _volsDao.getHypervisorType(volume.getId()); + if (rootDiskHyperType != dataDiskHyperType) { + throw new InvalidParameterValueException("Can't attach a volume created by: " + dataDiskHyperType + " to a " + rootDiskHyperType + " vm"); + } + List vols = _volsDao.findByInstance(vmId); if( deviceId != null ) { if( deviceId.longValue() > 15 || deviceId.longValue() == 0 || deviceId.longValue() == 3) {