diff options
author | Jan Kara <jack@suse.cz> | 2013-01-28 09:30:52 -0500 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2013-01-28 09:30:52 -0500 |
commit | 36ade451a5d736e61ac8302b64aacc5acb5e440f (patch) | |
tree | 4aab84ece1d56dac8fbd70377eb783ea138f35b1 /fs/ext4/inode.c | |
parent | 8bad6fc813a3a5300f51369c39d315679fd88c72 (diff) |
ext4: Always use ext4_bio_write_page() for writeout
Currently we sometimes used block_write_full_page() and sometimes
ext4_bio_write_page() for writeback (depending on mount options and call
path). Let's always use ext4_bio_write_page() to simplify things a bit.
Reviewed-by: Zheng Liu <wenqing.lz@taobao.com>
Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Diffstat (limited to 'fs/ext4/inode.c')
-rw-r--r-- | fs/ext4/inode.c | 129 |
1 files changed, 14 insertions, 115 deletions
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 80683bf0df1e..82f934282a1f 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c | |||
@@ -134,8 +134,6 @@ static inline int ext4_begin_ordered_truncate(struct inode *inode, | |||
134 | static void ext4_invalidatepage(struct page *page, unsigned long offset); | 134 | static void ext4_invalidatepage(struct page *page, unsigned long offset); |
135 | static int noalloc_get_block_write(struct inode *inode, sector_t iblock, | 135 | static int noalloc_get_block_write(struct inode *inode, sector_t iblock, |
136 | struct buffer_head *bh_result, int create); | 136 | struct buffer_head *bh_result, int create); |
137 | static int ext4_set_bh_endio(struct buffer_head *bh, struct inode *inode); | ||
138 | static void ext4_end_io_buffer_write(struct buffer_head *bh, int uptodate); | ||
139 | static int __ext4_journalled_writepage(struct page *page, unsigned int len); | 137 | static int __ext4_journalled_writepage(struct page *page, unsigned int len); |
140 | static int ext4_bh_delay_or_unwritten(handle_t *handle, struct buffer_head *bh); | 138 | static int ext4_bh_delay_or_unwritten(handle_t *handle, struct buffer_head *bh); |
141 | static int ext4_discard_partial_page_buffers_no_lock(handle_t *handle, | 139 | static int ext4_discard_partial_page_buffers_no_lock(handle_t *handle, |
@@ -808,11 +806,10 @@ int ext4_walk_page_buffers(handle_t *handle, | |||
808 | * and the commit_write(). So doing the jbd2_journal_start at the start of | 806 | * and the commit_write(). So doing the jbd2_journal_start at the start of |
809 | * prepare_write() is the right place. | 807 | * prepare_write() is the right place. |
810 | * | 808 | * |
811 | * Also, this function can nest inside ext4_writepage() -> | 809 | * Also, this function can nest inside ext4_writepage(). In that case, we |
812 | * block_write_full_page(). In that case, we *know* that ext4_writepage() | 810 | * *know* that ext4_writepage() has generated enough buffer credits to do the |
813 | * has generated enough buffer credits to do the whole page. So we won't | 811 | * whole page. So we won't block on the journal in that case, which is good, |
814 | * block on the journal in that case, which is good, because the caller may | 812 | * because the caller may be PF_MEMALLOC. |
815 | * be PF_MEMALLOC. | ||
816 | * | 813 | * |
817 | * By accident, ext4 can be reentered when a transaction is open via | 814 | * By accident, ext4 can be reentered when a transaction is open via |
818 | * quota file writes. If we were to commit the transaction while thus | 815 | * quota file writes. If we were to commit the transaction while thus |
@@ -1463,18 +1460,9 @@ static int mpage_da_submit_io(struct mpage_da_data *mpd, | |||
1463 | */ | 1460 | */ |
1464 | if (unlikely(journal_data && PageChecked(page))) | 1461 | if (unlikely(journal_data && PageChecked(page))) |
1465 | err = __ext4_journalled_writepage(page, len); | 1462 | err = __ext4_journalled_writepage(page, len); |
1466 | else if (test_opt(inode->i_sb, MBLK_IO_SUBMIT)) | 1463 | else |
1467 | err = ext4_bio_write_page(&io_submit, page, | 1464 | err = ext4_bio_write_page(&io_submit, page, |
1468 | len, mpd->wbc); | 1465 | len, mpd->wbc); |
1469 | else if (buffer_uninit(page_bufs)) { | ||
1470 | ext4_set_bh_endio(page_bufs, inode); | ||
1471 | err = block_write_full_page_endio(page, | ||
1472 | noalloc_get_block_write, | ||
1473 | mpd->wbc, ext4_end_io_buffer_write); | ||
1474 | } else | ||
1475 | err = block_write_full_page(page, | ||
1476 | noalloc_get_block_write, mpd->wbc); | ||
1477 | |||
1478 | if (!err) | 1466 | if (!err) |
1479 | mpd->pages_written++; | 1467 | mpd->pages_written++; |
1480 | /* | 1468 | /* |
@@ -1891,16 +1879,16 @@ int ext4_da_get_block_prep(struct inode *inode, sector_t iblock, | |||
1891 | } | 1879 | } |
1892 | 1880 | ||
1893 | /* | 1881 | /* |
1894 | * This function is used as a standard get_block_t calback function | 1882 | * This function is used as a standard get_block_t calback function when there |
1895 | * when there is no desire to allocate any blocks. It is used as a | 1883 | * is no desire to allocate any blocks. It is used as a callback function for |
1896 | * callback function for block_write_begin() and block_write_full_page(). | 1884 | * block_write_begin(). These functions should only try to map a single block |
1897 | * These functions should only try to map a single block at a time. | 1885 | * at a time. |
1898 | * | 1886 | * |
1899 | * Since this function doesn't do block allocations even if the caller | 1887 | * Since this function doesn't do block allocations even if the caller |
1900 | * requests it by passing in create=1, it is critically important that | 1888 | * requests it by passing in create=1, it is critically important that |
1901 | * any caller checks to make sure that any buffer heads are returned | 1889 | * any caller checks to make sure that any buffer heads are returned |
1902 | * by this function are either all already mapped or marked for | 1890 | * by this function are either all already mapped or marked for |
1903 | * delayed allocation before calling block_write_full_page(). Otherwise, | 1891 | * delayed allocation before calling ext4_bio_write_page(). Otherwise, |
1904 | * b_blocknr could be left unitialized, and the page write functions will | 1892 | * b_blocknr could be left unitialized, and the page write functions will |
1905 | * be taken by surprise. | 1893 | * be taken by surprise. |
1906 | */ | 1894 | */ |
@@ -2040,6 +2028,7 @@ static int ext4_writepage(struct page *page, | |||
2040 | unsigned int len; | 2028 | unsigned int len; |
2041 | struct buffer_head *page_bufs = NULL; | 2029 | struct buffer_head *page_bufs = NULL; |
2042 | struct inode *inode = page->mapping->host; | 2030 | struct inode *inode = page->mapping->host; |
2031 | struct ext4_io_submit io_submit; | ||
2043 | 2032 | ||
2044 | trace_ext4_writepage(page); | 2033 | trace_ext4_writepage(page); |
2045 | size = i_size_read(inode); | 2034 | size = i_size_read(inode); |
@@ -2089,14 +2078,9 @@ static int ext4_writepage(struct page *page, | |||
2089 | */ | 2078 | */ |
2090 | return __ext4_journalled_writepage(page, len); | 2079 | return __ext4_journalled_writepage(page, len); |
2091 | 2080 | ||
2092 | if (buffer_uninit(page_bufs)) { | 2081 | memset(&io_submit, 0, sizeof(io_submit)); |
2093 | ext4_set_bh_endio(page_bufs, inode); | 2082 | ret = ext4_bio_write_page(&io_submit, page, len, wbc); |
2094 | ret = block_write_full_page_endio(page, noalloc_get_block_write, | 2083 | ext4_io_submit(&io_submit); |
2095 | wbc, ext4_end_io_buffer_write); | ||
2096 | } else | ||
2097 | ret = block_write_full_page(page, noalloc_get_block_write, | ||
2098 | wbc); | ||
2099 | |||
2100 | return ret; | 2084 | return ret; |
2101 | } | 2085 | } |
2102 | 2086 | ||
@@ -2858,36 +2842,10 @@ ext4_readpages(struct file *file, struct address_space *mapping, | |||
2858 | return mpage_readpages(mapping, pages, nr_pages, ext4_get_block); | 2842 | return mpage_readpages(mapping, pages, nr_pages, ext4_get_block); |
2859 | } | 2843 | } |
2860 | 2844 | ||
2861 | static void ext4_invalidatepage_free_endio(struct page *page, unsigned long offset) | ||
2862 | { | ||
2863 | struct buffer_head *head, *bh; | ||
2864 | unsigned int curr_off = 0; | ||
2865 | |||
2866 | if (!page_has_buffers(page)) | ||
2867 | return; | ||
2868 | head = bh = page_buffers(page); | ||
2869 | do { | ||
2870 | if (offset <= curr_off && test_clear_buffer_uninit(bh) | ||
2871 | && bh->b_private) { | ||
2872 | ext4_free_io_end(bh->b_private); | ||
2873 | bh->b_private = NULL; | ||
2874 | bh->b_end_io = NULL; | ||
2875 | } | ||
2876 | curr_off = curr_off + bh->b_size; | ||
2877 | bh = bh->b_this_page; | ||
2878 | } while (bh != head); | ||
2879 | } | ||
2880 | |||
2881 | static void ext4_invalidatepage(struct page *page, unsigned long offset) | 2845 | static void ext4_invalidatepage(struct page *page, unsigned long offset) |
2882 | { | 2846 | { |
2883 | trace_ext4_invalidatepage(page, offset); | 2847 | trace_ext4_invalidatepage(page, offset); |
2884 | 2848 | ||
2885 | /* | ||
2886 | * free any io_end structure allocated for buffers to be discarded | ||
2887 | */ | ||
2888 | if (ext4_should_dioread_nolock(page->mapping->host)) | ||
2889 | ext4_invalidatepage_free_endio(page, offset); | ||
2890 | |||
2891 | /* No journalling happens on data buffers when this function is used */ | 2849 | /* No journalling happens on data buffers when this function is used */ |
2892 | WARN_ON(page_has_buffers(page) && buffer_jbd(page_buffers(page))); | 2850 | WARN_ON(page_has_buffers(page) && buffer_jbd(page_buffers(page))); |
2893 | 2851 | ||
@@ -2993,65 +2951,6 @@ out: | |||
2993 | ext4_add_complete_io(io_end); | 2951 | ext4_add_complete_io(io_end); |
2994 | } | 2952 | } |
2995 | 2953 | ||
2996 | static void ext4_end_io_buffer_write(struct buffer_head *bh, int uptodate) | ||
2997 | { | ||
2998 | ext4_io_end_t *io_end = bh->b_private; | ||
2999 | struct inode *inode; | ||
3000 | |||
3001 | if (!test_clear_buffer_uninit(bh) || !io_end) | ||
3002 | goto out; | ||
3003 | |||
3004 | if (!(io_end->inode->i_sb->s_flags & MS_ACTIVE)) { | ||
3005 | ext4_msg(io_end->inode->i_sb, KERN_INFO, | ||
3006 | "sb umounted, discard end_io request for inode %lu", | ||
3007 | io_end->inode->i_ino); | ||
3008 | ext4_free_io_end(io_end); | ||
3009 | goto out; | ||
3010 | } | ||
3011 | |||
3012 | /* | ||
3013 | * It may be over-defensive here to check EXT4_IO_END_UNWRITTEN now, | ||
3014 | * but being more careful is always safe for the future change. | ||
3015 | */ | ||
3016 | inode = io_end->inode; | ||
3017 | ext4_set_io_unwritten_flag(inode, io_end); | ||
3018 | ext4_add_complete_io(io_end); | ||
3019 | out: | ||
3020 | bh->b_private = NULL; | ||
3021 | bh->b_end_io = NULL; | ||
3022 | clear_buffer_uninit(bh); | ||
3023 | end_buffer_async_write(bh, uptodate); | ||
3024 | } | ||
3025 | |||
3026 | static int ext4_set_bh_endio(struct buffer_head *bh, struct inode *inode) | ||
3027 | { | ||
3028 | ext4_io_end_t *io_end; | ||
3029 | struct page *page = bh->b_page; | ||
3030 | loff_t offset = (sector_t)page->index << PAGE_CACHE_SHIFT; | ||
3031 | size_t size = bh->b_size; | ||
3032 | |||
3033 | retry: | ||
3034 | io_end = ext4_init_io_end(inode, GFP_ATOMIC); | ||
3035 | if (!io_end) { | ||
3036 | pr_warn_ratelimited("%s: allocation fail\n", __func__); | ||
3037 | schedule(); | ||
3038 | goto retry; | ||
3039 | } | ||
3040 | io_end->offset = offset; | ||
3041 | io_end->size = size; | ||
3042 | /* | ||
3043 | * We need to hold a reference to the page to make sure it | ||
3044 | * doesn't get evicted before ext4_end_io_work() has a chance | ||
3045 | * to convert the extent from written to unwritten. | ||
3046 | */ | ||
3047 | io_end->page = page; | ||
3048 | get_page(io_end->page); | ||
3049 | |||
3050 | bh->b_private = io_end; | ||
3051 | bh->b_end_io = ext4_end_io_buffer_write; | ||
3052 | return 0; | ||
3053 | } | ||
3054 | |||
3055 | /* | 2954 | /* |
3056 | * For ext4 extent files, ext4 will do direct-io write to holes, | 2955 | * For ext4 extent files, ext4 will do direct-io write to holes, |
3057 | * preallocated extents, and those write extend the file, no need to | 2956 | * preallocated extents, and those write extend the file, no need to |