diff options
author | Junxiao Bi <junxiao.bi@oracle.com> | 2014-02-10 17:25:53 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-02-10 19:01:43 -0500 |
commit | c7d2cbc364b2a237b0ed1bdd7cbf8a24c8a89dfd (patch) | |
tree | 660ee14df70bb80220b2e8c919b66f9f724890ef /fs/ocfs2 | |
parent | d62e74be1270c89fbaf7aada8218bfdf62d00a58 (diff) |
ocfs2: update inode size after zeroing the hole
fs-writeback will release the dirty pages without page lock whose offset
are over inode size, the release happens at
block_write_full_page_endio(). If not update, dirty pages in file holes
may be released before flushed to the disk, then file holes will contain
some non-zero data, this will cause sparse file md5sum error.
To reproduce the bug, find a big sparse file with many holes, like vm
image file, its actual size should be bigger than available mem size to
make writeback work more frequently, tar it with -S option, then keep
untar it and check its md5sum again and again until you get a wrong
md5sum.
Signed-off-by: Junxiao Bi <junxiao.bi@oracle.com>
Cc: Younger Liu <younger.liu@huawei.com>
Reviewed-by: Mark Fasheh <mfasheh@suse.de>
Cc: Joel Becker <jlbec@evilplan.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/ocfs2')
-rw-r--r-- | fs/ocfs2/file.c | 40 |
1 files changed, 32 insertions, 8 deletions
diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c index 9148353c5cf8..8450262bcf2a 100644 --- a/fs/ocfs2/file.c +++ b/fs/ocfs2/file.c | |||
@@ -716,7 +716,8 @@ leave: | |||
716 | * While a write will already be ordering the data, a truncate will not. | 716 | * While a write will already be ordering the data, a truncate will not. |
717 | * Thus, we need to explicitly order the zeroed pages. | 717 | * Thus, we need to explicitly order the zeroed pages. |
718 | */ | 718 | */ |
719 | static handle_t *ocfs2_zero_start_ordered_transaction(struct inode *inode) | 719 | static handle_t *ocfs2_zero_start_ordered_transaction(struct inode *inode, |
720 | struct buffer_head *di_bh) | ||
720 | { | 721 | { |
721 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | 722 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); |
722 | handle_t *handle = NULL; | 723 | handle_t *handle = NULL; |
@@ -733,7 +734,14 @@ static handle_t *ocfs2_zero_start_ordered_transaction(struct inode *inode) | |||
733 | } | 734 | } |
734 | 735 | ||
735 | ret = ocfs2_jbd2_file_inode(handle, inode); | 736 | ret = ocfs2_jbd2_file_inode(handle, inode); |
736 | if (ret < 0) | 737 | if (ret < 0) { |
738 | mlog_errno(ret); | ||
739 | goto out; | ||
740 | } | ||
741 | |||
742 | ret = ocfs2_journal_access_di(handle, INODE_CACHE(inode), di_bh, | ||
743 | OCFS2_JOURNAL_ACCESS_WRITE); | ||
744 | if (ret) | ||
737 | mlog_errno(ret); | 745 | mlog_errno(ret); |
738 | 746 | ||
739 | out: | 747 | out: |
@@ -749,7 +757,7 @@ out: | |||
749 | * to be too fragile to do exactly what we need without us having to | 757 | * to be too fragile to do exactly what we need without us having to |
750 | * worry about recursive locking in ->write_begin() and ->write_end(). */ | 758 | * worry about recursive locking in ->write_begin() and ->write_end(). */ |
751 | static int ocfs2_write_zero_page(struct inode *inode, u64 abs_from, | 759 | static int ocfs2_write_zero_page(struct inode *inode, u64 abs_from, |
752 | u64 abs_to) | 760 | u64 abs_to, struct buffer_head *di_bh) |
753 | { | 761 | { |
754 | struct address_space *mapping = inode->i_mapping; | 762 | struct address_space *mapping = inode->i_mapping; |
755 | struct page *page; | 763 | struct page *page; |
@@ -757,6 +765,7 @@ static int ocfs2_write_zero_page(struct inode *inode, u64 abs_from, | |||
757 | handle_t *handle = NULL; | 765 | handle_t *handle = NULL; |
758 | int ret = 0; | 766 | int ret = 0; |
759 | unsigned zero_from, zero_to, block_start, block_end; | 767 | unsigned zero_from, zero_to, block_start, block_end; |
768 | struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data; | ||
760 | 769 | ||
761 | BUG_ON(abs_from >= abs_to); | 770 | BUG_ON(abs_from >= abs_to); |
762 | BUG_ON(abs_to > (((u64)index + 1) << PAGE_CACHE_SHIFT)); | 771 | BUG_ON(abs_to > (((u64)index + 1) << PAGE_CACHE_SHIFT)); |
@@ -799,7 +808,8 @@ static int ocfs2_write_zero_page(struct inode *inode, u64 abs_from, | |||
799 | } | 808 | } |
800 | 809 | ||
801 | if (!handle) { | 810 | if (!handle) { |
802 | handle = ocfs2_zero_start_ordered_transaction(inode); | 811 | handle = ocfs2_zero_start_ordered_transaction(inode, |
812 | di_bh); | ||
803 | if (IS_ERR(handle)) { | 813 | if (IS_ERR(handle)) { |
804 | ret = PTR_ERR(handle); | 814 | ret = PTR_ERR(handle); |
805 | handle = NULL; | 815 | handle = NULL; |
@@ -816,8 +826,22 @@ static int ocfs2_write_zero_page(struct inode *inode, u64 abs_from, | |||
816 | ret = 0; | 826 | ret = 0; |
817 | } | 827 | } |
818 | 828 | ||
819 | if (handle) | 829 | if (handle) { |
830 | /* | ||
831 | * fs-writeback will release the dirty pages without page lock | ||
832 | * whose offset are over inode size, the release happens at | ||
833 | * block_write_full_page_endio(). | ||
834 | */ | ||
835 | i_size_write(inode, abs_to); | ||
836 | inode->i_blocks = ocfs2_inode_sector_count(inode); | ||
837 | di->i_size = cpu_to_le64((u64)i_size_read(inode)); | ||
838 | inode->i_mtime = inode->i_ctime = CURRENT_TIME; | ||
839 | di->i_mtime = di->i_ctime = cpu_to_le64(inode->i_mtime.tv_sec); | ||
840 | di->i_ctime_nsec = cpu_to_le32(inode->i_mtime.tv_nsec); | ||
841 | di->i_mtime_nsec = di->i_ctime_nsec; | ||
842 | ocfs2_journal_dirty(handle, di_bh); | ||
820 | ocfs2_commit_trans(OCFS2_SB(inode->i_sb), handle); | 843 | ocfs2_commit_trans(OCFS2_SB(inode->i_sb), handle); |
844 | } | ||
821 | 845 | ||
822 | out_unlock: | 846 | out_unlock: |
823 | unlock_page(page); | 847 | unlock_page(page); |
@@ -913,7 +937,7 @@ out: | |||
913 | * has made sure that the entire range needs zeroing. | 937 | * has made sure that the entire range needs zeroing. |
914 | */ | 938 | */ |
915 | static int ocfs2_zero_extend_range(struct inode *inode, u64 range_start, | 939 | static int ocfs2_zero_extend_range(struct inode *inode, u64 range_start, |
916 | u64 range_end) | 940 | u64 range_end, struct buffer_head *di_bh) |
917 | { | 941 | { |
918 | int rc = 0; | 942 | int rc = 0; |
919 | u64 next_pos; | 943 | u64 next_pos; |
@@ -929,7 +953,7 @@ static int ocfs2_zero_extend_range(struct inode *inode, u64 range_start, | |||
929 | next_pos = (zero_pos & PAGE_CACHE_MASK) + PAGE_CACHE_SIZE; | 953 | next_pos = (zero_pos & PAGE_CACHE_MASK) + PAGE_CACHE_SIZE; |
930 | if (next_pos > range_end) | 954 | if (next_pos > range_end) |
931 | next_pos = range_end; | 955 | next_pos = range_end; |
932 | rc = ocfs2_write_zero_page(inode, zero_pos, next_pos); | 956 | rc = ocfs2_write_zero_page(inode, zero_pos, next_pos, di_bh); |
933 | if (rc < 0) { | 957 | if (rc < 0) { |
934 | mlog_errno(rc); | 958 | mlog_errno(rc); |
935 | break; | 959 | break; |
@@ -975,7 +999,7 @@ int ocfs2_zero_extend(struct inode *inode, struct buffer_head *di_bh, | |||
975 | range_end = zero_to_size; | 999 | range_end = zero_to_size; |
976 | 1000 | ||
977 | ret = ocfs2_zero_extend_range(inode, range_start, | 1001 | ret = ocfs2_zero_extend_range(inode, range_start, |
978 | range_end); | 1002 | range_end, di_bh); |
979 | if (ret) { | 1003 | if (ret) { |
980 | mlog_errno(ret); | 1004 | mlog_errno(ret); |
981 | break; | 1005 | break; |