public inbox for fstests@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/4] fsx: allow zero range operations to cross eof
@ 2020-04-20 17:07 fdmanana
  2020-04-21 14:22 ` Brian Foster
  0 siblings, 1 reply; 2+ messages in thread
From: fdmanana @ 2020-04-20 17:07 UTC (permalink / raw)
  To: fstests; +Cc: linux-btrfs, Filipe Manana

From: Filipe Manana <fdmanana@suse.com>

Currently we are limiting the range for zero range operations to stay
within the i_size boundary. This is not optimal because like this we lose
coverage of the filesystem's zero range implementation, since zero range
operations are allowed to cross the i_size. Fix this by limiting the range
to 'maxfilelen' and not 'file_size', and update the 'file_size' after each
zero range operation if needed.

Signed-off-by: Filipe Manana <fdmanana@suse.com>
---
 ltp/fsx.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/ltp/fsx.c b/ltp/fsx.c
index 9d598a4f..56479eda 100644
--- a/ltp/fsx.c
+++ b/ltp/fsx.c
@@ -1244,6 +1244,17 @@ do_zero_range(unsigned offset, unsigned length, int keep_size)
 	}
 
 	memset(good_buf + offset, '\0', length);
+
+	if (!keep_size && end_offset > file_size) {
+		/*
+		 * If there's a gap between the old file size and the offset of
+		 * the zero range operation, fill the gap with zeroes.
+		 */
+		if (offset > file_size)
+			memset(good_buf + file_size, '\0', offset - file_size);
+
+		file_size = end_offset;
+	}
 }
 
 #else
@@ -2141,7 +2152,7 @@ have_op:
 		do_punch_hole(offset, size);
 		break;
 	case OP_ZERO_RANGE:
-		TRIM_OFF_LEN(offset, size, file_size);
+		TRIM_OFF_LEN(offset, size, maxfilelen);
 		do_zero_range(offset, size, keep_size);
 		break;
 	case OP_COLLAPSE_RANGE:
-- 
2.11.0


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

* Re: [PATCH 1/4] fsx: allow zero range operations to cross eof
  2020-04-20 17:07 [PATCH 1/4] fsx: allow zero range operations to cross eof fdmanana
@ 2020-04-21 14:22 ` Brian Foster
  0 siblings, 0 replies; 2+ messages in thread
From: Brian Foster @ 2020-04-21 14:22 UTC (permalink / raw)
  To: fdmanana; +Cc: fstests, linux-btrfs, Filipe Manana

On Mon, Apr 20, 2020 at 06:07:38PM +0100, fdmanana@kernel.org wrote:
> From: Filipe Manana <fdmanana@suse.com>
> 
> Currently we are limiting the range for zero range operations to stay
> within the i_size boundary. This is not optimal because like this we lose
> coverage of the filesystem's zero range implementation, since zero range
> operations are allowed to cross the i_size. Fix this by limiting the range
> to 'maxfilelen' and not 'file_size', and update the 'file_size' after each
> zero range operation if needed.
> 
> Signed-off-by: Filipe Manana <fdmanana@suse.com>
> ---

Thanks for the fixup. Looks good to me now:

Reviewed-by: Brian Foster <bfoster@redhat.com>

>  ltp/fsx.c | 13 ++++++++++++-
>  1 file changed, 12 insertions(+), 1 deletion(-)
> 
> diff --git a/ltp/fsx.c b/ltp/fsx.c
> index 9d598a4f..56479eda 100644
> --- a/ltp/fsx.c
> +++ b/ltp/fsx.c
> @@ -1244,6 +1244,17 @@ do_zero_range(unsigned offset, unsigned length, int keep_size)
>  	}
>  
>  	memset(good_buf + offset, '\0', length);
> +
> +	if (!keep_size && end_offset > file_size) {
> +		/*
> +		 * If there's a gap between the old file size and the offset of
> +		 * the zero range operation, fill the gap with zeroes.
> +		 */
> +		if (offset > file_size)
> +			memset(good_buf + file_size, '\0', offset - file_size);
> +
> +		file_size = end_offset;
> +	}
>  }
>  
>  #else
> @@ -2141,7 +2152,7 @@ have_op:
>  		do_punch_hole(offset, size);
>  		break;
>  	case OP_ZERO_RANGE:
> -		TRIM_OFF_LEN(offset, size, file_size);
> +		TRIM_OFF_LEN(offset, size, maxfilelen);
>  		do_zero_range(offset, size, keep_size);
>  		break;
>  	case OP_COLLAPSE_RANGE:
> -- 
> 2.11.0
> 


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

end of thread, other threads:[~2020-04-21 14:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-04-20 17:07 [PATCH 1/4] fsx: allow zero range operations to cross eof fdmanana
2020-04-21 14:22 ` Brian Foster

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox