aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ext4/inode.c
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2011-02-26 14:07:37 -0500
committerTheodore Ts'o <tytso@mit.edu>2011-02-26 14:07:37 -0500
commit4f01b02c8c4e4111bd1adbcafb5741e8e991f5fd (patch)
tree4b4793878e26779bf3bfe74028bd8b87de72609e /fs/ext4/inode.c
parent8eb9e5ce211de1b98bc84e93258b7db0860a103c (diff)
ext4: simple cleanups to write_cache_pages_da()
Eliminate duplicate code, unneeded variables, etc., to make it easier to understand the code. No behavioral changes were made in this patch. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Diffstat (limited to 'fs/ext4/inode.c')
-rw-r--r--fs/ext4/inode.c115
1 files changed, 48 insertions, 67 deletions
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index fcd08ca0643b..1e718e87f466 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -2723,17 +2723,14 @@ static int write_cache_pages_da(struct address_space *mapping,
2723 struct mpage_da_data *mpd, 2723 struct mpage_da_data *mpd,
2724 pgoff_t *done_index) 2724 pgoff_t *done_index)
2725{ 2725{
2726 struct inode *inode = mpd->inode; 2726 struct buffer_head *bh, *head;
2727 struct buffer_head *bh, *head; 2727 struct inode *inode = mpd->inode;
2728 sector_t logical; 2728 struct pagevec pvec;
2729 int ret = 0; 2729 unsigned int nr_pages;
2730 int done = 0; 2730 sector_t logical;
2731 struct pagevec pvec; 2731 pgoff_t index, end;
2732 unsigned nr_pages; 2732 long nr_to_write = wbc->nr_to_write;
2733 pgoff_t index; 2733 int i, tag, ret = 0;
2734 pgoff_t end; /* Inclusive */
2735 long nr_to_write = wbc->nr_to_write;
2736 int tag;
2737 2734
2738 pagevec_init(&pvec, 0); 2735 pagevec_init(&pvec, 0);
2739 index = wbc->range_start >> PAGE_CACHE_SHIFT; 2736 index = wbc->range_start >> PAGE_CACHE_SHIFT;
@@ -2745,13 +2742,11 @@ static int write_cache_pages_da(struct address_space *mapping,
2745 tag = PAGECACHE_TAG_DIRTY; 2742 tag = PAGECACHE_TAG_DIRTY;
2746 2743
2747 *done_index = index; 2744 *done_index = index;
2748 while (!done && (index <= end)) { 2745 while (index <= end) {
2749 int i;
2750
2751 nr_pages = pagevec_lookup_tag(&pvec, mapping, &index, tag, 2746 nr_pages = pagevec_lookup_tag(&pvec, mapping, &index, tag,
2752 min(end - index, (pgoff_t)PAGEVEC_SIZE-1) + 1); 2747 min(end - index, (pgoff_t)PAGEVEC_SIZE-1) + 1);
2753 if (nr_pages == 0) 2748 if (nr_pages == 0)
2754 break; 2749 return 0;
2755 2750
2756 for (i = 0; i < nr_pages; i++) { 2751 for (i = 0; i < nr_pages; i++) {
2757 struct page *page = pvec.pages[i]; 2752 struct page *page = pvec.pages[i];
@@ -2763,47 +2758,37 @@ static int write_cache_pages_da(struct address_space *mapping,
2763 * mapping. However, page->index will not change 2758 * mapping. However, page->index will not change
2764 * because we have a reference on the page. 2759 * because we have a reference on the page.
2765 */ 2760 */
2766 if (page->index > end) { 2761 if (page->index > end)
2767 done = 1; 2762 goto out;
2768 break;
2769 }
2770 2763
2771 *done_index = page->index + 1; 2764 *done_index = page->index + 1;
2772 2765
2773 lock_page(page); 2766 lock_page(page);
2774 2767
2775 /* 2768 /*
2776 * Page truncated or invalidated. We can freely skip it 2769 * If the page is no longer dirty, or its
2777 * then, even for data integrity operations: the page 2770 * mapping no longer corresponds to inode we
2778 * has disappeared concurrently, so there could be no 2771 * are writing (which means it has been
2779 * real expectation of this data interity operation 2772 * truncated or invalidated), or the page is
2780 * even if there is now a new, dirty page at the same 2773 * already under writeback and we are not
2781 * pagecache address. 2774 * doing a data integrity writeback, skip the page
2782 */ 2775 */
2783 if (unlikely(page->mapping != mapping)) { 2776 if (!PageDirty(page) ||
2784continue_unlock: 2777 (PageWriteback(page) &&
2778 (wbc->sync_mode == WB_SYNC_NONE)) ||
2779 unlikely(page->mapping != mapping)) {
2780 continue_unlock:
2785 unlock_page(page); 2781 unlock_page(page);
2786 continue; 2782 continue;
2787 } 2783 }
2788 2784
2789 if (!PageDirty(page)) { 2785 if (PageWriteback(page))
2790 /* someone wrote it for us */ 2786 wait_on_page_writeback(page);
2791 goto continue_unlock;
2792 }
2793
2794 if (PageWriteback(page)) {
2795 if (wbc->sync_mode != WB_SYNC_NONE)
2796 wait_on_page_writeback(page);
2797 else
2798 goto continue_unlock;
2799 }
2800 2787
2801 BUG_ON(PageWriteback(page)); 2788 BUG_ON(PageWriteback(page));
2802 if (!clear_page_dirty_for_io(page)) 2789 if (!clear_page_dirty_for_io(page))
2803 goto continue_unlock; 2790 goto continue_unlock;
2804 2791
2805 /* BEGIN __mpage_da_writepage */
2806
2807 /* 2792 /*
2808 * Can we merge this page to current extent? 2793 * Can we merge this page to current extent?
2809 */ 2794 */
@@ -2820,8 +2805,7 @@ continue_unlock:
2820 */ 2805 */
2821 redirty_page_for_writepage(wbc, page); 2806 redirty_page_for_writepage(wbc, page);
2822 unlock_page(page); 2807 unlock_page(page);
2823 ret = MPAGE_DA_EXTENT_TAIL; 2808 goto ret_extent_tail;
2824 goto out;
2825 } 2809 }
2826 2810
2827 /* 2811 /*
@@ -2838,15 +2822,15 @@ continue_unlock:
2838 (PAGE_CACHE_SHIFT - inode->i_blkbits); 2822 (PAGE_CACHE_SHIFT - inode->i_blkbits);
2839 2823
2840 if (!page_has_buffers(page)) { 2824 if (!page_has_buffers(page)) {
2841 mpage_add_bh_to_extent(mpd, logical, PAGE_CACHE_SIZE, 2825 mpage_add_bh_to_extent(mpd, logical,
2826 PAGE_CACHE_SIZE,
2842 (1 << BH_Dirty) | (1 << BH_Uptodate)); 2827 (1 << BH_Dirty) | (1 << BH_Uptodate));
2843 if (mpd->io_done) { 2828 if (mpd->io_done)
2844 ret = MPAGE_DA_EXTENT_TAIL; 2829 goto ret_extent_tail;
2845 goto out;
2846 }
2847 } else { 2830 } else {
2848 /* 2831 /*
2849 * Page with regular buffer heads, just add all dirty ones 2832 * Page with regular buffer heads,
2833 * just add all dirty ones
2850 */ 2834 */
2851 head = page_buffers(page); 2835 head = page_buffers(page);
2852 bh = head; 2836 bh = head;
@@ -2862,18 +2846,19 @@ continue_unlock:
2862 mpage_add_bh_to_extent(mpd, logical, 2846 mpage_add_bh_to_extent(mpd, logical,
2863 bh->b_size, 2847 bh->b_size,
2864 bh->b_state); 2848 bh->b_state);
2865 if (mpd->io_done) { 2849 if (mpd->io_done)
2866 ret = MPAGE_DA_EXTENT_TAIL; 2850 goto ret_extent_tail;
2867 goto out;
2868 }
2869 } else if (buffer_dirty(bh) && (buffer_mapped(bh))) { 2851 } else if (buffer_dirty(bh) && (buffer_mapped(bh))) {
2870 /* 2852 /*
2871 * mapped dirty buffer. We need to update 2853 * mapped dirty buffer. We need
2872 * the b_state because we look at 2854 * to update the b_state
2873 * b_state in mpage_da_map_blocks. We don't 2855 * because we look at b_state
2874 * update b_size because if we find an 2856 * in mpage_da_map_blocks. We
2875 * unmapped buffer_head later we need to 2857 * don't update b_size because
2876 * use the b_state flag of that buffer_head. 2858 * if we find an unmapped
2859 * buffer_head later we need to
2860 * use the b_state flag of that
2861 * buffer_head.
2877 */ 2862 */
2878 if (mpd->b_size == 0) 2863 if (mpd->b_size == 0)
2879 mpd->b_state = bh->b_state & BH_FLAGS; 2864 mpd->b_state = bh->b_state & BH_FLAGS;
@@ -2882,14 +2867,10 @@ continue_unlock:
2882 } while ((bh = bh->b_this_page) != head); 2867 } while ((bh = bh->b_this_page) != head);
2883 } 2868 }
2884 2869
2885 ret = 0;
2886
2887 /* END __mpage_da_writepage */
2888
2889 if (nr_to_write > 0) { 2870 if (nr_to_write > 0) {
2890 nr_to_write--; 2871 nr_to_write--;
2891 if (nr_to_write == 0 && 2872 if (nr_to_write == 0 &&
2892 wbc->sync_mode == WB_SYNC_NONE) { 2873 wbc->sync_mode == WB_SYNC_NONE)
2893 /* 2874 /*
2894 * We stop writing back only if we are 2875 * We stop writing back only if we are
2895 * not doing integrity sync. In case of 2876 * not doing integrity sync. In case of
@@ -2900,15 +2881,15 @@ continue_unlock:
2900 * pages, but have not synced all of the 2881 * pages, but have not synced all of the
2901 * old dirty pages. 2882 * old dirty pages.
2902 */ 2883 */
2903 done = 1; 2884 goto out;
2904 break;
2905 }
2906 } 2885 }
2907 } 2886 }
2908 pagevec_release(&pvec); 2887 pagevec_release(&pvec);
2909 cond_resched(); 2888 cond_resched();
2910 } 2889 }
2911 return ret; 2890 return 0;
2891ret_extent_tail:
2892 ret = MPAGE_DA_EXTENT_TAIL;
2912out: 2893out:
2913 pagevec_release(&pvec); 2894 pagevec_release(&pvec);
2914 cond_resched(); 2895 cond_resched();