aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ocfs2/file.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/ocfs2/file.c')
-rw-r--r--fs/ocfs2/file.c52
1 files changed, 37 insertions, 15 deletions
diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c
index d77d71ead8d1..8450262bcf2a 100644
--- a/fs/ocfs2/file.c
+++ b/fs/ocfs2/file.c
@@ -185,6 +185,9 @@ static int ocfs2_sync_file(struct file *file, loff_t start, loff_t end,
185 file->f_path.dentry->d_name.name, 185 file->f_path.dentry->d_name.name,
186 (unsigned long long)datasync); 186 (unsigned long long)datasync);
187 187
188 if (ocfs2_is_hard_readonly(osb) || ocfs2_is_soft_readonly(osb))
189 return -EROFS;
190
188 err = filemap_write_and_wait_range(inode->i_mapping, start, end); 191 err = filemap_write_and_wait_range(inode->i_mapping, start, end);
189 if (err) 192 if (err)
190 return err; 193 return err;
@@ -474,11 +477,6 @@ static int ocfs2_truncate_file(struct inode *inode,
474 goto bail; 477 goto bail;
475 } 478 }
476 479
477 /* lets handle the simple truncate cases before doing any more
478 * cluster locking. */
479 if (new_i_size == le64_to_cpu(fe->i_size))
480 goto bail;
481
482 down_write(&OCFS2_I(inode)->ip_alloc_sem); 480 down_write(&OCFS2_I(inode)->ip_alloc_sem);
483 481
484 ocfs2_resv_discard(&osb->osb_la_resmap, 482 ocfs2_resv_discard(&osb->osb_la_resmap,
@@ -718,7 +716,8 @@ leave:
718 * 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.
719 * Thus, we need to explicitly order the zeroed pages. 717 * Thus, we need to explicitly order the zeroed pages.
720 */ 718 */
721static handle_t *ocfs2_zero_start_ordered_transaction(struct inode *inode) 719static handle_t *ocfs2_zero_start_ordered_transaction(struct inode *inode,
720 struct buffer_head *di_bh)
722{ 721{
723 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); 722 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
724 handle_t *handle = NULL; 723 handle_t *handle = NULL;
@@ -735,7 +734,14 @@ static handle_t *ocfs2_zero_start_ordered_transaction(struct inode *inode)
735 } 734 }
736 735
737 ret = ocfs2_jbd2_file_inode(handle, inode); 736 ret = ocfs2_jbd2_file_inode(handle, inode);
738 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)
739 mlog_errno(ret); 745 mlog_errno(ret);
740 746
741out: 747out:
@@ -751,7 +757,7 @@ out:
751 * 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
752 * worry about recursive locking in ->write_begin() and ->write_end(). */ 758 * worry about recursive locking in ->write_begin() and ->write_end(). */
753static int ocfs2_write_zero_page(struct inode *inode, u64 abs_from, 759static int ocfs2_write_zero_page(struct inode *inode, u64 abs_from,
754 u64 abs_to) 760 u64 abs_to, struct buffer_head *di_bh)
755{ 761{
756 struct address_space *mapping = inode->i_mapping; 762 struct address_space *mapping = inode->i_mapping;
757 struct page *page; 763 struct page *page;
@@ -759,6 +765,7 @@ static int ocfs2_write_zero_page(struct inode *inode, u64 abs_from,
759 handle_t *handle = NULL; 765 handle_t *handle = NULL;
760 int ret = 0; 766 int ret = 0;
761 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;
762 769
763 BUG_ON(abs_from >= abs_to); 770 BUG_ON(abs_from >= abs_to);
764 BUG_ON(abs_to > (((u64)index + 1) << PAGE_CACHE_SHIFT)); 771 BUG_ON(abs_to > (((u64)index + 1) << PAGE_CACHE_SHIFT));
@@ -801,7 +808,8 @@ static int ocfs2_write_zero_page(struct inode *inode, u64 abs_from,
801 } 808 }
802 809
803 if (!handle) { 810 if (!handle) {
804 handle = ocfs2_zero_start_ordered_transaction(inode); 811 handle = ocfs2_zero_start_ordered_transaction(inode,
812 di_bh);
805 if (IS_ERR(handle)) { 813 if (IS_ERR(handle)) {
806 ret = PTR_ERR(handle); 814 ret = PTR_ERR(handle);
807 handle = NULL; 815 handle = NULL;
@@ -818,8 +826,22 @@ static int ocfs2_write_zero_page(struct inode *inode, u64 abs_from,
818 ret = 0; 826 ret = 0;
819 } 827 }
820 828
821 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);
822 ocfs2_commit_trans(OCFS2_SB(inode->i_sb), handle); 843 ocfs2_commit_trans(OCFS2_SB(inode->i_sb), handle);
844 }
823 845
824out_unlock: 846out_unlock:
825 unlock_page(page); 847 unlock_page(page);
@@ -915,7 +937,7 @@ out:
915 * has made sure that the entire range needs zeroing. 937 * has made sure that the entire range needs zeroing.
916 */ 938 */
917static int ocfs2_zero_extend_range(struct inode *inode, u64 range_start, 939static int ocfs2_zero_extend_range(struct inode *inode, u64 range_start,
918 u64 range_end) 940 u64 range_end, struct buffer_head *di_bh)
919{ 941{
920 int rc = 0; 942 int rc = 0;
921 u64 next_pos; 943 u64 next_pos;
@@ -931,7 +953,7 @@ static int ocfs2_zero_extend_range(struct inode *inode, u64 range_start,
931 next_pos = (zero_pos & PAGE_CACHE_MASK) + PAGE_CACHE_SIZE; 953 next_pos = (zero_pos & PAGE_CACHE_MASK) + PAGE_CACHE_SIZE;
932 if (next_pos > range_end) 954 if (next_pos > range_end)
933 next_pos = range_end; 955 next_pos = range_end;
934 rc = ocfs2_write_zero_page(inode, zero_pos, next_pos); 956 rc = ocfs2_write_zero_page(inode, zero_pos, next_pos, di_bh);
935 if (rc < 0) { 957 if (rc < 0) {
936 mlog_errno(rc); 958 mlog_errno(rc);
937 break; 959 break;
@@ -977,7 +999,7 @@ int ocfs2_zero_extend(struct inode *inode, struct buffer_head *di_bh,
977 range_end = zero_to_size; 999 range_end = zero_to_size;
978 1000
979 ret = ocfs2_zero_extend_range(inode, range_start, 1001 ret = ocfs2_zero_extend_range(inode, range_start,
980 range_end); 1002 range_end, di_bh);
981 if (ret) { 1003 if (ret) {
982 mlog_errno(ret); 1004 mlog_errno(ret);
983 break; 1005 break;
@@ -1145,14 +1167,14 @@ int ocfs2_setattr(struct dentry *dentry, struct iattr *attr)
1145 goto bail_unlock_rw; 1167 goto bail_unlock_rw;
1146 } 1168 }
1147 1169
1148 if (size_change && attr->ia_size != i_size_read(inode)) { 1170 if (size_change) {
1149 status = inode_newsize_ok(inode, attr->ia_size); 1171 status = inode_newsize_ok(inode, attr->ia_size);
1150 if (status) 1172 if (status)
1151 goto bail_unlock; 1173 goto bail_unlock;
1152 1174
1153 inode_dio_wait(inode); 1175 inode_dio_wait(inode);
1154 1176
1155 if (i_size_read(inode) > attr->ia_size) { 1177 if (i_size_read(inode) >= attr->ia_size) {
1156 if (ocfs2_should_order_data(inode)) { 1178 if (ocfs2_should_order_data(inode)) {
1157 status = ocfs2_begin_ordered_truncate(inode, 1179 status = ocfs2_begin_ordered_truncate(inode,
1158 attr->ia_size); 1180 attr->ia_size);