From: Konstantin Khlebnikov <k.khlebnikov@samsung.com>
To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
Alexander Viro <viro@zeniv.linux.org.uk>
Cc: koct9i@gmail.com
Subject: [PATCH RFC] fs: check and toss errors returned by ->sync_fs
Date: Mon, 17 Nov 2014 20:31:08 +0400 [thread overview]
Message-ID: <20141117173108.30234.59271.stgit@buzz> (raw)
->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);
reply other threads:[~2014-11-17 16:31 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20141117173108.30234.59271.stgit@buzz \
--to=k.khlebnikov@samsung.com \
--cc=koct9i@gmail.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).