code: private StorageDirView allocateBlock(long sessionId, long blockSize,
        BlockStoreLocation location) {
      Preconditions.checkNotNull(location, "location");
      if (location.equals(BlockStoreLocation.anyTier())) {
        // When any tier is ok, loop over all tier views and dir views,
        // and return a temp block meta from the first available dirview.
        for (StorageTierView tierView : mManagerView.getTierViews()) {
          for (StorageDirView dirView : tierView.getDirViews()) {
            if (dirView.getAvailableBytes() >= blockSize) {
              return dirView;
            }
          }
        }
        return null;
      }
  
      String tierAlias = location.tierAlias();
      StorageTierView tierView = mManagerView.getTierView(tierAlias);
      if (location.equals(BlockStoreLocation.anyDirInTier(tierAlias))) {
        // Loop over all dir views in the given tier
        for (StorageDirView dirView : tierView.getDirViews()) {
          if (dirView.getAvailableBytes() >= blockSize) {
            return dirView;
          }
        }
        return null;
      }
  
      int dirIndex = location.dir();
      StorageDirView dirView = tierView.getDirView(dirIndex);
      if (dirView.getAvailableBytes() >= blockSize) {
        return dirView;
      }
      return null;
    }
docs: Allocates a block from the given block store location. The location can be a specific location,
  or {@link BlockStoreLocation#anyTier()} or {@link BlockStoreLocation#anyDirInTier(String)}.
  
  @param sessionId the id of session to apply for the block allocation
  @param blockSize the size of block in bytes
  @param location the location in block store
  @return a {@link StorageDirView} in which to create the temp block meta if success, null
  otherwise
  @throws IllegalArgumentException if block location is invalid