@@ -2400,18 +2400,7 @@ protected StartAnswer execute(StartCommand cmd) {
24002400 if (vmSpec .getType () != VirtualMachine .Type .User ) {
24012401 // attach ISO (for patching of system VM)
24022402 Pair <String , Long > secStoreUrlAndId = mgr .getSecondaryStorageStoreUrlAndId (Long .parseLong (_dcId ));
2403- String secStoreUrl = secStoreUrlAndId .first ();
2404- if (secStoreUrl == null ) {
2405- String msg = String .format ("NFS secondary or cache storage of dc %s either doesn't have enough capacity (has reached %d%% usage threshold) or not ready yet, or non-NFS secondary storage is used" ,
2406- _dcId , Math .round (CapacityManager .SecondaryStorageCapacityThreshold .value () * 100 ));
2407- throw new Exception (msg );
2408- }
2409-
2410- ManagedObjectReference morSecDs = prepareSecondaryDatastoreOnHost (secStoreUrl );
2411- if (morSecDs == null ) {
2412- String msg = "Failed to prepare secondary storage on host, NFS secondary or cache store url: " + secStoreUrl + " in dc " + _dcId ;
2413- throw new Exception (msg );
2414- }
2403+ ManagedObjectReference morSecDs = mountSecondaryStorage (mgr , secStoreUrlAndId );
24152404 DatastoreMO secDsMo = new DatastoreMO (hyperHost .getContext (), morSecDs );
24162405
24172406 deviceConfigSpecArray [i ] = new VirtualDeviceConfigSpec ();
@@ -2880,7 +2869,7 @@ private Integer configureIso(VmwareHypervisorHost hyperHost, VirtualMachineMO vm
28802869 }
28812870 NfsTO nfsImageStore = (NfsTO ) imageStore ;
28822871 String isoPath = nfsImageStore .getUrl () + File .separator + iso .getPath ();
2883- Pair <String , ManagedObjectReference > isoDatastoreInfo = getIsoDatastoreInfo (hyperHost , isoPath );
2872+ Pair <String , ManagedObjectReference > isoDatastoreInfo = getIsoDatastoreInfo (hyperHost , isoPath , (( NfsTO ) imageStore ). getNfsVersion () );
28842873 assert (isoDatastoreInfo != null );
28852874 assert (isoDatastoreInfo .second () != null );
28862875
@@ -4232,7 +4221,7 @@ private VirtualMachineMO takeVmFromOtherHyperHost(VmwareHypervisorHost hyperHost
42324221
42334222 // isoUrl sample content :
42344223 // nfs://192.168.10.231/export/home/kelven/vmware-test/secondary/template/tmpl/2/200//200-2-80f7ee58-6eff-3a2d-bcb0-59663edf6d26.iso
4235- private Pair <String , ManagedObjectReference > getIsoDatastoreInfo (VmwareHypervisorHost hyperHost , String isoUrl ) throws Exception {
4224+ private Pair <String , ManagedObjectReference > getIsoDatastoreInfo (VmwareHypervisorHost hyperHost , String isoUrl , String nfsVersion ) throws Exception {
42364225
42374226 assert (isoUrl != null );
42384227 int isoFileNameStartPos = isoUrl .lastIndexOf ("/" );
@@ -4251,7 +4240,7 @@ private Pair<String, ManagedObjectReference> getIsoDatastoreInfo(VmwareHyperviso
42514240 String storeUrl = isoUrl .substring (0 , templateRootPos - 1 );
42524241 String isoPath = isoUrl .substring (templateRootPos , isoFileNameStartPos );
42534242
4254- ManagedObjectReference morDs = prepareSecondaryDatastoreOnHost (storeUrl );
4243+ ManagedObjectReference morDs = prepareSecondaryDatastoreOnHost (storeUrl , nfsVersion );
42554244 DatastoreMO dsMo = new DatastoreMO (getServiceContext (), morDs );
42564245
42574246 return new Pair <String , ManagedObjectReference >(String .format ("[%s] %s%s" , dsMo .getName (), isoPath , isoFileName ), morDs );
@@ -4749,25 +4738,31 @@ protected Answer execute(PrepareForMigrationCommand cmd) {
47494738
47504739 List <Pair <String , Long >> secStoreUrlAndIdList = mgr .getSecondaryStorageStoresUrlAndIdList (Long .parseLong (_dcId ));
47514740 for (Pair <String , Long > secStoreUrlAndId : secStoreUrlAndIdList ) {
4752- String secStoreUrl = secStoreUrlAndId .first ();
4753- if (secStoreUrl == null ) {
4754- String msg = String .format ("NFS secondary or cache storage of dc %s either doesn't have enough capacity (has reached %d%% usage threshold) or not ready yet, or non-NFS secondary storage is used" ,
4755- _dcId , Math .round (CapacityManager .SecondaryStorageCapacityThreshold .value () * 100 ));
4756- throw new Exception (msg );
4757- }
4758-
4759- ManagedObjectReference morSecDs = prepareSecondaryDatastoreOnHost (secStoreUrl );
4760- if (morSecDs == null ) {
4761- String msg = "Failed to prepare secondary storage on host, NFS secondary or cache store url: " + secStoreUrl + " in dc " + _dcId ;
4762- throw new Exception (msg );
4763- }
4741+ mountSecondaryStorage (mgr , secStoreUrlAndId );
47644742 }
47654743 return new PrepareForMigrationAnswer (cmd );
47664744 } catch (Throwable e ) {
47674745 return new PrepareForMigrationAnswer (cmd , createLogMessageException (e , cmd ));
47684746 }
47694747 }
47704748
4749+ private ManagedObjectReference mountSecondaryStorage (VmwareManager mgr , Pair <String , Long > secStoreUrlAndId ) throws Exception {
4750+ String secStoreUrl = secStoreUrlAndId .first ();
4751+ if (secStoreUrl == null ) {
4752+ String msg = String .format ("NFS secondary or cache storage of dc %s either doesn't have enough capacity (has reached %d%% usage threshold) or not ready yet, or non-NFS secondary storage is used" ,
4753+ _dcId , Math .round (CapacityManager .SecondaryStorageCapacityThreshold .value () * 100 ));
4754+ throw new Exception (msg );
4755+ }
4756+ String secondaryStorageNfsVersion = mgr .getSecondaryStorageNfsVersion (secStoreUrlAndId .second ());
4757+
4758+ ManagedObjectReference morSecDs = prepareSecondaryDatastoreOnHost (secStoreUrl , secondaryStorageNfsVersion );
4759+ if (morSecDs == null ) {
4760+ String msg = "Failed to prepare secondary storage on host, NFS secondary or cache store url: " + secStoreUrl + " in dc " + _dcId ;
4761+ throw new Exception (msg );
4762+ }
4763+ return morSecDs ;
4764+ }
4765+
47714766 protected Answer execute (MigrateVmToPoolCommand cmd ) {
47724767 final String vmName = cmd .getVmName ();
47734768
@@ -5355,6 +5350,10 @@ protected Answer execute(ModifyTargetsCommand cmd) {
53555350
53565351 protected Answer execute (ModifyStoragePoolCommand cmd ) {
53575352 try {
5353+ Map <String , String > details = cmd .getDetails ();
5354+ if (details .containsKey (ApiConstants .NFS_MOUNT_OPTIONS ) && details .get (ApiConstants .NFS_MOUNT_OPTIONS ).split ("nfsvers=" ).length > 1 ) {
5355+ storageNfsVersion = details .get (ApiConstants .NFS_MOUNT_OPTIONS ).split ("nfsvers=" )[1 ].split ("," )[0 ];
5356+ }
53585357 VmwareHypervisorHost hyperHost = getHyperHost (getServiceContext ());
53595358 StorageFilerTO pool = cmd .getPool ();
53605359
@@ -5365,7 +5364,7 @@ protected Answer execute(ModifyStoragePoolCommand cmd) {
53655364 ManagedObjectReference morDatastore = HypervisorHostHelper .findDatastoreWithBackwardsCompatibility (hyperHost , pool .getUuid ());
53665365
53675366 if (morDatastore == null ) {
5368- morDatastore = hyperHost .mountDatastore ((pool .getType () == StoragePoolType .VMFS || pool .getType () == StoragePoolType .PreSetup || pool .getType () == StoragePoolType .DatastoreCluster ), pool .getHost (), pool .getPort (), pool .getPath (), pool .getUuid ().replace ("-" , "" ), true );
5367+ morDatastore = hyperHost .mountDatastore ((pool .getType () == StoragePoolType .VMFS || pool .getType () == StoragePoolType .PreSetup || pool .getType () == StoragePoolType .DatastoreCluster ), pool .getHost (), pool .getPort (), pool .getPath (), pool .getUuid ().replace ("-" , "" ), true , storageNfsVersion );
53695368 }
53705369
53715370 assert (morDatastore != null );
@@ -5445,7 +5444,7 @@ protected Answer execute(GetStoragePoolCapabilitiesCommand cmd) {
54455444 ManagedObjectReference morDatastore = HypervisorHostHelper .findDatastoreWithBackwardsCompatibility (hyperHost , pool .getUuid ());
54465445
54475446 if (morDatastore == null ) {
5448- morDatastore = hyperHost .mountDatastore ((pool .getType () == StoragePoolType .VMFS || pool .getType () == StoragePoolType .PreSetup || pool .getType () == StoragePoolType .DatastoreCluster ), pool .getHost (), pool .getPort (), pool .getPath (), pool .getUuid ().replace ("-" , "" ), true );
5447+ morDatastore = hyperHost .mountDatastore ((pool .getType () == StoragePoolType .VMFS || pool .getType () == StoragePoolType .PreSetup || pool .getType () == StoragePoolType .DatastoreCluster ), pool .getHost (), pool .getPort (), pool .getPath (), pool .getUuid ().replace ("-" , "" ), true , null );
54495448 }
54505449
54515450 assert (morDatastore != null );
@@ -5565,7 +5564,10 @@ protected AttachIsoAnswer execute(AttachIsoCommand cmd) {
55655564 }
55665565 }
55675566
5568- ManagedObjectReference morSecondaryDs = prepareSecondaryDatastoreOnHost (storeUrl );
5567+ VmwareManager mgr = hyperHost .getContext ().getStockObject (VmwareManager .CONTEXT_STOCK_NAME );
5568+ Pair <String , Long > secStoreUrlAndId = mgr .getSecondaryStorageStoreUrlAndId (Long .parseLong (_dcId ));
5569+ ManagedObjectReference morSecondaryDs = mountSecondaryStorage (mgr , secStoreUrlAndId );
5570+
55695571 String isoPath = cmd .getIsoPath ();
55705572 if (!isoPath .startsWith (storeUrl )) {
55715573 assert (false );
@@ -5605,24 +5607,24 @@ protected AttachIsoAnswer execute(AttachIsoCommand cmd) {
56055607 }
56065608 }
56075609
5608- public synchronized ManagedObjectReference prepareSecondaryDatastoreOnHost (String storeUrl ) throws Exception {
5610+ public synchronized ManagedObjectReference prepareSecondaryDatastoreOnHost (String storeUrl , String nfsVersion ) throws Exception {
56095611 String storeName = getSecondaryDatastoreUUID (storeUrl );
56105612 URI uri = new URI (storeUrl );
56115613
56125614 VmwareHypervisorHost hyperHost = getHyperHost (getServiceContext ());
5613- ManagedObjectReference morDatastore = hyperHost .mountDatastore (false , uri .getHost (), 0 , uri .getPath (), storeName .replace ("-" , "" ), false );
5615+ ManagedObjectReference morDatastore = hyperHost .mountDatastore (false , uri .getHost (), 0 , uri .getPath (), storeName .replace ("-" , "" ), false , nfsVersion );
56145616
56155617 if (morDatastore == null )
56165618 throw new Exception ("Unable to mount secondary storage on host. storeUrl: " + storeUrl );
56175619
56185620 return morDatastore ;
56195621 }
56205622
5621- public synchronized ManagedObjectReference prepareSecondaryDatastoreOnSpecificHost (String storeUrl , VmwareHypervisorHost hyperHost ) throws Exception {
5623+ public synchronized ManagedObjectReference prepareSecondaryDatastoreOnSpecificHost (String storeUrl , VmwareHypervisorHost hyperHost , String nfsVersion ) throws Exception {
56225624 String storeName = getSecondaryDatastoreUUID (storeUrl );
56235625 URI uri = new URI (storeUrl );
56245626
5625- ManagedObjectReference morDatastore = hyperHost .mountDatastore (false , uri .getHost (), 0 , uri .getPath (), storeName .replace ("-" , "" ), false );
5627+ ManagedObjectReference morDatastore = hyperHost .mountDatastore (false , uri .getHost (), 0 , uri .getPath (), storeName .replace ("-" , "" ), false , nfsVersion );
56265628
56275629 if (morDatastore == null )
56285630 throw new Exception ("Unable to mount secondary storage on host. storeUrl: " + storeUrl );
@@ -7527,7 +7529,7 @@ private List<VolumeObjectTO> relocateVirtualMachine(final VmwareHypervisorHost h
75277529 _dcId , Math .round (CapacityManager .SecondaryStorageCapacityThreshold .value () * 100 ));
75287530 throw new Exception (msg );
75297531 }
7530- ManagedObjectReference morSecDs = prepareSecondaryDatastoreOnSpecificHost (secStoreUrl , targetHyperHost );
7532+ ManagedObjectReference morSecDs = prepareSecondaryDatastoreOnSpecificHost (secStoreUrl , targetHyperHost , mgr . getSecondaryStorageNfsVersion ( secStoreUrlAndId . second ()) );
75317533 if (morSecDs == null ) {
75327534 throw new Exception (String .format ("Failed to prepare secondary storage on host, NFS secondary or cache store url: %s in dc %s" , secStoreUrl , _dcId ));
75337535 }
@@ -7637,7 +7639,7 @@ private String getMountedDatastoreName(VmwareHypervisorHost sourceHyperHost, Str
76377639 // If datastore is NFS and target datastore is not already mounted on source host then mount the datastore.
76387640 if (filerTo .getType ().equals (StoragePoolType .NetworkFilesystem )) {
76397641 if (morVolumeDatastoreAtSource == null ) {
7640- morVolumeDatastoreAtSource = sourceHyperHost .mountDatastore (false , volumeDatastoreHost , volumeDatastorePort , volumeDatastorePath , volumeDatastoreName , false );
7642+ morVolumeDatastoreAtSource = sourceHyperHost .mountDatastore (false , volumeDatastoreHost , volumeDatastorePort , volumeDatastorePath , volumeDatastoreName , false , storageNfsVersion );
76417643 if (morVolumeDatastoreAtSource == null ) {
76427644 throw new Exception ("Unable to mount NFS datastore " + volumeDatastoreHost + ":/" + volumeDatastorePath + " on host: " + sourceHyperHost .getHyperHostName ());
76437645 }
0 commit comments