diff options
author | Paul Mundt <lethal@linux-sh.org> | 2011-01-12 00:37:42 -0500 |
---|---|---|
committer | Paul Mundt <lethal@linux-sh.org> | 2011-01-12 00:37:42 -0500 |
commit | 83eb95b852902f952ba594447a796ad8146b9462 (patch) | |
tree | 33c199aeeae58b69ad8d6d2a33c2d96ba2b98ddf /fs/ext4/inode.c | |
parent | efb3e34b6176d30c4fe8635fa8e1beb6280cc2cd (diff) | |
parent | 9bbe7b984096ac45586da2adf26c14069ecb79b2 (diff) |
Merge branch 'sh/sdio' into sh-latest
Diffstat (limited to 'fs/ext4/inode.c')
-rw-r--r-- | fs/ext4/inode.c | 74 |
1 files changed, 52 insertions, 22 deletions
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index e659597b690b..e80fc513eacc 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c | |||
@@ -40,6 +40,7 @@ | |||
40 | #include <linux/workqueue.h> | 40 | #include <linux/workqueue.h> |
41 | #include <linux/kernel.h> | 41 | #include <linux/kernel.h> |
42 | #include <linux/slab.h> | 42 | #include <linux/slab.h> |
43 | #include <linux/ratelimit.h> | ||
43 | 44 | ||
44 | #include "ext4_jbd2.h" | 45 | #include "ext4_jbd2.h" |
45 | #include "xattr.h" | 46 | #include "xattr.h" |
@@ -54,10 +55,17 @@ static inline int ext4_begin_ordered_truncate(struct inode *inode, | |||
54 | loff_t new_size) | 55 | loff_t new_size) |
55 | { | 56 | { |
56 | trace_ext4_begin_ordered_truncate(inode, new_size); | 57 | trace_ext4_begin_ordered_truncate(inode, new_size); |
57 | return jbd2_journal_begin_ordered_truncate( | 58 | /* |
58 | EXT4_SB(inode->i_sb)->s_journal, | 59 | * If jinode is zero, then we never opened the file for |
59 | &EXT4_I(inode)->jinode, | 60 | * writing, so there's no need to call |
60 | new_size); | 61 | * jbd2_journal_begin_ordered_truncate() since there's no |
62 | * outstanding writes we need to flush. | ||
63 | */ | ||
64 | if (!EXT4_I(inode)->jinode) | ||
65 | return 0; | ||
66 | return jbd2_journal_begin_ordered_truncate(EXT4_JOURNAL(inode), | ||
67 | EXT4_I(inode)->jinode, | ||
68 | new_size); | ||
61 | } | 69 | } |
62 | 70 | ||
63 | static void ext4_invalidatepage(struct page *page, unsigned long offset); | 71 | static void ext4_invalidatepage(struct page *page, unsigned long offset); |
@@ -552,7 +560,7 @@ static ext4_fsblk_t ext4_find_goal(struct inode *inode, ext4_lblk_t block, | |||
552 | } | 560 | } |
553 | 561 | ||
554 | /** | 562 | /** |
555 | * ext4_blks_to_allocate: Look up the block map and count the number | 563 | * 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. | 564 | * of direct blocks need to be allocated for the given branch. |
557 | * | 565 | * |
558 | * @branch: chain of indirect blocks | 566 | * @branch: chain of indirect blocks |
@@ -591,13 +599,19 @@ static int ext4_blks_to_allocate(Indirect *branch, int k, unsigned int blks, | |||
591 | 599 | ||
592 | /** | 600 | /** |
593 | * ext4_alloc_blocks: multiple allocate blocks needed for a branch | 601 | * ext4_alloc_blocks: multiple allocate blocks needed for a branch |
602 | * @handle: handle for this transaction | ||
603 | * @inode: inode which needs allocated blocks | ||
604 | * @iblock: the logical block to start allocated at | ||
605 | * @goal: preferred physical block of allocation | ||
594 | * @indirect_blks: the number of blocks need to allocate for indirect | 606 | * @indirect_blks: the number of blocks need to allocate for indirect |
595 | * blocks | 607 | * blocks |
596 | * | 608 | * @blks: number of desired blocks |
597 | * @new_blocks: on return it will store the new block numbers for | 609 | * @new_blocks: on return it will store the new block numbers for |
598 | * the indirect blocks(if needed) and the first direct block, | 610 | * the indirect blocks(if needed) and the first direct block, |
599 | * @blks: on return it will store the total number of allocated | 611 | * @err: on return it will store the error code |
600 | * direct blocks | 612 | * |
613 | * This function will return the number of blocks allocated as | ||
614 | * requested by the passed-in parameters. | ||
601 | */ | 615 | */ |
602 | static int ext4_alloc_blocks(handle_t *handle, struct inode *inode, | 616 | static int ext4_alloc_blocks(handle_t *handle, struct inode *inode, |
603 | ext4_lblk_t iblock, ext4_fsblk_t goal, | 617 | ext4_lblk_t iblock, ext4_fsblk_t goal, |
@@ -711,9 +725,11 @@ failed_out: | |||
711 | 725 | ||
712 | /** | 726 | /** |
713 | * ext4_alloc_branch - allocate and set up a chain of blocks. | 727 | * ext4_alloc_branch - allocate and set up a chain of blocks. |
728 | * @handle: handle for this transaction | ||
714 | * @inode: owner | 729 | * @inode: owner |
715 | * @indirect_blks: number of allocated indirect blocks | 730 | * @indirect_blks: number of allocated indirect blocks |
716 | * @blks: number of allocated direct blocks | 731 | * @blks: number of allocated direct blocks |
732 | * @goal: preferred place for allocation | ||
717 | * @offsets: offsets (in the blocks) to store the pointers to next. | 733 | * @offsets: offsets (in the blocks) to store the pointers to next. |
718 | * @branch: place to store the chain in. | 734 | * @branch: place to store the chain in. |
719 | * | 735 | * |
@@ -826,6 +842,7 @@ failed: | |||
826 | 842 | ||
827 | /** | 843 | /** |
828 | * ext4_splice_branch - splice the allocated branch onto inode. | 844 | * ext4_splice_branch - splice the allocated branch onto inode. |
845 | * @handle: handle for this transaction | ||
829 | * @inode: owner | 846 | * @inode: owner |
830 | * @block: (logical) number of block we are adding | 847 | * @block: (logical) number of block we are adding |
831 | * @chain: chain of indirect blocks (with a missing link - see | 848 | * @chain: chain of indirect blocks (with a missing link - see |
@@ -1081,7 +1098,7 @@ static int ext4_indirect_calc_metadata_amount(struct inode *inode, | |||
1081 | * Calculate the number of metadata blocks need to reserve | 1098 | * Calculate the number of metadata blocks need to reserve |
1082 | * to allocate a block located at @lblock | 1099 | * to allocate a block located at @lblock |
1083 | */ | 1100 | */ |
1084 | static int ext4_calc_metadata_amount(struct inode *inode, sector_t lblock) | 1101 | static int ext4_calc_metadata_amount(struct inode *inode, ext4_lblk_t lblock) |
1085 | { | 1102 | { |
1086 | if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) | 1103 | if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) |
1087 | return ext4_ext_calc_metadata_amount(inode, lblock); | 1104 | return ext4_ext_calc_metadata_amount(inode, lblock); |
@@ -1320,7 +1337,7 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode, | |||
1320 | * avoid double accounting | 1337 | * avoid double accounting |
1321 | */ | 1338 | */ |
1322 | if (flags & EXT4_GET_BLOCKS_DELALLOC_RESERVE) | 1339 | if (flags & EXT4_GET_BLOCKS_DELALLOC_RESERVE) |
1323 | EXT4_I(inode)->i_delalloc_reserved_flag = 1; | 1340 | ext4_set_inode_state(inode, EXT4_STATE_DELALLOC_RESERVED); |
1324 | /* | 1341 | /* |
1325 | * We need to check for EXT4 here because migrate | 1342 | * We need to check for EXT4 here because migrate |
1326 | * could have changed the inode type in between | 1343 | * could have changed the inode type in between |
@@ -1350,7 +1367,7 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode, | |||
1350 | ext4_da_update_reserve_space(inode, retval, 1); | 1367 | ext4_da_update_reserve_space(inode, retval, 1); |
1351 | } | 1368 | } |
1352 | if (flags & EXT4_GET_BLOCKS_DELALLOC_RESERVE) | 1369 | if (flags & EXT4_GET_BLOCKS_DELALLOC_RESERVE) |
1353 | EXT4_I(inode)->i_delalloc_reserved_flag = 0; | 1370 | ext4_clear_inode_state(inode, EXT4_STATE_DELALLOC_RESERVED); |
1354 | 1371 | ||
1355 | up_write((&EXT4_I(inode)->i_data_sem)); | 1372 | up_write((&EXT4_I(inode)->i_data_sem)); |
1356 | if (retval > 0 && map->m_flags & EXT4_MAP_MAPPED) { | 1373 | if (retval > 0 && map->m_flags & EXT4_MAP_MAPPED) { |
@@ -1878,7 +1895,7 @@ static int ext4_journalled_write_end(struct file *file, | |||
1878 | /* | 1895 | /* |
1879 | * Reserve a single block located at lblock | 1896 | * Reserve a single block located at lblock |
1880 | */ | 1897 | */ |
1881 | static int ext4_da_reserve_space(struct inode *inode, sector_t lblock) | 1898 | static int ext4_da_reserve_space(struct inode *inode, ext4_lblk_t lblock) |
1882 | { | 1899 | { |
1883 | int retries = 0; | 1900 | int retries = 0; |
1884 | struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); | 1901 | struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); |
@@ -2239,7 +2256,7 @@ static void mpage_da_map_and_submit(struct mpage_da_data *mpd) | |||
2239 | * affects functions in many different parts of the allocation | 2256 | * affects functions in many different parts of the allocation |
2240 | * call path. This flag exists primarily because we don't | 2257 | * call path. This flag exists primarily because we don't |
2241 | * want to change *many* call functions, so ext4_map_blocks() | 2258 | * want to change *many* call functions, so ext4_map_blocks() |
2242 | * will set the magic i_delalloc_reserved_flag once the | 2259 | * will set the EXT4_STATE_DELALLOC_RESERVED flag once the |
2243 | * inode's allocation semaphore is taken. | 2260 | * inode's allocation semaphore is taken. |
2244 | * | 2261 | * |
2245 | * If the blocks in questions were delalloc blocks, set | 2262 | * If the blocks in questions were delalloc blocks, set |
@@ -3720,8 +3737,7 @@ static int ext4_set_bh_endio(struct buffer_head *bh, struct inode *inode) | |||
3720 | retry: | 3737 | retry: |
3721 | io_end = ext4_init_io_end(inode, GFP_ATOMIC); | 3738 | io_end = ext4_init_io_end(inode, GFP_ATOMIC); |
3722 | if (!io_end) { | 3739 | if (!io_end) { |
3723 | if (printk_ratelimit()) | 3740 | pr_warning_ratelimited("%s: allocation fail\n", __func__); |
3724 | printk(KERN_WARNING "%s: allocation fail\n", __func__); | ||
3725 | schedule(); | 3741 | schedule(); |
3726 | goto retry; | 3742 | goto retry; |
3727 | } | 3743 | } |
@@ -4045,7 +4061,7 @@ int ext4_block_truncate_page(handle_t *handle, | |||
4045 | if (ext4_should_journal_data(inode)) { | 4061 | if (ext4_should_journal_data(inode)) { |
4046 | err = ext4_handle_dirty_metadata(handle, inode, bh); | 4062 | err = ext4_handle_dirty_metadata(handle, inode, bh); |
4047 | } else { | 4063 | } else { |
4048 | if (ext4_should_order_data(inode)) | 4064 | if (ext4_should_order_data(inode) && EXT4_I(inode)->jinode) |
4049 | err = ext4_jbd2_file_inode(handle, inode); | 4065 | err = ext4_jbd2_file_inode(handle, inode); |
4050 | mark_buffer_dirty(bh); | 4066 | mark_buffer_dirty(bh); |
4051 | } | 4067 | } |
@@ -4169,6 +4185,7 @@ static int ext4_clear_blocks(handle_t *handle, struct inode *inode, | |||
4169 | { | 4185 | { |
4170 | __le32 *p; | 4186 | __le32 *p; |
4171 | int flags = EXT4_FREE_BLOCKS_FORGET | EXT4_FREE_BLOCKS_VALIDATED; | 4187 | int flags = EXT4_FREE_BLOCKS_FORGET | EXT4_FREE_BLOCKS_VALIDATED; |
4188 | int err; | ||
4172 | 4189 | ||
4173 | if (S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode)) | 4190 | if (S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode)) |
4174 | flags |= EXT4_FREE_BLOCKS_METADATA; | 4191 | flags |= EXT4_FREE_BLOCKS_METADATA; |
@@ -4184,11 +4201,23 @@ static int ext4_clear_blocks(handle_t *handle, struct inode *inode, | |||
4184 | if (try_to_extend_transaction(handle, inode)) { | 4201 | if (try_to_extend_transaction(handle, inode)) { |
4185 | if (bh) { | 4202 | if (bh) { |
4186 | BUFFER_TRACE(bh, "call ext4_handle_dirty_metadata"); | 4203 | BUFFER_TRACE(bh, "call ext4_handle_dirty_metadata"); |
4187 | ext4_handle_dirty_metadata(handle, inode, bh); | 4204 | err = ext4_handle_dirty_metadata(handle, inode, bh); |
4205 | if (unlikely(err)) { | ||
4206 | ext4_std_error(inode->i_sb, err); | ||
4207 | return 1; | ||
4208 | } | ||
4209 | } | ||
4210 | err = ext4_mark_inode_dirty(handle, inode); | ||
4211 | if (unlikely(err)) { | ||
4212 | ext4_std_error(inode->i_sb, err); | ||
4213 | return 1; | ||
4214 | } | ||
4215 | err = ext4_truncate_restart_trans(handle, inode, | ||
4216 | blocks_for_truncate(inode)); | ||
4217 | if (unlikely(err)) { | ||
4218 | ext4_std_error(inode->i_sb, err); | ||
4219 | return 1; | ||
4188 | } | 4220 | } |
4189 | ext4_mark_inode_dirty(handle, inode); | ||
4190 | ext4_truncate_restart_trans(handle, inode, | ||
4191 | blocks_for_truncate(inode)); | ||
4192 | if (bh) { | 4221 | if (bh) { |
4193 | BUFFER_TRACE(bh, "retaking write access"); | 4222 | BUFFER_TRACE(bh, "retaking write access"); |
4194 | ext4_journal_get_write_access(handle, bh); | 4223 | ext4_journal_get_write_access(handle, bh); |
@@ -4349,6 +4378,7 @@ static void ext4_free_branches(handle_t *handle, struct inode *inode, | |||
4349 | (__le32 *) bh->b_data, | 4378 | (__le32 *) bh->b_data, |
4350 | (__le32 *) bh->b_data + addr_per_block, | 4379 | (__le32 *) bh->b_data + addr_per_block, |
4351 | depth); | 4380 | depth); |
4381 | brelse(bh); | ||
4352 | 4382 | ||
4353 | /* | 4383 | /* |
4354 | * Everything below this this pointer has been | 4384 | * Everything below this this pointer has been |
@@ -4859,7 +4889,7 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino) | |||
4859 | } | 4889 | } |
4860 | inode->i_nlink = le16_to_cpu(raw_inode->i_links_count); | 4890 | inode->i_nlink = le16_to_cpu(raw_inode->i_links_count); |
4861 | 4891 | ||
4862 | ei->i_state_flags = 0; | 4892 | ext4_clear_state_flags(ei); /* Only relevant on 32-bit archs */ |
4863 | ei->i_dir_start_lookup = 0; | 4893 | ei->i_dir_start_lookup = 0; |
4864 | ei->i_dtime = le32_to_cpu(raw_inode->i_dtime); | 4894 | 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. | 4895 | /* We now have enough fields to check if the inode was active or not. |
@@ -5118,7 +5148,7 @@ static int ext4_do_update_inode(handle_t *handle, | |||
5118 | if (ext4_inode_blocks_set(handle, raw_inode, ei)) | 5148 | if (ext4_inode_blocks_set(handle, raw_inode, ei)) |
5119 | goto out_brelse; | 5149 | goto out_brelse; |
5120 | raw_inode->i_dtime = cpu_to_le32(ei->i_dtime); | 5150 | raw_inode->i_dtime = cpu_to_le32(ei->i_dtime); |
5121 | raw_inode->i_flags = cpu_to_le32(ei->i_flags); | 5151 | raw_inode->i_flags = cpu_to_le32(ei->i_flags & 0xFFFFFFFF); |
5122 | if (EXT4_SB(inode->i_sb)->s_es->s_creator_os != | 5152 | if (EXT4_SB(inode->i_sb)->s_es->s_creator_os != |
5123 | cpu_to_le32(EXT4_OS_HURD)) | 5153 | cpu_to_le32(EXT4_OS_HURD)) |
5124 | raw_inode->i_file_acl_high = | 5154 | raw_inode->i_file_acl_high = |