@@ -2985,7 +2985,9 @@ private String[] syncDiskChain(DatacenterMO dcMo, VirtualMachineMO vmMo, Virtual
29852985
29862986 VolumeObjectTO volumeTO = (VolumeObjectTO )vol .getData ();
29872987 PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO )volumeTO .getDataStore ();
2988-
2988+ Map <String , String > details = vol .getDetails ();
2989+ boolean isManaged = details != null && Boolean .parseBoolean (details .get (DiskTO .MANAGED ));
2990+
29892991 Pair <ManagedObjectReference , DatastoreMO > volumeDsDetails = dataStoresDetails .get (primaryStore .getUuid ());
29902992 if (volumeDsDetails == null )
29912993 throw new Exception ("Primary datastore " + primaryStore .getUuid () + " is not mounted on host." );
@@ -2997,17 +2999,25 @@ private String[] syncDiskChain(DatacenterMO dcMo, VirtualMachineMO vmMo, Virtual
29972999 String disks [] = diskInfo .getDiskChain ();
29983000 for (int i = 0 ; i < disks .length ; i ++) {
29993001 DatastoreFile file = new DatastoreFile (disks [i ]);
3000- if ( file .getDir () != null && file .getDir ().isEmpty ()) {
3002+ if (! isManaged && file .getDir () != null && file .getDir ().isEmpty ()) {
30013003 s_logger .info ("Perform run-time datastore folder upgrade. sync " + disks [i ] + " to VM folder" );
30023004 disks [i ] = VmwareStorageLayoutHelper .syncVolumeToVmDefaultFolder (
30033005 dcMo , vmMo .getName (), dsMo , file .getFileBaseName ());
30043006 }
30053007 }
30063008 return disks ;
3007- }
3008-
3009- String datastoreDiskPath = VmwareStorageLayoutHelper .syncVolumeToVmDefaultFolder (
3010- dcMo , vmMo .getName (), dsMo , volumeTO .getPath ());
3009+ }
3010+
3011+ final String datastoreDiskPath ;
3012+
3013+ if (isManaged ) {
3014+ datastoreDiskPath = dsMo .getDatastorePath (dsMo .getName () + ".vmdk" );
3015+ }
3016+ else {
3017+ datastoreDiskPath = VmwareStorageLayoutHelper .syncVolumeToVmDefaultFolder (
3018+ dcMo , vmMo .getName (), dsMo , volumeTO .getPath ());
3019+ }
3020+
30113021 if (!dsMo .fileExists (datastoreDiskPath )) {
30123022 s_logger .warn ("Volume " + volumeTO .getId () + " does not seem to exist on datastore, out of sync? path: " + datastoreDiskPath );
30133023 }
@@ -3223,7 +3233,10 @@ private VirtualMachineDiskInfo getMatchingExistingDisk(VirtualMachineDiskInfoBui
32233233 if (diskInfoBuilder != null ) {
32243234 VolumeObjectTO volume = (VolumeObjectTO )vol .getData ();
32253235
3226- VirtualMachineDiskInfo diskInfo = diskInfoBuilder .getDiskInfoByBackingFileBaseName (volume .getPath ());
3236+ Map <String , String > details = vol .getDetails ();
3237+ boolean isManaged = details != null && Boolean .parseBoolean (details .get (DiskTO .MANAGED ));
3238+
3239+ VirtualMachineDiskInfo diskInfo = diskInfoBuilder .getDiskInfoByBackingFileBaseName (isManaged ? new DatastoreFile (volume .getPath ()).getFileBaseName () : volume .getPath ());
32273240 if (diskInfo != null ) {
32283241 s_logger .info ("Found existing disk info from volume path: " + volume .getPath ());
32293242 return diskInfo ;
@@ -3421,7 +3434,16 @@ private HashMap<String, Pair<ManagedObjectReference, DatastoreMO>> inferDatastor
34213434 PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO )volumeTO .getDataStore ();
34223435 String poolUuid = primaryStore .getUuid ();
34233436 if (poolMors .get (poolUuid ) == null ) {
3424- ManagedObjectReference morDataStore = HypervisorHostHelper .findDatastoreWithBackwardsCompatibility (hyperHost , poolUuid );
3437+ boolean isManaged = false ;
3438+ String iScsiName = null ;
3439+ Map <String , String > details = vol .getDetails ();
3440+
3441+ if (details != null ) {
3442+ isManaged = Boolean .parseBoolean (details .get (DiskTO .MANAGED ));
3443+ iScsiName = details .get (DiskTO .IQN );
3444+ }
3445+
3446+ ManagedObjectReference morDataStore = HypervisorHostHelper .findDatastoreWithBackwardsCompatibility (hyperHost , isManaged ? VmwareResource .getDatastoreName (iScsiName ) : poolUuid );
34253447 if (morDataStore == null ) {
34263448 String msg = "Failed to get the mounted datastore for the volume's pool " + poolUuid ;
34273449 s_logger .error (msg );
@@ -4534,7 +4556,7 @@ protected Answer execute(AttachVolumeCommand cmd) {
45344556 String volumeDatastorePath = String .format ("[%s] %s.vmdk" , dsMo .getName (), dsMo .getName ());
45354557
45364558 if (!dsMo .fileExists (volumeDatastorePath )) {
4537- createVmdk (cmd , dsMo , VmwareResource . getDatastoreName ( cmd . get_iScsiName ()) , cmd .getVolumeSize ());
4559+ createVmdk (cmd , dsMo , volumeDatastorePath , cmd .getVolumeSize ());
45384560 }
45394561 }
45404562 else {
@@ -4592,6 +4614,35 @@ protected Answer execute(AttachVolumeCommand cmd) {
45924614 }
45934615 }
45944616
4617+ @ Override
4618+ public void removeManagedTargetsFromCluster (List <String > iqns ) throws Exception {
4619+ List <HostInternetScsiHbaStaticTarget > lstManagedTargets = new ArrayList <HostInternetScsiHbaStaticTarget >();
4620+
4621+ VmwareContext context = getServiceContext ();
4622+ VmwareHypervisorHost hyperHost = getHyperHost (context );
4623+ ManagedObjectReference morCluster = hyperHost .getHyperHostCluster ();
4624+ ClusterMO cluster = new ClusterMO (context , morCluster );
4625+ List <Pair <ManagedObjectReference , String >> lstHosts = cluster .getClusterHosts ();
4626+ HostMO host = new HostMO (context , lstHosts .get (0 ).first ());
4627+ HostStorageSystemMO hostStorageSystem = host .getHostStorageSystemMO ();
4628+
4629+ for (HostHostBusAdapter hba : hostStorageSystem .getStorageDeviceInfo ().getHostBusAdapter ()) {
4630+ if (hba instanceof HostInternetScsiHba ) {
4631+ List <HostInternetScsiHbaStaticTarget > lstTargets = ((HostInternetScsiHba )hba ).getConfiguredStaticTarget ();
4632+
4633+ if (lstTargets != null ) {
4634+ for (HostInternetScsiHbaStaticTarget target : lstTargets ) {
4635+ if (iqns .contains (target .getIScsiName ())) {
4636+ lstManagedTargets .add (target );
4637+ }
4638+ }
4639+ }
4640+ }
4641+ }
4642+
4643+ addRemoveInternetScsiTargetsToAllHosts (false , lstManagedTargets , lstHosts );
4644+ }
4645+
45954646 private void addRemoveInternetScsiTargetsToAllHosts (final boolean add , final List <HostInternetScsiHbaStaticTarget > lstTargets ,
45964647 final List <Pair <ManagedObjectReference , String >> lstHosts ) throws Exception {
45974648 VmwareContext context = getServiceContext ();
0 commit comments