Commit b87846bd authored by Eric Biggers's avatar Eric Biggers Committed by Jaegeuk Kim

f2fs: use memcpy_{to,from}_page() where possible

This is simpler, and as a side effect it replaces several uses of
kmap_atomic() with its recommended replacement kmap_local_page().
Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
Reviewed-by: default avatarFabio M. De Francesco <fmdefrancesco@gmail.com>
Reviewed-by: default avatarChao Yu <chao@kernel.org>
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
parent 605b0a77
...@@ -64,7 +64,6 @@ bool f2fs_may_inline_dentry(struct inode *inode) ...@@ -64,7 +64,6 @@ bool f2fs_may_inline_dentry(struct inode *inode)
void f2fs_do_read_inline_data(struct page *page, struct page *ipage) void f2fs_do_read_inline_data(struct page *page, struct page *ipage)
{ {
struct inode *inode = page->mapping->host; struct inode *inode = page->mapping->host;
void *src_addr, *dst_addr;
if (PageUptodate(page)) if (PageUptodate(page))
return; return;
...@@ -74,11 +73,8 @@ void f2fs_do_read_inline_data(struct page *page, struct page *ipage) ...@@ -74,11 +73,8 @@ void f2fs_do_read_inline_data(struct page *page, struct page *ipage)
zero_user_segment(page, MAX_INLINE_DATA(inode), PAGE_SIZE); zero_user_segment(page, MAX_INLINE_DATA(inode), PAGE_SIZE);
/* Copy the whole inline data block */ /* Copy the whole inline data block */
src_addr = inline_data_addr(inode, ipage); memcpy_to_page(page, 0, inline_data_addr(inode, ipage),
dst_addr = kmap_atomic(page); MAX_INLINE_DATA(inode));
memcpy(dst_addr, src_addr, MAX_INLINE_DATA(inode));
flush_dcache_page(page);
kunmap_atomic(dst_addr);
if (!PageUptodate(page)) if (!PageUptodate(page))
SetPageUptodate(page); SetPageUptodate(page);
} }
...@@ -246,7 +242,6 @@ int f2fs_convert_inline_inode(struct inode *inode) ...@@ -246,7 +242,6 @@ int f2fs_convert_inline_inode(struct inode *inode)
int f2fs_write_inline_data(struct inode *inode, struct page *page) int f2fs_write_inline_data(struct inode *inode, struct page *page)
{ {
void *src_addr, *dst_addr;
struct dnode_of_data dn; struct dnode_of_data dn;
int err; int err;
...@@ -263,10 +258,8 @@ int f2fs_write_inline_data(struct inode *inode, struct page *page) ...@@ -263,10 +258,8 @@ int f2fs_write_inline_data(struct inode *inode, struct page *page)
f2fs_bug_on(F2FS_I_SB(inode), page->index); f2fs_bug_on(F2FS_I_SB(inode), page->index);
f2fs_wait_on_page_writeback(dn.inode_page, NODE, true, true); f2fs_wait_on_page_writeback(dn.inode_page, NODE, true, true);
src_addr = kmap_atomic(page); memcpy_from_page(inline_data_addr(inode, dn.inode_page),
dst_addr = inline_data_addr(inode, dn.inode_page); page, 0, MAX_INLINE_DATA(inode));
memcpy(dst_addr, src_addr, MAX_INLINE_DATA(inode));
kunmap_atomic(src_addr);
set_page_dirty(dn.inode_page); set_page_dirty(dn.inode_page);
f2fs_clear_page_cache_dirty_tag(page); f2fs_clear_page_cache_dirty_tag(page);
......
...@@ -2470,7 +2470,6 @@ static ssize_t f2fs_quota_read(struct super_block *sb, int type, char *data, ...@@ -2470,7 +2470,6 @@ static ssize_t f2fs_quota_read(struct super_block *sb, int type, char *data,
size_t toread; size_t toread;
loff_t i_size = i_size_read(inode); loff_t i_size = i_size_read(inode);
struct page *page; struct page *page;
char *kaddr;
if (off > i_size) if (off > i_size)
return 0; return 0;
...@@ -2503,9 +2502,7 @@ static ssize_t f2fs_quota_read(struct super_block *sb, int type, char *data, ...@@ -2503,9 +2502,7 @@ static ssize_t f2fs_quota_read(struct super_block *sb, int type, char *data,
return -EIO; return -EIO;
} }
kaddr = kmap_atomic(page); memcpy_from_page(data, page, offset, tocopy);
memcpy(data, kaddr + offset, tocopy);
kunmap_atomic(kaddr);
f2fs_put_page(page, 1); f2fs_put_page(page, 1);
offset = 0; offset = 0;
...@@ -2527,7 +2524,6 @@ static ssize_t f2fs_quota_write(struct super_block *sb, int type, ...@@ -2527,7 +2524,6 @@ static ssize_t f2fs_quota_write(struct super_block *sb, int type,
size_t towrite = len; size_t towrite = len;
struct page *page; struct page *page;
void *fsdata = NULL; void *fsdata = NULL;
char *kaddr;
int err = 0; int err = 0;
int tocopy; int tocopy;
...@@ -2546,10 +2542,7 @@ static ssize_t f2fs_quota_write(struct super_block *sb, int type, ...@@ -2546,10 +2542,7 @@ static ssize_t f2fs_quota_write(struct super_block *sb, int type,
break; break;
} }
kaddr = kmap_atomic(page); memcpy_to_page(page, offset, data, tocopy);
memcpy(kaddr + offset, data, tocopy);
kunmap_atomic(kaddr);
flush_dcache_page(page);
a_ops->write_end(NULL, mapping, off, tocopy, tocopy, a_ops->write_end(NULL, mapping, off, tocopy, tocopy,
page, fsdata); page, fsdata);
......
...@@ -47,16 +47,13 @@ static int pagecache_read(struct inode *inode, void *buf, size_t count, ...@@ -47,16 +47,13 @@ static int pagecache_read(struct inode *inode, void *buf, size_t count,
size_t n = min_t(size_t, count, size_t n = min_t(size_t, count,
PAGE_SIZE - offset_in_page(pos)); PAGE_SIZE - offset_in_page(pos));
struct page *page; struct page *page;
void *addr;
page = read_mapping_page(inode->i_mapping, pos >> PAGE_SHIFT, page = read_mapping_page(inode->i_mapping, pos >> PAGE_SHIFT,
NULL); NULL);
if (IS_ERR(page)) if (IS_ERR(page))
return PTR_ERR(page); return PTR_ERR(page);
addr = kmap_atomic(page); memcpy_from_page(buf, page, offset_in_page(pos), n);
memcpy(buf, addr + offset_in_page(pos), n);
kunmap_atomic(addr);
put_page(page); put_page(page);
...@@ -85,16 +82,13 @@ static int pagecache_write(struct inode *inode, const void *buf, size_t count, ...@@ -85,16 +82,13 @@ static int pagecache_write(struct inode *inode, const void *buf, size_t count,
PAGE_SIZE - offset_in_page(pos)); PAGE_SIZE - offset_in_page(pos));
struct page *page; struct page *page;
void *fsdata; void *fsdata;
void *addr;
int res; int res;
res = aops->write_begin(NULL, mapping, pos, n, &page, &fsdata); res = aops->write_begin(NULL, mapping, pos, n, &page, &fsdata);
if (res) if (res)
return res; return res;
addr = kmap_atomic(page); memcpy_to_page(page, offset_in_page(pos), buf, n);
memcpy(addr + offset_in_page(pos), buf, n);
kunmap_atomic(addr);
res = aops->write_end(NULL, mapping, pos, n, n, page, fsdata); res = aops->write_end(NULL, mapping, pos, n, n, page, fsdata);
if (res < 0) if (res < 0)
......
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