diff options
Diffstat (limited to 'fs/ext4/inode.c')
-rw-r--r-- | fs/ext4/inode.c | 81 |
1 files changed, 55 insertions, 26 deletions
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index ae44916d40e2..3131747199e1 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c | |||
@@ -51,25 +51,31 @@ static __u32 ext4_inode_csum(struct inode *inode, struct ext4_inode *raw, | |||
51 | struct ext4_inode_info *ei) | 51 | struct ext4_inode_info *ei) |
52 | { | 52 | { |
53 | struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); | 53 | struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); |
54 | __u16 csum_lo; | ||
55 | __u16 csum_hi = 0; | ||
56 | __u32 csum; | 54 | __u32 csum; |
55 | __u16 dummy_csum = 0; | ||
56 | int offset = offsetof(struct ext4_inode, i_checksum_lo); | ||
57 | unsigned int csum_size = sizeof(dummy_csum); | ||
57 | 58 | ||
58 | csum_lo = le16_to_cpu(raw->i_checksum_lo); | 59 | csum = ext4_chksum(sbi, ei->i_csum_seed, (__u8 *)raw, offset); |
59 | raw->i_checksum_lo = 0; | 60 | csum = ext4_chksum(sbi, csum, (__u8 *)&dummy_csum, csum_size); |
60 | if (EXT4_INODE_SIZE(inode->i_sb) > EXT4_GOOD_OLD_INODE_SIZE && | 61 | offset += csum_size; |
61 | EXT4_FITS_IN_INODE(raw, ei, i_checksum_hi)) { | 62 | csum = ext4_chksum(sbi, csum, (__u8 *)raw + offset, |
62 | csum_hi = le16_to_cpu(raw->i_checksum_hi); | 63 | EXT4_GOOD_OLD_INODE_SIZE - offset); |
63 | raw->i_checksum_hi = 0; | ||
64 | } | ||
65 | |||
66 | csum = ext4_chksum(sbi, ei->i_csum_seed, (__u8 *)raw, | ||
67 | EXT4_INODE_SIZE(inode->i_sb)); | ||
68 | 64 | ||
69 | raw->i_checksum_lo = cpu_to_le16(csum_lo); | 65 | if (EXT4_INODE_SIZE(inode->i_sb) > EXT4_GOOD_OLD_INODE_SIZE) { |
70 | if (EXT4_INODE_SIZE(inode->i_sb) > EXT4_GOOD_OLD_INODE_SIZE && | 66 | offset = offsetof(struct ext4_inode, i_checksum_hi); |
71 | EXT4_FITS_IN_INODE(raw, ei, i_checksum_hi)) | 67 | csum = ext4_chksum(sbi, csum, (__u8 *)raw + |
72 | raw->i_checksum_hi = cpu_to_le16(csum_hi); | 68 | EXT4_GOOD_OLD_INODE_SIZE, |
69 | offset - EXT4_GOOD_OLD_INODE_SIZE); | ||
70 | if (EXT4_FITS_IN_INODE(raw, ei, i_checksum_hi)) { | ||
71 | csum = ext4_chksum(sbi, csum, (__u8 *)&dummy_csum, | ||
72 | csum_size); | ||
73 | offset += csum_size; | ||
74 | csum = ext4_chksum(sbi, csum, (__u8 *)raw + offset, | ||
75 | EXT4_INODE_SIZE(inode->i_sb) - | ||
76 | offset); | ||
77 | } | ||
78 | } | ||
73 | 79 | ||
74 | return csum; | 80 | return csum; |
75 | } | 81 | } |
@@ -205,9 +211,9 @@ void ext4_evict_inode(struct inode *inode) | |||
205 | * Note that directories do not have this problem because they | 211 | * Note that directories do not have this problem because they |
206 | * don't use page cache. | 212 | * don't use page cache. |
207 | */ | 213 | */ |
208 | if (ext4_should_journal_data(inode) && | 214 | if (inode->i_ino != EXT4_JOURNAL_INO && |
209 | (S_ISLNK(inode->i_mode) || S_ISREG(inode->i_mode)) && | 215 | ext4_should_journal_data(inode) && |
210 | inode->i_ino != EXT4_JOURNAL_INO) { | 216 | (S_ISLNK(inode->i_mode) || S_ISREG(inode->i_mode))) { |
211 | journal_t *journal = EXT4_SB(inode->i_sb)->s_journal; | 217 | journal_t *journal = EXT4_SB(inode->i_sb)->s_journal; |
212 | tid_t commit_tid = EXT4_I(inode)->i_datasync_tid; | 218 | tid_t commit_tid = EXT4_I(inode)->i_datasync_tid; |
213 | 219 | ||
@@ -386,7 +392,7 @@ int ext4_issue_zeroout(struct inode *inode, ext4_lblk_t lblk, ext4_fsblk_t pblk, | |||
386 | int ret; | 392 | int ret; |
387 | 393 | ||
388 | if (ext4_encrypted_inode(inode)) | 394 | if (ext4_encrypted_inode(inode)) |
389 | return ext4_encrypted_zeroout(inode, lblk, pblk, len); | 395 | return fscrypt_zeroout_range(inode, lblk, pblk, len); |
390 | 396 | ||
391 | ret = sb_issue_zeroout(inode->i_sb, pblk, len, GFP_NOFS); | 397 | ret = sb_issue_zeroout(inode->i_sb, pblk, len, GFP_NOFS); |
392 | if (ret > 0) | 398 | if (ret > 0) |
@@ -1152,7 +1158,7 @@ static int ext4_block_write_begin(struct page *page, loff_t pos, unsigned len, | |||
1152 | if (unlikely(err)) | 1158 | if (unlikely(err)) |
1153 | page_zero_new_buffers(page, from, to); | 1159 | page_zero_new_buffers(page, from, to); |
1154 | else if (decrypt) | 1160 | else if (decrypt) |
1155 | err = ext4_decrypt(page); | 1161 | err = fscrypt_decrypt_page(page); |
1156 | return err; | 1162 | return err; |
1157 | } | 1163 | } |
1158 | #endif | 1164 | #endif |
@@ -2748,13 +2754,36 @@ retry: | |||
2748 | done = true; | 2754 | done = true; |
2749 | } | 2755 | } |
2750 | } | 2756 | } |
2751 | ext4_journal_stop(handle); | 2757 | /* |
2758 | * Caution: If the handle is synchronous, | ||
2759 | * ext4_journal_stop() can wait for transaction commit | ||
2760 | * to finish which may depend on writeback of pages to | ||
2761 | * complete or on page lock to be released. In that | ||
2762 | * case, we have to wait until after after we have | ||
2763 | * submitted all the IO, released page locks we hold, | ||
2764 | * and dropped io_end reference (for extent conversion | ||
2765 | * to be able to complete) before stopping the handle. | ||
2766 | */ | ||
2767 | if (!ext4_handle_valid(handle) || handle->h_sync == 0) { | ||
2768 | ext4_journal_stop(handle); | ||
2769 | handle = NULL; | ||
2770 | } | ||
2752 | /* Submit prepared bio */ | 2771 | /* Submit prepared bio */ |
2753 | ext4_io_submit(&mpd.io_submit); | 2772 | ext4_io_submit(&mpd.io_submit); |
2754 | /* Unlock pages we didn't use */ | 2773 | /* Unlock pages we didn't use */ |
2755 | mpage_release_unused_pages(&mpd, give_up_on_write); | 2774 | mpage_release_unused_pages(&mpd, give_up_on_write); |
2756 | /* Drop our io_end reference we got from init */ | 2775 | /* |
2757 | ext4_put_io_end(mpd.io_submit.io_end); | 2776 | * Drop our io_end reference we got from init. We have |
2777 | * to be careful and use deferred io_end finishing if | ||
2778 | * we are still holding the transaction as we can | ||
2779 | * release the last reference to io_end which may end | ||
2780 | * up doing unwritten extent conversion. | ||
2781 | */ | ||
2782 | if (handle) { | ||
2783 | ext4_put_io_end_defer(mpd.io_submit.io_end); | ||
2784 | ext4_journal_stop(handle); | ||
2785 | } else | ||
2786 | ext4_put_io_end(mpd.io_submit.io_end); | ||
2758 | 2787 | ||
2759 | if (ret == -ENOSPC && sbi->s_journal) { | 2788 | if (ret == -ENOSPC && sbi->s_journal) { |
2760 | /* | 2789 | /* |
@@ -3706,9 +3735,9 @@ static int __ext4_block_zero_page_range(handle_t *handle, | |||
3706 | if (S_ISREG(inode->i_mode) && | 3735 | if (S_ISREG(inode->i_mode) && |
3707 | ext4_encrypted_inode(inode)) { | 3736 | ext4_encrypted_inode(inode)) { |
3708 | /* We expect the key to be set. */ | 3737 | /* We expect the key to be set. */ |
3709 | BUG_ON(!ext4_has_encryption_key(inode)); | 3738 | BUG_ON(!fscrypt_has_encryption_key(inode)); |
3710 | BUG_ON(blocksize != PAGE_SIZE); | 3739 | BUG_ON(blocksize != PAGE_SIZE); |
3711 | WARN_ON_ONCE(ext4_decrypt(page)); | 3740 | WARN_ON_ONCE(fscrypt_decrypt_page(page)); |
3712 | } | 3741 | } |
3713 | } | 3742 | } |
3714 | if (ext4_should_journal_data(inode)) { | 3743 | if (ext4_should_journal_data(inode)) { |