Commit 65c4db8c authored by Ryan Ding's avatar Ryan Ding Committed by Linus Torvalds

ocfs2: test target page before change it

To support direct io in ocfs2_write_begin_nolock & ocfs2_write_end_nolock.

Direct io data will not appear in buffer.  The w_target_page member will
not be filled by direct io.  So avoid to use it when it's NULL.  Unlinke
buffer io and mmap, direct io will call write_begin with more than 1
page a time.  So the target_index is not sufficient to describe the
actual data.  change it to a range start at target_index, end in
end_index.
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 b46637d5
...@@ -1406,12 +1406,13 @@ static void ocfs2_write_failure(struct inode *inode, ...@@ -1406,12 +1406,13 @@ static void ocfs2_write_failure(struct inode *inode,
to = user_pos + user_len; to = user_pos + user_len;
struct page *tmppage; struct page *tmppage;
if (wc->w_target_page)
ocfs2_zero_new_buffers(wc->w_target_page, from, to); ocfs2_zero_new_buffers(wc->w_target_page, from, to);
for(i = 0; i < wc->w_num_pages; i++) { for(i = 0; i < wc->w_num_pages; i++) {
tmppage = wc->w_pages[i]; tmppage = wc->w_pages[i];
if (page_has_buffers(tmppage)) { if (tmppage && page_has_buffers(tmppage)) {
if (ocfs2_should_order_data(inode)) if (ocfs2_should_order_data(inode))
ocfs2_jbd2_file_inode(wc->w_handle, inode); ocfs2_jbd2_file_inode(wc->w_handle, inode);
...@@ -1541,11 +1542,13 @@ static int ocfs2_grab_pages_for_write(struct address_space *mapping, ...@@ -1541,11 +1542,13 @@ static int ocfs2_grab_pages_for_write(struct address_space *mapping,
wc->w_num_pages = 1; wc->w_num_pages = 1;
start = target_index; start = target_index;
} }
end_index = (user_pos + user_len - 1) >> PAGE_CACHE_SHIFT;
for(i = 0; i < wc->w_num_pages; i++) { for(i = 0; i < wc->w_num_pages; i++) {
index = start + i; index = start + i;
if (index == target_index && mmap_page) { if (index >= target_index && index <= end_index &&
wc->w_type == OCFS2_WRITE_MMAP) {
/* /*
* ocfs2_pagemkwrite() is a little different * ocfs2_pagemkwrite() is a little different
* and wants us to directly use the page * and wants us to directly use the page
...@@ -1564,6 +1567,11 @@ static int ocfs2_grab_pages_for_write(struct address_space *mapping, ...@@ -1564,6 +1567,11 @@ static int ocfs2_grab_pages_for_write(struct address_space *mapping,
page_cache_get(mmap_page); page_cache_get(mmap_page);
wc->w_pages[i] = mmap_page; wc->w_pages[i] = mmap_page;
wc->w_target_locked = true; wc->w_target_locked = true;
} else if (index >= target_index && index <= end_index &&
wc->w_type == OCFS2_WRITE_DIRECT) {
/* Direct write has no mapping page. */
wc->w_pages[i] = NULL;
continue;
} else { } else {
wc->w_pages[i] = find_or_create_page(mapping, index, wc->w_pages[i] = find_or_create_page(mapping, index,
GFP_NOFS); GFP_NOFS);
...@@ -1665,6 +1673,12 @@ static int ocfs2_write_cluster(struct address_space *mapping, ...@@ -1665,6 +1673,12 @@ static int ocfs2_write_cluster(struct address_space *mapping,
for(i = 0; i < wc->w_num_pages; i++) { for(i = 0; i < wc->w_num_pages; i++) {
int tmpret; int tmpret;
/* This is the direct io target page. */
if (wc->w_pages[i] == NULL) {
p_blkno++;
continue;
}
tmpret = ocfs2_prepare_page_for_write(inode, &p_blkno, wc, tmpret = ocfs2_prepare_page_for_write(inode, &p_blkno, wc,
wc->w_pages[i], cpos, wc->w_pages[i], cpos,
user_pos, user_len, user_pos, user_len,
...@@ -2266,6 +2280,7 @@ int ocfs2_write_begin_nolock(struct address_space *mapping, ...@@ -2266,6 +2280,7 @@ int ocfs2_write_begin_nolock(struct address_space *mapping,
ocfs2_free_alloc_context(meta_ac); ocfs2_free_alloc_context(meta_ac);
success: success:
if (pagep)
*pagep = wc->w_target_page; *pagep = wc->w_target_page;
*fsdata = wc; *fsdata = wc;
return 0; return 0;
...@@ -2400,18 +2415,23 @@ int ocfs2_write_end_nolock(struct address_space *mapping, ...@@ -2400,18 +2415,23 @@ int ocfs2_write_end_nolock(struct address_space *mapping,
goto out_write_size; goto out_write_size;
} }
if (unlikely(copied < len)) { if (unlikely(copied < len) && wc->w_target_page) {
if (!PageUptodate(wc->w_target_page)) if (!PageUptodate(wc->w_target_page))
copied = 0; copied = 0;
ocfs2_zero_new_buffers(wc->w_target_page, start+copied, ocfs2_zero_new_buffers(wc->w_target_page, start+copied,
start+len); start+len);
} }
if (wc->w_target_page)
flush_dcache_page(wc->w_target_page); flush_dcache_page(wc->w_target_page);
for(i = 0; i < wc->w_num_pages; i++) { for(i = 0; i < wc->w_num_pages; i++) {
tmppage = wc->w_pages[i]; tmppage = wc->w_pages[i];
/* This is the direct io target page. */
if (tmppage == NULL)
continue;
if (tmppage == wc->w_target_page) { if (tmppage == wc->w_target_page) {
from = wc->w_target_from; from = wc->w_target_from;
to = wc->w_target_to; to = wc->w_target_to;
......
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