add support for fallocate mode 0
Subsystems (2)
cover add support for fallocate mode 0
Steve,
Please find a small patch that adds support for fallocate mode 0 to extend a non-sparse file.
PATCH 1/1 cifs: add support for fallocate mode 0 for non-sparse files
RHBZ 1336264
--- fs/cifs/smb2ops.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
fs/cifs/smb2ops.c +7 -3
@@ -3106,9 +3106,13 @@ static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,else if (i_size_read (inode) >= off + len)/* not extending file and already not sparse */ rc =0 ; -/* BB: in future add else clause to extend file */ -else - rc = -EOPNOTSUPP ; +/* extend file */ +else { + eof =cpu_to_le64 (off + len); + rc =SMB2_set_eof (xid, tcon, cfile->fid.persistent_fid, + cfile->fid.volatile_fid, cfile->pid, + &eof); + }if (rc)trace_smb3_falloc_err (xid, cfile->fid.persistent_fid, tcon->tid, tcon->ses->Suid, off, len, rc);
Signature · 1 line
2.13.6
Re: [PATCH] cifs: add support for fallocate mode 0 for non-sparse files
Does it affect (or enable) any xfstests?
Quoted 32 lines · Ronnie Sahlberg
RHBZ 1336264
Signed-off-by Ronnie Sahlberg <[email protected]>--- fs/cifs/smb2ops.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)fs/cifs/smb2ops.c +7
-4@@ -3106,9 +3106,13 @@ static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,else if (i_size_read (inode) >= off + len)/* not extending file and already not sparse */ rc =0 ; -/* BB: in future add else clause to extend file */ -else - rc = -EOPNOTSUPP ; +/* extend file */ +else { + eof =cpu_to_le64 (off + len); + rc =SMB2_set_eof (xid, tcon, cfile->fid.persistent_fid, + cfile->fid.volatile_fid, cfile->pid, + &eof); + }if (rc)trace_smb3_falloc_err (xid, cfile->fid.persistent_fid, tcon->tid, tcon->ses->Suid, off, len, rc); --2.13.6
Signature · 3 lines
Thanks, Steve
ronnie sahlberg
reviewerRe: [PATCH] cifs: add support for fallocate mode 0 for non-sparse files
Quoted 2 lines · Steve French
Does it affect (or enable) any xfstests?
It shouldn't affect any current tests.
It adds support for
xfs_io -c "falloc 0 512M" <file>
generic/071 now passes with this patch. Possibly other tests as well
that use "xfs_io -c falloc" as well
Quoted 40 lines · Ronnie Sahlberg
Quoted 30 lines
RHBZ 1336264
Signed-off-by Ronnie Sahlberg <[email protected]>--- fs/cifs/smb2ops.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)fs/cifs/smb2ops.c +7
-4@@ -3106,9 +3106,13 @@ static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,else if (i_size_read (inode) >= off + len)/* not extending file and already not sparse */ rc =0 ; -/* BB: in future add else clause to extend file */ -else - rc = -EOPNOTSUPP ; +/* extend file */ +else { + eof =cpu_to_le64 (off + len); + rc =SMB2_set_eof (xid, tcon, cfile->fid.persistent_fid, + cfile->fid.volatile_fid, cfile->pid, + &eof); + }if (rc)trace_smb3_falloc_err (xid, cfile->fid.persistent_fid, tcon->tid, tcon->ses->Suid, off, len, rc); --Quoted 2 lines
2.13.6
--
Thanks,Steve
Re: [PATCH] cifs: add support for fallocate mode 0 for non-sparse files
Tentatively merged into cifs-2.6.git for-next pending more testing
Quoted 53 lines · ronnie sahlberg
Quoted 2 lines · Steve French
Does it affect (or enable) any xfstests?
It shouldn't affect any current tests.
It adds support for
xfs_io-c "falloc 0 512M" <file>generic/071 now passes with this patch. Possibly other tests as well
that use "xfs_io-c falloc" as wellQuoted 40 lines · Ronnie Sahlberg
Quoted 30 lines
RHBZ 1336264
Signed-off-by Ronnie Sahlberg <[email protected]>--- fs/cifs/smb2ops.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)fs/cifs/smb2ops.c +7
-4@@ -3106,9 +3106,13 @@ static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,else if (i_size_read (inode) >= off + len)/* not extending file and already not sparse */ rc =0 ; -/* BB: in future add else clause to extend file */ -else - rc = -EOPNOTSUPP ; +/* extend file */ +else { + eof =cpu_to_le64 (off + len); + rc =SMB2_set_eof (xid, tcon, cfile->fid.persistent_fid, + cfile->fid.volatile_fid, cfile->pid, + &eof); + }if (rc)trace_smb3_falloc_err (xid, cfile->fid.persistent_fid, tcon->tid, tcon->ses->Suid, off, len, rc); --Quoted 2 lines
2.13.6
--
Thanks,Steve
Signature · 3 lines
Thanks, Steve
Re: [PATCH] cifs: add support for fallocate mode 0 for non-sparse files
temporarily removed to allow Ronnie to debug a test failure
Quoted 65 lines · Steve French
Tentatively merged into cifs-2.6.git for-next pending more testing
Quoted 53 lines · ronnie sahlberg
Quoted 2 lines · Steve French
Does it affect (or enable) any xfstests?
It shouldn't affect any current tests.
It adds support for
xfs_io-c "falloc 0 512M" <file>generic/071 now passes with this patch. Possibly other tests as well
that use "xfs_io-c falloc" as wellQuoted 40 lines · Ronnie Sahlberg
Quoted 30 lines
RHBZ 1336264
Signed-off-by Ronnie Sahlberg <[email protected]>--- fs/cifs/smb2ops.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)fs/cifs/smb2ops.c +7
-4@@ -3106,9 +3106,13 @@ static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,else if (i_size_read (inode) >= off + len)/* not extending file and already not sparse */ rc =0 ; -/* BB: in future add else clause to extend file */ -else - rc = -EOPNOTSUPP ; +/* extend file */ +else { + eof =cpu_to_le64 (off + len); + rc =SMB2_set_eof (xid, tcon, cfile->fid.persistent_fid, + cfile->fid.volatile_fid, cfile->pid, + &eof); + }if (rc)trace_smb3_falloc_err (xid, cfile->fid.persistent_fid, tcon->tid, tcon->ses->Suid, off, len, rc); --Quoted 2 lines
2.13.6
--
Thanks,Steve
--
Thanks,Steve
Signature · 3 lines
Thanks, Steve
ronnie sahlberg
reviewerRe: [PATCH] cifs: add support for fallocate mode 0 for non-sparse files
The bug is basically that if we extend a file by fallocate mode==0 and immediately afterwards mmap() the file we will only mmap() as much as end-of-file was
prior to the truncate and then if we try to touch any address in this extended region userspace dies with bus error.
The patch added "extend a file with fallocate mode==0 for NON-Sparse files" and caused xfstest to fail.
The fix is to force us to revalidate the file attributes (the size is the important one) when we extend the file sommap() will work properly.
I have fixed this in the patch and will resend tomorrow after some more testing.
Looking for other SMB2_set_eof() callsites I see we already had the same bug for the case of extending a SPARSE
file using fallocate mode==0. I fixed that too and will audit all other plases where we use SMB2_set_eof()
to see if they are safe or not before resending.
Quoted 76 lines · Steve French
temporarily removed to allow Ronnie to debug a test failure
Quoted 57 lines · Steve French
Tentatively merged into cifs-2.6.git for-next pending more testing
Quoted 52 lines · ronnie sahlberg
Quoted 2 lines · Steve French
Does it affect (or enable) any xfstests?
It shouldn't affect any current tests.
It adds support for
xfs_io-c "falloc 0 512M" <file>generic/071 now passes with this patch. Possibly other tests as well
that use "xfs_io-c falloc" as wellQuoted 39 lines · Ronnie Sahlberg
Quoted 30 lines
RHBZ 1336264
Signed-off-by Ronnie Sahlberg <[email protected]>--- fs/cifs/smb2ops.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)fs/cifs/smb2ops.c +7
-4@@ -3106,9 +3106,13 @@ static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,else if (i_size_read (inode) >= off + len)/* not extending file and already not sparse */ rc =0 ; -/* BB: in future add else clause to extend file */ -else - rc = -EOPNOTSUPP ; +/* extend file */ +else { + eof =cpu_to_le64 (off + len); + rc =SMB2_set_eof (xid, tcon, cfile->fid.persistent_fid, + cfile->fid.volatile_fid, cfile->pid, + &eof); + }if (rc)trace_smb3_falloc_err (xid, cfile->fid.persistent_fid, tcon->tid, tcon->ses->Suid, off, len, rc); --Quoted 2 lines
2.13.6
--
Thanks,Quoted 8 lines
Quoted 1 line
Quoted 1 line
Steve
--
Thanks,Steve
--
Thanks,Steve
Re: [PATCH] cifs: add support for fallocate mode 0 for non-sparse files
чт, 16 янв. 2020 г. в 01:05, ronnie sahlberg <[email protected]>:
Quoted 14 lines
The bug is basically that if we extend a file by fallocate mode==0 and immediately afterwards
mmap()the file we will onlymmap()as much as end-of-file was
prior to the truncate and then if we try to touch any address in this extended region userspace dies with bus error.The patch added "extend a file with fallocate mode==0 for NON-Sparse files" and caused xfstest to fail.
The fix is to force us to revalidate the file attributes (the size is the important one) when we extend the file sommap()will work properly.
I have fixed this in the patch and will resend tomorrow after some more testing.
Quoted 2 lines
Looking for other
SMB2_set_eof()callsites I see we already had the same bug for the case of extending a SPARSE
I agree that regardless of file being sparse or not, we should somehow update a size in the VFS after calling SMB2_set_eof().
Quoted 3 lines
file using fallocate mode==0. I fixed that too and will audit all other plases where we use
SMB2_set_eof()
to see if they are safe or not before resending.
One of those places where SMB2_set_eof() is called is cifs_set_file_size() which does call the following after getting a successful response from the server:
2250 >-------if (rc == 0) {
2251 >------->-------cifsInode->server_eof = attrs->ia_size; 2252 >------->-------cifs_setsize(inode, attrs->ia_size); 2253 >------->-------cifs_truncate_page(inode->i_mapping, inode->i_size); 2254 >-------}
This is called by cifs_setattr_[no]unix() which does the following afterwards:
2569 >-------if ((attrs->ia_valid & ATTR_SIZE) &&
2570 >------- attrs->ia_size != i_size_read(inode))
2571 >------->-------truncate_setsize(inode, attrs->ia_size);
truncate_setsize() does similar things as cifs_setsize() besides setting cinode->time to 0. This code path probably needs to be refactored. But putting this aside, for the current fallocate fix I think we should use the same existing mechanism to update a file size in the VFS without revalidating the inode.
--
Best regards,
Pavel Shilovsky
ronnie sahlberg
reviewerRe: [PATCH] cifs: add support for fallocate mode 0 for non-sparse files
Quoted 1 line · Pavel Shilovsky
Thanks.
Quoted 41 lines
чт, 16 янв. 2020 г. в 01:05, ronnie sahlberg <[email protected]>:
Quoted 14 lines
The bug is basically that if we extend a file by fallocate mode==0 and immediately afterwards
mmap()the file we will onlymmap()as much as end-of-file was
prior to the truncate and then if we try to touch any address in this extended region userspace dies with bus error.The patch added "extend a file with fallocate mode==0 for NON-Sparse files" and caused xfstest to fail.
The fix is to force us to revalidate the file attributes (the size is the important one) when we extend the file sommap()will work properly.
I have fixed this in the patch and will resend tomorrow after some more testing.Quoted 2 lines
Looking for other
SMB2_set_eof()callsites I see we already had the same bug for the case of extending a SPARSEI agree that regardless of file being sparse or not, we should somehow update a size in the VFS after calling
SMB2_set_eof().Quoted 3 lines
file using fallocate mode==0. I fixed that too and will audit all other plases where we use
SMB2_set_eof()
to see if they are safe or not before resending.One of those places where
SMB2_set_eof()is called iscifs_set_file_size()which does call the following after getting a successful response from the server:2250 >-------if (rc == 0) {
2251 >------->-------cifsInode->server_eof =attrs->ia_size; 2252 >------->-------cifs_setsize(inode,attrs->ia_size); 2253 >------->-------cifs_truncate_page(inode->i_mapping,inode->i_size); 2254 >-------}This is called by cifs_setattr_[no]unix() which does the following afterwards:
2569 >-------if ((
attrs->ia_valid&ATTR_SIZE) &&
2570 >-------attrs->ia_size!=i_size_read(inode))
2571 >------->-------truncate_setsize(inode,attrs->ia_size);
Quoted 5 lines
truncate_setsize()does similar things ascifs_setsize()besides settingcinode->timeto 0. This code path probably needs to be refactored. But putting this aside, for the current fallocate fix I think we should use the same existing mechanism to update a file size in the VFS without revalidating the inode.
I can do that change. Note however that since we are still setting cinode->time to 0
we are still going to trigger a revalidation at some stage.
Quoted 4 lines
--
Best regards,
Pavel Shilovsky