linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH RFC] fs: check and toss errors returned by ->sync_fs
@ 2014-11-17 16:31 Konstantin Khlebnikov
  0 siblings, 0 replies; only message in thread
From: Konstantin Khlebnikov @ 2014-11-17 16:31 UTC (permalink / raw)
  To: linux-fsdevel, linux-kernel, Alexander Viro; +Cc: koct9i

->ssync_fs returns int but the result is always ignored silently.
Of course syscall sync is declared as void and it writes multiple
fs thus returning error codes here is impossible and meaningless.
But recently added syscall syncfs writes only one filesystem, it
returns int but only -EBADF is documented for now.

After this patch sync_filesystem() and syscall syncfs returns these
error codes. Also they will skip waiting if somebody returned -EIO,
the same logic is used in filemap_write_and_wait().

Signed-off-by: Konstantin Khlebnikov <k.khlebnikov@samsung.com>
---
 fs/sync.c |   26 +++++++++++++++++++++-----
 1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/fs/sync.c b/fs/sync.c
index bdc729d..e2c3622 100644
--- a/fs/sync.c
+++ b/fs/sync.c
@@ -29,14 +29,21 @@
  */
 static int __sync_filesystem(struct super_block *sb, int wait)
 {
+	int ret = 0, ret2;
+
 	if (wait)
 		sync_inodes_sb(sb);
 	else
 		writeback_inodes_sb(sb, WB_REASON_SYNC);
 
 	if (sb->s_op->sync_fs)
-		sb->s_op->sync_fs(sb, wait);
-	return __sync_blockdev(sb->s_bdev, wait);
+		ret = sb->s_op->sync_fs(sb, wait);
+
+	ret2 = __sync_blockdev(sb->s_bdev, wait);
+	if (!ret)
+		ret = ret2;
+
+	return ret;
 }
 
 /*
@@ -46,7 +53,7 @@ static int __sync_filesystem(struct super_block *sb, int wait)
  */
 int sync_filesystem(struct super_block *sb)
 {
-	int ret;
+	int ret, ret2;
 
 	/*
 	 * We need to be protected against the filesystem going from
@@ -61,9 +68,18 @@ int sync_filesystem(struct super_block *sb)
 		return 0;
 
 	ret = __sync_filesystem(sb, 0);
-	if (ret < 0)
+	/*
+	 * EIO may indicate the worst thing: bug or hardware failure.
+	 * In other cases it's better to wait for partially written data.
+	 */
+	if (ret == -EIO)
 		return ret;
-	return __sync_filesystem(sb, 1);
+
+	ret2 = __sync_filesystem(sb, 1);
+	if (!ret)
+		ret = ret2;
+
+	return ret;
 }
 EXPORT_SYMBOL(sync_filesystem);
 


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2014-11-17 17:31 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-17 16:31 [PATCH RFC] fs: check and toss errors returned by ->sync_fs Konstantin Khlebnikov

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).