Teach do_mpage_readpage() about unwritten extents so we can always
map them in get_blocks rather than treating them as are holes on
read.

This makes it one less hoop we have to jump through when dealing
with unwritten extents and it also allows setup_swap_extents() to
use preallocated files on XFS filesystems for swap files without
ever needing to convert them.

Signed-Off-By: Dave Chinner <dgc@sgi.com>
---
 fs/mpage.c                  |    5 +++--
 fs/xfs/linux-2.6/xfs_aops.c |   13 +++----------
 2 files changed, 6 insertions(+), 12 deletions(-)

Index: 2.6.x-xfs-new/fs/mpage.c
===================================================================
--- 2.6.x-xfs-new.orig/fs/mpage.c	2007-11-22 10:25:26.870114975 +1100
+++ 2.6.x-xfs-new/fs/mpage.c	2007-11-22 10:31:34.235189359 +1100
@@ -207,7 +207,8 @@ do_mpage_readpage(struct bio *bio, struc
 	 * Map blocks using the result from the previous get_blocks call first.
 	 */
 	nblocks = map_bh->b_size >> blkbits;
-	if (buffer_mapped(map_bh) && block_in_file > *first_logical_block &&
+	if (buffer_mapped(map_bh) && !buffer_unwritten(map_bh) &&
+			block_in_file > *first_logical_block &&
 			block_in_file < (*first_logical_block + nblocks)) {
 		unsigned map_offset = block_in_file - *first_logical_block;
 		unsigned last = nblocks - map_offset;
@@ -242,7 +243,7 @@ do_mpage_readpage(struct bio *bio, struc
 			*first_logical_block = block_in_file;
 		}
 
-		if (!buffer_mapped(map_bh)) {
+		if (!buffer_mapped(map_bh) || buffer_unwritten(map_bh)) {
 			fully_mapped = 0;
 			if (first_hole == blocks_per_page)
 				first_hole = page_block;
Index: 2.6.x-xfs-new/fs/xfs/linux-2.6/xfs_aops.c
===================================================================
--- 2.6.x-xfs-new.orig/fs/xfs/linux-2.6/xfs_aops.c	2007-11-22 10:31:31.495539463 +1100
+++ 2.6.x-xfs-new/fs/xfs/linux-2.6/xfs_aops.c	2007-11-22 10:31:34.235189359 +1100
@@ -1349,16 +1349,9 @@ __xfs_get_blocks(
 		return 0;
 
 	if (iomap.iomap_bn != IOMAP_DADDR_NULL) {
-		/*
-		 * For unwritten extents do not report a disk address on
-		 * the read case (treat as if we're reading into a hole).
-		 */
-		if (create || !(iomap.iomap_flags & IOMAP_UNWRITTEN)) {
-			xfs_map_buffer(bh_result, &iomap, offset,
-				       inode->i_blkbits);
-		}
-		if (create && (iomap.iomap_flags & IOMAP_UNWRITTEN)) {
-			if (direct)
+		xfs_map_buffer(bh_result, &iomap, offset, inode->i_blkbits);
+		if (iomap.iomap_flags & IOMAP_UNWRITTEN) {
+			if (create && direct)
 				bh_result->b_private = inode;
 			set_buffer_unwritten(bh_result);
 		}
