2727import com .cloud .hypervisor .Hypervisor ;
2828import com .cloud .storage .ScopeType ;
2929import com .cloud .storage .Storage ;
30- import com .cloud .storage .StoragePoolHostVO ;
3130import com .cloud .storage .Volume ;
3231import com .cloud .storage .VolumeVO ;
33- import com .cloud .storage .dao .StoragePoolHostDao ;
3432import com .cloud .storage .dao .VolumeDao ;
3533import com .cloud .utils .Pair ;
3634import com .cloud .utils .component .AdapterBase ;
@@ -84,9 +82,6 @@ public class NASBackupProvider extends AdapterBase implements BackupProvider, Co
8482 @ Inject
8583 private VolumeDao volumeDao ;
8684
87- @ Inject
88- private StoragePoolHostDao storagePoolHostDao ;
89-
9085 @ Inject
9186 private VMInstanceDao vmInstanceDao ;
9287
@@ -268,19 +263,27 @@ private List<String> getVolumePaths(List<VolumeVO> volumes) {
268263 return volumePaths ;
269264 }
270265
266+ private String getVolumePathPrefix (StoragePoolVO storagePool ) {
267+ String volumePathPrefix ;
268+ if (ScopeType .HOST .equals (storagePool .getScope ()) ||
269+ Storage .StoragePoolType .SharedMountPoint .equals (storagePool .getPoolType ()) ||
270+ Storage .StoragePoolType .RBD .equals (storagePool .getPoolType ())) {
271+ volumePathPrefix = storagePool .getPath ();
272+ } else {
273+ // Should be Storage.StoragePoolType.NetworkFilesystem
274+ volumePathPrefix = String .format ("/mnt/%s" , storagePool .getUuid ());
275+ }
276+ return volumePathPrefix ;
277+ }
278+
271279 @ Override
272280 public Pair <Boolean , String > restoreBackedUpVolume (Backup backup , String volumeUuid , String hostIp , String dataStoreUuid , Pair <String , VirtualMachine .State > vmNameAndState ) {
273281 final VolumeVO volume = volumeDao .findByUuid (volumeUuid );
274282 final VirtualMachine backupSourceVm = vmInstanceDao .findById (backup .getVmId ());
275- final StoragePoolHostVO dataStore = storagePoolHostDao .findByUuid (dataStoreUuid );
276- LOG .info ("NASBackupProvider.java restoreBackedUpVolume:::::" );
277- LOG .info ("hostIP: " +hostIp );
283+ final StoragePoolVO pool = primaryDataStoreDao .findByUuid (dataStoreUuid );
278284 HostVO hostVO = hostDao .findByIp (hostIp );
279- LOG .info ("hostVO: " +hostVO );
280285 if (hostVO == null ) {
281- LOG .info ("hostVO == null" );
282286 hostVO = hostDao .findByName (hostIp );
283- LOG .info ("hostVO: " +hostVO );
284287 }
285288
286289 Optional <Backup .VolumeInfo > matchingVolume = getBackedUpVolumeInfo (backupSourceVm .getBackupVolumeList (), volumeUuid );
@@ -299,7 +302,7 @@ public Pair<Boolean, String> restoreBackedUpVolume(Backup backup, String volumeU
299302 restoredVolume .setUuid (volumeUUID );
300303 restoredVolume .setRemoved (null );
301304 restoredVolume .setDisplayVolume (true );
302- restoredVolume .setPoolId (dataStore . getPoolId ());
305+ restoredVolume .setPoolId (pool . getId ());
303306 restoredVolume .setPath (restoredVolume .getUuid ());
304307 restoredVolume .setState (Volume .State .Copying );
305308 restoredVolume .setFormat (Storage .ImageFormat .QCOW2 );
@@ -311,7 +314,7 @@ public Pair<Boolean, String> restoreBackedUpVolume(Backup backup, String volumeU
311314 restoreCommand .setBackupRepoType (backupRepository .getType ());
312315 restoreCommand .setBackupRepoAddress (backupRepository .getAddress ());
313316 restoreCommand .setVmName (vmNameAndState .first ());
314- restoreCommand .setVolumePaths (Collections .singletonList (String .format ("%s/%s" , dataStore . getLocalPath ( ), volumeUUID )));
317+ restoreCommand .setVolumePaths (Collections .singletonList (String .format ("%s/%s" , getVolumePathPrefix ( pool ), volumeUUID )));
315318 restoreCommand .setDiskType (volume .getVolumeType ().name ().toLowerCase (Locale .ROOT ));
316319 restoreCommand .setVmExists (null );
317320 restoreCommand .setVmState (vmNameAndState .second ());
0 commit comments