From 4a9e5ef1f4f15205e477817a5cefc34bd3f65f55 Mon Sep 17 00:00:00 2001 From: Nick Piggin Date: Tue, 16 Oct 2007 01:24:58 -0700 Subject: mm: write iovec cleanup Hide some of the open-coded nr_segs tests into the iovec helpers. This is all to simplify generic_file_buffered_write, because that gets more complex in the next patch. Signed-off-by: Nick Piggin Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- mm/filemap.c | 36 ++++++++++-------------------------- 1 file changed, 10 insertions(+), 26 deletions(-) (limited to 'mm/filemap.c') diff --git a/mm/filemap.c b/mm/filemap.c index fb4c1c0792e7..c59d5b3cd99a 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1823,12 +1823,7 @@ generic_file_buffered_write(struct kiocb *iocb, const struct iovec *iov, /* * handle partial DIO write. Adjust cur_iov if needed. */ - if (likely(nr_segs == 1)) - buf = iov->iov_base + written; - else { - filemap_set_next_iovec(&cur_iov, &iov_offset, written); - buf = cur_iov->iov_base + iov_offset; - } + filemap_set_next_iovec(&cur_iov, nr_segs, &iov_offset, written); do { struct page *page; @@ -1838,6 +1833,7 @@ generic_file_buffered_write(struct kiocb *iocb, const struct iovec *iov, size_t bytes; /* Bytes to write to page */ size_t copied; /* Bytes copied from user */ + buf = cur_iov->iov_base + iov_offset; offset = (pos & (PAGE_CACHE_SIZE - 1)); index = pos >> PAGE_CACHE_SHIFT; bytes = PAGE_CACHE_SIZE - offset; @@ -1869,13 +1865,10 @@ generic_file_buffered_write(struct kiocb *iocb, const struct iovec *iov, if (unlikely(status)) goto fs_write_aop_error; - if (likely(nr_segs == 1)) - copied = filemap_copy_from_user(page, offset, - buf, bytes); - else - copied = filemap_copy_from_user_iovec(page, offset, - cur_iov, iov_offset, bytes); + copied = filemap_copy_from_user(page, offset, + cur_iov, nr_segs, iov_offset, bytes); flush_dcache_page(page); + status = a_ops->commit_write(file, page, offset, offset+bytes); if (unlikely(status < 0 || status == AOP_TRUNCATED_PAGE)) goto fs_write_aop_error; @@ -1886,20 +1879,11 @@ generic_file_buffered_write(struct kiocb *iocb, const struct iovec *iov, if (unlikely(status > 0)) /* filesystem did partial write */ copied = status; - if (likely(copied > 0)) { - written += copied; - count -= copied; - pos += copied; - buf += copied; - if (unlikely(nr_segs > 1)) { - filemap_set_next_iovec(&cur_iov, - &iov_offset, copied); - if (count) - buf = cur_iov->iov_base + iov_offset; - } else { - iov_offset += copied; - } - } + written += copied; + count -= copied; + pos += copied; + filemap_set_next_iovec(&cur_iov, nr_segs, &iov_offset, copied); + unlock_page(page); mark_page_accessed(page); page_cache_release(page); -- cgit v1.2.3-58-ga151