Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ext4: move common truncate functions to header file

Move two functions that will be needed by the indirect functions to be
moved to indirect.c as well as inode.c to truncate.h as inline
functions, so that we can avoid having duplicate copies of the
function (which can be a maintenance problem) without having to expose
them as globally functions.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>

+49 -42
+6 -42
fs/ext4/inode.c
··· 47 47 #include "xattr.h" 48 48 #include "acl.h" 49 49 #include "ext4_extents.h" 50 + #include "truncate.h" 50 51 51 52 #include <trace/events/ext4.h> 52 53 ··· 90 89 } 91 90 92 91 /* 93 - * Work out how many blocks we need to proceed with the next chunk of a 94 - * truncate transaction. 95 - */ 96 - static unsigned long blocks_for_truncate(struct inode *inode) 97 - { 98 - ext4_lblk_t needed; 99 - 100 - needed = inode->i_blocks >> (inode->i_sb->s_blocksize_bits - 9); 101 - 102 - /* Give ourselves just enough room to cope with inodes in which 103 - * i_blocks is corrupt: we've seen disk corruptions in the past 104 - * which resulted in random data in an inode which looked enough 105 - * like a regular file for ext4 to try to delete it. Things 106 - * will go a bit crazy if that happens, but at least we should 107 - * try not to panic the whole kernel. */ 108 - if (needed < 2) 109 - needed = 2; 110 - 111 - /* But we need to bound the transaction so we don't overflow the 112 - * journal. */ 113 - if (needed > EXT4_MAX_TRANS_DATA) 114 - needed = EXT4_MAX_TRANS_DATA; 115 - 116 - return EXT4_DATA_TRANS_BLOCKS(inode->i_sb) + needed; 117 - } 118 - 119 - /* 120 92 * Truncate transactions can be complex and absolutely huge. So we need to 121 93 * be able to restart the transaction at a conventient checkpoint to make 122 94 * sure we don't overflow the journal. ··· 103 129 { 104 130 handle_t *result; 105 131 106 - result = ext4_journal_start(inode, blocks_for_truncate(inode)); 132 + result = ext4_journal_start(inode, ext4_blocks_for_truncate(inode)); 107 133 if (!IS_ERR(result)) 108 134 return result; 109 135 ··· 123 149 return 0; 124 150 if (ext4_handle_has_enough_credits(handle, EXT4_RESERVE_TRANS_BLOCKS+1)) 125 151 return 0; 126 - if (!ext4_journal_extend(handle, blocks_for_truncate(inode))) 152 + if (!ext4_journal_extend(handle, ext4_blocks_for_truncate(inode))) 127 153 return 0; 128 154 return 1; 129 155 } ··· 178 204 if (is_bad_inode(inode)) 179 205 goto no_delete; 180 206 181 - handle = ext4_journal_start(inode, blocks_for_truncate(inode)+3); 207 + handle = ext4_journal_start(inode, ext4_blocks_for_truncate(inode)+3); 182 208 if (IS_ERR(handle)) { 183 209 ext4_std_error(inode->i_sb, PTR_ERR(handle)); 184 210 /* ··· 1527 1553 if (!ret && dirty) 1528 1554 ret = ext4_handle_dirty_metadata(handle, NULL, bh); 1529 1555 return ret; 1530 - } 1531 - 1532 - /* 1533 - * Truncate blocks that were not used by write. We have to truncate the 1534 - * pagecache as well so that corresponding buffers get properly unmapped. 1535 - */ 1536 - static void ext4_truncate_failed_write(struct inode *inode) 1537 - { 1538 - truncate_inode_pages(inode->i_mapping, inode->i_size); 1539 - ext4_truncate(inode); 1540 1556 } 1541 1557 1542 1558 static int ext4_get_block_write(struct inode *inode, sector_t iblock, ··· 4098 4134 if (unlikely(err)) 4099 4135 goto out_err; 4100 4136 err = ext4_truncate_restart_trans(handle, inode, 4101 - blocks_for_truncate(inode)); 4137 + ext4_blocks_for_truncate(inode)); 4102 4138 if (unlikely(err)) 4103 4139 goto out_err; 4104 4140 if (bh) { ··· 4293 4329 if (try_to_extend_transaction(handle, inode)) { 4294 4330 ext4_mark_inode_dirty(handle, inode); 4295 4331 ext4_truncate_restart_trans(handle, inode, 4296 - blocks_for_truncate(inode)); 4332 + ext4_blocks_for_truncate(inode)); 4297 4333 } 4298 4334 4299 4335 /*
+43
fs/ext4/truncate.h
··· 1 + /* 2 + * linux/fs/ext4/truncate.h 3 + * 4 + * Common inline functions needed for truncate support 5 + */ 6 + 7 + /* 8 + * Truncate blocks that were not used by write. We have to truncate the 9 + * pagecache as well so that corresponding buffers get properly unmapped. 10 + */ 11 + static inline void ext4_truncate_failed_write(struct inode *inode) 12 + { 13 + truncate_inode_pages(inode->i_mapping, inode->i_size); 14 + ext4_truncate(inode); 15 + } 16 + 17 + /* 18 + * Work out how many blocks we need to proceed with the next chunk of a 19 + * truncate transaction. 20 + */ 21 + static inline unsigned long ext4_blocks_for_truncate(struct inode *inode) 22 + { 23 + ext4_lblk_t needed; 24 + 25 + needed = inode->i_blocks >> (inode->i_sb->s_blocksize_bits - 9); 26 + 27 + /* Give ourselves just enough room to cope with inodes in which 28 + * i_blocks is corrupt: we've seen disk corruptions in the past 29 + * which resulted in random data in an inode which looked enough 30 + * like a regular file for ext4 to try to delete it. Things 31 + * will go a bit crazy if that happens, but at least we should 32 + * try not to panic the whole kernel. */ 33 + if (needed < 2) 34 + needed = 2; 35 + 36 + /* But we need to bound the transaction so we don't overflow the 37 + * journal. */ 38 + if (needed > EXT4_MAX_TRANS_DATA) 39 + needed = EXT4_MAX_TRANS_DATA; 40 + 41 + return EXT4_DATA_TRANS_BLOCKS(inode->i_sb) + needed; 42 + } 43 +