Commit 9326c9b2 authored by Jeff Layton's avatar Jeff Layton

mm: consolidate dax / non-dax checks for writeback

We have this complex conditional copied to several places. Turn it into
a helper function.
Reviewed-by: default avatarJan Kara <jack@suse.cz>
Signed-off-by: default avatarJeff Layton <jlayton@redhat.com>
parent 80aafd50
...@@ -522,12 +522,17 @@ int filemap_fdatawait(struct address_space *mapping) ...@@ -522,12 +522,17 @@ int filemap_fdatawait(struct address_space *mapping)
} }
EXPORT_SYMBOL(filemap_fdatawait); EXPORT_SYMBOL(filemap_fdatawait);
static bool mapping_needs_writeback(struct address_space *mapping)
{
return (!dax_mapping(mapping) && mapping->nrpages) ||
(dax_mapping(mapping) && mapping->nrexceptional);
}
int filemap_write_and_wait(struct address_space *mapping) int filemap_write_and_wait(struct address_space *mapping)
{ {
int err = 0; int err = 0;
if ((!dax_mapping(mapping) && mapping->nrpages) || if (mapping_needs_writeback(mapping)) {
(dax_mapping(mapping) && mapping->nrexceptional)) {
err = filemap_fdatawrite(mapping); err = filemap_fdatawrite(mapping);
/* /*
* Even if the above returned error, the pages may be * Even if the above returned error, the pages may be
...@@ -566,8 +571,7 @@ int filemap_write_and_wait_range(struct address_space *mapping, ...@@ -566,8 +571,7 @@ int filemap_write_and_wait_range(struct address_space *mapping,
{ {
int err = 0; int err = 0;
if ((!dax_mapping(mapping) && mapping->nrpages) || if (mapping_needs_writeback(mapping)) {
(dax_mapping(mapping) && mapping->nrexceptional)) {
err = __filemap_fdatawrite_range(mapping, lstart, lend, err = __filemap_fdatawrite_range(mapping, lstart, lend,
WB_SYNC_ALL); WB_SYNC_ALL);
/* See comment of filemap_write_and_wait() */ /* See comment of filemap_write_and_wait() */
...@@ -656,8 +660,7 @@ int file_write_and_wait_range(struct file *file, loff_t lstart, loff_t lend) ...@@ -656,8 +660,7 @@ int file_write_and_wait_range(struct file *file, loff_t lstart, loff_t lend)
int err = 0, err2; int err = 0, err2;
struct address_space *mapping = file->f_mapping; struct address_space *mapping = file->f_mapping;
if ((!dax_mapping(mapping) && mapping->nrpages) || if (mapping_needs_writeback(mapping)) {
(dax_mapping(mapping) && mapping->nrexceptional)) {
err = __filemap_fdatawrite_range(mapping, lstart, lend, err = __filemap_fdatawrite_range(mapping, lstart, lend,
WB_SYNC_ALL); WB_SYNC_ALL);
/* See comment of filemap_write_and_wait() */ /* See comment of filemap_write_and_wait() */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment