diff mbox series

[1/4] fsx: allow zero range operations to cross eof

Message ID 20200420170738.9879-1-fdmanana@kernel.org (mailing list archive)
State New, archived
Headers show
Series [1/4] fsx: allow zero range operations to cross eof | expand

Commit Message

Filipe Manana April 20, 2020, 5:07 p.m. UTC
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(-)

Comments

Brian Foster April 21, 2020, 2:22 p.m. UTC | #1
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
>
diff mbox series

Patch

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: