diff options
Diffstat (limited to 'fs/ext4/inode.c')
-rw-r--r-- | fs/ext4/inode.c | 133 |
1 files changed, 67 insertions, 66 deletions
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 3aa26e9117c4..e9777f93cf05 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c | |||
@@ -83,8 +83,7 @@ static int ext4_inode_csum_verify(struct inode *inode, struct ext4_inode *raw, | |||
83 | 83 | ||
84 | if (EXT4_SB(inode->i_sb)->s_es->s_creator_os != | 84 | if (EXT4_SB(inode->i_sb)->s_es->s_creator_os != |
85 | cpu_to_le32(EXT4_OS_LINUX) || | 85 | cpu_to_le32(EXT4_OS_LINUX) || |
86 | !EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb, | 86 | !ext4_has_metadata_csum(inode->i_sb)) |
87 | EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)) | ||
88 | return 1; | 87 | return 1; |
89 | 88 | ||
90 | provided = le16_to_cpu(raw->i_checksum_lo); | 89 | provided = le16_to_cpu(raw->i_checksum_lo); |
@@ -105,8 +104,7 @@ static void ext4_inode_csum_set(struct inode *inode, struct ext4_inode *raw, | |||
105 | 104 | ||
106 | if (EXT4_SB(inode->i_sb)->s_es->s_creator_os != | 105 | if (EXT4_SB(inode->i_sb)->s_es->s_creator_os != |
107 | cpu_to_le32(EXT4_OS_LINUX) || | 106 | cpu_to_le32(EXT4_OS_LINUX) || |
108 | !EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb, | 107 | !ext4_has_metadata_csum(inode->i_sb)) |
109 | EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)) | ||
110 | return; | 108 | return; |
111 | 109 | ||
112 | csum = ext4_inode_csum(inode, raw, ei); | 110 | csum = ext4_inode_csum(inode, raw, ei); |
@@ -224,16 +222,15 @@ void ext4_evict_inode(struct inode *inode) | |||
224 | goto no_delete; | 222 | goto no_delete; |
225 | } | 223 | } |
226 | 224 | ||
227 | if (!is_bad_inode(inode)) | 225 | if (is_bad_inode(inode)) |
228 | dquot_initialize(inode); | 226 | goto no_delete; |
227 | dquot_initialize(inode); | ||
229 | 228 | ||
230 | if (ext4_should_order_data(inode)) | 229 | if (ext4_should_order_data(inode)) |
231 | ext4_begin_ordered_truncate(inode, 0); | 230 | ext4_begin_ordered_truncate(inode, 0); |
232 | truncate_inode_pages_final(&inode->i_data); | 231 | truncate_inode_pages_final(&inode->i_data); |
233 | 232 | ||
234 | WARN_ON(atomic_read(&EXT4_I(inode)->i_ioend_count)); | 233 | WARN_ON(atomic_read(&EXT4_I(inode)->i_ioend_count)); |
235 | if (is_bad_inode(inode)) | ||
236 | goto no_delete; | ||
237 | 234 | ||
238 | /* | 235 | /* |
239 | * Protect us against freezing - iput() caller didn't have to have any | 236 | * Protect us against freezing - iput() caller didn't have to have any |
@@ -590,20 +587,12 @@ found: | |||
590 | /* | 587 | /* |
591 | * New blocks allocate and/or writing to unwritten extent | 588 | * New blocks allocate and/or writing to unwritten extent |
592 | * will possibly result in updating i_data, so we take | 589 | * will possibly result in updating i_data, so we take |
593 | * the write lock of i_data_sem, and call get_blocks() | 590 | * the write lock of i_data_sem, and call get_block() |
594 | * with create == 1 flag. | 591 | * with create == 1 flag. |
595 | */ | 592 | */ |
596 | down_write(&EXT4_I(inode)->i_data_sem); | 593 | down_write(&EXT4_I(inode)->i_data_sem); |
597 | 594 | ||
598 | /* | 595 | /* |
599 | * if the caller is from delayed allocation writeout path | ||
600 | * we have already reserved fs blocks for allocation | ||
601 | * let the underlying get_block() function know to | ||
602 | * avoid double accounting | ||
603 | */ | ||
604 | if (flags & EXT4_GET_BLOCKS_DELALLOC_RESERVE) | ||
605 | ext4_set_inode_state(inode, EXT4_STATE_DELALLOC_RESERVED); | ||
606 | /* | ||
607 | * We need to check for EXT4 here because migrate | 596 | * We need to check for EXT4 here because migrate |
608 | * could have changed the inode type in between | 597 | * could have changed the inode type in between |
609 | */ | 598 | */ |
@@ -631,8 +620,6 @@ found: | |||
631 | (flags & EXT4_GET_BLOCKS_DELALLOC_RESERVE)) | 620 | (flags & EXT4_GET_BLOCKS_DELALLOC_RESERVE)) |
632 | ext4_da_update_reserve_space(inode, retval, 1); | 621 | ext4_da_update_reserve_space(inode, retval, 1); |
633 | } | 622 | } |
634 | if (flags & EXT4_GET_BLOCKS_DELALLOC_RESERVE) | ||
635 | ext4_clear_inode_state(inode, EXT4_STATE_DELALLOC_RESERVED); | ||
636 | 623 | ||
637 | if (retval > 0) { | 624 | if (retval > 0) { |
638 | unsigned int status; | 625 | unsigned int status; |
@@ -734,11 +721,11 @@ int ext4_get_block(struct inode *inode, sector_t iblock, | |||
734 | * `handle' can be NULL if create is zero | 721 | * `handle' can be NULL if create is zero |
735 | */ | 722 | */ |
736 | struct buffer_head *ext4_getblk(handle_t *handle, struct inode *inode, | 723 | struct buffer_head *ext4_getblk(handle_t *handle, struct inode *inode, |
737 | ext4_lblk_t block, int create, int *errp) | 724 | ext4_lblk_t block, int create) |
738 | { | 725 | { |
739 | struct ext4_map_blocks map; | 726 | struct ext4_map_blocks map; |
740 | struct buffer_head *bh; | 727 | struct buffer_head *bh; |
741 | int fatal = 0, err; | 728 | int err; |
742 | 729 | ||
743 | J_ASSERT(handle != NULL || create == 0); | 730 | J_ASSERT(handle != NULL || create == 0); |
744 | 731 | ||
@@ -747,21 +734,14 @@ struct buffer_head *ext4_getblk(handle_t *handle, struct inode *inode, | |||
747 | err = ext4_map_blocks(handle, inode, &map, | 734 | err = ext4_map_blocks(handle, inode, &map, |
748 | create ? EXT4_GET_BLOCKS_CREATE : 0); | 735 | create ? EXT4_GET_BLOCKS_CREATE : 0); |
749 | 736 | ||
750 | /* ensure we send some value back into *errp */ | 737 | if (err == 0) |
751 | *errp = 0; | 738 | return create ? ERR_PTR(-ENOSPC) : NULL; |
752 | |||
753 | if (create && err == 0) | ||
754 | err = -ENOSPC; /* should never happen */ | ||
755 | if (err < 0) | 739 | if (err < 0) |
756 | *errp = err; | 740 | return ERR_PTR(err); |
757 | if (err <= 0) | ||
758 | return NULL; | ||
759 | 741 | ||
760 | bh = sb_getblk(inode->i_sb, map.m_pblk); | 742 | bh = sb_getblk(inode->i_sb, map.m_pblk); |
761 | if (unlikely(!bh)) { | 743 | if (unlikely(!bh)) |
762 | *errp = -ENOMEM; | 744 | return ERR_PTR(-ENOMEM); |
763 | return NULL; | ||
764 | } | ||
765 | if (map.m_flags & EXT4_MAP_NEW) { | 745 | if (map.m_flags & EXT4_MAP_NEW) { |
766 | J_ASSERT(create != 0); | 746 | J_ASSERT(create != 0); |
767 | J_ASSERT(handle != NULL); | 747 | J_ASSERT(handle != NULL); |
@@ -775,44 +755,44 @@ struct buffer_head *ext4_getblk(handle_t *handle, struct inode *inode, | |||
775 | */ | 755 | */ |
776 | lock_buffer(bh); | 756 | lock_buffer(bh); |
777 | BUFFER_TRACE(bh, "call get_create_access"); | 757 | BUFFER_TRACE(bh, "call get_create_access"); |
778 | fatal = ext4_journal_get_create_access(handle, bh); | 758 | err = ext4_journal_get_create_access(handle, bh); |
779 | if (!fatal && !buffer_uptodate(bh)) { | 759 | if (unlikely(err)) { |
760 | unlock_buffer(bh); | ||
761 | goto errout; | ||
762 | } | ||
763 | if (!buffer_uptodate(bh)) { | ||
780 | memset(bh->b_data, 0, inode->i_sb->s_blocksize); | 764 | memset(bh->b_data, 0, inode->i_sb->s_blocksize); |
781 | set_buffer_uptodate(bh); | 765 | set_buffer_uptodate(bh); |
782 | } | 766 | } |
783 | unlock_buffer(bh); | 767 | unlock_buffer(bh); |
784 | BUFFER_TRACE(bh, "call ext4_handle_dirty_metadata"); | 768 | BUFFER_TRACE(bh, "call ext4_handle_dirty_metadata"); |
785 | err = ext4_handle_dirty_metadata(handle, inode, bh); | 769 | err = ext4_handle_dirty_metadata(handle, inode, bh); |
786 | if (!fatal) | 770 | if (unlikely(err)) |
787 | fatal = err; | 771 | goto errout; |
788 | } else { | 772 | } else |
789 | BUFFER_TRACE(bh, "not a new buffer"); | 773 | BUFFER_TRACE(bh, "not a new buffer"); |
790 | } | ||
791 | if (fatal) { | ||
792 | *errp = fatal; | ||
793 | brelse(bh); | ||
794 | bh = NULL; | ||
795 | } | ||
796 | return bh; | 774 | return bh; |
775 | errout: | ||
776 | brelse(bh); | ||
777 | return ERR_PTR(err); | ||
797 | } | 778 | } |
798 | 779 | ||
799 | struct buffer_head *ext4_bread(handle_t *handle, struct inode *inode, | 780 | struct buffer_head *ext4_bread(handle_t *handle, struct inode *inode, |
800 | ext4_lblk_t block, int create, int *err) | 781 | ext4_lblk_t block, int create) |
801 | { | 782 | { |
802 | struct buffer_head *bh; | 783 | struct buffer_head *bh; |
803 | 784 | ||
804 | bh = ext4_getblk(handle, inode, block, create, err); | 785 | bh = ext4_getblk(handle, inode, block, create); |
805 | if (!bh) | 786 | if (IS_ERR(bh)) |
806 | return bh; | 787 | return bh; |
807 | if (buffer_uptodate(bh)) | 788 | if (!bh || buffer_uptodate(bh)) |
808 | return bh; | 789 | return bh; |
809 | ll_rw_block(READ | REQ_META | REQ_PRIO, 1, &bh); | 790 | ll_rw_block(READ | REQ_META | REQ_PRIO, 1, &bh); |
810 | wait_on_buffer(bh); | 791 | wait_on_buffer(bh); |
811 | if (buffer_uptodate(bh)) | 792 | if (buffer_uptodate(bh)) |
812 | return bh; | 793 | return bh; |
813 | put_bh(bh); | 794 | put_bh(bh); |
814 | *err = -EIO; | 795 | return ERR_PTR(-EIO); |
815 | return NULL; | ||
816 | } | 796 | } |
817 | 797 | ||
818 | int ext4_walk_page_buffers(handle_t *handle, | 798 | int ext4_walk_page_buffers(handle_t *handle, |
@@ -1536,7 +1516,7 @@ out_unlock: | |||
1536 | } | 1516 | } |
1537 | 1517 | ||
1538 | /* | 1518 | /* |
1539 | * This is a special get_blocks_t callback which is used by | 1519 | * This is a special get_block_t callback which is used by |
1540 | * ext4_da_write_begin(). It will either return mapped block or | 1520 | * ext4_da_write_begin(). It will either return mapped block or |
1541 | * reserve space for a single block. | 1521 | * reserve space for a single block. |
1542 | * | 1522 | * |
@@ -2011,12 +1991,10 @@ static int mpage_map_one_extent(handle_t *handle, struct mpage_da_data *mpd) | |||
2011 | * in data loss. So use reserved blocks to allocate metadata if | 1991 | * in data loss. So use reserved blocks to allocate metadata if |
2012 | * possible. | 1992 | * possible. |
2013 | * | 1993 | * |
2014 | * We pass in the magic EXT4_GET_BLOCKS_DELALLOC_RESERVE if the blocks | 1994 | * We pass in the magic EXT4_GET_BLOCKS_DELALLOC_RESERVE if |
2015 | * in question are delalloc blocks. This affects functions in many | 1995 | * the blocks in question are delalloc blocks. This indicates |
2016 | * different parts of the allocation call path. This flag exists | 1996 | * that the blocks and quotas has already been checked when |
2017 | * primarily because we don't want to change *many* call functions, so | 1997 | * the data was copied into the page cache. |
2018 | * ext4_map_blocks() will set the EXT4_STATE_DELALLOC_RESERVED flag | ||
2019 | * once the inode's allocation semaphore is taken. | ||
2020 | */ | 1998 | */ |
2021 | get_blocks_flags = EXT4_GET_BLOCKS_CREATE | | 1999 | get_blocks_flags = EXT4_GET_BLOCKS_CREATE | |
2022 | EXT4_GET_BLOCKS_METADATA_NOFAIL; | 2000 | EXT4_GET_BLOCKS_METADATA_NOFAIL; |
@@ -2515,6 +2493,20 @@ static int ext4_nonda_switch(struct super_block *sb) | |||
2515 | return 0; | 2493 | return 0; |
2516 | } | 2494 | } |
2517 | 2495 | ||
2496 | /* We always reserve for an inode update; the superblock could be there too */ | ||
2497 | static int ext4_da_write_credits(struct inode *inode, loff_t pos, unsigned len) | ||
2498 | { | ||
2499 | if (likely(EXT4_HAS_RO_COMPAT_FEATURE(inode->i_sb, | ||
2500 | EXT4_FEATURE_RO_COMPAT_LARGE_FILE))) | ||
2501 | return 1; | ||
2502 | |||
2503 | if (pos + len <= 0x7fffffffULL) | ||
2504 | return 1; | ||
2505 | |||
2506 | /* We might need to update the superblock to set LARGE_FILE */ | ||
2507 | return 2; | ||
2508 | } | ||
2509 | |||
2518 | static int ext4_da_write_begin(struct file *file, struct address_space *mapping, | 2510 | static int ext4_da_write_begin(struct file *file, struct address_space *mapping, |
2519 | loff_t pos, unsigned len, unsigned flags, | 2511 | loff_t pos, unsigned len, unsigned flags, |
2520 | struct page **pagep, void **fsdata) | 2512 | struct page **pagep, void **fsdata) |
@@ -2565,7 +2557,8 @@ retry_grab: | |||
2565 | * of file which has an already mapped buffer. | 2557 | * of file which has an already mapped buffer. |
2566 | */ | 2558 | */ |
2567 | retry_journal: | 2559 | retry_journal: |
2568 | handle = ext4_journal_start(inode, EXT4_HT_WRITE_PAGE, 1); | 2560 | handle = ext4_journal_start(inode, EXT4_HT_WRITE_PAGE, |
2561 | ext4_da_write_credits(inode, pos, len)); | ||
2569 | if (IS_ERR(handle)) { | 2562 | if (IS_ERR(handle)) { |
2570 | page_cache_release(page); | 2563 | page_cache_release(page); |
2571 | return PTR_ERR(handle); | 2564 | return PTR_ERR(handle); |
@@ -2658,10 +2651,7 @@ static int ext4_da_write_end(struct file *file, | |||
2658 | if (copied && new_i_size > EXT4_I(inode)->i_disksize) { | 2651 | if (copied && new_i_size > EXT4_I(inode)->i_disksize) { |
2659 | if (ext4_has_inline_data(inode) || | 2652 | if (ext4_has_inline_data(inode) || |
2660 | ext4_da_should_update_i_disksize(page, end)) { | 2653 | ext4_da_should_update_i_disksize(page, end)) { |
2661 | down_write(&EXT4_I(inode)->i_data_sem); | 2654 | ext4_update_i_disksize(inode, new_i_size); |
2662 | if (new_i_size > EXT4_I(inode)->i_disksize) | ||
2663 | EXT4_I(inode)->i_disksize = new_i_size; | ||
2664 | up_write(&EXT4_I(inode)->i_data_sem); | ||
2665 | /* We need to mark inode dirty even if | 2655 | /* We need to mark inode dirty even if |
2666 | * new_i_size is less that inode->i_size | 2656 | * new_i_size is less that inode->i_size |
2667 | * bu greater than i_disksize.(hint delalloc) | 2657 | * bu greater than i_disksize.(hint delalloc) |
@@ -3936,8 +3926,7 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino) | |||
3936 | ei->i_extra_isize = 0; | 3926 | ei->i_extra_isize = 0; |
3937 | 3927 | ||
3938 | /* Precompute checksum seed for inode metadata */ | 3928 | /* Precompute checksum seed for inode metadata */ |
3939 | if (EXT4_HAS_RO_COMPAT_FEATURE(sb, | 3929 | if (ext4_has_metadata_csum(sb)) { |
3940 | EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)) { | ||
3941 | struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); | 3930 | struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); |
3942 | __u32 csum; | 3931 | __u32 csum; |
3943 | __le32 inum = cpu_to_le32(inode->i_ino); | 3932 | __le32 inum = cpu_to_le32(inode->i_ino); |
@@ -4127,6 +4116,13 @@ bad_inode: | |||
4127 | return ERR_PTR(ret); | 4116 | return ERR_PTR(ret); |
4128 | } | 4117 | } |
4129 | 4118 | ||
4119 | struct inode *ext4_iget_normal(struct super_block *sb, unsigned long ino) | ||
4120 | { | ||
4121 | if (ino < EXT4_FIRST_INO(sb) && ino != EXT4_ROOT_INO) | ||
4122 | return ERR_PTR(-EIO); | ||
4123 | return ext4_iget(sb, ino); | ||
4124 | } | ||
4125 | |||
4130 | static int ext4_inode_blocks_set(handle_t *handle, | 4126 | static int ext4_inode_blocks_set(handle_t *handle, |
4131 | struct ext4_inode *raw_inode, | 4127 | struct ext4_inode *raw_inode, |
4132 | struct ext4_inode_info *ei) | 4128 | struct ext4_inode_info *ei) |
@@ -4226,7 +4222,8 @@ static int ext4_do_update_inode(handle_t *handle, | |||
4226 | EXT4_INODE_SET_XTIME(i_atime, inode, raw_inode); | 4222 | EXT4_INODE_SET_XTIME(i_atime, inode, raw_inode); |
4227 | EXT4_EINODE_SET_XTIME(i_crtime, ei, raw_inode); | 4223 | EXT4_EINODE_SET_XTIME(i_crtime, ei, raw_inode); |
4228 | 4224 | ||
4229 | if (ext4_inode_blocks_set(handle, raw_inode, ei)) { | 4225 | err = ext4_inode_blocks_set(handle, raw_inode, ei); |
4226 | if (err) { | ||
4230 | spin_unlock(&ei->i_raw_lock); | 4227 | spin_unlock(&ei->i_raw_lock); |
4231 | goto out_brelse; | 4228 | goto out_brelse; |
4232 | } | 4229 | } |
@@ -4536,8 +4533,12 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr) | |||
4536 | ext4_orphan_del(NULL, inode); | 4533 | ext4_orphan_del(NULL, inode); |
4537 | goto err_out; | 4534 | goto err_out; |
4538 | } | 4535 | } |
4539 | } else | 4536 | } else { |
4537 | loff_t oldsize = inode->i_size; | ||
4538 | |||
4540 | i_size_write(inode, attr->ia_size); | 4539 | i_size_write(inode, attr->ia_size); |
4540 | pagecache_isize_extended(inode, oldsize, inode->i_size); | ||
4541 | } | ||
4541 | 4542 | ||
4542 | /* | 4543 | /* |
4543 | * Blocks are going to be removed from the inode. Wait | 4544 | * Blocks are going to be removed from the inode. Wait |