Re: [PATCH 2/4] fs/ntfs3: Fix fiemap + fix shrink file size (to remove preallocated space)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Oct 25, 2021 at 07:58:57PM +0300, Konstantin Komarov wrote:
> Two problems:
> 1. ntfs3_setattr can't truncate preallocated space;
> 2. if allocated fragment "cross" valid size, then fragment splits into two parts:
> - normal part;
> - unwritten part (here we must return FIEMAP_EXTENT_LAST).
> Before this commit we returned FIEMAP_EXTENT_LAST for whole fragment.
> Fixes xfstest generic/092

I do not have time for now to got through more. Maybe you have some
ideas here.

generic/092		[21:16:19][   18.906951] run fstests generic/092 at 2021-10-26 21:16:19
 [21:16:22]- output mismatch (see /results/ntfs3/results-default/generic/092.out.bad)
    --- tests/generic/092.out	2021-08-03 00:08:10.000000000 +0000
    +++ /results/ntfs3/results-default/generic/092.out.bad	2021-10-26 21:16:22.127859289 +0000
    @@ -2,5 +2,6 @@
     wrote 5242880/5242880 bytes at offset 0
     XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
     0: [0..10239]: data
    +1: [10240..20479]: unwritten
     0: [0..10239]: data
     1: [10240..20479]: unwritten

  Argillander

> Fixes: 4342306f0f0d ("fs/ntfs3: Add file operations and implementation")
> 
> Signed-off-by: Konstantin Komarov <almaz.alexandrovich@xxxxxxxxxxxxxxxxxxxx>
> ---
>  fs/ntfs3/file.c    |  2 +-
>  fs/ntfs3/frecord.c | 10 +++++++---
>  2 files changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/ntfs3/file.c b/fs/ntfs3/file.c
> index 43b1451bff53..5418e5ba64b3 100644
> --- a/fs/ntfs3/file.c
> +++ b/fs/ntfs3/file.c
> @@ -761,7 +761,7 @@ int ntfs3_setattr(struct user_namespace *mnt_userns, struct dentry *dentry,
>  		}
>  		inode_dio_wait(inode);
>  
> -		if (attr->ia_size < oldsize)
> +		if (attr->ia_size <= oldsize)
>  			err = ntfs_truncate(inode, attr->ia_size);
>  		else if (attr->ia_size > oldsize)
>  			err = ntfs_extend(inode, attr->ia_size, 0, NULL);
> diff --git a/fs/ntfs3/frecord.c b/fs/ntfs3/frecord.c
> index 6f47a9c17f89..18842998c8fa 100644
> --- a/fs/ntfs3/frecord.c
> +++ b/fs/ntfs3/frecord.c
> @@ -1964,10 +1964,8 @@ int ni_fiemap(struct ntfs_inode *ni, struct fiemap_extent_info *fieinfo,
>  
>  		vcn += clen;
>  
> -		if (vbo + bytes >= end) {
> +		if (vbo + bytes >= end)
>  			bytes = end - vbo;
> -			flags |= FIEMAP_EXTENT_LAST;
> -		}
>  
>  		if (vbo + bytes <= valid) {
>  			;
> @@ -1977,6 +1975,9 @@ int ni_fiemap(struct ntfs_inode *ni, struct fiemap_extent_info *fieinfo,
>  			/* vbo < valid && valid < vbo + bytes */
>  			u64 dlen = valid - vbo;
>  
> +			if (vbo + dlen >= end)
> +				flags |= FIEMAP_EXTENT_LAST;
> +
>  			err = fiemap_fill_next_extent(fieinfo, vbo, lbo, dlen,
>  						      flags);
>  			if (err < 0)
> @@ -1995,6 +1996,9 @@ int ni_fiemap(struct ntfs_inode *ni, struct fiemap_extent_info *fieinfo,
>  			flags |= FIEMAP_EXTENT_UNWRITTEN;
>  		}
>  
> +		if (vbo + bytes >= end)
> +			flags |= FIEMAP_EXTENT_LAST;
> +
>  		err = fiemap_fill_next_extent(fieinfo, vbo, lbo, bytes, flags);
>  		if (err < 0)
>  			break;
> -- 
> 2.33.0
> 
> 
> 




[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux