fs/ntfs3: Various fixes for xfstests problems
Subsystems (2)
Konstantin Komarov
maintainercover fs/ntfs3: Various fixes for xfstests problems
This series fixes generic/444 generic/092 generic/228 generic/240
Konstantin Komarov (4):
fs/ntfs3: In function ntfs_set_acl_ex do not change inode->i_mode if
called from function ntfs_init_acl
fs/ntfs3: Fix fiemap + fix shrink file size (to remove preallocated
space)
fs/ntfs3: Check new size for limits
fs/ntfs3: Update valid size if -EIOCBQUEUED
fs/ntfs3/file.c | 10 ++++++++-- fs/ntfs3/frecord.c | 10 +++++++--- fs/ntfs3/inode.c | 9 +++++++-- fs/ntfs3/xattr.c | 13 +++++++------ 4 files changed, 29 insertions(+), 13 deletions(-)
Signature · 1 line
2.33.0
Konstantin Komarov
maintainerPATCH 1/4 fs/ntfs3: In function ntfs_set_acl_ex do not change inode->i_mode if called from function ntfs_init_acl
ntfs_init_acl sets mode. ntfs_init_acl calls ntfs_set_acl_ex. ntfs_set_acl_ex must not change this mode.
Fixes xfstest generic/444
--- fs/ntfs3/xattr.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
fs/ntfs3/xattr.c +7 -6
@@ -538,7 +538,7 @@ struct posix_acl *ntfs_get_acl(struct inode *inode, int type) static noinline int ntfs_set_acl_ex(struct user_namespace *mnt_userns,struct inode *inode,struct posix_acl *acl, -int type) +int type,int init_acl) {const char *name;size_t size, name_len;
@@ -551,8 +551,9 @@ static noinline int ntfs_set_acl_ex(struct user_namespace *mnt_userns,switch (type) {case ACL_TYPE_ACCESS : -if (acl) { -umode_t mode = inode->i_mode; +/* Do not change i_mode if we are in init_acl */ +if (acl && !init_acl) { +umode_t mode; err =posix_acl_update_mode (mnt_userns, inode, &mode, &acl);
@@ -613,7 +614,7 @@ static noinline int ntfs_set_acl_ex(struct user_namespace *mnt_userns,int ntfs_set_acl (struct user_namespace *mnt_userns,struct inode *inode,struct posix_acl *acl,int type) { -return ntfs_set_acl_ex (mnt_userns, inode, acl, type); +return ntfs_set_acl_ex (mnt_userns, inode, acl, type,0 ); }/*
@@ -633,7 +634,7 @@ int ntfs_init_acl(struct user_namespace *mnt_userns, struct inode *inode,if (default_acl) { err =ntfs_set_acl_ex (mnt_userns, inode, default_acl, -ACL_TYPE_DEFAULT ); +ACL_TYPE_DEFAULT ,1 );posix_acl_release (default_acl); }else { inode->i_default_acl =NULL ;
@@ -644,7 +645,7 @@ int ntfs_init_acl(struct user_namespace *mnt_userns, struct inode *inode,else {if (!err) err =ntfs_set_acl_ex (mnt_userns, inode, acl, -ACL_TYPE_ACCESS ); +ACL_TYPE_ACCESS ,1 );posix_acl_release (acl); }
Signature · 1 line
2.33.0
Re: [PATCH 1/4] fs/ntfs3: In function ntfs_set_acl_ex do not change inode->i_mode if called from function ntfs_init_acl
Quoted 4 lines · Konstantin Komarov
ntfs_init_aclsets mode.ntfs_init_aclcallsntfs_set_acl_ex.ntfs_set_acl_exmust not change this mode.
Fixes xfstest generic/444Fixes 83e8f5032e2d ("fs/ntfs3: Add attrib operations")
trivia:
fs/ntfs3/xattr.c
Quoted 1 line
fs/ntfs3/xattr.c +0
-0
[]
fs/ntfs3/xattr.c struct posix_acl *ntfs_get_acl(struct inode *inode, int type) · line 541
Quoted 6 lines
fs/ntfs3/xattr.c +1
-1@@ -538,7 +538,7 @@ struct posix_acl *ntfs_get_acl(struct inode *inode, int type) static noinline int ntfs_set_acl_ex(struct user_namespace *mnt_userns,struct inode *inode,struct posix_acl *acl, -int type) +int type,int init_acl)
bool init_acl?
fs/ntfs3/xattr.c static noinline int ntfs_set_acl_ex(struct user_namespace *mnt_userns, · line 617
Quoted 6 lines
fs/ntfs3/xattr.c +1
-1@@ -613,7 +614,7 @@ static noinline int ntfs_set_acl_ex(struct user_namespace *mnt_userns,int ntfs_set_acl (struct user_namespace *mnt_userns,struct inode *inode,struct posix_acl *acl,int type) { -return ntfs_set_acl_ex (mnt_userns, inode, acl, type); +return ntfs_set_acl_ex (mnt_userns, inode, acl, type,0 );
false
fs/ntfs3/xattr.c int ntfs_init_acl(struct user_namespace *mnt_userns, struct inode *inode, · line 637
Quoted 9 lines
fs/ntfs3/xattr.c +1
-1}/* @@ -633,7 +634,7 @@ int ntfs_init_acl(struct user_namespace *mnt_userns, struct inode *inode,if (default_acl) { err =ntfs_set_acl_ex (mnt_userns, inode, default_acl, -ACL_TYPE_DEFAULT ); +ACL_TYPE_DEFAULT ,1 );
true, etc...
Re: [PATCH 1/4] fs/ntfs3: In function ntfs_set_acl_ex do not change inode->i_mode if called from function ntfs_init_acl
In reply to Konstantin KomarovMaybe little too long subject line.
Quoted 4 lines · Konstantin Komarov
ntfs_init_aclsets mode.ntfs_init_aclcallsntfs_set_acl_ex.ntfs_set_acl_exmust not change this mode.
Fixes xfstest generic/444Fixes 83e8f5032e2d ("fs/ntfs3: Add attrib operations")
Where does this commit id come from? Seems wrong to me.
Quoted 11 lines
Signed-off-by Konstantin Komarov <[email protected]>--- fs/ntfs3/xattr.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)fs/ntfs3/xattr.c +0
-0
fs/ntfs3/xattr.c struct posix_acl *ntfs_get_acl(struct inode *inode, int type) · line 541
Quoted 5 lines
fs/ntfs3/xattr.c +1
-1@@ -538,7 +538,7 @@ struct posix_acl *ntfs_get_acl(struct inode *inode, int type) static noinline int ntfs_set_acl_ex(struct user_namespace *mnt_userns,struct inode *inode,struct posix_acl *acl, -int type) +int type,int init_acl)
Like Joe say. Bool here and use true/false
Quoted 45 lines
fs/ntfs3/xattr.c +6
-5{const char *name;size_t size, name_len;@@ -551,8 +551,9 @@ static noinline int ntfs_set_acl_ex(struct user_namespace *mnt_userns,switch (type) {case ACL_TYPE_ACCESS : -if (acl) { -umode_t mode = inode->i_mode; +/* Do not change i_mode if we are in init_acl */ +if (acl && !init_acl) { +umode_t mode; err =posix_acl_update_mode (mnt_userns, inode, &mode, &acl);@@ -613,7 +614,7 @@ static noinline int ntfs_set_acl_ex(struct user_namespace *mnt_userns,int ntfs_set_acl (struct user_namespace *mnt_userns,struct inode *inode,struct posix_acl *acl,int type) { -return ntfs_set_acl_ex (mnt_userns, inode, acl, type); +return ntfs_set_acl_ex (mnt_userns, inode, acl, type,0 ); }/* @@ -633,7 +634,7 @@ int ntfs_init_acl(struct user_namespace *mnt_userns, struct inode *inode,if (default_acl) { err =ntfs_set_acl_ex (mnt_userns, inode, default_acl, -ACL_TYPE_DEFAULT ); +ACL_TYPE_DEFAULT ,1 );posix_acl_release (default_acl); }else { inode->i_default_acl =NULL ;@@ -644,7 +645,7 @@ int ntfs_init_acl(struct user_namespace *mnt_userns, struct inode *inode,else {if (!err) err =ntfs_set_acl_ex (mnt_userns, inode, acl, -ACL_TYPE_ACCESS ); +ACL_TYPE_ACCESS ,1 );posix_acl_release (acl); }Signature · 1 line
2.33.0
Konstantin Komarov
maintainerPATCH 2/4 fs/ntfs3: Fix fiemap + fix shrink file size (to remove preallocated space)
In reply to Konstantin KomarovTwo 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
--- fs/ntfs3/file.c | 2 +- fs/ntfs3/frecord.c | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-)
fs/ntfs3/file.c +1 -1
@@ -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 );
fs/ntfs3/frecord.c +7 -3
@@ -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 ;
Signature · 1 line
2.33.0
Re: [PATCH 2/4] fs/ntfs3: Fix fiemap + fix shrink file size (to remove preallocated space)
Quoted 7 lines · Konstantin Komarov
Two problems:
1.ntfs3_setattrcan't truncate preallocated space;
2. if allocated fragment "cross" valid size, then fragment splits into two parts:
- normal part;
- unwritten part (here we must returnFIEMAP_EXTENT_LAST).
Before this commit we returnedFIEMAP_EXTENT_LASTfor 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]: unwrittenArgillander
Quoted 62 lines
Fixes 4342306f0f0d ("fs/ntfs3: Add file operations and implementation")Signed-off-by Konstantin Komarov <[email protected]>--- fs/ntfs3/file.c | 2 +- fs/ntfs3/frecord.c | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-)fs/ntfs3/file.c +1
-1@@ -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 );fs/ntfs3/frecord.c +7
-3@@ -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 ;Signature · 1 line
2.33.0
Konstantin Komarov
maintainerPATCH 3/4 fs/ntfs3: Check new size for limits
In reply to Konstantin KomarovWe must check size before trying to allocate.
Size can be set for example by "ulimit -f".
Fixes xfstest generic/228
--- fs/ntfs3/file.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
fs/ntfs3/file.c +7 -1
@@ -661,7 +661,13 @@ static long ntfs_fallocate(struct file *file, int mode, loff_t vbo, loff_t len)/* * Normal file: Allocate clusters, do not change 'valid' size. */ - err =ntfs_set_size (inode,max (end, i_size)); +loff_t new_size =max (end, i_size); + + err =inode_newsize_ok (inode, new_size); +if (err) + goto out; + + err =ntfs_set_size (inode, new_size);if (err) goto out;
Signature · 1 line
2.33.0
Re: [PATCH 3/4] fs/ntfs3: Check new size for limits
Quoted 3 lines · Konstantin Komarov
We must check size before trying to allocate.
Size can be set for example by "ulimit -f".
Fixes xfstest generic/228
generic/228 [21:20:39][ 18.058334] run fstests generic/228 at 2021-10-26 21:20:39
[21:20:41] 2s
Ran: generic/228
Passed all 1 tests
Quoted 3 lines
Fixes 4342306f0f0d ("fs/ntfs3: Add file operations and implementation")Signed-off-by Konstantin Komarov <[email protected]>
Quoted 27 lines
--- fs/ntfs3/file.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)fs/ntfs3/file.c +7
-1@@ -661,7 +661,13 @@ static long ntfs_fallocate(struct file *file, int mode, loff_t vbo, loff_t len)/* * Normal file: Allocate clusters, do not change 'valid' size. */ - err =ntfs_set_size (inode,max (end, i_size)); +loff_t new_size =max (end, i_size); + + err =inode_newsize_ok (inode, new_size); +if (err) + goto out; + + err =ntfs_set_size (inode, new_size);if (err) goto out;Signature · 1 line
2.33.0
Konstantin Komarov
maintainerPATCH 4/4 fs/ntfs3: Update valid size if -EIOCBQUEUED
In reply to Konstantin KomarovUpdate valid size if write is still in I/O queue.
Fixes xfstest generic/240
--- fs/ntfs3/inode.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
fs/ntfs3/inode.c +7 -2
@@ -757,6 +757,7 @@ static ssize_t ntfs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)loff_t vbo = iocb->ki_pos;loff_t end;int wr =iov_iter_rw (iter) &WRITE ; +size_t iter_count =iov_iter_count (iter);loff_t valid;ssize_t ret;
@@ -770,10 +771,14 @@ static ssize_t ntfs_direct_IO(struct kiocb *iocb, struct iov_iter *iter) wr ? ntfs_get_block_direct_IO_W : ntfs_get_block_direct_IO_R); -if (ret <=0 ) +if (ret >0 ) + end = vbo + ret; +else if (wr && -EIOCBQUEUED == ret) + end = vbo + iter_count; +else { goto out; + } - end = vbo + ret; valid = ni->i_valid;if (wr) {if (end > valid && !S_ISBLK (inode->i_mode)) {
Signature · 1 line
2.33.0
Re: [PATCH 4/4] fs/ntfs3: Update valid size if -EIOCBQUEUED
Quoted 2 lines · Konstantin Komarov
Update valid size if write is still in I/O queue.
Fixes xfstest generic/240
generic/240 [21:23:16][ 17.933690] run fstests generic/240 at 2021-10-26 21:23:16
[21:23:18] 2s
Ran: generic/240
Passed all 1 tests
Quoted 20 lines
Fixes 82cae269cfa9 ("fs/ntfs3: Add initialization of super block")Signed-off-by Konstantin Komarov <[email protected]>--- fs/ntfs3/inode.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)fs/ntfs3/inode.c +1
-0@@ -757,6 +757,7 @@ static ssize_t ntfs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)loff_t vbo = iocb->ki_pos;loff_t end;int wr =iov_iter_rw (iter) &WRITE ; +size_t iter_count =iov_iter_count (iter);loff_t valid;ssize_t ret;
fs/ntfs3/inode.c static ssize_t ntfs_direct_IO(struct kiocb *iocb, struct iov_iter *iter) · line 776
Quoted 7 lines
fs/ntfs3/inode.c +3
-1@@ -770,10 +771,14 @@ static ssize_t ntfs_direct_IO(struct kiocb *iocb, struct iov_iter *iter) wr ? ntfs_get_block_direct_IO_W : ntfs_get_block_direct_IO_R); -if (ret <=0 ) +if (ret >0 ) + end = vbo + ret; +else if (wr && -EIOCBQUEUED == ret)
ret == -EIOCBQUEUED
fs/ntfs3/inode.c static ssize_t ntfs_direct_IO(struct kiocb *iocb, struct iov_iter *iter) · line 777
Quoted 1 line
fs/ntfs3/inode.c +1
-0+ end = vbo + iter_count;
Use iov_iter_count() instead of tmp var?
fs/ntfs3/inode.c static ssize_t ntfs_direct_IO(struct kiocb *iocb, struct iov_iter *iter) · line 778
Quoted 1 line
fs/ntfs3/inode.c +1
-0+else {
Take brackets off.
Quoted 12 lines
fs/ntfs3/inode.c +1
-1goto out; + } - end = vbo + ret; valid = ni->i_valid;if (wr) {if (end > valid && !S_ISBLK (inode->i_mode)) {Signature · 1 line
2.33.0
Quoted 1 line · Konstantin Komarov
This series fixes generic/444 generic/092 generic/228 generic/240
Now that 5.15 is just behind corner we need to start think about stable also. Please read [1]. So basically this kind of fixes needs also
to sign-off-area. I know that stable team will try to pick also fixes automatically, but this is "right" way. You can add this Cc lable also when you make git am, but it is good the be there right away people can discuss if it should be stable or not.
Please also add cc tag to other patch series 1-3 patches.
[1]: https://www.kernel.org/doc/Documentation/process/stable-kernel-rules.rst
Quoted 17 lines
Konstantin Komarov (4):
fs/ntfs3: In functionntfs_set_acl_exdo not changeinode->i_modeif
called from functionntfs_init_acl
fs/ntfs3: Fix fiemap + fix shrink file size (to remove preallocated
space)
fs/ntfs3: Check new size for limits
fs/ntfs3: Update valid size if-EIOCBQUEUEDfs/ntfs3/file.c | 10 ++++++++-- fs/ntfs3/frecord.c | 10 +++++++--- fs/ntfs3/inode.c | 9 +++++++-- fs/ntfs3/xattr.c | 13 +++++++------ 4 files changed, 29 insertions(+), 13 deletions(-)Signature · 1 line
2.33.0