Commit b6aa5901 authored by Henry C Chang's avatar Henry C Chang Committed by Sage Weil

ceph: mark user pages dirty on direct-io reads

For read operation, we have to set the argument _write_ of get_user_pages
to 1 since we will write data to pages. Also, we need to SetPageDirty before
releasing these pages.
Signed-off-by: default avatarHenry C Chang <henry_c_chang@tcloudcomputing.com>
Signed-off-by: default avatarSage Weil <sage@newdream.net>
parent 92cf7652
...@@ -384,7 +384,7 @@ static ssize_t ceph_sync_read(struct file *file, char __user *data, ...@@ -384,7 +384,7 @@ static ssize_t ceph_sync_read(struct file *file, char __user *data,
if (file->f_flags & O_DIRECT) { if (file->f_flags & O_DIRECT) {
num_pages = calc_pages_for((unsigned long)data, len); num_pages = calc_pages_for((unsigned long)data, len);
pages = ceph_get_direct_page_vector(data, num_pages); pages = ceph_get_direct_page_vector(data, num_pages, true);
} else { } else {
num_pages = calc_pages_for(off, len); num_pages = calc_pages_for(off, len);
pages = ceph_alloc_page_vector(num_pages, GFP_NOFS); pages = ceph_alloc_page_vector(num_pages, GFP_NOFS);
...@@ -413,7 +413,7 @@ static ssize_t ceph_sync_read(struct file *file, char __user *data, ...@@ -413,7 +413,7 @@ static ssize_t ceph_sync_read(struct file *file, char __user *data,
done: done:
if (file->f_flags & O_DIRECT) if (file->f_flags & O_DIRECT)
ceph_put_page_vector(pages, num_pages); ceph_put_page_vector(pages, num_pages, true);
else else
ceph_release_page_vector(pages, num_pages); ceph_release_page_vector(pages, num_pages);
dout("sync_read result %d\n", ret); dout("sync_read result %d\n", ret);
...@@ -522,7 +522,7 @@ static ssize_t ceph_sync_write(struct file *file, const char __user *data, ...@@ -522,7 +522,7 @@ static ssize_t ceph_sync_write(struct file *file, const char __user *data,
return -ENOMEM; return -ENOMEM;
if (file->f_flags & O_DIRECT) { if (file->f_flags & O_DIRECT) {
pages = ceph_get_direct_page_vector(data, num_pages); pages = ceph_get_direct_page_vector(data, num_pages, false);
if (IS_ERR(pages)) { if (IS_ERR(pages)) {
ret = PTR_ERR(pages); ret = PTR_ERR(pages);
goto out; goto out;
...@@ -572,7 +572,7 @@ static ssize_t ceph_sync_write(struct file *file, const char __user *data, ...@@ -572,7 +572,7 @@ static ssize_t ceph_sync_write(struct file *file, const char __user *data,
} }
if (file->f_flags & O_DIRECT) if (file->f_flags & O_DIRECT)
ceph_put_page_vector(pages, num_pages); ceph_put_page_vector(pages, num_pages, false);
else if (file->f_flags & O_SYNC) else if (file->f_flags & O_SYNC)
ceph_release_page_vector(pages, num_pages); ceph_release_page_vector(pages, num_pages);
......
...@@ -227,8 +227,10 @@ extern int ceph_open_session(struct ceph_client *client); ...@@ -227,8 +227,10 @@ extern int ceph_open_session(struct ceph_client *client);
extern void ceph_release_page_vector(struct page **pages, int num_pages); extern void ceph_release_page_vector(struct page **pages, int num_pages);
extern struct page **ceph_get_direct_page_vector(const char __user *data, extern struct page **ceph_get_direct_page_vector(const char __user *data,
int num_pages); int num_pages,
extern void ceph_put_page_vector(struct page **pages, int num_pages); bool write_page);
extern void ceph_put_page_vector(struct page **pages, int num_pages,
bool dirty);
extern void ceph_release_page_vector(struct page **pages, int num_pages); extern void ceph_release_page_vector(struct page **pages, int num_pages);
extern struct page **ceph_alloc_page_vector(int num_pages, gfp_t flags); extern struct page **ceph_alloc_page_vector(int num_pages, gfp_t flags);
extern int ceph_copy_user_to_page_vector(struct page **pages, extern int ceph_copy_user_to_page_vector(struct page **pages,
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
* build a vector of user pages * build a vector of user pages
*/ */
struct page **ceph_get_direct_page_vector(const char __user *data, struct page **ceph_get_direct_page_vector(const char __user *data,
int num_pages) int num_pages, bool write_page)
{ {
struct page **pages; struct page **pages;
int rc; int rc;
...@@ -24,7 +24,7 @@ struct page **ceph_get_direct_page_vector(const char __user *data, ...@@ -24,7 +24,7 @@ struct page **ceph_get_direct_page_vector(const char __user *data,
down_read(&current->mm->mmap_sem); down_read(&current->mm->mmap_sem);
rc = get_user_pages(current, current->mm, (unsigned long)data, rc = get_user_pages(current, current->mm, (unsigned long)data,
num_pages, 0, 0, pages, NULL); num_pages, write_page, 0, pages, NULL);
up_read(&current->mm->mmap_sem); up_read(&current->mm->mmap_sem);
if (rc < 0) if (rc < 0)
goto fail; goto fail;
...@@ -36,12 +36,15 @@ struct page **ceph_get_direct_page_vector(const char __user *data, ...@@ -36,12 +36,15 @@ struct page **ceph_get_direct_page_vector(const char __user *data,
} }
EXPORT_SYMBOL(ceph_get_direct_page_vector); EXPORT_SYMBOL(ceph_get_direct_page_vector);
void ceph_put_page_vector(struct page **pages, int num_pages) void ceph_put_page_vector(struct page **pages, int num_pages, bool dirty)
{ {
int i; int i;
for (i = 0; i < num_pages; i++) for (i = 0; i < num_pages; i++) {
if (dirty)
set_page_dirty_lock(pages[i]);
put_page(pages[i]); put_page(pages[i]);
}
kfree(pages); kfree(pages);
} }
EXPORT_SYMBOL(ceph_put_page_vector); EXPORT_SYMBOL(ceph_put_page_vector);
......
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