2323import java .util .Comparator ;
2424import java .util .Date ;
2525import java .util .HashMap ;
26+ import java .util .LinkedHashSet ;
2627import java .util .List ;
2728import java .util .Map ;
2829import java .util .Set ;
187188
188189@ Component
189190public 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 );
0 commit comments