linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] btrfs: handle failures of set_extent_bits in add_excluded_extent
@ 2018-05-22  9:46 Gu Jinxiang
  2018-05-22  9:46 ` [PATCH 2/2] btrfs: propagate failures of __exclude_logged_extent to upper caller Gu Jinxiang
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Gu Jinxiang @ 2018-05-22  9:46 UTC (permalink / raw)
  To: linux-btrfs; +Cc: nborisov

set_extent_bits may return 0/-EEXIST, so return the result in
add_excluded_extent.

Signed-off-by: Gu Jinxiang <gujx@cn.fujitsu.com>
---
 fs/btrfs/extent-tree.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 75cfb80d2551..2e85e99b5e6f 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -215,11 +215,16 @@ static int add_excluded_extent(struct btrfs_fs_info *fs_info,
 			       u64 start, u64 num_bytes)
 {
 	u64 end = start + num_bytes - 1;
-	set_extent_bits(&fs_info->freed_extents[0],
+	int ret = 0;
+
+	ret = set_extent_bits(&fs_info->freed_extents[0],
 			start, end, EXTENT_UPTODATE);
-	set_extent_bits(&fs_info->freed_extents[1],
+	if (ret)
+		goto out;
+	ret = set_extent_bits(&fs_info->freed_extents[1],
 			start, end, EXTENT_UPTODATE);
-	return 0;
+out:
+	return ret;
 }
 
 static void free_excluded_extents(struct btrfs_fs_info *fs_info,
-- 
1.9.1




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

* [PATCH 2/2] btrfs: propagate failures of __exclude_logged_extent to upper caller
  2018-05-22  9:46 [PATCH 1/2] btrfs: handle failures of set_extent_bits in add_excluded_extent Gu Jinxiang
@ 2018-05-22  9:46 ` Gu Jinxiang
  2018-05-22 10:51   ` Nikolay Borisov
  2018-05-22 16:03   ` David Sterba
  2018-05-22 10:51 ` [PATCH 1/2] btrfs: handle failures of set_extent_bits in add_excluded_extent Nikolay Borisov
  2018-05-22 15:56 ` David Sterba
  2 siblings, 2 replies; 6+ messages in thread
From: Gu Jinxiang @ 2018-05-22  9:46 UTC (permalink / raw)
  To: linux-btrfs; +Cc: nborisov

Function btrfs_exclude_logged_extents may call __exclude_logged_extent
which may fail.
Propagate the failures of __exclude_logged_extent to upper caller.

Signed-off-by: Gu Jinxiang <gujx@cn.fujitsu.com>
---
 fs/btrfs/extent-tree.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 2e85e99b5e6f..28fd71579141 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -6468,6 +6468,7 @@ int btrfs_exclude_logged_extents(struct btrfs_fs_info *fs_info,
 	struct btrfs_key key;
 	int found_type;
 	int i;
+	int ret = 0;
 
 	if (!btrfs_fs_incompat(fs_info, MIXED_GROUPS))
 		return 0;
@@ -6484,10 +6485,14 @@ int btrfs_exclude_logged_extents(struct btrfs_fs_info *fs_info,
 			continue;
 		key.objectid = btrfs_file_extent_disk_bytenr(eb, item);
 		key.offset = btrfs_file_extent_disk_num_bytes(eb, item);
-		__exclude_logged_extent(fs_info, key.objectid, key.offset);
+		ret = __exclude_logged_extent(fs_info, key.objectid,
+				key.offset);
+		if (ret)
+			goto out;
 	}
 
-	return 0;
+out:
+	return ret;
 }
 
 static void
-- 
1.9.1




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

* Re: [PATCH 1/2] btrfs: handle failures of set_extent_bits in add_excluded_extent
  2018-05-22  9:46 [PATCH 1/2] btrfs: handle failures of set_extent_bits in add_excluded_extent Gu Jinxiang
  2018-05-22  9:46 ` [PATCH 2/2] btrfs: propagate failures of __exclude_logged_extent to upper caller Gu Jinxiang
@ 2018-05-22 10:51 ` Nikolay Borisov
  2018-05-22 15:56 ` David Sterba
  2 siblings, 0 replies; 6+ messages in thread
From: Nikolay Borisov @ 2018-05-22 10:51 UTC (permalink / raw)
  To: Gu Jinxiang, linux-btrfs



On 22.05.2018 12:46, Gu Jinxiang wrote:
> set_extent_bits may return 0/-EEXIST, so return the result in
> add_excluded_extent.
> 
> Signed-off-by: Gu Jinxiang <gujx@cn.fujitsu.com>

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

> ---
>  fs/btrfs/extent-tree.c | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
> index 75cfb80d2551..2e85e99b5e6f 100644
> --- a/fs/btrfs/extent-tree.c
> +++ b/fs/btrfs/extent-tree.c
> @@ -215,11 +215,16 @@ static int add_excluded_extent(struct btrfs_fs_info *fs_info,
>  			       u64 start, u64 num_bytes)
>  {
>  	u64 end = start + num_bytes - 1;
> -	set_extent_bits(&fs_info->freed_extents[0],
> +	int ret = 0;
> +
> +	ret = set_extent_bits(&fs_info->freed_extents[0],
>  			start, end, EXTENT_UPTODATE);
> -	set_extent_bits(&fs_info->freed_extents[1],
> +	if (ret)
> +		goto out;
> +	ret = set_extent_bits(&fs_info->freed_extents[1],
>  			start, end, EXTENT_UPTODATE);
> -	return 0;
> +out:
> +	return ret;
>  }
>  
>  static void free_excluded_extents(struct btrfs_fs_info *fs_info,
> 

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

* Re: [PATCH 2/2] btrfs: propagate failures of __exclude_logged_extent to upper caller
  2018-05-22  9:46 ` [PATCH 2/2] btrfs: propagate failures of __exclude_logged_extent to upper caller Gu Jinxiang
@ 2018-05-22 10:51   ` Nikolay Borisov
  2018-05-22 16:03   ` David Sterba
  1 sibling, 0 replies; 6+ messages in thread
From: Nikolay Borisov @ 2018-05-22 10:51 UTC (permalink / raw)
  To: Gu Jinxiang, linux-btrfs



On 22.05.2018 12:46, Gu Jinxiang wrote:
> Function btrfs_exclude_logged_extents may call __exclude_logged_extent
> which may fail.
> Propagate the failures of __exclude_logged_extent to upper caller.
> 
> Signed-off-by: Gu Jinxiang <gujx@cn.fujitsu.com>

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

> ---
>  fs/btrfs/extent-tree.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
> index 2e85e99b5e6f..28fd71579141 100644
> --- a/fs/btrfs/extent-tree.c
> +++ b/fs/btrfs/extent-tree.c
> @@ -6468,6 +6468,7 @@ int btrfs_exclude_logged_extents(struct btrfs_fs_info *fs_info,
>  	struct btrfs_key key;
>  	int found_type;
>  	int i;
> +	int ret = 0;
>  
>  	if (!btrfs_fs_incompat(fs_info, MIXED_GROUPS))
>  		return 0;
> @@ -6484,10 +6485,14 @@ int btrfs_exclude_logged_extents(struct btrfs_fs_info *fs_info,
>  			continue;
>  		key.objectid = btrfs_file_extent_disk_bytenr(eb, item);
>  		key.offset = btrfs_file_extent_disk_num_bytes(eb, item);
> -		__exclude_logged_extent(fs_info, key.objectid, key.offset);
> +		ret = __exclude_logged_extent(fs_info, key.objectid,
> +				key.offset);
> +		if (ret)
> +			goto out;
>  	}
>  
> -	return 0;
> +out:
> +	return ret;
>  }
>  
>  static void
> 

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

* Re: [PATCH 1/2] btrfs: handle failures of set_extent_bits in add_excluded_extent
  2018-05-22  9:46 [PATCH 1/2] btrfs: handle failures of set_extent_bits in add_excluded_extent Gu Jinxiang
  2018-05-22  9:46 ` [PATCH 2/2] btrfs: propagate failures of __exclude_logged_extent to upper caller Gu Jinxiang
  2018-05-22 10:51 ` [PATCH 1/2] btrfs: handle failures of set_extent_bits in add_excluded_extent Nikolay Borisov
@ 2018-05-22 15:56 ` David Sterba
  2 siblings, 0 replies; 6+ messages in thread
From: David Sterba @ 2018-05-22 15:56 UTC (permalink / raw)
  To: Gu Jinxiang; +Cc: linux-btrfs, nborisov

On Tue, May 22, 2018 at 05:46:50PM +0800, Gu Jinxiang wrote:
> set_extent_bits may return 0/-EEXIST, so return the result in
> add_excluded_extent.

This is misleading, set_extent_bits can return anything that gets
propagated from the callees, which is 0 and -EEXIST for now but will be
also -ENOMEM eventually. And some callers expect values >= 0 (eg. in
btrfs_get_io_failure_record) , but I haven't examined if this can really
happen.

> Signed-off-by: Gu Jinxiang <gujx@cn.fujitsu.com>
> ---
>  fs/btrfs/extent-tree.c | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
> index 75cfb80d2551..2e85e99b5e6f 100644
> --- a/fs/btrfs/extent-tree.c
> +++ b/fs/btrfs/extent-tree.c
> @@ -215,11 +215,16 @@ static int add_excluded_extent(struct btrfs_fs_info *fs_info,
>  			       u64 start, u64 num_bytes)
>  {
>  	u64 end = start + num_bytes - 1;
> -	set_extent_bits(&fs_info->freed_extents[0],
> +	int ret = 0;
> +
> +	ret = set_extent_bits(&fs_info->freed_extents[0],
>  			start, end, EXTENT_UPTODATE);
> -	set_extent_bits(&fs_info->freed_extents[1],
> +	if (ret)
> +		goto out;
> +	ret = set_extent_bits(&fs_info->freed_extents[1],
>  			start, end, EXTENT_UPTODATE);
> -	return 0;
> +out:

The function is short and fairly linear so you don't need to add the
label, 'return ret' would be ok.

> +	return ret;
>  }
>  
>  static void free_excluded_extents(struct btrfs_fs_info *fs_info,
> -- 
> 1.9.1
> 
> 
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH 2/2] btrfs: propagate failures of __exclude_logged_extent to upper caller
  2018-05-22  9:46 ` [PATCH 2/2] btrfs: propagate failures of __exclude_logged_extent to upper caller Gu Jinxiang
  2018-05-22 10:51   ` Nikolay Borisov
@ 2018-05-22 16:03   ` David Sterba
  1 sibling, 0 replies; 6+ messages in thread
From: David Sterba @ 2018-05-22 16:03 UTC (permalink / raw)
  To: Gu Jinxiang; +Cc: linux-btrfs, nborisov

On Tue, May 22, 2018 at 05:46:51PM +0800, Gu Jinxiang wrote:
> Function btrfs_exclude_logged_extents may call __exclude_logged_extent
> which may fail.
> Propagate the failures of __exclude_logged_extent to upper caller.
> 
> Signed-off-by: Gu Jinxiang <gujx@cn.fujitsu.com>

Reviewed-by: David Sterba <dsterba@suse.com>

The whole group of extent exclusion functions needs to be audited for
proper error handling.

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

end of thread, other threads:[~2018-05-22 16:06 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-05-22  9:46 [PATCH 1/2] btrfs: handle failures of set_extent_bits in add_excluded_extent Gu Jinxiang
2018-05-22  9:46 ` [PATCH 2/2] btrfs: propagate failures of __exclude_logged_extent to upper caller Gu Jinxiang
2018-05-22 10:51   ` Nikolay Borisov
2018-05-22 16:03   ` David Sterba
2018-05-22 10:51 ` [PATCH 1/2] btrfs: handle failures of set_extent_bits in add_excluded_extent Nikolay Borisov
2018-05-22 15:56 ` David Sterba

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