code: public static StorageDirView getDirWithMaxFreeSpace(long bytesToBeAvailable,
        BlockStoreLocation location, BlockMetadataManagerView mManagerView) {
      long maxFreeSize = -1;
      StorageDirView selectedDirView = null;
  
      if (location.equals(BlockStoreLocation.anyTier())) {
        for (StorageTierView tierView : mManagerView.getTierViews()) {
          for (StorageDirView dirView : tierView.getDirViews()) {
            if (dirView.getCommittedBytes() + dirView.getAvailableBytes() >= bytesToBeAvailable
                && dirView.getAvailableBytes() > maxFreeSize) {
              selectedDirView = dirView;
              maxFreeSize = dirView.getAvailableBytes();
            }
          }
        }
      } else {
        String tierAlias = location.tierAlias();
        StorageTierView tierView = mManagerView.getTierView(tierAlias);
        if (location.equals(BlockStoreLocation.anyDirInTier(tierAlias))) {
          for (StorageDirView dirView : tierView.getDirViews()) {
            if (dirView.getCommittedBytes() + dirView.getAvailableBytes() >= bytesToBeAvailable
                && dirView.getAvailableBytes() > maxFreeSize) {
              selectedDirView = dirView;
              maxFreeSize = dirView.getAvailableBytes();
            }
          }
        } else {
          int dirIndex = location.dir();
          StorageDirView dirView = tierView.getDirView(dirIndex);
          if (dirView.getCommittedBytes() + dirView.getAvailableBytes() >= bytesToBeAvailable
              && dirView.getAvailableBytes() > maxFreeSize) {
            selectedDirView = dirView;
          }
        }
      }
      return selectedDirView;
    }
docs: Gets {@link StorageDirView} with max free space.
  
  @param bytesToBeAvailable space size to be requested
  @param location location that the space will be allocated in
  @param mManagerView a view of block metadata information
  @return the {@link StorageDirView} selected