@@ -1858,6 +1858,18 @@ private VolumeVO setPassphraseForVolumeEncryption(VolumeVO volume) {
1858
1858
return _volsDao .persist (volume );
1859
1859
}
1860
1860
1861
+ protected void grantVolumeAccessToHostIfNeeded (PrimaryDataStore volumeStore , long volumeId , Host host , String volToString ) {
1862
+ PrimaryDataStoreDriver driver = (PrimaryDataStoreDriver )volumeStore .getDriver ();
1863
+ if (!driver .volumesRequireGrantAccessWhenUsed ()) {
1864
+ return ;
1865
+ }
1866
+ try {
1867
+ volService .grantAccess (volFactory .getVolume (volumeId ), host , volumeStore );
1868
+ } catch (Exception e ) {
1869
+ throw new StorageAccessException (String .format ("Unable to grant access to volume [%s] on host [%s]." , volToString , host ));
1870
+ }
1871
+ }
1872
+
1861
1873
@ Override
1862
1874
public void prepare (VirtualMachineProfile vm , DeployDestination dest ) throws StorageUnavailableException , InsufficientStorageCapacityException , ConcurrentOperationException , StorageAccessException {
1863
1875
if (dest == null ) {
@@ -1875,18 +1887,18 @@ public void prepare(VirtualMachineProfile vm, DeployDestination dest) throws Sto
1875
1887
1876
1888
List <VolumeTask > tasks = getTasks (vols , dest .getStorageForDisks (), vm );
1877
1889
Volume vol = null ;
1878
- StoragePool pool ;
1890
+ PrimaryDataStore store ;
1879
1891
for (VolumeTask task : tasks ) {
1880
1892
if (task .type == VolumeTaskType .NOP ) {
1881
1893
vol = task .volume ;
1882
1894
1883
1895
String volToString = getReflectOnlySelectedFields (vol );
1884
1896
1885
- pool = (StoragePool )dataStoreMgr .getDataStore (task .pool .getId (), DataStoreRole .Primary );
1897
+ store = (PrimaryDataStore )dataStoreMgr .getDataStore (task .pool .getId (), DataStoreRole .Primary );
1886
1898
1887
1899
// For zone-wide managed storage, it is possible that the VM can be started in another
1888
1900
// cluster. In that case, make sure that the volume is in the right access group.
1889
- if (pool .isManaged ()) {
1901
+ if (store .isManaged ()) {
1890
1902
Host lastHost = _hostDao .findById (vm .getVirtualMachine ().getLastHostId ());
1891
1903
Host host = _hostDao .findById (vm .getVirtualMachine ().getHostId ());
1892
1904
@@ -1895,37 +1907,27 @@ public void prepare(VirtualMachineProfile vm, DeployDestination dest) throws Sto
1895
1907
1896
1908
if (lastClusterId != clusterId ) {
1897
1909
if (lastHost != null ) {
1898
- storageMgr .removeStoragePoolFromCluster (lastHost .getId (), vol .get_iScsiName (), pool );
1899
-
1900
- DataStore storagePool = dataStoreMgr .getDataStore (pool .getId (), DataStoreRole .Primary );
1901
-
1902
- volService .revokeAccess (volFactory .getVolume (vol .getId ()), lastHost , storagePool );
1910
+ storageMgr .removeStoragePoolFromCluster (lastHost .getId (), vol .get_iScsiName (), store );
1911
+ volService .revokeAccess (volFactory .getVolume (vol .getId ()), lastHost , store );
1903
1912
}
1904
1913
1905
1914
try {
1906
- volService .grantAccess (volFactory .getVolume (vol .getId ()), host , ( DataStore ) pool );
1915
+ volService .grantAccess (volFactory .getVolume (vol .getId ()), host , store );
1907
1916
} catch (Exception e ) {
1908
1917
throw new StorageAccessException (String .format ("Unable to grant access to volume [%s] on host [%s]." , volToString , host ));
1909
1918
}
1910
1919
} else {
1911
- // This might impact other managed storages, grant access for PowerFlex and Iscsi/Solidfire storage pool only
1912
- if (pool .getPoolType () == Storage .StoragePoolType .PowerFlex || pool .getPoolType () == Storage .StoragePoolType .Iscsi ) {
1913
- try {
1914
- volService .grantAccess (volFactory .getVolume (vol .getId ()), host , (DataStore )pool );
1915
- } catch (Exception e ) {
1916
- throw new StorageAccessException (String .format ("Unable to grant access to volume [%s] on host [%s]." , volToString , host ));
1917
- }
1918
- }
1920
+ grantVolumeAccessToHostIfNeeded (store , vol .getId (), host , volToString );
1919
1921
}
1920
1922
} else {
1921
1923
handleCheckAndRepairVolume (vol , vm .getVirtualMachine ().getHostId ());
1922
1924
}
1923
1925
} else if (task .type == VolumeTaskType .MIGRATE ) {
1924
- pool = (StoragePool ) dataStoreMgr .getDataStore (task .pool .getId (), DataStoreRole .Primary );
1925
- vol = migrateVolume (task .volume , pool );
1926
+ store = (PrimaryDataStore ) dataStoreMgr .getDataStore (task .pool .getId (), DataStoreRole .Primary );
1927
+ vol = migrateVolume (task .volume , store );
1926
1928
} else if (task .type == VolumeTaskType .RECREATE ) {
1927
1929
Pair <VolumeVO , DataStore > result = recreateVolume (task .volume , vm , dest );
1928
- pool = (StoragePool ) dataStoreMgr .getDataStore (result .second ().getId (), DataStoreRole .Primary );
1930
+ store = (PrimaryDataStore ) dataStoreMgr .getDataStore (result .second ().getId (), DataStoreRole .Primary );
1929
1931
vol = result .first ();
1930
1932
}
1931
1933
0 commit comments