ocfs2: Allow direct I/O read past end of file

ocfs2_direct_IO_get_blocks() was incorrectly returning -EIO for a direct I/O
read whose start block was past the end of the file allocation tree. Fix
things so that we return a hole instead. do_direct_IO() will then notice
that the range start is past eof and return a short read.

While there, remove the unused vbo_max variable.

Signed-off-by: Mark Fasheh <mark.fasheh@oracle.com>

+17 -7
+17 -7
fs/ocfs2/aops.c
··· 540 540 struct buffer_head *bh_result, int create) 541 541 { 542 542 int ret; 543 - u64 vbo_max; /* file offset, max_blocks from iblock */ 544 - u64 p_blkno; 543 + u64 p_blkno, inode_blocks; 545 544 int contig_blocks; 546 545 unsigned char blocksize_bits = inode->i_sb->s_blocksize_bits; 547 546 unsigned long max_blocks = bh_result->b_size >> inode->i_blkbits; ··· 549 550 * nicely aligned and of the right size, so there's no need 550 551 * for us to check any of that. */ 551 552 552 - vbo_max = ((u64)iblock + max_blocks) << blocksize_bits; 553 - 554 553 spin_lock(&OCFS2_I(inode)->ip_lock); 555 - if ((iblock + max_blocks) > 556 - ocfs2_clusters_to_blocks(inode->i_sb, 557 - OCFS2_I(inode)->ip_clusters)) { 554 + inode_blocks = ocfs2_clusters_to_blocks(inode->i_sb, 555 + OCFS2_I(inode)->ip_clusters); 556 + 557 + /* 558 + * For a read which begins past the end of file, we return a hole. 559 + */ 560 + if (!create && (iblock >= inode_blocks)) { 561 + spin_unlock(&OCFS2_I(inode)->ip_lock); 562 + ret = 0; 563 + goto bail; 564 + } 565 + 566 + /* 567 + * Any write past EOF is not allowed because we'd be extending. 568 + */ 569 + if (create && (iblock + max_blocks) > inode_blocks) { 558 570 spin_unlock(&OCFS2_I(inode)->ip_lock); 559 571 ret = -EIO; 560 572 goto bail;