private FSVolume findVolumeForHardLink ( String srcFileSystem , int srcNamespaceId , Block srcBlock , File srcBlockFile ) throws IOException { FSVolume dstVol = null ; if ( srcBlockFile == null || ! srcBlockFile . exists ( ) ) { throw new IOException ( "File " + srcBlockFile + " is not valid or does not have" + " a valid block file" ) ; } // The source file might not necessarily be a part of the FSVolumeSet of // this datanode, it could be part of a FSVolumeSet of another datanode on // the same host. DatanodeBlockInfo blockInfo = volumeMap . get ( srcNamespaceId , srcBlock ) ; if ( blockInfo != null ) { dstVol = blockInfo . getBlockDataFile ( ) . getVolume ( ) ; } else { for ( FSVolume volume : volumes . getVolumes ( ) ) { String volFileSystem = volume . getFileSystem ( ) ; if ( volFileSystem . equals ( srcFileSystem ) ) { dstVol = volume ; break ; } } } return dstVol ; }
Find a volume on the datanode for the destination block to be placed on . It tries to place the destination block on the same volume as the source block since hardlinks can be performed only between two files on the same disk