19f125d64STheodore Ts'o /* 29f125d64STheodore Ts'o * linux/fs/ext4/truncate.h 39f125d64STheodore Ts'o * 49f125d64STheodore Ts'o * Common inline functions needed for truncate support 59f125d64STheodore Ts'o */ 69f125d64STheodore Ts'o 79f125d64STheodore Ts'o /* 89f125d64STheodore Ts'o * Truncate blocks that were not used by write. We have to truncate the 99f125d64STheodore Ts'o * pagecache as well so that corresponding buffers get properly unmapped. 109f125d64STheodore Ts'o */ 119f125d64STheodore Ts'o static inline void ext4_truncate_failed_write(struct inode *inode) 129f125d64STheodore Ts'o { 13*ea3d7209SJan Kara down_write(&EXT4_I(inode)->i_mmap_sem); 149f125d64STheodore Ts'o truncate_inode_pages(inode->i_mapping, inode->i_size); 159f125d64STheodore Ts'o ext4_truncate(inode); 16*ea3d7209SJan Kara up_write(&EXT4_I(inode)->i_mmap_sem); 179f125d64STheodore Ts'o } 189f125d64STheodore Ts'o 199f125d64STheodore Ts'o /* 209f125d64STheodore Ts'o * Work out how many blocks we need to proceed with the next chunk of a 219f125d64STheodore Ts'o * truncate transaction. 229f125d64STheodore Ts'o */ 239f125d64STheodore Ts'o static inline unsigned long ext4_blocks_for_truncate(struct inode *inode) 249f125d64STheodore Ts'o { 259f125d64STheodore Ts'o ext4_lblk_t needed; 269f125d64STheodore Ts'o 279f125d64STheodore Ts'o needed = inode->i_blocks >> (inode->i_sb->s_blocksize_bits - 9); 289f125d64STheodore Ts'o 299f125d64STheodore Ts'o /* Give ourselves just enough room to cope with inodes in which 309f125d64STheodore Ts'o * i_blocks is corrupt: we've seen disk corruptions in the past 319f125d64STheodore Ts'o * which resulted in random data in an inode which looked enough 329f125d64STheodore Ts'o * like a regular file for ext4 to try to delete it. Things 339f125d64STheodore Ts'o * will go a bit crazy if that happens, but at least we should 349f125d64STheodore Ts'o * try not to panic the whole kernel. */ 359f125d64STheodore Ts'o if (needed < 2) 369f125d64STheodore Ts'o needed = 2; 379f125d64STheodore Ts'o 389f125d64STheodore Ts'o /* But we need to bound the transaction so we don't overflow the 399f125d64STheodore Ts'o * journal. */ 409f125d64STheodore Ts'o if (needed > EXT4_MAX_TRANS_DATA) 419f125d64STheodore Ts'o needed = EXT4_MAX_TRANS_DATA; 429f125d64STheodore Ts'o 439f125d64STheodore Ts'o return EXT4_DATA_TRANS_BLOCKS(inode->i_sb) + needed; 449f125d64STheodore Ts'o } 459f125d64STheodore Ts'o 46