All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] btrfs-progs: report I/O errors when closing the filesystem
@ 2017-03-03 16:59 Omar Sandoval
  2017-03-03 17:02 ` [PATCH v2] " Omar Sandoval
  2017-03-06  0:40 ` [PATCH] " Qu Wenruo
  0 siblings, 2 replies; 5+ messages in thread
From: Omar Sandoval @ 2017-03-03 16:59 UTC (permalink / raw)
  To: linux-btrfs, David Sterba; +Cc: kernel-team

From: Omar Sandoval <osandov@fb.com>

If the final fsync() on the Btrfs device fails, we just swallow the
error and don't alert the user in any way. This was uncovered by xfstest
generic/405, which checks that mkfs fails when it encounters EIO.

Signed-off-by: Omar Sandoval <osandov@fb.com>
---
 disk-io.c | 4 ++--
 volumes.c | 9 +++++++--
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/disk-io.c b/disk-io.c
index 2a94d4fc..48fb3c6b 100644
--- a/disk-io.c
+++ b/disk-io.c
@@ -1817,10 +1817,10 @@ int close_ctree_fs_info(struct btrfs_fs_info *fs_info)
 	free_fs_roots_tree(&fs_info->fs_root_tree);
 
 	btrfs_release_all_roots(fs_info);
-	btrfs_close_devices(fs_info->fs_devices);
+	ret = btrfs_close_devices(fs_info->fs_devices);
 	btrfs_cleanup_all_caches(fs_info);
 	btrfs_free_fs_info(fs_info);
-	return 0;
+	return ret;
 }
 
 int clean_tree_block(struct btrfs_trans_handle *trans, struct btrfs_root *root,
diff --git a/volumes.c b/volumes.c
index a0a85edd..89335d35 100644
--- a/volumes.c
+++ b/volumes.c
@@ -160,6 +160,7 @@ int btrfs_close_devices(struct btrfs_fs_devices *fs_devices)
 {
 	struct btrfs_fs_devices *seed_devices;
 	struct btrfs_device *device;
+	int ret = 0;
 
 again:
 	if (!fs_devices)
@@ -168,7 +169,11 @@ again:
 		device = list_entry(fs_devices->devices.next,
 				    struct btrfs_device, dev_list);
 		if (device->fd != -1) {
-			fsync(device->fd);
+			if (fsync(device->fd) == -1) {
+				warning("fsync on device %llu failed: %s",
+					device->devid, strerror(errno));
+				ret = -1;
+			}
 			if (posix_fadvise(device->fd, 0, 0, POSIX_FADV_DONTNEED))
 				fprintf(stderr, "Warning, could not drop caches\n");
 			close(device->fd);
@@ -197,7 +202,7 @@ again:
 		free(fs_devices);
 	}
 
-	return 0;
+	return ret;
 }
 
 void btrfs_close_all_devices(void)
-- 
2.12.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2] btrfs-progs: report I/O errors when closing the filesystem
  2017-03-03 16:59 [PATCH] btrfs-progs: report I/O errors when closing the filesystem Omar Sandoval
@ 2017-03-03 17:02 ` Omar Sandoval
  2017-03-06  0:42   ` Qu Wenruo
  2017-03-06  0:40 ` [PATCH] " Qu Wenruo
  1 sibling, 1 reply; 5+ messages in thread
From: Omar Sandoval @ 2017-03-03 17:02 UTC (permalink / raw)
  To: linux-btrfs, David Sterba; +Cc: kernel-team

From: Omar Sandoval <osandov@fb.com>

If the final fsync() on the Btrfs device fails, we just swallow the
error and don't alert the user in any way. This was uncovered by xfstest
generic/405, which checks that mkfs fails when it encounters EIO.

Signed-off-by: Omar Sandoval <osandov@fb.com>
---
Changes from v1: return -errno instead of -1

 disk-io.c | 4 ++--
 volumes.c | 9 +++++++--
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/disk-io.c b/disk-io.c
index 2a94d4fc..48fb3c6b 100644
--- a/disk-io.c
+++ b/disk-io.c
@@ -1817,10 +1817,10 @@ int close_ctree_fs_info(struct btrfs_fs_info *fs_info)
 	free_fs_roots_tree(&fs_info->fs_root_tree);
 
 	btrfs_release_all_roots(fs_info);
-	btrfs_close_devices(fs_info->fs_devices);
+	ret = btrfs_close_devices(fs_info->fs_devices);
 	btrfs_cleanup_all_caches(fs_info);
 	btrfs_free_fs_info(fs_info);
-	return 0;
+	return ret;
 }
 
 int clean_tree_block(struct btrfs_trans_handle *trans, struct btrfs_root *root,
diff --git a/volumes.c b/volumes.c
index a0a85edd..f7d82d51 100644
--- a/volumes.c
+++ b/volumes.c
@@ -160,6 +160,7 @@ int btrfs_close_devices(struct btrfs_fs_devices *fs_devices)
 {
 	struct btrfs_fs_devices *seed_devices;
 	struct btrfs_device *device;
+	int ret = 0;
 
 again:
 	if (!fs_devices)
@@ -168,7 +169,11 @@ again:
 		device = list_entry(fs_devices->devices.next,
 				    struct btrfs_device, dev_list);
 		if (device->fd != -1) {
-			fsync(device->fd);
+			if (fsync(device->fd) == -1) {
+				warning("fsync on device %llu failed: %s",
+					device->devid, strerror(errno));
+				ret = -errno;
+			}
 			if (posix_fadvise(device->fd, 0, 0, POSIX_FADV_DONTNEED))
 				fprintf(stderr, "Warning, could not drop caches\n");
 			close(device->fd);
@@ -197,7 +202,7 @@ again:
 		free(fs_devices);
 	}
 
-	return 0;
+	return ret;
 }
 
 void btrfs_close_all_devices(void)
-- 
2.12.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] btrfs-progs: report I/O errors when closing the filesystem
  2017-03-03 16:59 [PATCH] btrfs-progs: report I/O errors when closing the filesystem Omar Sandoval
  2017-03-03 17:02 ` [PATCH v2] " Omar Sandoval
@ 2017-03-06  0:40 ` Qu Wenruo
  1 sibling, 0 replies; 5+ messages in thread
From: Qu Wenruo @ 2017-03-06  0:40 UTC (permalink / raw)
  To: Omar Sandoval, linux-btrfs, David Sterba; +Cc: kernel-team



At 03/04/2017 12:59 AM, Omar Sandoval wrote:
> From: Omar Sandoval <osandov@fb.com>
>
> If the final fsync() on the Btrfs device fails, we just swallow the
> error and don't alert the user in any way. This was uncovered by xfstest
> generic/405, which checks that mkfs fails when it encounters EIO.
>
> Signed-off-by: Omar Sandoval <osandov@fb.com>
> ---
>  disk-io.c | 4 ++--
>  volumes.c | 9 +++++++--
>  2 files changed, 9 insertions(+), 4 deletions(-)
>
> diff --git a/disk-io.c b/disk-io.c
> index 2a94d4fc..48fb3c6b 100644
> --- a/disk-io.c
> +++ b/disk-io.c
> @@ -1817,10 +1817,10 @@ int close_ctree_fs_info(struct btrfs_fs_info *fs_info)
>  	free_fs_roots_tree(&fs_info->fs_root_tree);
>
>  	btrfs_release_all_roots(fs_info);
> -	btrfs_close_devices(fs_info->fs_devices);
> +	ret = btrfs_close_devices(fs_info->fs_devices);
>  	btrfs_cleanup_all_caches(fs_info);
>  	btrfs_free_fs_info(fs_info);
> -	return 0;
> +	return ret;
>  }
>
>  int clean_tree_block(struct btrfs_trans_handle *trans, struct btrfs_root *root,
> diff --git a/volumes.c b/volumes.c
> index a0a85edd..89335d35 100644
> --- a/volumes.c
> +++ b/volumes.c
> @@ -160,6 +160,7 @@ int btrfs_close_devices(struct btrfs_fs_devices *fs_devices)
>  {
>  	struct btrfs_fs_devices *seed_devices;
>  	struct btrfs_device *device;
> +	int ret = 0;
>
>  again:
>  	if (!fs_devices)
> @@ -168,7 +169,11 @@ again:
>  		device = list_entry(fs_devices->devices.next,
>  				    struct btrfs_device, dev_list);
>  		if (device->fd != -1) {
> -			fsync(device->fd);
> +			if (fsync(device->fd) == -1) {
> +				warning("fsync on device %llu failed: %s",
> +					device->devid, strerror(errno));
> +				ret = -1;

-1 is -EINVAL, better using -errno here.

Despite of that, looks good.

Thanks,
Qu
> +			}
>  			if (posix_fadvise(device->fd, 0, 0, POSIX_FADV_DONTNEED))
>  				fprintf(stderr, "Warning, could not drop caches\n");
>  			close(device->fd);
> @@ -197,7 +202,7 @@ again:
>  		free(fs_devices);
>  	}
>
> -	return 0;
> +	return ret;
>  }
>
>  void btrfs_close_all_devices(void)
>



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] btrfs-progs: report I/O errors when closing the filesystem
  2017-03-03 17:02 ` [PATCH v2] " Omar Sandoval
@ 2017-03-06  0:42   ` Qu Wenruo
  2017-03-08 12:18     ` David Sterba
  0 siblings, 1 reply; 5+ messages in thread
From: Qu Wenruo @ 2017-03-06  0:42 UTC (permalink / raw)
  To: Omar Sandoval, linux-btrfs, David Sterba; +Cc: kernel-team



At 03/04/2017 01:02 AM, Omar Sandoval wrote:
> From: Omar Sandoval <osandov@fb.com>
>
> If the final fsync() on the Btrfs device fails, we just swallow the
> error and don't alert the user in any way. This was uncovered by xfstest
> generic/405, which checks that mkfs fails when it encounters EIO.
>
> Signed-off-by: Omar Sandoval <osandov@fb.com>

Please ignore my comment on v1 patch, didn't see the v2 one.

Looks good to me.

Reviewed-by: Qu Wenruo <quwenruo@cn.fujitsu.com>

Thanks,
Qu
> ---
> Changes from v1: return -errno instead of -1
>
>  disk-io.c | 4 ++--
>  volumes.c | 9 +++++++--
>  2 files changed, 9 insertions(+), 4 deletions(-)
>
> diff --git a/disk-io.c b/disk-io.c
> index 2a94d4fc..48fb3c6b 100644
> --- a/disk-io.c
> +++ b/disk-io.c
> @@ -1817,10 +1817,10 @@ int close_ctree_fs_info(struct btrfs_fs_info *fs_info)
>  	free_fs_roots_tree(&fs_info->fs_root_tree);
>
>  	btrfs_release_all_roots(fs_info);
> -	btrfs_close_devices(fs_info->fs_devices);
> +	ret = btrfs_close_devices(fs_info->fs_devices);
>  	btrfs_cleanup_all_caches(fs_info);
>  	btrfs_free_fs_info(fs_info);
> -	return 0;
> +	return ret;
>  }
>
>  int clean_tree_block(struct btrfs_trans_handle *trans, struct btrfs_root *root,
> diff --git a/volumes.c b/volumes.c
> index a0a85edd..f7d82d51 100644
> --- a/volumes.c
> +++ b/volumes.c
> @@ -160,6 +160,7 @@ int btrfs_close_devices(struct btrfs_fs_devices *fs_devices)
>  {
>  	struct btrfs_fs_devices *seed_devices;
>  	struct btrfs_device *device;
> +	int ret = 0;
>
>  again:
>  	if (!fs_devices)
> @@ -168,7 +169,11 @@ again:
>  		device = list_entry(fs_devices->devices.next,
>  				    struct btrfs_device, dev_list);
>  		if (device->fd != -1) {
> -			fsync(device->fd);
> +			if (fsync(device->fd) == -1) {
> +				warning("fsync on device %llu failed: %s",
> +					device->devid, strerror(errno));
> +				ret = -errno;
> +			}
>  			if (posix_fadvise(device->fd, 0, 0, POSIX_FADV_DONTNEED))
>  				fprintf(stderr, "Warning, could not drop caches\n");
>  			close(device->fd);
> @@ -197,7 +202,7 @@ again:
>  		free(fs_devices);
>  	}
>
> -	return 0;
> +	return ret;
>  }
>
>  void btrfs_close_all_devices(void)
>



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] btrfs-progs: report I/O errors when closing the filesystem
  2017-03-06  0:42   ` Qu Wenruo
@ 2017-03-08 12:18     ` David Sterba
  0 siblings, 0 replies; 5+ messages in thread
From: David Sterba @ 2017-03-08 12:18 UTC (permalink / raw)
  To: Qu Wenruo; +Cc: Omar Sandoval, linux-btrfs, David Sterba, kernel-team

On Mon, Mar 06, 2017 at 08:42:01AM +0800, Qu Wenruo wrote:
> 
> 
> At 03/04/2017 01:02 AM, Omar Sandoval wrote:
> > From: Omar Sandoval <osandov@fb.com>
> >
> > If the final fsync() on the Btrfs device fails, we just swallow the
> > error and don't alert the user in any way. This was uncovered by xfstest
> > generic/405, which checks that mkfs fails when it encounters EIO.
> >
> > Signed-off-by: Omar Sandoval <osandov@fb.com>
> 
> Please ignore my comment on v1 patch, didn't see the v2 one.
> 
> Looks good to me.
> 
> Reviewed-by: Qu Wenruo <quwenruo@cn.fujitsu.com>

Applied, thanks.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-03-08 12:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-03 16:59 [PATCH] btrfs-progs: report I/O errors when closing the filesystem Omar Sandoval
2017-03-03 17:02 ` [PATCH v2] " Omar Sandoval
2017-03-06  0:42   ` Qu Wenruo
2017-03-08 12:18     ` David Sterba
2017-03-06  0:40 ` [PATCH] " Qu Wenruo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.