@@ -2350,13 +2350,58 @@ protected StartAnswer execute(StartCommand cmd) {
23502350 continue ;
23512351 }
23522352
2353+ VirtualMachineDiskInfo matchingExistingDisk = getMatchingExistingDisk (diskInfoBuilder , vol , hyperHost , context );
2354+ VolumeObjectTO volumeTO = (VolumeObjectTO ) vol .getData ();
2355+ DataStoreTO primaryStore = volumeTO .getDataStore ();
2356+ Map <String , String > details = vol .getDetails ();
2357+ boolean managed = false ;
2358+ String iScsiName = null ;
2359+
2360+ if (details != null ) {
2361+ managed = Boolean .parseBoolean (details .get (DiskTO .MANAGED ));
2362+ iScsiName = details .get (DiskTO .IQN );
2363+ }
2364+
2365+ String primaryStoreUuid = primaryStore .getUuid ();
2366+ // if the storage is managed, iScsiName should not be null
2367+ String datastoreName = managed ? VmwareResource .getDatastoreName (iScsiName ) : primaryStoreUuid ;
2368+ Pair <ManagedObjectReference , DatastoreMO > volumeDsDetails = dataStoresDetails .get (datastoreName );
2369+
2370+ assert (volumeDsDetails != null );
2371+ if (volumeDsDetails == null ) {
2372+ throw new Exception ("Primary datastore " + primaryStore .getUuid () + " is not mounted on host." );
2373+ }
2374+
2375+ if (vol .getDetails ().get (DiskTO .PROTOCOL_TYPE ) != null && vol .getDetails ().get (DiskTO .PROTOCOL_TYPE ).equalsIgnoreCase ("DatastoreCluster" )) {
2376+ if (diskInfoBuilder != null && matchingExistingDisk != null ) {
2377+ String [] diskChain = matchingExistingDisk .getDiskChain ();
2378+ if (diskChain != null && diskChain .length > 0 ) {
2379+ DatastoreFile file = new DatastoreFile (diskChain [0 ]);
2380+ if (!file .getFileBaseName ().equalsIgnoreCase (volumeTO .getPath ())) {
2381+ if (logger .isInfoEnabled ())
2382+ logger .info ("Detected disk-chain top file change on volume: " + volumeTO .getId () + " " + volumeTO .getPath () + " -> " + file .getFileBaseName ());
2383+ volumeTO .setPath (file .getFileBaseName ());
2384+ }
2385+ }
2386+ DatastoreMO diskDatastoreMofromVM = getDataStoreWhereDiskExists (hyperHost , context , diskInfoBuilder , vol , diskDatastores );
2387+ if (diskDatastoreMofromVM != null ) {
2388+ String actualPoolUuid = diskDatastoreMofromVM .getCustomFieldValue (CustomFieldConstants .CLOUD_UUID );
2389+ if (actualPoolUuid != null && !actualPoolUuid .equalsIgnoreCase (primaryStore .getUuid ())) {
2390+ volumeDsDetails = new Pair <>(diskDatastoreMofromVM .getMor (), diskDatastoreMofromVM );
2391+ if (logger .isInfoEnabled ())
2392+ logger .info ("Detected datastore uuid change on volume: " + volumeTO .getId () + " " + primaryStore .getUuid () + " -> " + actualPoolUuid );
2393+ ((PrimaryDataStoreTO )primaryStore ).setUuid (actualPoolUuid );
2394+ }
2395+ }
2396+ }
2397+ }
2398+
23532399 if (deployAsIs && vol .getType () == Volume .Type .ROOT ) {
23542400 rootDiskTO = vol ;
23552401 resizeRootDiskOnVMStart (vmMo , rootDiskTO , hyperHost , context );
23562402 continue ;
23572403 }
23582404
2359- VirtualMachineDiskInfo matchingExistingDisk = getMatchingExistingDisk (diskInfoBuilder , vol , hyperHost , context );
23602405 String diskController = getDiskController (vmMo , matchingExistingDisk , vol , chosenDiskControllers , deployAsIs );
23612406 if (DiskControllerType .getType (diskController ) == DiskControllerType .ide ) {
23622407 controllerKey = vmMo .getIDEControllerKey (ideUnitNumber );
@@ -2365,7 +2410,7 @@ protected StartAnswer execute(StartCommand cmd) {
23652410 // Ensure maximum of 2 data volumes over IDE controller, 3 includeing root volume
23662411 if (vmMo .getNumberOfVirtualDisks () > 3 ) {
23672412 throw new CloudRuntimeException ("Found more than 3 virtual disks attached to this VM [" + vmMo .getVmName () + "]. Unable to implement the disks over "
2368- + diskController + " controller, as maximum number of devices supported over IDE controller is 4 includeing CDROM device." );
2413+ + diskController + " controller, as maximum number of devices supported over IDE controller is 4 including CDROM device." );
23692414 }
23702415 }
23712416 } else {
@@ -2385,51 +2430,6 @@ protected StartAnswer execute(StartCommand cmd) {
23852430 if (!hasSnapshot ) {
23862431 deviceConfigSpecArray [i ] = new VirtualDeviceConfigSpec ();
23872432
2388- VolumeObjectTO volumeTO = (VolumeObjectTO ) vol .getData ();
2389- DataStoreTO primaryStore = volumeTO .getDataStore ();
2390- Map <String , String > details = vol .getDetails ();
2391- boolean managed = false ;
2392- String iScsiName = null ;
2393-
2394- if (details != null ) {
2395- managed = Boolean .parseBoolean (details .get (DiskTO .MANAGED ));
2396- iScsiName = details .get (DiskTO .IQN );
2397- }
2398-
2399- String primaryStoreUuid = primaryStore .getUuid ();
2400- // if the storage is managed, iScsiName should not be null
2401- String datastoreName = managed ? VmwareResource .getDatastoreName (iScsiName ) : primaryStoreUuid ;
2402- Pair <ManagedObjectReference , DatastoreMO > volumeDsDetails = dataStoresDetails .get (datastoreName );
2403-
2404- assert (volumeDsDetails != null );
2405- if (volumeDsDetails == null ) {
2406- throw new Exception ("Primary datastore " + primaryStore .getUuid () + " is not mounted on host." );
2407- }
2408-
2409- if (vol .getDetails ().get (DiskTO .PROTOCOL_TYPE ) != null && vol .getDetails ().get (DiskTO .PROTOCOL_TYPE ).equalsIgnoreCase ("DatastoreCluster" )) {
2410- if (diskInfoBuilder != null && matchingExistingDisk != null ) {
2411- String [] diskChain = matchingExistingDisk .getDiskChain ();
2412- if (diskChain != null && diskChain .length > 0 ) {
2413- DatastoreFile file = new DatastoreFile (diskChain [0 ]);
2414- if (!file .getFileBaseName ().equalsIgnoreCase (volumeTO .getPath ())) {
2415- if (logger .isInfoEnabled ())
2416- logger .info ("Detected disk-chain top file change on volume: " + volumeTO .getId () + " " + volumeTO .getPath () + " -> " + file .getFileBaseName ());
2417- volumeTO .setPath (file .getFileBaseName ());
2418- }
2419- }
2420- DatastoreMO diskDatastoreMofromVM = getDataStoreWhereDiskExists (hyperHost , context , diskInfoBuilder , vol , diskDatastores );
2421- if (diskDatastoreMofromVM != null ) {
2422- String actualPoolUuid = diskDatastoreMofromVM .getCustomFieldValue (CustomFieldConstants .CLOUD_UUID );
2423- if (actualPoolUuid != null && !actualPoolUuid .equalsIgnoreCase (primaryStore .getUuid ())) {
2424- volumeDsDetails = new Pair <>(diskDatastoreMofromVM .getMor (), diskDatastoreMofromVM );
2425- if (logger .isInfoEnabled ())
2426- logger .info ("Detected datastore uuid change on volume: " + volumeTO .getId () + " " + primaryStore .getUuid () + " -> " + actualPoolUuid );
2427- ((PrimaryDataStoreTO )primaryStore ).setUuid (actualPoolUuid );
2428- }
2429- }
2430- }
2431- }
2432-
24332433 String [] diskChain = syncDiskChain (dcMo , vmMo , vol , matchingExistingDisk , volumeDsDetails .second ());
24342434
24352435 int deviceNumber = -1 ;
0 commit comments