diff mbox series

[URGENT,v1.1,1/2] btrfs-progs: disk-io: Make super block write error easier to read

Message ID 20190327094652.16078-2-wqu@suse.com (mailing list archive)
State New, archived
Headers show
Series btrfs-progs: Fix the nobarrier behavior of write | expand

Commit Message

Qu Wenruo March 27, 2019, 9:46 a.m. UTC
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 for devid 1: write error: I/O error

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

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 disk-io.c | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)

Comments

Nikolay Borisov March 27, 2019, 11:34 a.m. UTC | #1
On 27.03.19 г. 11:46 ч., Qu Wenruo wrote:
> 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 for devid 1: write error: I/O error
> 
> This provides the basis for later super block flush error handling.
> 
> Signed-off-by: Qu Wenruo <wqu@suse.com>

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

> ---
>  disk-io.c | 25 ++++++++++++++-----------
>  1 file changed, 14 insertions(+), 11 deletions(-)
> 
> diff --git a/disk-io.c b/disk-io.c
> index 797b9b79ea3c..f7fb7026cd94 100644
> --- a/disk-io.c
> +++ b/disk-io.c
> @@ -1599,8 +1599,13 @@ 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)
> -			goto write_err;
> +		if (ret != BTRFS_SUPER_INFO_SIZE) {
> +			errno = EIO;
> +			error(
> +		"failed to write super block for devid %llu: write error: %m",
> +				device->devid);
> +			return -EIO;
> +		}
>  		return 0;
>  	}
>  
> @@ -1622,18 +1627,16 @@ 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)
> -			goto write_err;
> +		if (ret != BTRFS_SUPER_INFO_SIZE) {
> +			errno = EIO;
> +			error(
> +		"failed to write super block for devid %llu: write error: %m",
> +				device->devid);
> +			return -errno;
> +		}
>  	}
>  
>  	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");
> -	return ret;
>  }
>  
>  int write_all_supers(struct btrfs_fs_info *fs_info)
>
diff mbox series

Patch

diff --git a/disk-io.c b/disk-io.c
index 797b9b79ea3c..f7fb7026cd94 100644
--- a/disk-io.c
+++ b/disk-io.c
@@ -1599,8 +1599,13 @@  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)
-			goto write_err;
+		if (ret != BTRFS_SUPER_INFO_SIZE) {
+			errno = EIO;
+			error(
+		"failed to write super block for devid %llu: write error: %m",
+				device->devid);
+			return -EIO;
+		}
 		return 0;
 	}
 
@@ -1622,18 +1627,16 @@  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)
-			goto write_err;
+		if (ret != BTRFS_SUPER_INFO_SIZE) {
+			errno = EIO;
+			error(
+		"failed to write super block for devid %llu: write error: %m",
+				device->devid);
+			return -errno;
+		}
 	}
 
 	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");
-	return ret;
 }
 
 int write_all_supers(struct btrfs_fs_info *fs_info)