Skip to content

Commit 0d24227

Browse files
committed
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.
1 parent 9fbc81e commit 0d24227

4 files changed

Lines changed: 25 additions & 1 deletion

File tree

api/src/com/cloud/storage/Volume.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ enum State {
3333
Expunging("The volume is being expunging"),
3434
Destroy("The volume is destroyed, and can't be recovered."),
3535
Uploading ("The volume upload is in progress"),
36-
Uploaded ("The volume is uploaded"),
36+
Uploaded ("The volume is uploaded and present on secondary storage"),
3737
UploadError ("The volume couldnt be uploaded");
3838

3939
String _description;

server/src/com/cloud/storage/StorageManager.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,4 +226,6 @@ VolumeVO copyVolumeFromSecToPrimary(VolumeVO volume, VMInstanceVO vm,
226226
Long clusterId, ServiceOfferingVO offering,
227227
DiskOfferingVO diskOffering, List<StoragePoolVO> avoids, long size,
228228
HypervisorType hyperType) throws NoTransitionException;
229+
230+
String getSupportedImageFormatForCluster(Long clusterId);
229231
}

server/src/com/cloud/storage/StorageManagerImpl.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3802,4 +3802,21 @@ public List<VolumeVO> searchForVolumes(ListVolumesCmd cmd) {
38023802
return _volumeDao.search(sc, searchFilter);
38033803
}
38043804

3805+
@Override
3806+
public String getSupportedImageFormatForCluster(Long clusterId) {
3807+
ClusterVO cluster = ApiDBUtils.findClusterById(clusterId);
3808+
3809+
if (cluster.getHypervisorType() == HypervisorType.XenServer) {
3810+
return "vhd";
3811+
} else if (cluster.getHypervisorType() == HypervisorType.KVM) {
3812+
return "qcow2";
3813+
} else if (cluster.getHypervisorType() == HypervisorType.VMware) {
3814+
return "ova";
3815+
} else if (cluster.getHypervisorType() == HypervisorType.Ovm) {
3816+
return "raw";
3817+
} else {
3818+
return null;
3819+
}
3820+
}
3821+
38053822
}

server/src/com/cloud/vm/UserVmManagerImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,11 @@ public Volume attachVolumeToVM(AttachVolumeCmd command) {
590590
volume = _storageMgr.createVolume(volume, vm, rootDiskTmplt, dcVO, pod, rootDiskPool.getClusterId(), svo, diskVO, new ArrayList<StoragePoolVO>(), volume.getSize(), rootDiskHyperType);
591591
}else {
592592
try {
593+
// Format of data disk should be the same as root disk
594+
if(_storageMgr.getSupportedImageFormatForCluster(rootDiskPool.getClusterId()) != volHostVO.getFormat().getFileExtension()){
595+
throw new InvalidParameterValueException("Failed to attach volume to VM since volumes format " +volHostVO.getFormat().getFileExtension()+
596+
" is not compatible with the vm hypervisor type" );
597+
}
593598
volume = _storageMgr.copyVolumeFromSecToPrimary(volume, vm, rootDiskTmplt, dcVO, pod, rootDiskPool.getClusterId(), svo, diskVO, new ArrayList<StoragePoolVO>(), volume.getSize(), rootDiskHyperType);
594599
} catch (NoTransitionException e) {
595600
e.printStackTrace();

0 commit comments

Comments
 (0)