@@ -4668,20 +4668,13 @@ private void prepareDatastoreForZoneWideManagedStorageInterClusterMigration(Disk
46684668 boolean isInterClusterMigration = details .containsKey (DiskTO .INTER_CLUSTER_MIGRATION ) && BooleanUtils .toBoolean (details .get (DiskTO .INTER_CLUSTER_MIGRATION ));
46694669
46704670 if (isManaged && isZoneWideStorage && isInterClusterMigration ) {
4671- s_logger .debug ("Preparing storage on destination host " + hyperHost .getHyperHostName ());
4671+ s_logger .debug (String . format ( "Preparing storage on destination cluster for host %s" , hyperHost .getHyperHostName () ));
46724672 String iScsiName = details .get (DiskTO .IQN ); // details should not be null for managed storage (it may or may not be null for non-managed storage)
46734673 String datastoreName = VmwareResource .getDatastoreName (iScsiName );
4674- s_logger .debug ("Checking for datastore " + datastoreName );
4675- ManagedObjectReference morDatastore = HypervisorHostHelper .findDatastoreWithBackwardsCompatibility (hyperHost , datastoreName );
4676-
4677- // if the datastore is not present, we need to discover the iSCSI device that will support it,
4678- // create the datastore
4679- if (morDatastore == null ) {
4680- s_logger .debug ("The datastore " + datastoreName + " is not mounted, mounting" );
4681- _storageProcessor .prepareManagedDatastore (context , getHyperHost (context ), datastoreName ,
4682- details .get (DiskTO .IQN ), details .get (DiskTO .STORAGE_HOST ),
4683- Integer .parseInt (details .get (DiskTO .STORAGE_PORT )));
4684- }
4674+ s_logger .debug (String .format ("Ensuring datastore %s is mounted on destination cluster" , datastoreName ));
4675+ _storageProcessor .prepareManagedDatastore (context , hyperHost , datastoreName ,
4676+ details .get (DiskTO .IQN ), details .get (DiskTO .STORAGE_HOST ),
4677+ Integer .parseInt (details .get (DiskTO .STORAGE_PORT )));
46854678 }
46864679 }
46874680
@@ -5380,24 +5373,29 @@ private void handleTargets(boolean add, ModifyTargetsCommand.TargetTypeToRemove
53805373 }
53815374
53825375 private Answer execute (UnmountDatastoresCommand cmd ) {
5383- VmwareHypervisorHost hyperHost = getHyperHost (getServiceContext ());
5376+ VmwareContext context = getServiceContext (cmd );
5377+ VmwareHypervisorHost hyperHost = getHyperHost (context , cmd );
53845378 if (hyperHost == null ) {
53855379 throw new CloudRuntimeException ("No hypervisor host found to unmount datastore" );
53865380 }
5387- List <String > datastorePools = cmd .getDatastorePools ();
5388- if (CollectionUtils .isNotEmpty (datastorePools )) {
5389- try {
5381+ try {
5382+ List <String > datastorePools = cmd .getDatastorePools ();
5383+ if (CollectionUtils .isNotEmpty (datastorePools )) {
5384+ ManagedObjectReference clusterMor = hyperHost .getHyperHostCluster ();
5385+ if (clusterMor == null ) {
5386+ return new Answer (cmd , false , "Cannot unmount datastore pools as the cluster is not found" );
5387+ }
5388+ ClusterMO clusterMO = new ClusterMO (context , clusterMor );
5389+ List <Pair <ManagedObjectReference , String >> clusterHosts = clusterMO .getClusterHosts ();
53905390 for (String datastorePool : datastorePools ) {
53915391 String datastoreName = VmwareResource .getDatastoreName (datastorePool );
5392- s_logger .debug ("Checking for datastore " + datastoreName );
5393- ManagedObjectReference morDatastore = HypervisorHostHelper .findDatastoreWithBackwardsCompatibility (hyperHost , datastoreName );
5394- if (morDatastore != null ) {
5395- hyperHost .unmountDatastore (datastoreName );
5396- }
5392+ s_logger .debug (String .format ("Unmounting datastore %s from cluster %s hosts" , datastoreName , clusterMO .getName ()));
5393+ _storageProcessor .unmountVmfsDatastore (context , hyperHost , datastoreName , clusterHosts );
53975394 }
5398- } catch (Exception e ) {
5399- throw new RuntimeException (e );
54005395 }
5396+ } catch (Exception e ) {
5397+ s_logger .error ("Error unmounting datastores" , e );
5398+ return new Answer (cmd , e );
54015399 }
54025400 return new Answer (cmd , true , "success" );
54035401 }
0 commit comments