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