ext4: Handle unwritten extent properly with delayed allocation

When using fallocate the buffer_heads are marked unwritten and unmapped.
We need to map them in the writepages after a get_block. Otherwise we
split the uninit extents, but never write the content to disk.

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

authored by Aneesh Kumar K.V and committed by Theodore Ts'o bf068ee2 30a2f3c6

+10 -2
+10 -2
fs/ext4/inode.c
··· 1741 if (buffer_delay(bh)) { 1742 bh->b_blocknr = pblock; 1743 clear_buffer_delay(bh); 1744 } else if (buffer_mapped(bh)) 1745 BUG_ON(bh->b_blocknr != pblock); 1746 ··· 1821 * If blocks are delayed marked, we need to 1822 * put actual blocknr and drop delayed bit 1823 */ 1824 - if (buffer_delay(lbh)) 1825 mpage_put_bnr_to_bhs(mpd, next, &new); 1826 1827 /* go for the remaining blocks */ ··· 1830 } 1831 } 1832 1833 - #define BH_FLAGS ((1 << BH_Uptodate) | (1 << BH_Mapped) | (1 << BH_Delay)) 1834 1835 /* 1836 * mpage_add_bh_to_extent - try to add one more block to extent of blocks
··· 1741 if (buffer_delay(bh)) { 1742 bh->b_blocknr = pblock; 1743 clear_buffer_delay(bh); 1744 + bh->b_bdev = inode->i_sb->s_bdev; 1745 + } else if (buffer_unwritten(bh)) { 1746 + bh->b_blocknr = pblock; 1747 + clear_buffer_unwritten(bh); 1748 + set_buffer_mapped(bh); 1749 + set_buffer_new(bh); 1750 + bh->b_bdev = inode->i_sb->s_bdev; 1751 } else if (buffer_mapped(bh)) 1752 BUG_ON(bh->b_blocknr != pblock); 1753 ··· 1814 * If blocks are delayed marked, we need to 1815 * put actual blocknr and drop delayed bit 1816 */ 1817 + if (buffer_delay(lbh) || buffer_unwritten(lbh)) 1818 mpage_put_bnr_to_bhs(mpd, next, &new); 1819 1820 /* go for the remaining blocks */ ··· 1823 } 1824 } 1825 1826 + #define BH_FLAGS ((1 << BH_Uptodate) | (1 << BH_Mapped) | \ 1827 + (1 << BH_Delay) | (1 << BH_Unwritten)) 1828 1829 /* 1830 * mpage_add_bh_to_extent - try to add one more block to extent of blocks