[PATCH URGENT 1/2] btrfs-progs: disk-io: Make super block write error more easy to read

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When we failed to write super blocks, we just output something like:
  WARNING: failed to write sb: I/O error
Or
  WARNING: failed to write all sb data

There is no info about which device failed and there are two different
error message for the same write error.

This patch will change it to something more detailed:
ERROR: failed to write super block: I/O error
ERROR: failed to write super block for devid 1

This provides the basis for later super block flush error handling.

Signed-off-by: Qu Wenruo <wqu@xxxxxxxx>
---
 disk-io.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/disk-io.c b/disk-io.c
index 797b9b79ea3c..238b1821be14 100644
--- a/disk-io.c
+++ b/disk-io.c
@@ -1599,8 +1599,12 @@ static int write_dev_supers(struct btrfs_fs_info *fs_info,
 		ret = pwrite64(device->fd, fs_info->super_copy,
 				BTRFS_SUPER_INFO_SIZE,
 				fs_info->super_bytenr);
-		if (ret != BTRFS_SUPER_INFO_SIZE)
+		if (ret != BTRFS_SUPER_INFO_SIZE) {
+			errno = EIO;
+			ret = -errno;
+			error("failed to write super block: %m");
 			goto write_err;
+		}
 		return 0;
 	}
 
@@ -1622,17 +1626,18 @@ static int write_dev_supers(struct btrfs_fs_info *fs_info,
 		 */
 		ret = pwrite64(device->fd, fs_info->super_copy,
 				BTRFS_SUPER_INFO_SIZE, bytenr);
-		if (ret != BTRFS_SUPER_INFO_SIZE)
+		if (ret != BTRFS_SUPER_INFO_SIZE) {
+			errno = EIO;
+			ret = -errno;
+			error("failed to write super block %i: %m", i);
 			goto write_err;
+		}
 	}
 
 	return 0;
 
 write_err:
-	if (ret > 0)
-		fprintf(stderr, "WARNING: failed to write all sb data\n");
-	else
-		fprintf(stderr, "WARNING: failed to write sb: %m\n");
+	error("failed to write super block for devid %llu", device->devid);
 	return ret;
 }
 
-- 
2.21.0




[Index of Archives]     [Linux Filesystem Development]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux