Commit 46e62556 authored by Ryan Ding's avatar Ryan Ding Committed by Linus Torvalds

ocfs2: do not change i_size in write_end for direct io

To support direct io in ocfs2_write_begin_nolock & ocfs2_write_end_nolock.

Append direct io do not change i_size in get block phase.  It only move
to orphan when starting write.  After data is written to disk, it will
delete itself from orphan and update i_size.  So skip i_size change
section in write_begin for direct io.

And when there is no extents alloc, no meta data changes needed for
direct io (since write_begin start trans for 2 reason: alloc extents &
change i_size.  Now none of them needed).  So we can skip start trans
procedure.
Signed-off-by: default avatarRyan Ding <ryan.ding@oracle.com>
Reviewed-by: default avatarJunxiao Bi <junxiao.bi@oracle.com>
Cc: Joseph Qi <joseph.qi@huawei.com>
Cc: Mark Fasheh <mfasheh@suse.de>
Cc: Joel Becker <jlbec@evilplan.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 65c4db8c
...@@ -2043,6 +2043,8 @@ static int ocfs2_expand_nonsparse_inode(struct inode *inode, ...@@ -2043,6 +2043,8 @@ static int ocfs2_expand_nonsparse_inode(struct inode *inode,
if (ret) if (ret)
mlog_errno(ret); mlog_errno(ret);
/* There is no wc if this is call from direct. */
if (wc)
wc->w_first_new_cpos = wc->w_first_new_cpos =
ocfs2_clusters_for_bytes(inode->i_sb, i_size_read(inode)); ocfs2_clusters_for_bytes(inode->i_sb, i_size_read(inode));
...@@ -2135,15 +2137,18 @@ int ocfs2_write_begin_nolock(struct address_space *mapping, ...@@ -2135,15 +2137,18 @@ int ocfs2_write_begin_nolock(struct address_space *mapping,
} }
} }
/* Direct io change i_size late, should not zero tail here. */
if (type != OCFS2_WRITE_DIRECT) {
if (ocfs2_sparse_alloc(osb)) if (ocfs2_sparse_alloc(osb))
ret = ocfs2_zero_tail(inode, di_bh, pos); ret = ocfs2_zero_tail(inode, di_bh, pos);
else else
ret = ocfs2_expand_nonsparse_inode(inode, di_bh, pos, len, ret = ocfs2_expand_nonsparse_inode(inode, di_bh, pos,
wc); len, wc);
if (ret) { if (ret) {
mlog_errno(ret); mlog_errno(ret);
goto out; goto out;
} }
}
ret = ocfs2_check_range_for_refcount(inode, pos, len); ret = ocfs2_check_range_for_refcount(inode, pos, len);
if (ret < 0) { if (ret < 0) {
...@@ -2203,8 +2208,9 @@ int ocfs2_write_begin_nolock(struct address_space *mapping, ...@@ -2203,8 +2208,9 @@ int ocfs2_write_begin_nolock(struct address_space *mapping,
credits = ocfs2_calc_extend_credits(inode->i_sb, credits = ocfs2_calc_extend_credits(inode->i_sb,
&di->id2.i_list); &di->id2.i_list);
} else if (type == OCFS2_WRITE_DIRECT)
} /* direct write needs not to start trans if no extents alloc. */
goto success;
/* /*
* We have to zero sparse allocated clusters, unwritten extent clusters, * We have to zero sparse allocated clusters, unwritten extent clusters,
...@@ -2402,13 +2408,15 @@ int ocfs2_write_end_nolock(struct address_space *mapping, ...@@ -2402,13 +2408,15 @@ int ocfs2_write_end_nolock(struct address_space *mapping,
handle_t *handle = wc->w_handle; handle_t *handle = wc->w_handle;
struct page *tmppage; struct page *tmppage;
ret = ocfs2_journal_access_di(handle, INODE_CACHE(inode), wc->w_di_bh, if (handle) {
OCFS2_JOURNAL_ACCESS_WRITE); ret = ocfs2_journal_access_di(handle, INODE_CACHE(inode),
wc->w_di_bh, OCFS2_JOURNAL_ACCESS_WRITE);
if (ret) { if (ret) {
copied = ret; copied = ret;
mlog_errno(ret); mlog_errno(ret);
goto out; goto out;
} }
}
if (OCFS2_I(inode)->ip_dyn_features & OCFS2_INLINE_DATA_FL) { if (OCFS2_I(inode)->ip_dyn_features & OCFS2_INLINE_DATA_FL) {
ocfs2_write_end_inline(inode, pos, len, &copied, di, wc); ocfs2_write_end_inline(inode, pos, len, &copied, di, wc);
...@@ -2450,13 +2458,15 @@ int ocfs2_write_end_nolock(struct address_space *mapping, ...@@ -2450,13 +2458,15 @@ int ocfs2_write_end_nolock(struct address_space *mapping,
} }
if (page_has_buffers(tmppage)) { if (page_has_buffers(tmppage)) {
if (ocfs2_should_order_data(inode)) if (handle && ocfs2_should_order_data(inode))
ocfs2_jbd2_file_inode(wc->w_handle, inode); ocfs2_jbd2_file_inode(handle, inode);
block_commit_write(tmppage, from, to); block_commit_write(tmppage, from, to);
} }
} }
out_write_size: out_write_size:
/* Direct io do not update i_size here. */
if (wc->w_type != OCFS2_WRITE_DIRECT) {
pos += copied; pos += copied;
if (pos > i_size_read(inode)) { if (pos > i_size_read(inode)) {
i_size_write(inode, pos); i_size_write(inode, pos);
...@@ -2468,6 +2478,8 @@ int ocfs2_write_end_nolock(struct address_space *mapping, ...@@ -2468,6 +2478,8 @@ int ocfs2_write_end_nolock(struct address_space *mapping,
di->i_mtime = di->i_ctime = cpu_to_le64(inode->i_mtime.tv_sec); di->i_mtime = di->i_ctime = cpu_to_le64(inode->i_mtime.tv_sec);
di->i_mtime_nsec = di->i_ctime_nsec = cpu_to_le32(inode->i_mtime.tv_nsec); di->i_mtime_nsec = di->i_ctime_nsec = cpu_to_le32(inode->i_mtime.tv_nsec);
ocfs2_update_inode_fsync_trans(handle, inode, 1); ocfs2_update_inode_fsync_trans(handle, inode, 1);
}
if (handle)
ocfs2_journal_dirty(handle, wc->w_di_bh); ocfs2_journal_dirty(handle, wc->w_di_bh);
out: out:
...@@ -2478,6 +2490,7 @@ int ocfs2_write_end_nolock(struct address_space *mapping, ...@@ -2478,6 +2490,7 @@ int ocfs2_write_end_nolock(struct address_space *mapping,
*/ */
ocfs2_unlock_pages(wc); ocfs2_unlock_pages(wc);
if (handle)
ocfs2_commit_trans(osb, handle); ocfs2_commit_trans(osb, handle);
ocfs2_run_deallocs(osb, &wc->w_dealloc); ocfs2_run_deallocs(osb, &wc->w_dealloc);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment