From 8ac10c5941db1fe1bdf3646363312ed08ec1e357 Mon Sep 17 00:00:00 2001 From: Nitin Mehta Date: Fri, 4 May 2012 16:30:08 +0530 Subject: [PATCH] bug CS-14739: Check for the volume and vm hypervisor compatibility before attaching the volume to vm in case the volume is on secondary storage. --- api/src/com/cloud/storage/Volume.java | 2 +- .../src/com/cloud/storage/StorageManager.java | 2 ++ .../com/cloud/storage/StorageManagerImpl.java | 17 +++++++++++++++++ server/src/com/cloud/vm/UserVmManagerImpl.java | 5 +++++ 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/api/src/com/cloud/storage/Volume.java b/api/src/com/cloud/storage/Volume.java index 25d64e8d891..f31454e66c2 100755 --- a/api/src/com/cloud/storage/Volume.java +++ b/api/src/com/cloud/storage/Volume.java @@ -33,7 +33,7 @@ public interface Volume extends ControlledEntity, BasedOn, StateObject avoids, long size, HypervisorType hyperType) throws NoTransitionException; + + String getSupportedImageFormatForCluster(Long clusterId); } diff --git a/server/src/com/cloud/storage/StorageManagerImpl.java b/server/src/com/cloud/storage/StorageManagerImpl.java index 7be946b2849..87012fbb8d5 100755 --- a/server/src/com/cloud/storage/StorageManagerImpl.java +++ b/server/src/com/cloud/storage/StorageManagerImpl.java @@ -3802,4 +3802,21 @@ public class StorageManagerImpl implements StorageManager, Manager, ClusterManag return _volumeDao.search(sc, searchFilter); } + @Override + public String getSupportedImageFormatForCluster(Long clusterId) { + ClusterVO cluster = ApiDBUtils.findClusterById(clusterId); + + if (cluster.getHypervisorType() == HypervisorType.XenServer) { + return "vhd"; + } else if (cluster.getHypervisorType() == HypervisorType.KVM) { + return "qcow2"; + } else if (cluster.getHypervisorType() == HypervisorType.VMware) { + return "ova"; + } else if (cluster.getHypervisorType() == HypervisorType.Ovm) { + return "raw"; + } else { + return null; + } + } + } diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index 96e94f7125e..a6ff9941cac 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -590,6 +590,11 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager volume = _storageMgr.createVolume(volume, vm, rootDiskTmplt, dcVO, pod, rootDiskPool.getClusterId(), svo, diskVO, new ArrayList(), volume.getSize(), rootDiskHyperType); }else { try { + // Format of data disk should be the same as root disk + if(_storageMgr.getSupportedImageFormatForCluster(rootDiskPool.getClusterId()) != volHostVO.getFormat().getFileExtension()){ + throw new InvalidParameterValueException("Failed to attach volume to VM since volumes format " +volHostVO.getFormat().getFileExtension()+ + " is not compatible with the vm hypervisor type" ); + } volume = _storageMgr.copyVolumeFromSecToPrimary(volume, vm, rootDiskTmplt, dcVO, pod, rootDiskPool.getClusterId(), svo, diskVO, new ArrayList(), volume.getSize(), rootDiskHyperType); } catch (NoTransitionException e) { e.printStackTrace();