aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ext4/extents.c
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2013-04-03 12:47:17 -0400
committerTheodore Ts'o <tytso@mit.edu>2013-04-03 12:47:17 -0400
commit819c4920b7e60ecfd6f0f61d890af4cdf3873d18 (patch)
tree85f995b14c7308080d196d85b9b3d148337a6382 /fs/ext4/extents.c
parent26a4c0c6ccecf6814cf44f951c97222bd795bc1a (diff)
ext4: refactor truncate code
Move common code in ext4_ind_truncate() and ext4_ext_truncate() into ext4_truncate(). This saves over 60 lines of code. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Diffstat (limited to 'fs/ext4/extents.c')
-rw-r--r--fs/ext4/extents.c60
1 files changed, 1 insertions, 59 deletions
diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index d58365e40df7..cbbe8a4deac6 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -4257,48 +4257,13 @@ out3:
4257 return err ? err : allocated; 4257 return err ? err : allocated;
4258} 4258}
4259 4259
4260void ext4_ext_truncate(struct inode *inode) 4260void ext4_ext_truncate(handle_t *handle, struct inode *inode)
4261{ 4261{
4262 struct address_space *mapping = inode->i_mapping;
4263 struct super_block *sb = inode->i_sb; 4262 struct super_block *sb = inode->i_sb;
4264 ext4_lblk_t last_block; 4263 ext4_lblk_t last_block;
4265 handle_t *handle;
4266 loff_t page_len;
4267 int err = 0; 4264 int err = 0;
4268 4265
4269 /* 4266 /*
4270 * finish any pending end_io work so we won't run the risk of
4271 * converting any truncated blocks to initialized later
4272 */
4273 ext4_flush_unwritten_io(inode);
4274
4275 /*
4276 * probably first extent we're gonna free will be last in block
4277 */
4278 err = ext4_writepage_trans_blocks(inode);
4279 handle = ext4_journal_start(inode, EXT4_HT_TRUNCATE, err);
4280 if (IS_ERR(handle))
4281 return;
4282
4283 if (inode->i_size % PAGE_CACHE_SIZE != 0) {
4284 page_len = PAGE_CACHE_SIZE -
4285 (inode->i_size & (PAGE_CACHE_SIZE - 1));
4286
4287 err = ext4_discard_partial_page_buffers(handle,
4288 mapping, inode->i_size, page_len, 0);
4289
4290 if (err)
4291 goto out_stop;
4292 }
4293
4294 if (ext4_orphan_add(handle, inode))
4295 goto out_stop;
4296
4297 down_write(&EXT4_I(inode)->i_data_sem);
4298
4299 ext4_discard_preallocations(inode);
4300
4301 /*
4302 * TODO: optimization is possible here. 4267 * TODO: optimization is possible here.
4303 * Probably we need not scan at all, 4268 * Probably we need not scan at all,
4304 * because page truncation is enough. 4269 * because page truncation is enough.
@@ -4313,29 +4278,6 @@ void ext4_ext_truncate(struct inode *inode)
4313 err = ext4_es_remove_extent(inode, last_block, 4278 err = ext4_es_remove_extent(inode, last_block,
4314 EXT_MAX_BLOCKS - last_block); 4279 EXT_MAX_BLOCKS - last_block);
4315 err = ext4_ext_remove_space(inode, last_block, EXT_MAX_BLOCKS - 1); 4280 err = ext4_ext_remove_space(inode, last_block, EXT_MAX_BLOCKS - 1);
4316
4317 /* In a multi-transaction truncate, we only make the final
4318 * transaction synchronous.
4319 */
4320 if (IS_SYNC(inode))
4321 ext4_handle_sync(handle);
4322
4323 up_write(&EXT4_I(inode)->i_data_sem);
4324
4325out_stop:
4326 /*
4327 * If this was a simple ftruncate() and the file will remain alive,
4328 * then we need to clear up the orphan record which we created above.
4329 * However, if this was a real unlink then we were called by
4330 * ext4_delete_inode(), and we allow that function to clean up the
4331 * orphan info for us.
4332 */
4333 if (inode->i_nlink)
4334 ext4_orphan_del(handle, inode);
4335
4336 inode->i_mtime = inode->i_ctime = ext4_current_time(inode);
4337 ext4_mark_inode_dirty(handle, inode);
4338 ext4_journal_stop(handle);
4339} 4281}
4340 4282
4341static void ext4_falloc_update_inode(struct inode *inode, 4283static void ext4_falloc_update_inode(struct inode *inode,