lkml.org 
[lkml]   [2017]   [Jul]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectRe: [PATCH v2 2/4] mm: add file_fdatawait_range and file_write_and_wait
----- Original Message -----
| From: Jeff Layton <jlayton@redhat.com>
|
| Some filesystem fsync routines will need these.
|
| Signed-off-by: Jeff Layton <jlayton@redhat.com>
| ---
| include/linux/fs.h | 7 ++++++-
| mm/filemap.c | 56
| ++++++++++++++++++++++++++++++++++++++++++++++++++++++
| 2 files changed, 62 insertions(+), 1 deletion(-)
(snip)
| diff --git a/mm/filemap.c b/mm/filemap.c
| index 72e46e6f0d9a..b904a8dfa43d 100644
| --- a/mm/filemap.c
| +++ b/mm/filemap.c
(snip)
| @@ -675,6 +698,39 @@ int file_write_and_wait_range(struct file *file, loff_t
| lstart, loff_t lend)
| EXPORT_SYMBOL(file_write_and_wait_range);
|
| /**
| + * file_write_and_wait - write out whole file and wait on it and return any
| + * writeback errors since we last checked
| + * @file: file to write back and wait on
| + *
| + * Write back the whole file and wait on its mapping. Afterward, check for
| + * errors that may have occurred since our file->f_wb_err cursor was last
| + * updated.
| + */
| +int file_write_and_wait(struct file *file)
| +{
| + int err = 0, err2;
| + struct address_space *mapping = file->f_mapping;
| +
| + if ((!dax_mapping(mapping) && mapping->nrpages) ||
| + (dax_mapping(mapping) && mapping->nrexceptional)) {

Seems like we should make the new function mapping_needs_writeback more
central (mm.h or fs.h?) and call it here ^.

| + err = filemap_fdatawrite(mapping);
| + /* See comment of filemap_write_and_wait() */
| + if (err != -EIO) {
| + loff_t i_size = i_size_read(mapping->host);
| +
| + if (i_size != 0)
| + __filemap_fdatawait_range(mapping, 0,
| + i_size - 1);
| + }
| + }
| + err2 = file_check_and_advance_wb_err(file);
| + if (!err)
| + err = err2;
| + return err;

In the past, I've seen more elegant constructs like:
return (err ? err : err2);
but I don't know what's considered more ugly or hackish.

Regards,

Bob Peterson
Red Hat File Systems
\
 
 \ /
  Last update: 2017-07-26 21:50    [W:0.181 / U:10.548 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site