ext4: make ext4_ext_get_blocks always return <= max_blocks
authorAneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Tue, 29 Apr 2008 12:11:12 +0000 (08:11 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Tue, 29 Apr 2008 12:11:12 +0000 (08:11 -0400)
ext4_ext_get_blocks() returns number of blocks allocated with buffer
heads unmapped for a read from prealloc space.  This is needed so that
delayed allocation doesn't do block reservation for prealloc space since
the blocks are already resevred on disk.  Fix ext4_ext_get_blocks to not
return greater than max_blocks, since some of the code paths cannot
handle such a return value.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
fs/ext4/extents.c

index c2b004e29ad8f239c2cc66bb80f331d0b1e7ca79..f4ef0b745a53f97b5547199e1d8cd6d0b65bb367 100644 (file)
@@ -2570,8 +2570,18 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode,
                        }
                        if (create == EXT4_CREATE_UNINITIALIZED_EXT)
                                goto out;
-                       if (!create)
+                       if (!create) {
+                               /*
+                                * We have blocks reserved already.  We
+                                * return allocated blocks so that delalloc
+                                * won't do block reservation for us.  But
+                                * the buffer head will be unmapped so that
+                                * a read from the block returns 0s.
+                                */
+                               if (allocated > max_blocks)
+                                       allocated = max_blocks;
                                goto out2;
+                       }
 
                        ret = ext4_ext_convert_to_initialized(handle, inode,
                                                                path, iblock,