OCFS2 1.2.4-2 の r2948 fs - Allow direct I/O read past end of file 純粋な変更点

OCFS2 1.2.4-2 の r2948 fs - Allow direct I/O read past end of file - tmpfile::memoの続き

Revision: 2948
Author: mfasheh
Date: 6:54:42, 2006年12月21日
Message:
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: smushran

      • -

Modified : /branches/ocfs2-1.2/fs/ocfs2/aops.c

diff

Index: C:/home/work/OCFS2_after2006/fs/ocfs2/aops.c
===================================================================
--- C:/home/work/OCFS2_after2006/fs/ocfs2/aops.c	(リビジョン 2947)
+++ C:/home/work/OCFS2_after2006/fs/ocfs2/aops.c	(リビジョン 2948)
@@ -340,8 +340,7 @@
 	unsigned long max_blocks = bh_result->b_size >> inode->i_blkbits;
 #endif
 	int ret;
-	u64 vbo_max; /* file offset, max_blocks from iblock */
-	u64 p_blkno;
+	u64 p_blkno, inode_blocks;
 	int contig_blocks;
 	unsigned char blocksize_bits;
 
@@ -356,13 +355,24 @@
 	 * nicely aligned and of the right size, so there's no need
 	 * for us to check any of that. */
 
-	vbo_max = ((u64)iblock + max_blocks) << blocksize_bits;
+	spin_lock(&OCFS2_I(inode)->ip_lock);
+	inode_blocks = ocfs2_clusters_to_blocks(inode->i_sb,
+						OCFS2_I(inode)->ip_clusters);
 
-	spin_lock(&OCFS2_I(inode)->ip_lock);
-	if ((iblock + max_blocks) >
-	    ocfs2_clusters_to_blocks(inode->i_sb,
-				     OCFS2_I(inode)->ip_clusters)) {
+	/*
+	 * For a read which begins past the end of file, we return a hole.
+	 */
+	if (!create && (iblock >= inode_blocks)) {
 		spin_unlock(&OCFS2_I(inode)->ip_lock);
+		ret = 0;
+		goto bail;
+	}
+
+	/*
+	 * Any write past EOF is not allowed because we'd be extending.
+	 */
+	if (create && (iblock + max_blocks) > inode_blocks) {
+		spin_unlock(&OCFS2_I(inode)->ip_lock);
 		ret = -EIO;
 		goto bail;
 	}

Project Source Control: OCFS2 Tools - oss.oracle.comを応用して

svn checkout http://oss.oracle.com/projects/ocfs2/src/branches/ocfs2-1.2/ 

をやっときゃわかる話だけど。