#include <linux/flex_proportions.h>
#include <linux/backing-dev-defs.h>
#include <linux/blk_types.h>
+#include <linux/pagevec.h>
struct bio;
loff_t range_start;
loff_t range_end;
+ struct folio_batch fbatch;
+ pgoff_t done_index;
+ int err;
+
enum writeback_sync_modes sync_mode;
unsigned for_kupdate:1; /* A kupdate writeback */
unsigned tagged_writepages:1; /* tag-and-write to avoid livelock */
unsigned for_reclaim:1; /* Invoked from the page allocator */
unsigned range_cyclic:1; /* range_start is cyclic */
+ unsigned range_whole:1; /* entire file */
unsigned for_sync:1; /* sync(2) WB_SYNC_ALL writeback */
unsigned unpinned_fscache_wb:1; /* Cleared I_PINNING_FSCACHE_WB */
}
EXPORT_SYMBOL(tag_pages_for_writeback);
+static int writeback_finish(struct address_space *mapping,
+ struct writeback_control *wbc, bool done)
+{
+ folio_batch_release(&wbc->fbatch);
+
+ /*
+ * If we hit the last page and there is more work to be done:
+ * wrap the index back to the start of the file for the next
+ * time we are called.
+ */
+ if (wbc->range_cyclic && !done)
+ wbc->done_index = 0;
+ if (wbc->range_cyclic || (wbc->range_whole && wbc->nr_to_write > 0))
+ mapping->writeback_index = wbc->done_index;
+
+ return wbc->err;
+}
+
/**
* write_cache_pages - walk the list of dirty pages of the given address space and write all of them.
* @mapping: address space structure to write
struct writeback_control *wbc, writepage_t writepage,
void *data)
{
- int ret = 0;
- int done = 0;
int error;
- struct folio_batch fbatch;
int nr_folios;
pgoff_t index;
pgoff_t end; /* Inclusive */
- pgoff_t done_index;
- int range_whole = 0;
xa_mark_t tag;
- folio_batch_init(&fbatch);
if (wbc->range_cyclic) {
index = mapping->writeback_index; /* prev offset */
end = -1;
index = wbc->range_start >> PAGE_SHIFT;
end = wbc->range_end >> PAGE_SHIFT;
if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
- range_whole = 1;
+ wbc->range_whole = 1;
}
if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages) {
tag_pages_for_writeback(mapping, index, end);
} else {
tag = PAGECACHE_TAG_DIRTY;
}
- done_index = index;
- while (!done && (index <= end)) {
+
+ wbc->done_index = index;
+ folio_batch_init(&wbc->fbatch);
+ wbc->err = 0;
+
+ while (index <= end) {
int i;
nr_folios = filemap_get_folios_tag(mapping, &index, end,
- tag, &fbatch);
+ tag, &wbc->fbatch);
if (nr_folios == 0)
break;
for (i = 0; i < nr_folios; i++) {
- struct folio *folio = fbatch.folios[i];
+ struct folio *folio = wbc->fbatch.folios[i];
unsigned long nr;
- done_index = folio->index;
+ wbc->done_index = folio->index;
folio_lock(folio);
folio_unlock(folio);
error = 0;
} else if (wbc->sync_mode != WB_SYNC_ALL) {
- ret = error;
- done_index = folio->index + nr;
- done = 1;
- break;
+ wbc->err = error;
+ wbc->done_index = folio->index + nr;
+ return writeback_finish(mapping,
+ wbc, true);
}
- if (!ret)
- ret = error;
+ if (!wbc->err)
+ wbc->err = error;
}
/*
*/
wbc->nr_to_write -= nr;
if (wbc->nr_to_write <= 0 &&
- wbc->sync_mode == WB_SYNC_NONE) {
- done = 1;
- break;
- }
+ wbc->sync_mode == WB_SYNC_NONE)
+ return writeback_finish(mapping, wbc, true);
}
- folio_batch_release(&fbatch);
+ folio_batch_release(&wbc->fbatch);
cond_resched();
}
- /*
- * If we hit the last page and there is more work to be done: wrap
- * back the index back to the start of the file for the next
- * time we are called.
- */
- if (wbc->range_cyclic && !done)
- done_index = 0;
- if (wbc->range_cyclic || (range_whole && wbc->nr_to_write > 0))
- mapping->writeback_index = done_index;
-
- return ret;
+ return writeback_finish(mapping, wbc, false);
}
EXPORT_SYMBOL(write_cache_pages);