Skip to contentSkip to conversation

fs: check and toss errors returned by ->sync_fs

RFC PATCH New Konstantin Khlebnikov 1 participant 1 message Nov 17, 2014 VFS

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 fs: check and toss errors returned by ->sync_fs

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

---
 fs/sync.c |   26 +++++++++++++++++++++-----
 1 file changed, 21 insertions(+), 5 deletions(-)
fs/sync.c +21 -5
index bdc729d..e2c3622 100644
@@ -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);