linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: Clean up filemap_write_and_wait()
@ 2019-11-20  6:23 ira.weiny
  2019-11-20  8:03 ` Nikolay Borisov
  2019-11-20 13:36 ` Matthew Wilcox
  0 siblings, 2 replies; 3+ messages in thread
From: ira.weiny @ 2019-11-20  6:23 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-fsdevel, linux-kernel, linux-mm, Ira Weiny

From: Ira Weiny <ira.weiny@intel.com>

At some point filemap_write_and_wait() and
filemap_write_and_wait_range() got the exact same implementation with
the exception of the range being specified in *_range()

Similar to other functions in fs.h which call
*_range(..., 0, LLONG_MAX), change filemap_write_and_wait() to be a
static inline which calls filemap_write_and_wait_range()

Signed-off-by: Ira Weiny <ira.weiny@intel.com>
---
 include/linux/fs.h |  6 +++++-
 mm/filemap.c       | 34 ++++++----------------------------
 2 files changed, 11 insertions(+), 29 deletions(-)

diff --git a/include/linux/fs.h b/include/linux/fs.h
index 1175815da3df..1007742711e5 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2745,7 +2745,6 @@ static inline int filemap_fdatawait(struct address_space *mapping)
 
 extern bool filemap_range_has_page(struct address_space *, loff_t lstart,
 				  loff_t lend);
-extern int filemap_write_and_wait(struct address_space *mapping);
 extern int filemap_write_and_wait_range(struct address_space *mapping,
 				        loff_t lstart, loff_t lend);
 extern int __filemap_fdatawrite_range(struct address_space *mapping,
@@ -2755,6 +2754,11 @@ extern int filemap_fdatawrite_range(struct address_space *mapping,
 extern int filemap_check_errors(struct address_space *mapping);
 extern void __filemap_set_wb_err(struct address_space *mapping, int err);
 
+static inline int filemap_write_and_wait(struct address_space *mapping)
+{
+	return filemap_write_and_wait_range(mapping, 0, LLONG_MAX);
+}
+
 extern int __must_check file_fdatawait_range(struct file *file, loff_t lstart,
 						loff_t lend);
 extern int __must_check file_check_and_advance_wb_err(struct file *file);
diff --git a/mm/filemap.c b/mm/filemap.c
index 1f5731768222..f4d1a4fb63a6 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -632,33 +632,6 @@ static bool mapping_needs_writeback(struct address_space *mapping)
 	return mapping->nrpages;
 }
 
-int filemap_write_and_wait(struct address_space *mapping)
-{
-	int err = 0;
-
-	if (mapping_needs_writeback(mapping)) {
-		err = filemap_fdatawrite(mapping);
-		/*
-		 * Even if the above returned error, the pages may be
-		 * written partially (e.g. -ENOSPC), so we wait for it.
-		 * But the -EIO is special case, it may indicate the worst
-		 * thing (e.g. bug) happened, so we avoid waiting for it.
-		 */
-		if (err != -EIO) {
-			int err2 = filemap_fdatawait(mapping);
-			if (!err)
-				err = err2;
-		} else {
-			/* Clear any previously stored errors */
-			filemap_check_errors(mapping);
-		}
-	} else {
-		err = filemap_check_errors(mapping);
-	}
-	return err;
-}
-EXPORT_SYMBOL(filemap_write_and_wait);
-
 /**
  * filemap_write_and_wait_range - write out & wait on a file range
  * @mapping:	the address_space for the pages
@@ -680,7 +653,12 @@ int filemap_write_and_wait_range(struct address_space *mapping,
 	if (mapping_needs_writeback(mapping)) {
 		err = __filemap_fdatawrite_range(mapping, lstart, lend,
 						 WB_SYNC_ALL);
-		/* See comment of filemap_write_and_wait() */
+		/*
+		 * Even if the above returned error, the pages may be
+		 * written partially (e.g. -ENOSPC), so we wait for it.
+		 * But the -EIO is special case, it may indicate the worst
+		 * thing (e.g. bug) happened, so we avoid waiting for it.
+		 */
 		if (err != -EIO) {
 			int err2 = filemap_fdatawait_range(mapping,
 						lstart, lend);
-- 
2.21.0



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm: Clean up filemap_write_and_wait()
  2019-11-20  6:23 [PATCH] mm: Clean up filemap_write_and_wait() ira.weiny
@ 2019-11-20  8:03 ` Nikolay Borisov
  2019-11-20 13:36 ` Matthew Wilcox
  1 sibling, 0 replies; 3+ messages in thread
From: Nikolay Borisov @ 2019-11-20  8:03 UTC (permalink / raw)
  To: ira.weiny, Andrew Morton; +Cc: linux-fsdevel, linux-kernel, linux-mm



On 20.11.19 г. 8:23 ч., ira.weiny@intel.com wrote:
> From: Ira Weiny <ira.weiny@intel.com>
> 
> At some point filemap_write_and_wait() and
> filemap_write_and_wait_range() got the exact same implementation with
> the exception of the range being specified in *_range()
> 
> Similar to other functions in fs.h which call
> *_range(..., 0, LLONG_MAX), change filemap_write_and_wait() to be a
> static inline which calls filemap_write_and_wait_range()
> 
> Signed-off-by: Ira Weiny <ira.weiny@intel.com>

Reviewed-by: Nikolay Borisov <nborisov@suse.com>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm: Clean up filemap_write_and_wait()
  2019-11-20  6:23 [PATCH] mm: Clean up filemap_write_and_wait() ira.weiny
  2019-11-20  8:03 ` Nikolay Borisov
@ 2019-11-20 13:36 ` Matthew Wilcox
  1 sibling, 0 replies; 3+ messages in thread
From: Matthew Wilcox @ 2019-11-20 13:36 UTC (permalink / raw)
  To: ira.weiny; +Cc: Andrew Morton, linux-fsdevel, linux-kernel, linux-mm

On Tue, Nov 19, 2019 at 10:23:34PM -0800, ira.weiny@intel.com wrote:
> At some point filemap_write_and_wait() and
> filemap_write_and_wait_range() got the exact same implementation with
> the exception of the range being specified in *_range()
> 
> Similar to other functions in fs.h which call
> *_range(..., 0, LLONG_MAX), change filemap_write_and_wait() to be a
> static inline which calls filemap_write_and_wait_range()
> 
> Signed-off-by: Ira Weiny <ira.weiny@intel.com>

Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-11-20 13:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-20  6:23 [PATCH] mm: Clean up filemap_write_and_wait() ira.weiny
2019-11-20  8:03 ` Nikolay Borisov
2019-11-20 13:36 ` Matthew Wilcox

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).