aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ext4/inode.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/ext4/inode.c')
-rw-r--r--fs/ext4/inode.c81
1 files changed, 56 insertions, 25 deletions
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index e659597b690b..9f7f9e49914f 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -39,7 +39,9 @@
39#include <linux/bio.h> 39#include <linux/bio.h>
40#include <linux/workqueue.h> 40#include <linux/workqueue.h>
41#include <linux/kernel.h> 41#include <linux/kernel.h>
42#include <linux/printk.h>
42#include <linux/slab.h> 43#include <linux/slab.h>
44#include <linux/ratelimit.h>
43 45
44#include "ext4_jbd2.h" 46#include "ext4_jbd2.h"
45#include "xattr.h" 47#include "xattr.h"
@@ -54,10 +56,17 @@ static inline int ext4_begin_ordered_truncate(struct inode *inode,
54 loff_t new_size) 56 loff_t new_size)
55{ 57{
56 trace_ext4_begin_ordered_truncate(inode, new_size); 58 trace_ext4_begin_ordered_truncate(inode, new_size);
57 return jbd2_journal_begin_ordered_truncate( 59 /*
58 EXT4_SB(inode->i_sb)->s_journal, 60 * If jinode is zero, then we never opened the file for
59 &EXT4_I(inode)->jinode, 61 * writing, so there's no need to call
60 new_size); 62 * jbd2_journal_begin_ordered_truncate() since there's no
63 * outstanding writes we need to flush.
64 */
65 if (!EXT4_I(inode)->jinode)
66 return 0;
67 return jbd2_journal_begin_ordered_truncate(EXT4_JOURNAL(inode),
68 EXT4_I(inode)->jinode,
69 new_size);
61} 70}
62 71
63static void ext4_invalidatepage(struct page *page, unsigned long offset); 72static void ext4_invalidatepage(struct page *page, unsigned long offset);
@@ -552,7 +561,7 @@ static ext4_fsblk_t ext4_find_goal(struct inode *inode, ext4_lblk_t block,
552} 561}
553 562
554/** 563/**
555 * ext4_blks_to_allocate: Look up the block map and count the number 564 * ext4_blks_to_allocate - Look up the block map and count the number
556 * of direct blocks need to be allocated for the given branch. 565 * of direct blocks need to be allocated for the given branch.
557 * 566 *
558 * @branch: chain of indirect blocks 567 * @branch: chain of indirect blocks
@@ -591,13 +600,19 @@ static int ext4_blks_to_allocate(Indirect *branch, int k, unsigned int blks,
591 600
592/** 601/**
593 * ext4_alloc_blocks: multiple allocate blocks needed for a branch 602 * ext4_alloc_blocks: multiple allocate blocks needed for a branch
603 * @handle: handle for this transaction
604 * @inode: inode which needs allocated blocks
605 * @iblock: the logical block to start allocated at
606 * @goal: preferred physical block of allocation
594 * @indirect_blks: the number of blocks need to allocate for indirect 607 * @indirect_blks: the number of blocks need to allocate for indirect
595 * blocks 608 * blocks
596 * 609 * @blks: number of desired blocks
597 * @new_blocks: on return it will store the new block numbers for 610 * @new_blocks: on return it will store the new block numbers for
598 * the indirect blocks(if needed) and the first direct block, 611 * the indirect blocks(if needed) and the first direct block,
599 * @blks: on return it will store the total number of allocated 612 * @err: on return it will store the error code
600 * direct blocks 613 *
614 * This function will return the number of blocks allocated as
615 * requested by the passed-in parameters.
601 */ 616 */
602static int ext4_alloc_blocks(handle_t *handle, struct inode *inode, 617static int ext4_alloc_blocks(handle_t *handle, struct inode *inode,
603 ext4_lblk_t iblock, ext4_fsblk_t goal, 618 ext4_lblk_t iblock, ext4_fsblk_t goal,
@@ -711,9 +726,11 @@ failed_out:
711 726
712/** 727/**
713 * ext4_alloc_branch - allocate and set up a chain of blocks. 728 * ext4_alloc_branch - allocate and set up a chain of blocks.
729 * @handle: handle for this transaction
714 * @inode: owner 730 * @inode: owner
715 * @indirect_blks: number of allocated indirect blocks 731 * @indirect_blks: number of allocated indirect blocks
716 * @blks: number of allocated direct blocks 732 * @blks: number of allocated direct blocks
733 * @goal: preferred place for allocation
717 * @offsets: offsets (in the blocks) to store the pointers to next. 734 * @offsets: offsets (in the blocks) to store the pointers to next.
718 * @branch: place to store the chain in. 735 * @branch: place to store the chain in.
719 * 736 *
@@ -826,6 +843,7 @@ failed:
826 843
827/** 844/**
828 * ext4_splice_branch - splice the allocated branch onto inode. 845 * ext4_splice_branch - splice the allocated branch onto inode.
846 * @handle: handle for this transaction
829 * @inode: owner 847 * @inode: owner
830 * @block: (logical) number of block we are adding 848 * @block: (logical) number of block we are adding
831 * @chain: chain of indirect blocks (with a missing link - see 849 * @chain: chain of indirect blocks (with a missing link - see
@@ -1081,7 +1099,7 @@ static int ext4_indirect_calc_metadata_amount(struct inode *inode,
1081 * Calculate the number of metadata blocks need to reserve 1099 * Calculate the number of metadata blocks need to reserve
1082 * to allocate a block located at @lblock 1100 * to allocate a block located at @lblock
1083 */ 1101 */
1084static int ext4_calc_metadata_amount(struct inode *inode, sector_t lblock) 1102static int ext4_calc_metadata_amount(struct inode *inode, ext4_lblk_t lblock)
1085{ 1103{
1086 if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) 1104 if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))
1087 return ext4_ext_calc_metadata_amount(inode, lblock); 1105 return ext4_ext_calc_metadata_amount(inode, lblock);
@@ -1320,7 +1338,7 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode,
1320 * avoid double accounting 1338 * avoid double accounting
1321 */ 1339 */
1322 if (flags & EXT4_GET_BLOCKS_DELALLOC_RESERVE) 1340 if (flags & EXT4_GET_BLOCKS_DELALLOC_RESERVE)
1323 EXT4_I(inode)->i_delalloc_reserved_flag = 1; 1341 ext4_set_inode_state(inode, EXT4_STATE_DELALLOC_RESERVED);
1324 /* 1342 /*
1325 * We need to check for EXT4 here because migrate 1343 * We need to check for EXT4 here because migrate
1326 * could have changed the inode type in between 1344 * could have changed the inode type in between
@@ -1350,7 +1368,7 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode,
1350 ext4_da_update_reserve_space(inode, retval, 1); 1368 ext4_da_update_reserve_space(inode, retval, 1);
1351 } 1369 }
1352 if (flags & EXT4_GET_BLOCKS_DELALLOC_RESERVE) 1370 if (flags & EXT4_GET_BLOCKS_DELALLOC_RESERVE)
1353 EXT4_I(inode)->i_delalloc_reserved_flag = 0; 1371 ext4_clear_inode_state(inode, EXT4_STATE_DELALLOC_RESERVED);
1354 1372
1355 up_write((&EXT4_I(inode)->i_data_sem)); 1373 up_write((&EXT4_I(inode)->i_data_sem));
1356 if (retval > 0 && map->m_flags & EXT4_MAP_MAPPED) { 1374 if (retval > 0 && map->m_flags & EXT4_MAP_MAPPED) {
@@ -1878,7 +1896,7 @@ static int ext4_journalled_write_end(struct file *file,
1878/* 1896/*
1879 * Reserve a single block located at lblock 1897 * Reserve a single block located at lblock
1880 */ 1898 */
1881static int ext4_da_reserve_space(struct inode *inode, sector_t lblock) 1899static int ext4_da_reserve_space(struct inode *inode, ext4_lblk_t lblock)
1882{ 1900{
1883 int retries = 0; 1901 int retries = 0;
1884 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); 1902 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
@@ -2239,7 +2257,7 @@ static void mpage_da_map_and_submit(struct mpage_da_data *mpd)
2239 * affects functions in many different parts of the allocation 2257 * affects functions in many different parts of the allocation
2240 * call path. This flag exists primarily because we don't 2258 * call path. This flag exists primarily because we don't
2241 * want to change *many* call functions, so ext4_map_blocks() 2259 * want to change *many* call functions, so ext4_map_blocks()
2242 * will set the magic i_delalloc_reserved_flag once the 2260 * will set the EXT4_STATE_DELALLOC_RESERVED flag once the
2243 * inode's allocation semaphore is taken. 2261 * inode's allocation semaphore is taken.
2244 * 2262 *
2245 * If the blocks in questions were delalloc blocks, set 2263 * If the blocks in questions were delalloc blocks, set
@@ -3362,7 +3380,7 @@ int ext4_alloc_da_blocks(struct inode *inode)
3362 * doing I/O at all. 3380 * doing I/O at all.
3363 * 3381 *
3364 * We could call write_cache_pages(), and then redirty all of 3382 * We could call write_cache_pages(), and then redirty all of
3365 * the pages by calling redirty_page_for_writeback() but that 3383 * the pages by calling redirty_page_for_writepage() but that
3366 * would be ugly in the extreme. So instead we would need to 3384 * would be ugly in the extreme. So instead we would need to
3367 * replicate parts of the code in the above functions, 3385 * replicate parts of the code in the above functions,
3368 * simplifying them becuase we wouldn't actually intend to 3386 * simplifying them becuase we wouldn't actually intend to
@@ -3720,8 +3738,7 @@ static int ext4_set_bh_endio(struct buffer_head *bh, struct inode *inode)
3720retry: 3738retry:
3721 io_end = ext4_init_io_end(inode, GFP_ATOMIC); 3739 io_end = ext4_init_io_end(inode, GFP_ATOMIC);
3722 if (!io_end) { 3740 if (!io_end) {
3723 if (printk_ratelimit()) 3741 pr_warn_ratelimited("%s: allocation fail\n", __func__);
3724 printk(KERN_WARNING "%s: allocation fail\n", __func__);
3725 schedule(); 3742 schedule();
3726 goto retry; 3743 goto retry;
3727 } 3744 }
@@ -3745,9 +3762,9 @@ retry:
3745 * preallocated extents, and those write extend the file, no need to 3762 * preallocated extents, and those write extend the file, no need to
3746 * fall back to buffered IO. 3763 * fall back to buffered IO.
3747 * 3764 *
3748 * For holes, we fallocate those blocks, mark them as unintialized 3765 * For holes, we fallocate those blocks, mark them as uninitialized
3749 * If those blocks were preallocated, we mark sure they are splited, but 3766 * If those blocks were preallocated, we mark sure they are splited, but
3750 * still keep the range to write as unintialized. 3767 * still keep the range to write as uninitialized.
3751 * 3768 *
3752 * The unwrritten extents will be converted to written when DIO is completed. 3769 * The unwrritten extents will be converted to written when DIO is completed.
3753 * For async direct IO, since the IO may still pending when return, we 3770 * For async direct IO, since the IO may still pending when return, we
@@ -4045,7 +4062,7 @@ int ext4_block_truncate_page(handle_t *handle,
4045 if (ext4_should_journal_data(inode)) { 4062 if (ext4_should_journal_data(inode)) {
4046 err = ext4_handle_dirty_metadata(handle, inode, bh); 4063 err = ext4_handle_dirty_metadata(handle, inode, bh);
4047 } else { 4064 } else {
4048 if (ext4_should_order_data(inode)) 4065 if (ext4_should_order_data(inode) && EXT4_I(inode)->jinode)
4049 err = ext4_jbd2_file_inode(handle, inode); 4066 err = ext4_jbd2_file_inode(handle, inode);
4050 mark_buffer_dirty(bh); 4067 mark_buffer_dirty(bh);
4051 } 4068 }
@@ -4169,6 +4186,7 @@ static int ext4_clear_blocks(handle_t *handle, struct inode *inode,
4169{ 4186{
4170 __le32 *p; 4187 __le32 *p;
4171 int flags = EXT4_FREE_BLOCKS_FORGET | EXT4_FREE_BLOCKS_VALIDATED; 4188 int flags = EXT4_FREE_BLOCKS_FORGET | EXT4_FREE_BLOCKS_VALIDATED;
4189 int err;
4172 4190
4173 if (S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode)) 4191 if (S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode))
4174 flags |= EXT4_FREE_BLOCKS_METADATA; 4192 flags |= EXT4_FREE_BLOCKS_METADATA;
@@ -4184,11 +4202,23 @@ static int ext4_clear_blocks(handle_t *handle, struct inode *inode,
4184 if (try_to_extend_transaction(handle, inode)) { 4202 if (try_to_extend_transaction(handle, inode)) {
4185 if (bh) { 4203 if (bh) {
4186 BUFFER_TRACE(bh, "call ext4_handle_dirty_metadata"); 4204 BUFFER_TRACE(bh, "call ext4_handle_dirty_metadata");
4187 ext4_handle_dirty_metadata(handle, inode, bh); 4205 err = ext4_handle_dirty_metadata(handle, inode, bh);
4206 if (unlikely(err)) {
4207 ext4_std_error(inode->i_sb, err);
4208 return 1;
4209 }
4210 }
4211 err = ext4_mark_inode_dirty(handle, inode);
4212 if (unlikely(err)) {
4213 ext4_std_error(inode->i_sb, err);
4214 return 1;
4215 }
4216 err = ext4_truncate_restart_trans(handle, inode,
4217 blocks_for_truncate(inode));
4218 if (unlikely(err)) {
4219 ext4_std_error(inode->i_sb, err);
4220 return 1;
4188 } 4221 }
4189 ext4_mark_inode_dirty(handle, inode);
4190 ext4_truncate_restart_trans(handle, inode,
4191 blocks_for_truncate(inode));
4192 if (bh) { 4222 if (bh) {
4193 BUFFER_TRACE(bh, "retaking write access"); 4223 BUFFER_TRACE(bh, "retaking write access");
4194 ext4_journal_get_write_access(handle, bh); 4224 ext4_journal_get_write_access(handle, bh);
@@ -4349,6 +4379,7 @@ static void ext4_free_branches(handle_t *handle, struct inode *inode,
4349 (__le32 *) bh->b_data, 4379 (__le32 *) bh->b_data,
4350 (__le32 *) bh->b_data + addr_per_block, 4380 (__le32 *) bh->b_data + addr_per_block,
4351 depth); 4381 depth);
4382 brelse(bh);
4352 4383
4353 /* 4384 /*
4354 * Everything below this this pointer has been 4385 * Everything below this this pointer has been
@@ -4859,7 +4890,7 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino)
4859 } 4890 }
4860 inode->i_nlink = le16_to_cpu(raw_inode->i_links_count); 4891 inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
4861 4892
4862 ei->i_state_flags = 0; 4893 ext4_clear_state_flags(ei); /* Only relevant on 32-bit archs */
4863 ei->i_dir_start_lookup = 0; 4894 ei->i_dir_start_lookup = 0;
4864 ei->i_dtime = le32_to_cpu(raw_inode->i_dtime); 4895 ei->i_dtime = le32_to_cpu(raw_inode->i_dtime);
4865 /* We now have enough fields to check if the inode was active or not. 4896 /* We now have enough fields to check if the inode was active or not.
@@ -5118,7 +5149,7 @@ static int ext4_do_update_inode(handle_t *handle,
5118 if (ext4_inode_blocks_set(handle, raw_inode, ei)) 5149 if (ext4_inode_blocks_set(handle, raw_inode, ei))
5119 goto out_brelse; 5150 goto out_brelse;
5120 raw_inode->i_dtime = cpu_to_le32(ei->i_dtime); 5151 raw_inode->i_dtime = cpu_to_le32(ei->i_dtime);
5121 raw_inode->i_flags = cpu_to_le32(ei->i_flags); 5152 raw_inode->i_flags = cpu_to_le32(ei->i_flags & 0xFFFFFFFF);
5122 if (EXT4_SB(inode->i_sb)->s_es->s_creator_os != 5153 if (EXT4_SB(inode->i_sb)->s_es->s_creator_os !=
5123 cpu_to_le32(EXT4_OS_HURD)) 5154 cpu_to_le32(EXT4_OS_HURD))
5124 raw_inode->i_file_acl_high = 5155 raw_inode->i_file_acl_high =