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>
This commit is contained in:
105
fs/ext4/inode.c
105
fs/ext4/inode.c
@@ -2723,17 +2723,14 @@ static int write_cache_pages_da(struct address_space *mapping,
|
|||||||
struct mpage_da_data *mpd,
|
struct mpage_da_data *mpd,
|
||||||
pgoff_t *done_index)
|
pgoff_t *done_index)
|
||||||
{
|
{
|
||||||
struct inode *inode = mpd->inode;
|
|
||||||
struct buffer_head *bh, *head;
|
struct buffer_head *bh, *head;
|
||||||
sector_t logical;
|
struct inode *inode = mpd->inode;
|
||||||
int ret = 0;
|
|
||||||
int done = 0;
|
|
||||||
struct pagevec pvec;
|
struct pagevec pvec;
|
||||||
unsigned nr_pages;
|
unsigned int nr_pages;
|
||||||
pgoff_t index;
|
sector_t logical;
|
||||||
pgoff_t end; /* Inclusive */
|
pgoff_t index, end;
|
||||||
long nr_to_write = wbc->nr_to_write;
|
long nr_to_write = wbc->nr_to_write;
|
||||||
int tag;
|
int i, tag, ret = 0;
|
||||||
|
|
||||||
pagevec_init(&pvec, 0);
|
pagevec_init(&pvec, 0);
|
||||||
index = wbc->range_start >> PAGE_CACHE_SHIFT;
|
index = wbc->range_start >> PAGE_CACHE_SHIFT;
|
||||||
@@ -2745,13 +2742,11 @@ static int write_cache_pages_da(struct address_space *mapping,
|
|||||||
tag = PAGECACHE_TAG_DIRTY;
|
tag = PAGECACHE_TAG_DIRTY;
|
||||||
|
|
||||||
*done_index = index;
|
*done_index = index;
|
||||||
while (!done && (index <= end)) {
|
while (index <= end) {
|
||||||
int i;
|
|
||||||
|
|
||||||
nr_pages = pagevec_lookup_tag(&pvec, mapping, &index, tag,
|
nr_pages = pagevec_lookup_tag(&pvec, mapping, &index, tag,
|
||||||
min(end - index, (pgoff_t)PAGEVEC_SIZE-1) + 1);
|
min(end - index, (pgoff_t)PAGEVEC_SIZE-1) + 1);
|
||||||
if (nr_pages == 0)
|
if (nr_pages == 0)
|
||||||
break;
|
return 0;
|
||||||
|
|
||||||
for (i = 0; i < nr_pages; i++) {
|
for (i = 0; i < nr_pages; i++) {
|
||||||
struct page *page = pvec.pages[i];
|
struct page *page = pvec.pages[i];
|
||||||
@@ -2763,47 +2758,37 @@ static int write_cache_pages_da(struct address_space *mapping,
|
|||||||
* mapping. However, page->index will not change
|
* mapping. However, page->index will not change
|
||||||
* because we have a reference on the page.
|
* because we have a reference on the page.
|
||||||
*/
|
*/
|
||||||
if (page->index > end) {
|
if (page->index > end)
|
||||||
done = 1;
|
goto out;
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
*done_index = page->index + 1;
|
*done_index = page->index + 1;
|
||||||
|
|
||||||
lock_page(page);
|
lock_page(page);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Page truncated or invalidated. We can freely skip it
|
* If the page is no longer dirty, or its
|
||||||
* then, even for data integrity operations: the page
|
* mapping no longer corresponds to inode we
|
||||||
* has disappeared concurrently, so there could be no
|
* are writing (which means it has been
|
||||||
* real expectation of this data interity operation
|
* truncated or invalidated), or the page is
|
||||||
* even if there is now a new, dirty page at the same
|
* already under writeback and we are not
|
||||||
* pagecache address.
|
* doing a data integrity writeback, skip the page
|
||||||
*/
|
*/
|
||||||
if (unlikely(page->mapping != mapping)) {
|
if (!PageDirty(page) ||
|
||||||
|
(PageWriteback(page) &&
|
||||||
|
(wbc->sync_mode == WB_SYNC_NONE)) ||
|
||||||
|
unlikely(page->mapping != mapping)) {
|
||||||
continue_unlock:
|
continue_unlock:
|
||||||
unlock_page(page);
|
unlock_page(page);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!PageDirty(page)) {
|
if (PageWriteback(page))
|
||||||
/* someone wrote it for us */
|
|
||||||
goto continue_unlock;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (PageWriteback(page)) {
|
|
||||||
if (wbc->sync_mode != WB_SYNC_NONE)
|
|
||||||
wait_on_page_writeback(page);
|
wait_on_page_writeback(page);
|
||||||
else
|
|
||||||
goto continue_unlock;
|
|
||||||
}
|
|
||||||
|
|
||||||
BUG_ON(PageWriteback(page));
|
BUG_ON(PageWriteback(page));
|
||||||
if (!clear_page_dirty_for_io(page))
|
if (!clear_page_dirty_for_io(page))
|
||||||
goto continue_unlock;
|
goto continue_unlock;
|
||||||
|
|
||||||
/* BEGIN __mpage_da_writepage */
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Can we merge this page to current extent?
|
* Can we merge this page to current extent?
|
||||||
*/
|
*/
|
||||||
@@ -2820,8 +2805,7 @@ continue_unlock:
|
|||||||
*/
|
*/
|
||||||
redirty_page_for_writepage(wbc, page);
|
redirty_page_for_writepage(wbc, page);
|
||||||
unlock_page(page);
|
unlock_page(page);
|
||||||
ret = MPAGE_DA_EXTENT_TAIL;
|
goto ret_extent_tail;
|
||||||
goto out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -2838,15 +2822,15 @@ continue_unlock:
|
|||||||
(PAGE_CACHE_SHIFT - inode->i_blkbits);
|
(PAGE_CACHE_SHIFT - inode->i_blkbits);
|
||||||
|
|
||||||
if (!page_has_buffers(page)) {
|
if (!page_has_buffers(page)) {
|
||||||
mpage_add_bh_to_extent(mpd, logical, PAGE_CACHE_SIZE,
|
mpage_add_bh_to_extent(mpd, logical,
|
||||||
|
PAGE_CACHE_SIZE,
|
||||||
(1 << BH_Dirty) | (1 << BH_Uptodate));
|
(1 << BH_Dirty) | (1 << BH_Uptodate));
|
||||||
if (mpd->io_done) {
|
if (mpd->io_done)
|
||||||
ret = MPAGE_DA_EXTENT_TAIL;
|
goto ret_extent_tail;
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
/*
|
/*
|
||||||
* Page with regular buffer heads, just add all dirty ones
|
* Page with regular buffer heads,
|
||||||
|
* just add all dirty ones
|
||||||
*/
|
*/
|
||||||
head = page_buffers(page);
|
head = page_buffers(page);
|
||||||
bh = head;
|
bh = head;
|
||||||
@@ -2862,18 +2846,19 @@ continue_unlock:
|
|||||||
mpage_add_bh_to_extent(mpd, logical,
|
mpage_add_bh_to_extent(mpd, logical,
|
||||||
bh->b_size,
|
bh->b_size,
|
||||||
bh->b_state);
|
bh->b_state);
|
||||||
if (mpd->io_done) {
|
if (mpd->io_done)
|
||||||
ret = MPAGE_DA_EXTENT_TAIL;
|
goto ret_extent_tail;
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
} else if (buffer_dirty(bh) && (buffer_mapped(bh))) {
|
} else if (buffer_dirty(bh) && (buffer_mapped(bh))) {
|
||||||
/*
|
/*
|
||||||
* mapped dirty buffer. We need to update
|
* mapped dirty buffer. We need
|
||||||
* the b_state because we look at
|
* to update the b_state
|
||||||
* b_state in mpage_da_map_blocks. We don't
|
* because we look at b_state
|
||||||
* update b_size because if we find an
|
* in mpage_da_map_blocks. We
|
||||||
* unmapped buffer_head later we need to
|
* don't update b_size because
|
||||||
* use the b_state flag of that buffer_head.
|
* if we find an unmapped
|
||||||
|
* buffer_head later we need to
|
||||||
|
* use the b_state flag of that
|
||||||
|
* buffer_head.
|
||||||
*/
|
*/
|
||||||
if (mpd->b_size == 0)
|
if (mpd->b_size == 0)
|
||||||
mpd->b_state = bh->b_state & BH_FLAGS;
|
mpd->b_state = bh->b_state & BH_FLAGS;
|
||||||
@@ -2882,14 +2867,10 @@ continue_unlock:
|
|||||||
} while ((bh = bh->b_this_page) != head);
|
} while ((bh = bh->b_this_page) != head);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = 0;
|
|
||||||
|
|
||||||
/* END __mpage_da_writepage */
|
|
||||||
|
|
||||||
if (nr_to_write > 0) {
|
if (nr_to_write > 0) {
|
||||||
nr_to_write--;
|
nr_to_write--;
|
||||||
if (nr_to_write == 0 &&
|
if (nr_to_write == 0 &&
|
||||||
wbc->sync_mode == WB_SYNC_NONE) {
|
wbc->sync_mode == WB_SYNC_NONE)
|
||||||
/*
|
/*
|
||||||
* We stop writing back only if we are
|
* We stop writing back only if we are
|
||||||
* not doing integrity sync. In case of
|
* not doing integrity sync. In case of
|
||||||
@@ -2900,15 +2881,15 @@ continue_unlock:
|
|||||||
* pages, but have not synced all of the
|
* pages, but have not synced all of the
|
||||||
* old dirty pages.
|
* old dirty pages.
|
||||||
*/
|
*/
|
||||||
done = 1;
|
goto out;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pagevec_release(&pvec);
|
pagevec_release(&pvec);
|
||||||
cond_resched();
|
cond_resched();
|
||||||
}
|
}
|
||||||
return ret;
|
return 0;
|
||||||
|
ret_extent_tail:
|
||||||
|
ret = MPAGE_DA_EXTENT_TAIL;
|
||||||
out:
|
out:
|
||||||
pagevec_release(&pvec);
|
pagevec_release(&pvec);
|
||||||
cond_resched();
|
cond_resched();
|
||||||
|
Reference in New Issue
Block a user