@@ -1412,9 +1412,8 @@ protected StartAnswer execute(StartCommand cmd) {
14121412 DiskTO [] disks = validateDisks (vmSpec .getDisks ());
14131413 assert (disks .length > 0 );
14141414 NicTO [] nics = vmSpec .getNics ();
1415- Map <String , String > iqnToPath = new HashMap <String , String >();
14161415
1417- HashMap <String , Pair <ManagedObjectReference , DatastoreMO >> dataStoresDetails = inferDatastoreDetailsFromDiskInfo (hyperHost , context , disks , iqnToPath , cmd );
1416+ HashMap <String , Pair <ManagedObjectReference , DatastoreMO >> dataStoresDetails = inferDatastoreDetailsFromDiskInfo (hyperHost , context , disks , cmd );
14181417 if ((dataStoresDetails == null ) || (dataStoresDetails .isEmpty ())) {
14191418 String msg = "Unable to locate datastore details of the volumes to be attached" ;
14201419 s_logger .error (msg );
@@ -1471,9 +1470,23 @@ protected StartAnswer execute(StartCommand cmd) {
14711470 Pair <ManagedObjectReference , DatastoreMO > rootDiskDataStoreDetails = null ;
14721471 for (DiskTO vol : disks ) {
14731472 if (vol .getType () == Volume .Type .ROOT ) {
1474- DataStoreTO primaryStore = vol .getData ().getDataStore ();
1475- /** @todo Mike T. update this in 4.4 to support root disks on managed storage */
1476- rootDiskDataStoreDetails = dataStoresDetails .get (primaryStore .getUuid ());
1473+ Map <String , String > details = vol .getDetails ();
1474+ boolean managed = false ;
1475+
1476+ if (details != null ) {
1477+ managed = Boolean .parseBoolean (details .get (DiskTO .MANAGED ));
1478+ }
1479+
1480+ if (managed ) {
1481+ String datastoreName = VmwareResource .getDatastoreName (details .get (DiskTO .IQN ));
1482+
1483+ rootDiskDataStoreDetails = dataStoresDetails .get (datastoreName );
1484+ }
1485+ else {
1486+ DataStoreTO primaryStore = vol .getData ().getDataStore ();
1487+
1488+ rootDiskDataStoreDetails = dataStoresDetails .get (primaryStore .getUuid ());
1489+ }
14771490 }
14781491 }
14791492
@@ -1759,7 +1772,10 @@ protected StartAnswer execute(StartCommand cmd) {
17591772
17601773 vmMo .setCustomFieldValue (CustomFieldConstants .CLOUD_NIC_MASK , String .valueOf (nicMask ));
17611774 postNvpConfigBeforeStart (vmMo , vmSpec );
1762- postDiskConfigBeforeStart (vmMo , vmSpec , sortedDisks , ideControllerKey , scsiControllerKey );
1775+
1776+ Map <String , String > iqnToPath = new HashMap <String , String >();
1777+
1778+ postDiskConfigBeforeStart (vmMo , vmSpec , sortedDisks , ideControllerKey , scsiControllerKey , iqnToPath );
17631779
17641780 //
17651781 // Power-on VM
@@ -1891,7 +1907,12 @@ private String[] syncDiskChain(DatacenterMO dcMo, VirtualMachineMO vmMo, Virtual
18911907 final String datastoreDiskPath ;
18921908
18931909 if (isManaged ) {
1894- datastoreDiskPath = dsMo .getDatastorePath (dsMo .getName () + ".vmdk" );
1910+ if (volumeTO .getVolumeType () == Volume .Type .ROOT ) {
1911+ datastoreDiskPath = VmwareStorageLayoutHelper .syncVolumeToVmDefaultFolder (dcMo , vmMo .getName (), dsMo , dsMo .getName ());
1912+ }
1913+ else {
1914+ datastoreDiskPath = dsMo .getDatastorePath (dsMo .getName () + ".vmdk" );
1915+ }
18951916 } else {
18961917 datastoreDiskPath = VmwareStorageLayoutHelper .syncVolumeToVmDefaultFolder (dcMo , vmMo .getName (), dsMo , volumeTO .getPath ());
18971918 }
@@ -2177,9 +2198,8 @@ private int getDiskController(VirtualMachineDiskInfo matchingExistingDisk, DiskT
21772198 return controllerKey ;
21782199 }
21792200
2180- private void postDiskConfigBeforeStart (VirtualMachineMO vmMo , VirtualMachineTO vmSpec , DiskTO [] sortedDisks , int ideControllerKey , int scsiControllerKey )
2181- throws Exception {
2182-
2201+ private void postDiskConfigBeforeStart (VirtualMachineMO vmMo , VirtualMachineTO vmSpec , DiskTO [] sortedDisks , int ideControllerKey ,
2202+ int scsiControllerKey , Map <String , String > iqnToPath ) throws Exception {
21832203 VirtualMachineDiskInfoBuilder diskInfoBuilder = vmMo .getDiskInfoBuilder ();
21842204
21852205 for (DiskTO vol : sortedDisks ) {
@@ -2194,14 +2214,45 @@ private void postDiskConfigBeforeStart(VirtualMachineMO vmMo, VirtualMachineTO v
21942214 String [] diskChain = diskInfo .getDiskChain ();
21952215 assert (diskChain .length > 0 );
21962216
2217+ Map <String , String > details = vol .getDetails ();
2218+ boolean managed = false ;
2219+
2220+ if (details != null ) {
2221+ managed = Boolean .parseBoolean (details .get (DiskTO .MANAGED ));
2222+ }
2223+
21972224 DatastoreFile file = new DatastoreFile (diskChain [0 ]);
2198- if (!file .getFileBaseName ().equalsIgnoreCase (volumeTO .getPath ())) {
2199- if (s_logger .isInfoEnabled ())
2200- s_logger .info ("Detected disk-chain top file change on volume: " + volumeTO .getId () + " " + volumeTO .getPath () + " -> " + file .getFileBaseName ());
2225+
2226+ if (managed ) {
2227+ DatastoreFile originalFile = new DatastoreFile (volumeTO .getPath ());
2228+
2229+ if (!file .getFileBaseName ().equalsIgnoreCase (originalFile .getFileBaseName ())) {
2230+ if (s_logger .isInfoEnabled ())
2231+ s_logger .info ("Detected disk-chain top file change on volume: " + volumeTO .getId () + " " + volumeTO .getPath () + " -> " + diskChain [0 ]);
2232+ }
2233+ }
2234+ else {
2235+ if (!file .getFileBaseName ().equalsIgnoreCase (volumeTO .getPath ())) {
2236+ if (s_logger .isInfoEnabled ())
2237+ s_logger .info ("Detected disk-chain top file change on volume: " + volumeTO .getId () + " " + volumeTO .getPath () + " -> " + file .getFileBaseName ());
2238+ }
22012239 }
22022240
22032241 VolumeObjectTO volInSpec = getVolumeInSpec (vmSpec , volumeTO );
2204- volInSpec .setPath (file .getFileBaseName ());
2242+
2243+ if (managed ) {
2244+ String datastoreVolumePath = diskChain [0 ];
2245+
2246+ iqnToPath .put (details .get (DiskTO .IQN ), datastoreVolumePath );
2247+
2248+ vol .setPath (datastoreVolumePath );
2249+ volumeTO .setPath (datastoreVolumePath );
2250+ volInSpec .setPath (datastoreVolumePath );
2251+ }
2252+ else {
2253+ volInSpec .setPath (file .getFileBaseName ());
2254+ }
2255+
22052256 volInSpec .setChainInfo (_gson .toJson (diskInfo ));
22062257 }
22072258 }
@@ -2263,7 +2314,7 @@ public int compare(DiskTO arg0, DiskTO arg1) {
22632314 }
22642315
22652316 private HashMap <String , Pair <ManagedObjectReference , DatastoreMO >> inferDatastoreDetailsFromDiskInfo (VmwareHypervisorHost hyperHost , VmwareContext context ,
2266- DiskTO [] disks , Map < String , String > iqnToPath , Command cmd ) throws Exception {
2317+ DiskTO [] disks , Command cmd ) throws Exception {
22672318 HashMap <String , Pair <ManagedObjectReference , DatastoreMO >> mapIdToMors = new HashMap <String , Pair <ManagedObjectReference , DatastoreMO >>();
22682319
22692320 assert (hyperHost != null ) && (context != null );
@@ -2299,8 +2350,6 @@ private HashMap<String, Pair<ManagedObjectReference, DatastoreMO>> inferDatastor
22992350 DatastoreMO dsMo = new DatastoreMO (getServiceContext (), morDatastore );
23002351 String datastoreVolumePath = dsMo .getDatastorePath (dsMo .getName () + ".vmdk" );
23012352
2302- iqnToPath .put (iScsiName , datastoreVolumePath );
2303-
23042353 volumeTO .setPath (datastoreVolumePath );
23052354 vol .setPath (datastoreVolumePath );
23062355 }
@@ -3462,6 +3511,8 @@ public void removeManagedTargetsFromCluster(List<String> iqns) throws Exception
34623511 }
34633512
34643513 addRemoveInternetScsiTargetsToAllHosts (false , lstManagedTargets , lstHosts );
3514+
3515+ rescanAllHosts (lstHosts );
34653516 }
34663517
34673518 private void addRemoveInternetScsiTargetsToAllHosts (final boolean add , final List <HostInternetScsiHbaStaticTarget > lstTargets ,
@@ -4281,7 +4332,7 @@ protected Answer execute(UnregisterNicCommand cmd) {
42814332
42824333 public Answer execute (DeleteCommand cmd ) {
42834334 if (s_logger .isInfoEnabled ()) {
4284- s_logger .info ("Executing resource DestroyCommand : " + _gson .toJson (cmd ));
4335+ s_logger .info ("Executing resource DeleteCommand : " + _gson .toJson (cmd ));
42854336 }
42864337
42874338 /*
0 commit comments