@@ -2593,7 +2593,7 @@ protected StartAnswer execute(StartCommand cmd) {
25932593
25942594 Map <String , Map <String , String >> iqnToData = new HashMap <>();
25952595
2596- postDiskConfigBeforeStart (vmMo , vmSpec , sortedDisks , ideControllerKey , scsiControllerKey , iqnToData , hyperHost , context );
2596+ postDiskConfigBeforeStart (vmMo , vmSpec , sortedDisks , iqnToData , hyperHost , context );
25972597
25982598 //
25992599 // Power-on VM
@@ -3640,18 +3640,18 @@ private Pair<String, String> getVMDiskInfo(String volumePath, boolean isManaged,
36403640
36413641 private VirtualMachineDiskInfo getMatchingExistingDisk (VirtualMachineDiskInfoBuilder diskInfoBuilder , DiskTO vol , VmwareHypervisorHost hyperHost , VmwareContext context )
36423642 throws Exception {
3643- if (diskInfoBuilder != null ) {
3644- VolumeObjectTO volume = (VolumeObjectTO ) vol .getData ();
3645- String chainInfo = volume .getChainInfo ();
3646- Map <String , String > details = vol .getDetails ();
3647- boolean isManaged = details != null && Boolean .parseBoolean (details .get (DiskTO .MANAGED ));
3648- String iScsiName = details .get (DiskTO .IQN );
3649- String datastoreUUID = volume .getDataStore ().getUuid ();
3650-
3651- return getMatchingExistingDiskWithVolumeDetails (diskInfoBuilder , volume .getPath (), chainInfo , isManaged , iScsiName , datastoreUUID , hyperHost , context );
3652- } else {
3643+ if (diskInfoBuilder == null ) {
36533644 return null ;
36543645 }
3646+
3647+ VolumeObjectTO volume = (VolumeObjectTO ) vol .getData ();
3648+ String chainInfo = volume .getChainInfo ();
3649+ Map <String , String > details = vol .getDetails ();
3650+ boolean isManaged = details != null && Boolean .parseBoolean (details .get (DiskTO .MANAGED ));
3651+ String iScsiName = details .get (DiskTO .IQN );
3652+ String datastoreUUID = volume .getDataStore ().getUuid ();
3653+
3654+ return getMatchingExistingDiskWithVolumeDetails (diskInfoBuilder , volume .getPath (), chainInfo , isManaged , iScsiName , datastoreUUID , hyperHost , context );
36553655 }
36563656
36573657 private String getDiskController (VirtualMachineMO vmMo , VirtualMachineDiskInfo matchingExistingDisk , DiskTO vol , Pair <String , String > controllerInfo , boolean deployAsIs ) throws Exception {
@@ -3676,34 +3676,36 @@ private String getDiskController(VirtualMachineMO vmMo, VirtualMachineDiskInfo m
36763676 return VmwareHelper .getControllerBasedOnDiskType (controllerInfo , vol );
36773677 }
36783678
3679- private void postDiskConfigBeforeStart (VirtualMachineMO vmMo , VirtualMachineTO vmSpec , DiskTO [] sortedDisks , int ideControllerKey ,
3680- int scsiControllerKey , Map <String , Map <String , String >> iqnToData , VmwareHypervisorHost hyperHost , VmwareContext context ) throws Exception {
3679+ private void postDiskConfigBeforeStart (VirtualMachineMO vmMo , VirtualMachineTO vmSpec , DiskTO [] sortedDisks ,
3680+ Map <String , Map <String , String >> iqnToData , VmwareHypervisorHost hyperHost , VmwareContext context ) throws Exception {
36813681 VirtualMachineDiskInfoBuilder diskInfoBuilder = vmMo .getDiskInfoBuilder ();
36823682
36833683 for (DiskTO vol : sortedDisks ) {
36843684 if (vol .getType () == Volume .Type .ISO )
36853685 continue ;
36863686
3687- VolumeObjectTO volumeTO = (VolumeObjectTO ) vol .getData ();
3688-
36893687 VirtualMachineDiskInfo diskInfo = getMatchingExistingDisk (diskInfoBuilder , vol , hyperHost , context );
3690- assert (diskInfo != null );
3688+ if (diskInfo == null ) {
3689+ continue ;
3690+ }
36913691
36923692 String [] diskChain = diskInfo .getDiskChain ();
3693- assert (diskChain .length > 0 );
3693+ if (diskChain .length <= 0 ) {
3694+ continue ;
3695+ }
36943696
3695- Map <String , String > details = vol .getDetails ();
3696- boolean managed = false ;
3697+ DatastoreFile file = new DatastoreFile (diskChain [0 ]);
36973698
3699+ boolean managed = false ;
3700+ Map <String , String > details = vol .getDetails ();
36983701 if (details != null ) {
36993702 managed = Boolean .parseBoolean (details .get (DiskTO .MANAGED ));
37003703 }
37013704
3702- DatastoreFile file = new DatastoreFile ( diskChain [ 0 ] );
3705+ VolumeObjectTO volumeTO = ( VolumeObjectTO ) vol . getData ( );
37033706
37043707 if (managed ) {
37053708 DatastoreFile originalFile = new DatastoreFile (volumeTO .getPath ());
3706-
37073709 if (!file .getFileBaseName ().equalsIgnoreCase (originalFile .getFileBaseName ())) {
37083710 if (logger .isInfoEnabled ())
37093711 logger .info ("Detected disk-chain top file change on volume: " + volumeTO .getId () + " " + volumeTO .getPath () + " -> " + diskChain [0 ]);
@@ -3716,7 +3718,6 @@ private void postDiskConfigBeforeStart(VirtualMachineMO vmMo, VirtualMachineTO v
37163718 }
37173719
37183720 VolumeObjectTO volInSpec = getVolumeInSpec (vmSpec , volumeTO );
3719-
37203721 if (volInSpec != null ) {
37213722 if (managed ) {
37223723 Map <String , String > data = new HashMap <>();
@@ -3881,20 +3882,20 @@ private DatastoreMO getDataStoreWhereDiskExists(VmwareHypervisorHost hyperHost,
38813882 if (diskInfo != null ) {
38823883 logger .info ("Found existing disk info from volume path: " + volume .getPath ());
38833884 return dsMo ;
3884- } else {
3885- String chainInfo = volume . getChainInfo ();
3886- if ( chainInfo != null ) {
3887- VirtualMachineDiskInfo infoInChain = _gson . fromJson (chainInfo , VirtualMachineDiskInfo . class );
3888- if ( infoInChain != null ) {
3889- String [] disks = infoInChain . getDiskChain ();
3890- if ( disks . length > 0 ) {
3891- for ( String diskPath : disks ) {
3892- DatastoreFile file = new DatastoreFile ( diskPath );
3893- diskInfo = diskInfoBuilder . getDiskInfoByBackingFileBaseName ( file . getFileBaseName (), dsName );
3894- if ( diskInfo != null ) {
3895- logger . info ( "Found existing disk from chain info: " + diskPath );
3896- return dsMo ;
3897- }
3885+ }
3886+
3887+ String chainInfo = volume . getChainInfo ();
3888+ if (chainInfo != null ) {
3889+ VirtualMachineDiskInfo infoInChain = _gson . fromJson ( chainInfo , VirtualMachineDiskInfo . class );
3890+ if ( infoInChain != null ) {
3891+ String [] disks = infoInChain . getDiskChain ();
3892+ if ( disks . length > 0 ) {
3893+ for ( String diskPath : disks ) {
3894+ DatastoreFile file = new DatastoreFile ( diskPath );
3895+ diskInfo = diskInfoBuilder . getDiskInfoByBackingFileBaseName ( file . getFileBaseName (), dsName );
3896+ if ( diskInfo != null ) {
3897+ logger . info ( "Found existing disk from chain info: " + diskPath ) ;
3898+ return dsMo ;
38983899 }
38993900 }
39003901 }
@@ -4757,7 +4758,7 @@ private Answer migrateAndAnswer(VirtualMachineMO vmMo, String poolUuid, VmwareHy
47574758 Map <Integer , Long > volumeDeviceKey = new HashMap <>();
47584759 if (cmd instanceof MigrateVolumeCommand ) { // Else device keys will be found in relocateVirtualMachine
47594760 MigrateVolumeCommand mcmd = (MigrateVolumeCommand ) cmd ;
4760- addVolumeDiskmapping (vmMo , volumeDeviceKey , mcmd .getVolumePath (), mcmd .getVolumeId ());
4761+ addVolumeDiskMapping (vmMo , volumeDeviceKey , mcmd .getVolumePath (), mcmd .getVolumeId ());
47614762 if (logger .isTraceEnabled ()) {
47624763 for (Integer diskId : volumeDeviceKey .keySet ()) {
47634764 logger .trace (String .format ("Disk to migrate has disk id %d and volumeId %d" , diskId , volumeDeviceKey .get (diskId )));
@@ -4775,9 +4776,7 @@ private Answer migrateAndAnswer(VirtualMachineMO vmMo, String poolUuid, VmwareHy
47754776
47764777 Answer createAnswerForCmd (VirtualMachineMO vmMo , List <VolumeObjectTO > volumeObjectToList , Command cmd , Map <Integer , Long > volumeDeviceKey ) throws Exception {
47774778 List <VolumeObjectTO > volumeToList ;
4778- VirtualMachineDiskInfoBuilder diskInfoBuilder = vmMo .getDiskInfoBuilder ();
47794779 VirtualDisk [] disks = vmMo .getAllDiskDevice ();
4780- Answer answer ;
47814780 if (logger .isTraceEnabled ()) {
47824781 logger .trace (String .format ("creating answer for %s" , cmd .getClass ().getSimpleName ()));
47834782 }
@@ -4794,7 +4793,7 @@ Answer createAnswerForCmd(VirtualMachineMO vmMo, List<VolumeObjectTO> volumeObje
47944793 return new Answer (cmd , false , null );
47954794 }
47964795
4797- private void addVolumeDiskmapping (VirtualMachineMO vmMo , Map <Integer , Long > volumeDeviceKey , String volumePath , long volumeId ) throws Exception {
4796+ private void addVolumeDiskMapping (VirtualMachineMO vmMo , Map <Integer , Long > volumeDeviceKey , String volumePath , long volumeId ) throws Exception {
47984797 if (logger .isDebugEnabled ()) {
47994798 logger .debug (String .format ("locating disk for volume (%d) using path %s" , volumeId , volumePath ));
48004799 }
0 commit comments