Skip to content

Commit 393c3d2

Browse files
committed
복제 기능중 RBD, SharedMountPoint 형식의 두가지 기본스토리지에서 vm스냅샷 기능이 유지 되도록 수정
1 parent 6740e8c commit 393c3d2

2 files changed

Lines changed: 54 additions & 3 deletions

File tree

server/src/main/java/com/cloud/storage/snapshot/SnapshotManagerImpl.java

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.Comparator;
2424
import java.util.Date;
2525
import java.util.HashMap;
26+
import java.util.LinkedHashSet;
2627
import java.util.List;
2728
import java.util.Map;
2829
import java.util.Set;
@@ -187,6 +188,9 @@
187188

188189
@Component
189190
public class SnapshotManagerImpl extends MutualExclusiveIdsManagerBase implements SnapshotManager, SnapshotApiService, Configurable {
191+
192+
private static final String KVM_STORAGE_SNAPSHOT_DETAIL = "kvmStorageSnapshot";
193+
private static final String KVM_FILE_BASED_STORAGE_SNAPSHOT_DETAIL = "kvmFileBasedStorageSnapshot";
190194
@Inject
191195
VMTemplateDao _templateDao;
192196
@Inject
@@ -703,8 +707,8 @@ public Snapshot backupSnapshotFromVmSnapshot(Long snapshotId, Long vmId, Long vo
703707

704708
private void updateSnapshotInfo(Long volumeId, Long vmSnapshotId, VMSnapshotVO vmSnapshot, SnapshotVO snapshot,
705709
SnapshotDataStoreVO snapshotOnPrimaryStore, StoragePoolVO storagePool) {
706-
if ((storagePool.getPoolType() == StoragePoolType.NetworkFilesystem || storagePool.getPoolType() == StoragePoolType.Filesystem) && vmSnapshot.getType() == VMSnapshot.Type.Disk) {
707-
List<VMSnapshotDetailsVO> vmSnapshotDetails = vmSnapshotDetailsDao.findDetails(vmSnapshotId, "kvmStorageSnapshot");
710+
if (isFileBasedKvmPrimaryPool(storagePool.getPoolType()) && vmSnapshot.getType() == VMSnapshot.Type.Disk) {
711+
List<VMSnapshotDetailsVO> vmSnapshotDetails = getVmSnapshotVolumeDetails(vmSnapshotId);
708712
for (VMSnapshotDetailsVO vmSnapshotDetailsVO : vmSnapshotDetails) {
709713
SnapshotInfo sInfo = snapshotDataFactory.getSnapshot(Long.parseLong(vmSnapshotDetailsVO.getValue()), storagePool.getId(), DataStoreRole.Primary);
710714
if (sInfo.getVolumeId() == volumeId) {
@@ -722,6 +726,30 @@ private void updateSnapshotInfo(Long volumeId, Long vmSnapshotId, VMSnapshotVO v
722726
}
723727
}
724728

729+
private boolean isFileBasedKvmPrimaryPool(StoragePoolType poolType) {
730+
return poolType == StoragePoolType.NetworkFilesystem
731+
|| poolType == StoragePoolType.Filesystem
732+
|| poolType == StoragePoolType.SharedMountPoint;
733+
}
734+
735+
private List<VMSnapshotDetailsVO> getVmSnapshotVolumeDetails(Long vmSnapshotId) {
736+
List<VMSnapshotDetailsVO> details = new ArrayList<>();
737+
Set<String> uniqueSnapshotIds = new LinkedHashSet<>();
738+
for (String detailName : List.of(KVM_STORAGE_SNAPSHOT_DETAIL, KVM_FILE_BASED_STORAGE_SNAPSHOT_DETAIL)) {
739+
List<VMSnapshotDetailsVO> found = vmSnapshotDetailsDao.findDetails(vmSnapshotId, detailName);
740+
if (CollectionUtils.isEmpty(found)) {
741+
continue;
742+
}
743+
for (VMSnapshotDetailsVO detail : found) {
744+
if (detail == null || !uniqueSnapshotIds.add(detail.getValue())) {
745+
continue;
746+
}
747+
details.add(detail);
748+
}
749+
}
750+
return details;
751+
}
752+
725753
@Override
726754
public SnapshotVO getParentSnapshot(VolumeInfo volume) {
727755
long preId = _snapshotDao.getLastSnapshot(volume.getId(), DataStoreRole.Primary);

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,8 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
443443

444444
private static final String VM_IMPORT_DEFAULT_TEMPLATE_NAME = "system-default-vm-import-dummy-template.iso";
445445
private static final String KVM_VM_IMPORT_DEFAULT_TEMPLATE_NAME = "kvm-default-vm-import-dummy-template";
446+
private static final String KVM_STORAGE_SNAPSHOT_DETAIL = "kvmStorageSnapshot";
447+
private static final String KVM_FILE_BASED_STORAGE_SNAPSHOT_DETAIL = "kvmFileBasedStorageSnapshot";
446448

447449
@Inject
448450
private EntityManager _entityMgr;
@@ -10704,7 +10706,10 @@ public Optional<UserVm> cloneVirtualMachine(CloneVMCmd cmd) throws ResourceAlloc
1070410706
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create vm snapshot: " + e.getMessage(), e);
1070510707
}
1070610708

10707-
List<VMSnapshotDetailsVO> listSnapshots = vmSnapshotDetailsDao.findDetails(vmSnapshot.getId(), "kvmStorageSnapshot");
10709+
List<VMSnapshotDetailsVO> listSnapshots = getVmSnapshotVolumeDetails(vmSnapshot.getId());
10710+
if (CollectionUtils.isEmpty(listSnapshots)) {
10711+
throw new CloudRuntimeException("Could not find volume snapshots mapped to VM snapshot");
10712+
}
1070810713

1070910714
Integer countOfCloneVM = cmd.getCount();
1071010715
for (int cnt = 1; cnt <= countOfCloneVM; cnt++) {
@@ -10823,6 +10828,24 @@ public Optional<UserVm> cloneVirtualMachine(CloneVMCmd cmd) throws ResourceAlloc
1082310828
return null;
1082410829
}
1082510830

10831+
private List<VMSnapshotDetailsVO> getVmSnapshotVolumeDetails(Long vmSnapshotId) {
10832+
List<VMSnapshotDetailsVO> details = new ArrayList<>();
10833+
Set<String> uniqueSnapshotIds = new LinkedHashSet<>();
10834+
for (String detailName : List.of(KVM_STORAGE_SNAPSHOT_DETAIL, KVM_FILE_BASED_STORAGE_SNAPSHOT_DETAIL)) {
10835+
List<VMSnapshotDetailsVO> found = vmSnapshotDetailsDao.findDetails(vmSnapshotId, detailName);
10836+
if (CollectionUtils.isEmpty(found)) {
10837+
continue;
10838+
}
10839+
for (VMSnapshotDetailsVO detail : found) {
10840+
if (detail == null || !uniqueSnapshotIds.add(detail.getValue())) {
10841+
continue;
10842+
}
10843+
details.add(detail);
10844+
}
10845+
}
10846+
return details;
10847+
}
10848+
1082610849
public UserVm createCloneVM(CloneVMCmd cmd, Long rootVolumeId) throws ConcurrentOperationException, ResourceAllocationException, InsufficientCapacityException, ResourceUnavailableException {
1082710850
//network configurations and check, then create the template
1082810851
UserVm curVm = cmd.getTargetVM();

0 commit comments

Comments
 (0)