@@ -2037,21 +2037,46 @@ public void moveAllVmDiskFiles(DatastoreMO destDsMo, String destDsDir, boolean f
20372037 vmdkDescriptor = getVmdkFileInfo (fileItem .first ());
20382038
20392039 logger .info ("Move VM disk file " + srcFile .getPath () + " to " + destFile .getPath ());
2040- srcDsMo . moveDatastoreFile (fileItem .first (), dcMo .getMor (), destDsMo .getMor (), destFile .getPath (), dcMo .getMor (), true );
2040+ moveDatastoreFile (srcDsMo , fileItem .first (), dcMo .getMor (), destDsMo .getMor (), destFile .getPath (), dcMo .getMor (), true );
20412041
20422042 if (vmdkDescriptor != null ) {
20432043 String vmdkBaseFileName = vmdkDescriptor .first ().getBaseFileName ();
20442044 String baseFilePath = srcFile .getCompanionPath (vmdkBaseFileName );
20452045 destFile = new DatastoreFile (destDsMo .getName (), destDsDir , vmdkBaseFileName );
20462046
20472047 logger .info ("Move VM disk file " + baseFilePath + " to " + destFile .getPath ());
2048- srcDsMo . moveDatastoreFile (baseFilePath , dcMo .getMor (), destDsMo .getMor (), destFile .getPath (), dcMo .getMor (), true );
2048+ moveDatastoreFile (srcDsMo , baseFilePath , dcMo .getMor (), destDsMo .getMor (), destFile .getPath (), dcMo .getMor (), true );
20492049 }
20502050 }
20512051 }
20522052 }
20532053 }
20542054
2055+ private boolean moveDatastoreFile (final DatastoreMO dsMo , String srcFilePath , ManagedObjectReference morSrcDc , ManagedObjectReference morDestDs ,
2056+ String destFilePath , ManagedObjectReference morDestDc , boolean forceOverwrite ) throws Exception {
2057+ final int retry = 20 ;
2058+ int retryAttempt = 0 ;
2059+ while (++retryAttempt <= retry ) {
2060+ try {
2061+ logger .debug (String .format ("Move datastore file %s, attempt #%d" , srcFilePath , retryAttempt ));
2062+ return dsMo .moveDatastoreFile (srcFilePath , morSrcDc , morDestDs , destFilePath , morDestDc , forceOverwrite );
2063+ } catch (Exception e ) {
2064+ logger .info (String .format ("Got exception while moving datastore file %s " , srcFilePath ), e );
2065+ if (e .getMessage () != null && e .getMessage ().contains ("Unable to access file" )) {
2066+ logger .debug (String .format ("Failed to move datastore file %s. Retrying" , srcFilePath ));
2067+ try {
2068+ Thread .sleep (1000 );
2069+ } catch (InterruptedException ie ) {
2070+ logger .debug (String .format ("Waiting to move datastore file %s been interrupted: " , srcFilePath ));
2071+ }
2072+ } else {
2073+ throw e ;
2074+ }
2075+ }
2076+ }
2077+ return false ;
2078+ }
2079+
20552080 protected VirtualSCSIController getScsiController (DiskControllerType type ) {
20562081 switch (type ) {
20572082 case pvscsi :
0 commit comments