From e2e7da3ff471cd40ded82150037e292a47c0c031 Mon Sep 17 00:00:00 2001 From: Nitin Date: Wed, 9 Nov 2011 16:33:09 +0530 Subject: [PATCH] bug 11428: Under VMware with current version, for snapshot related related operations, 1) if snapshot is originally created from root volume, allow only CreateTemplateCommand from snapshot 2) if snapshot is originally created from data volume, allow only CreateVolumeCommand from snapshot Reviewed by - Kishan status 11428: resolved fixed --- server/src/com/cloud/storage/StorageManagerImpl.java | 7 +++++++ server/src/com/cloud/vm/UserVmManagerImpl.java | 12 ++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/server/src/com/cloud/storage/StorageManagerImpl.java b/server/src/com/cloud/storage/StorageManagerImpl.java index 2da24e40ff0..5ced49fea08 100755 --- a/server/src/com/cloud/storage/StorageManagerImpl.java +++ b/server/src/com/cloud/storage/StorageManagerImpl.java @@ -107,6 +107,7 @@ import com.cloud.exception.ResourceAllocationException; import com.cloud.exception.ResourceInUseException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.exception.StorageUnavailableException; +import com.cloud.exception.UnsupportedServiceException; import com.cloud.host.Host; import com.cloud.host.HostVO; import com.cloud.host.Status; @@ -1674,6 +1675,12 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag //check snapshot permissions _accountMgr.checkAccess(caller, null, snapshotCheck); + + // bug #11428. Operation not supported if vmware and snapshots parent volume = ROOT + if(snapshotCheck.getHypervisorType() == HypervisorType.VMware + && _volumeDao.findByIdIncludingRemoved(snapshotCheck.getVolumeId()).getVolumeType() == Type.ROOT){ + throw new UnsupportedServiceException("operation not supported, snapshot with id " + snapshotId + " is created from ROOT volume"); + } } // Verify that zone exists diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index 70f8a1e92f4..3ad1b3a0a35 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -108,6 +108,7 @@ import com.cloud.exception.PermissionDeniedException; import com.cloud.exception.ResourceAllocationException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.exception.StorageUnavailableException; +import com.cloud.exception.UnsupportedServiceException; import com.cloud.exception.VirtualMachineMigrationException; import com.cloud.ha.HighAvailabilityManager; import com.cloud.host.Host; @@ -1357,6 +1358,9 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager hyperType = _volsDao.getHypervisorType(volumeId); } else { // create template from snapshot SnapshotVO snapshot = _snapshotDao.findById(snapshotId); + volume = _volsDao.findById(snapshot.getVolumeId()); + VolumeVO snapshotVolume = _volsDao.findByIdIncludingRemoved(snapshot.getVolumeId()); + if (snapshot == null) { throw new InvalidParameterValueException("Failed to create private template record, unable to find snapshot " + snapshotId); } @@ -1367,11 +1371,15 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager if (snapshot.getStatus() != Snapshot.Status.BackedUp) { throw new InvalidParameterValueException("Snapshot id=" + snapshotId + " is not in " + Snapshot.Status.BackedUp + " state yet and can't be used for template creation"); } + + // bug #11428. Operation not supported if vmware and snapshots parent volume = ROOT + if(snapshot.getHypervisorType() == HypervisorType.VMware && snapshotVolume.getVolumeType() == Type.DATADISK){ + throw new UnsupportedServiceException("operation not supported, snapshot with id " + snapshotId + " is created from Data Disk"); + } domainId = snapshot.getDomainId(); accountId = snapshot.getAccountId(); - hyperType = snapshot.getHypervisorType(); - volume = _volsDao.findById(snapshot.getVolumeId()); + hyperType = snapshot.getHypervisorType(); } VMTemplateVO existingTemplate = _templateDao.findByTemplateNameAccountId(name, accountId);