15 #include <linux/slab.h>
44 retval = PTR_ERR(path);
61 if (needed && ext4_handle_has_enough_credits(handle,
63 retval = ext4_journal_restart(handle, needed);
67 retval = ext4_journal_extend(handle, needed);
72 retval = ext4_journal_restart(handle, needed);
87 static int update_extent_range(handle_t *handle,
struct inode *inode,
105 retval = finish_range(handle, inode, lb);
112 static int update_ind_extent_range(handle_t *handle,
struct inode *inode,
116 struct buffer_head *bh;
121 bh = sb_bread(inode->
i_sb, pblock);
125 i_data = (
__le32 *)bh->b_data;
128 retval = update_extent_range(handle, inode,
141 static int update_dind_extent_range(handle_t *handle,
struct inode *inode,
145 struct buffer_head *bh;
148 unsigned long max_entries = inode->
i_sb->s_blocksize >> 2;
150 bh = sb_bread(inode->
i_sb, pblock);
154 i_data = (
__le32 *)bh->b_data;
157 retval = update_ind_extent_range(handle, inode,
171 static int update_tind_extent_range(handle_t *handle,
struct inode *inode,
175 struct buffer_head *bh;
178 unsigned long max_entries = inode->
i_sb->s_blocksize >> 2;
180 bh = sb_bread(inode->
i_sb, pblock);
184 i_data = (
__le32 *)bh->b_data;
187 retval = update_dind_extent_range(handle, inode,
201 static int extend_credit_for_blkdel(handle_t *handle,
struct inode *inode)
203 int retval = 0, needed;
215 if (ext4_journal_extend(handle, needed) != 0)
216 retval = ext4_journal_restart(handle, needed);
221 static int free_dind_blocks(handle_t *handle,
222 struct inode *inode,
__le32 i_data)
226 struct buffer_head *bh;
227 unsigned long max_entries = inode->
i_sb->s_blocksize >> 2;
233 tmp_idata = (
__le32 *)bh->b_data;
236 extend_credit_for_blkdel(handle, inode);
244 extend_credit_for_blkdel(handle, inode);
251 static int free_tind_blocks(handle_t *handle,
252 struct inode *inode,
__le32 i_data)
256 struct buffer_head *bh;
257 unsigned long max_entries = inode->
i_sb->s_blocksize >> 2;
263 tmp_idata = (
__le32 *)bh->b_data;
266 retval = free_dind_blocks(handle,
267 inode, tmp_idata[i]);
275 extend_credit_for_blkdel(handle, inode);
282 static int free_ind_block(handle_t *handle,
struct inode *inode,
__le32 *i_data)
288 extend_credit_for_blkdel(handle, inode);
297 retval = free_dind_blocks(handle, inode, i_data[1]);
304 retval = free_tind_blocks(handle, inode, i_data[2]);
311 static int ext4_ext_swap_inode_data(handle_t *handle,
struct inode *inode,
312 struct inode *tmp_inode)
323 retval = ext4_journal_extend(handle, 1);
325 retval = ext4_journal_restart(handle, 1);
340 if (!ext4_test_inode_state(inode, EXT4_STATE_EXT_MIGRATE)) {
345 ext4_clear_inode_state(inode, EXT4_STATE_EXT_MIGRATE);
362 spin_lock(&inode->
i_lock);
364 spin_unlock(&inode->
i_lock);
371 retval = free_ind_block(handle, inode, i_data);
378 static int free_ext_idx(handle_t *handle,
struct inode *inode,
383 struct buffer_head *bh;
386 block = ext4_idx_pblock(ix);
387 bh = sb_bread(inode->
i_sb, block);
395 retval = free_ext_idx(handle, inode, ix);
401 extend_credit_for_blkdel(handle, inode);
410 static int free_ext_block(handle_t *handle,
struct inode *inode)
423 retval = free_ext_idx(handle, inode, ix);
437 struct inode *tmp_inode =
NULL;
458 handle = ext4_journal_start(inode,
463 if (IS_ERR(handle)) {
464 retval = PTR_ERR(handle);
469 owner[0] = i_uid_read(inode);
470 owner[1] = i_gid_read(inode);
473 if (IS_ERR(tmp_inode)) {
474 retval = PTR_ERR(tmp_inode);
478 i_size_write(tmp_inode, i_size_read(inode));
506 ext4_set_inode_state(inode, EXT4_STATE_EXT_MIGRATE);
509 handle = ext4_journal_start(inode, 1);
510 if (IS_ERR(handle)) {
517 retval = PTR_ERR(handle);
523 memset(&lb, 0,
sizeof(lb));
526 max_entries = inode->
i_sb->s_blocksize >> 2;
529 retval = update_extent_range(handle, tmp_inode,
537 retval = update_ind_extent_range(handle, tmp_inode,
544 retval = update_dind_extent_range(handle, tmp_inode,
551 retval = update_tind_extent_range(handle, tmp_inode,
559 retval = finish_range(handle, tmp_inode, &lb);
566 free_ext_block(handle, tmp_inode);
568 retval = ext4_ext_swap_inode_data(handle, inode, tmp_inode);
574 free_ext_block(handle, tmp_inode);
578 if (ext4_journal_extend(handle, 1) != 0)
579 ext4_journal_restart(handle, 1);
584 i_size_write(tmp_inode, 0);