ext4: Clear the unwritten buffer_head flag after the extent is initialized

The BH_Unwritten flag indicates that the buffer is allocated on disk
but has not been written; that is, the disk was part of a persistent
preallocation area. That flag should only be set when a get_blocks()
function is looking up a inode's logical to physical block mapping.

When ext4_get_blocks_wrap() is called with create=1, the uninitialized
extent is converted into an initialized one, so the BH_Unwritten flag
is no longer appropriate. Hence, we need to make sure the
BH_Unwritten is not left set, since the combination of BH_Mapped and
BH_Unwritten is not allowed; among other things, it will result ext4's
get_block() to be called over and over again during the write_begin
phase of write(2).

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

authored by Aneesh Kumar K.V and committed by Theodore Ts'o 2a8964d6 33b9817e

+13
+13
fs/ext4/inode.c
··· 1149 1149 int retval; 1150 1150 1151 1151 clear_buffer_mapped(bh); 1152 + clear_buffer_unwritten(bh); 1152 1153 1153 1154 /* 1154 1155 * Try to see if we can get the block without requesting ··· 1178 1177 */ 1179 1178 if (retval > 0 && buffer_mapped(bh)) 1180 1179 return retval; 1180 + 1181 + /* 1182 + * When we call get_blocks without the create flag, the 1183 + * BH_Unwritten flag could have gotten set if the blocks 1184 + * requested were part of a uninitialized extent. We need to 1185 + * clear this flag now that we are committed to convert all or 1186 + * part of the uninitialized extent to be an initialized 1187 + * extent. This is because we need to avoid the combination 1188 + * of BH_Unwritten and BH_Mapped flags being simultaneously 1189 + * set on the buffer_head. 1190 + */ 1191 + clear_buffer_unwritten(bh); 1181 1192 1182 1193 /* 1183 1194 * New blocks allocate and/or writing to uninitialized extent