4848import com .cloud .agent .api .GetStoragePoolCapabilitiesAnswer ;
4949import com .cloud .agent .api .GetStoragePoolCapabilitiesCommand ;
5050import com .cloud .network .router .VirtualNetworkApplianceManager ;
51+ import com .cloud .server .StatsCollector ;
5152import com .cloud .upgrade .SystemVmTemplateRegistration ;
5253import org .apache .cloudstack .annotation .AnnotationService ;
5354import org .apache .cloudstack .annotation .dao .AnnotationDao ;
@@ -469,13 +470,9 @@ public Answer sendToPool(StoragePool pool, long[] hostIdsToTryFirst, Command cmd
469470
470471 @ Override
471472 public Answer sendToPool (StoragePool pool , Command cmd ) throws StorageUnavailableException {
472- if (cmd instanceof GetStorageStatsCommand ) {
473- DataStoreProvider storeProvider = _dataStoreProviderMgr .getDataStoreProvider (pool .getStorageProviderName ());
474- DataStoreDriver storeDriver = storeProvider .getDataStoreDriver ();
475- if (storeDriver instanceof PrimaryDataStoreDriver && ((PrimaryDataStoreDriver )storeDriver ).canProvideStorageStats ()) {
476- // Get stats from the pool directly instead of sending cmd to host
477- return getStoragePoolStats (pool , (GetStorageStatsCommand ) cmd );
478- }
473+ if (cmd instanceof GetStorageStatsCommand && canPoolProvideStorageStats (pool )) {
474+ // Get stats from the pool directly instead of sending cmd to host
475+ return getStoragePoolStats (pool , (GetStorageStatsCommand ) cmd );
479476 }
480477
481478 Answer [] answers = sendToPool (pool , new Commands (cmd ));
@@ -501,6 +498,13 @@ private GetStorageStatsAnswer getStoragePoolStats(StoragePool pool, GetStorageSt
501498 return answer ;
502499 }
503500
501+ @ Override
502+ public boolean canPoolProvideStorageStats (StoragePool pool ) {
503+ DataStoreProvider storeProvider = _dataStoreProviderMgr .getDataStoreProvider (pool .getStorageProviderName ());
504+ DataStoreDriver storeDriver = storeProvider .getDataStoreDriver ();
505+ return storeDriver instanceof PrimaryDataStoreDriver && ((PrimaryDataStoreDriver )storeDriver ).canProvideStorageStats ();
506+ }
507+
504508 @ Override
505509 public Answer getVolumeStats (StoragePool pool , Command cmd ) {
506510 DataStoreProvider storeProvider = _dataStoreProviderMgr .getDataStoreProvider (pool .getStorageProviderName ());
@@ -2265,14 +2269,14 @@ public HypervisorType getHypervisorTypeFromFormat(ImageFormat format) {
22652269
22662270 private boolean checkUsagedSpace (StoragePool pool ) {
22672271 // Managed storage does not currently deal with accounting for physically used space (only provisioned space). Just return true if "pool" is managed.
2268- // StatsCollector gets the storage stats from the ScaleIO/PowerFlex pool directly, limit the usage based on the capacity disable threshold
2269- if (pool .isManaged () && pool .getPoolType () != StoragePoolType .PowerFlex ) {
2272+ if (pool .isManaged () && !canPoolProvideStorageStats (pool )) {
22702273 return true ;
22712274 }
22722275
2273- double storageUsedThreshold = CapacityManager .StorageCapacityDisableThreshold .valueIn (pool .getDataCenterId ());
22742276 long totalSize = pool .getCapacityBytes ();
2275- double usedPercentage = ((double )pool .getUsedBytes () / (double )totalSize );
2277+ long usedSize = getUsedSize (pool );
2278+ double usedPercentage = ((double )usedSize / (double )totalSize );
2279+ double storageUsedThreshold = CapacityManager .StorageCapacityDisableThreshold .valueIn (pool .getDataCenterId ());
22762280 if (s_logger .isDebugEnabled ()) {
22772281 s_logger .debug ("Checking pool " + pool .getId () + " for storage, totalSize: " + pool .getCapacityBytes () + ", usedBytes: " + pool .getUsedBytes () +
22782282 ", usedPct: " + usedPercentage + ", disable threshold: " + storageUsedThreshold );
@@ -2287,6 +2291,25 @@ private boolean checkUsagedSpace(StoragePool pool) {
22872291 return true ;
22882292 }
22892293
2294+ private long getUsedSize (StoragePool pool ) {
2295+ if (pool .getStorageProviderName ().equalsIgnoreCase (DataStoreProvider .DEFAULT_PRIMARY ) || canPoolProvideStorageStats (pool )) {
2296+ return (pool .getUsedBytes ());
2297+ }
2298+
2299+ StatsCollector sc = StatsCollector .getInstance ();
2300+ if (sc != null ) {
2301+ StorageStats stats = sc .getStoragePoolStats (pool .getId ());
2302+ if (stats == null ) {
2303+ stats = sc .getStorageStats (pool .getId ());
2304+ }
2305+ if (stats != null ) {
2306+ return (stats .getByteUsed ());
2307+ }
2308+ }
2309+
2310+ return 0 ;
2311+ }
2312+
22902313 @ Override
22912314 public boolean storagePoolHasEnoughIops (List <Volume > requestedVolumes , StoragePool pool ) {
22922315 if (requestedVolumes == null || requestedVolumes .isEmpty () || pool == null ) {
0 commit comments