@@ -2037,21 +2037,46 @@ public void moveAllVmDiskFiles(DatastoreMO destDsMo, String destDsDir, boolean f
2037
2037
vmdkDescriptor = getVmdkFileInfo (fileItem .first ());
2038
2038
2039
2039
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 );
2041
2041
2042
2042
if (vmdkDescriptor != null ) {
2043
2043
String vmdkBaseFileName = vmdkDescriptor .first ().getBaseFileName ();
2044
2044
String baseFilePath = srcFile .getCompanionPath (vmdkBaseFileName );
2045
2045
destFile = new DatastoreFile (destDsMo .getName (), destDsDir , vmdkBaseFileName );
2046
2046
2047
2047
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 );
2049
2049
}
2050
2050
}
2051
2051
}
2052
2052
}
2053
2053
}
2054
2054
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
+
2055
2080
protected VirtualSCSIController getScsiController (DiskControllerType type ) {
2056
2081
switch (type ) {
2057
2082
case pvscsi :
0 commit comments