Message ID | 3349332.1704123610@warthog.procyon.org.uk (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | cifs: Pass unbyteswapped eof value into SMB2_set_eof() | expand |
merged into cifs-2.6.git for-next On Mon, Jan 1, 2024 at 9:40 AM David Howells <dhowells@redhat.com> wrote: > > Hi Steve, > > How about something like the attached? > > David > --- > cifs: Pass unbyteswapped eof value into SMB2_set_eof() > > Change SMB2_set_eof() to take eof as CPU order rather than __le64 and pass > it directly rather than by pointer. This moves the conversion down into > SMB_set_eof() rather than all of its callers and means we don't need to > undo it for the traceline. > > Signed-off-by: David Howells <dhowells@redhat.com> > cc: Steve French <sfrench@samba.org> > cc: Shyam Prasad N <nspmangalore@gmail.com> > cc: Rohith Surabattula <rohiths.msft@gmail.com> > cc: Jeff Layton <jlayton@kernel.org> > cc: linux-cifs@vger.kernel.org > --- > fs/smb/client/smb2ops.c | 37 ++++++++++++++++--------------------- > fs/smb/client/smb2pdu.c | 6 +++--- > fs/smb/client/smb2proto.h | 2 +- > 3 files changed, 20 insertions(+), 25 deletions(-) > > diff --git a/fs/smb/client/smb2ops.c b/fs/smb/client/smb2ops.c > index 66b310208545..82de0e205607 100644 > --- a/fs/smb/client/smb2ops.c > +++ b/fs/smb/client/smb2ops.c > @@ -1923,7 +1923,6 @@ static int > smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon, > struct cifsFileInfo *cfile, __u64 size, bool set_alloc) > { > - __le64 eof = cpu_to_le64(size); > struct inode *inode; > > /* > @@ -1940,7 +1939,7 @@ smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon, > } > > return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid, > - cfile->fid.volatile_fid, cfile->pid, &eof); > + cfile->fid.volatile_fid, cfile->pid, size); > } > > static int > @@ -3324,7 +3323,6 @@ static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon, > unsigned long long new_size; > long rc; > unsigned int xid; > - __le64 eof; > > xid = get_xid(); > > @@ -3354,9 +3352,8 @@ static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon, > */ > new_size = offset + len; > if (keep_size == false && (unsigned long long)i_size_read(inode) < new_size) { > - eof = cpu_to_le64(new_size); > rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid, > - cfile->fid.volatile_fid, cfile->pid, &eof); > + cfile->fid.volatile_fid, cfile->pid, new_size); > if (rc >= 0) { > truncate_setsize(inode, new_size); > fscache_resize_cookie(cifs_inode_cookie(inode), new_size); > @@ -3549,7 +3546,7 @@ static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon, > struct cifsFileInfo *cfile = file->private_data; > long rc = -EOPNOTSUPP; > unsigned int xid; > - __le64 eof; > + loff_t new_eof; > > xid = get_xid(); > > @@ -3578,14 +3575,14 @@ static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon, > if (cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) > smb2_set_sparse(xid, tcon, cfile, inode, false); > > - eof = cpu_to_le64(off + len); > + new_eof = off + len; > rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid, > - cfile->fid.volatile_fid, cfile->pid, &eof); > + cfile->fid.volatile_fid, cfile->pid, new_eof); > if (rc == 0) { > - cifsi->server_eof = off + len; > - cifs_setsize(inode, off + len); > + cifsi->server_eof = new_eof; > + cifs_setsize(inode, new_eof); > cifs_truncate_page(inode->i_mapping, inode->i_size); > - truncate_setsize(inode, off + len); > + truncate_setsize(inode, new_eof); > } > goto out; > } > @@ -3676,8 +3673,7 @@ static long smb3_collapse_range(struct file *file, struct cifs_tcon *tcon, > struct inode *inode = file_inode(file); > struct cifsFileInfo *cfile = file->private_data; > struct cifsInodeInfo *cifsi = CIFS_I(inode); > - __le64 eof; > - loff_t old_eof; > + loff_t old_eof, new_eof; > > xid = get_xid(); > > @@ -3702,9 +3698,9 @@ static long smb3_collapse_range(struct file *file, struct cifs_tcon *tcon, > if (rc < 0) > goto out_2; > > - eof = cpu_to_le64(old_eof - len); > + new_eof = old_eof - len; > rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid, > - cfile->fid.volatile_fid, cfile->pid, &eof); > + cfile->fid.volatile_fid, cfile->pid, new_eof); > if (rc < 0) > goto out_2; > > @@ -3728,8 +3724,7 @@ static long smb3_insert_range(struct file *file, struct cifs_tcon *tcon, > unsigned int xid; > struct cifsFileInfo *cfile = file->private_data; > struct inode *inode = file_inode(file); > - __le64 eof; > - __u64 count, old_eof; > + __u64 count, old_eof, new_eof; > > xid = get_xid(); > > @@ -3742,20 +3737,20 @@ static long smb3_insert_range(struct file *file, struct cifs_tcon *tcon, > } > > count = old_eof - off; > - eof = cpu_to_le64(old_eof + len); > + new_eof = old_eof + len; > > filemap_invalidate_lock(inode->i_mapping); > - rc = filemap_write_and_wait_range(inode->i_mapping, off, old_eof + len - 1); > + rc = filemap_write_and_wait_range(inode->i_mapping, off, new_eof - 1); > if (rc < 0) > goto out_2; > truncate_pagecache_range(inode, off, old_eof); > > rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid, > - cfile->fid.volatile_fid, cfile->pid, &eof); > + cfile->fid.volatile_fid, cfile->pid, new_eof); > if (rc < 0) > goto out_2; > > - truncate_setsize(inode, old_eof + len); > + truncate_setsize(inode, new_eof); > fscache_resize_cookie(cifs_inode_cookie(inode), i_size_read(inode)); > > rc = smb2_copychunk_range(xid, cfile, cfile, off, count, off + len); > diff --git a/fs/smb/client/smb2pdu.c b/fs/smb/client/smb2pdu.c > index 4f971c1061f0..bd25c34dc398 100644 > --- a/fs/smb/client/smb2pdu.c > +++ b/fs/smb/client/smb2pdu.c > @@ -5347,18 +5347,18 @@ send_set_info(const unsigned int xid, struct cifs_tcon *tcon, > > int > SMB2_set_eof(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid, > - u64 volatile_fid, u32 pid, __le64 *eof) > + u64 volatile_fid, u32 pid, loff_t new_eof) > { > struct smb2_file_eof_info info; > void *data; > unsigned int size; > > - info.EndOfFile = *eof; > + info.EndOfFile = cpu_to_le64(new_eof); > > data = &info; > size = sizeof(struct smb2_file_eof_info); > > - trace_smb3_set_eof(xid, persistent_fid, tcon->tid, tcon->ses->Suid, le64_to_cpu(*eof)); > + trace_smb3_set_eof(xid, persistent_fid, tcon->tid, tcon->ses->Suid, new_eof); > > return send_set_info(xid, tcon, persistent_fid, volatile_fid, > pid, FILE_END_OF_FILE_INFORMATION, SMB2_O_INFO_FILE, > diff --git a/fs/smb/client/smb2proto.h b/fs/smb/client/smb2proto.h > index 0e371f7e2854..95e5ca69fdf3 100644 > --- a/fs/smb/client/smb2proto.h > +++ b/fs/smb/client/smb2proto.h > @@ -205,7 +205,7 @@ extern int SMB2_query_directory_init(unsigned int xid, struct cifs_tcon *tcon, > extern void SMB2_query_directory_free(struct smb_rqst *rqst); > extern int SMB2_set_eof(const unsigned int xid, struct cifs_tcon *tcon, > u64 persistent_fid, u64 volatile_fid, u32 pid, > - __le64 *eof); > + loff_t new_eof); > extern int SMB2_set_info_init(struct cifs_tcon *tcon, > struct TCP_Server_Info *server, > struct smb_rqst *rqst, > >
diff --git a/fs/smb/client/smb2ops.c b/fs/smb/client/smb2ops.c index 66b310208545..82de0e205607 100644 --- a/fs/smb/client/smb2ops.c +++ b/fs/smb/client/smb2ops.c @@ -1923,7 +1923,6 @@ static int smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon, struct cifsFileInfo *cfile, __u64 size, bool set_alloc) { - __le64 eof = cpu_to_le64(size); struct inode *inode; /* @@ -1940,7 +1939,7 @@ smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon, } return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid, - cfile->fid.volatile_fid, cfile->pid, &eof); + cfile->fid.volatile_fid, cfile->pid, size); } static int @@ -3324,7 +3323,6 @@ static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon, unsigned long long new_size; long rc; unsigned int xid; - __le64 eof; xid = get_xid(); @@ -3354,9 +3352,8 @@ static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon, */ new_size = offset + len; if (keep_size == false && (unsigned long long)i_size_read(inode) < new_size) { - eof = cpu_to_le64(new_size); rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid, - cfile->fid.volatile_fid, cfile->pid, &eof); + cfile->fid.volatile_fid, cfile->pid, new_size); if (rc >= 0) { truncate_setsize(inode, new_size); fscache_resize_cookie(cifs_inode_cookie(inode), new_size); @@ -3549,7 +3546,7 @@ static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon, struct cifsFileInfo *cfile = file->private_data; long rc = -EOPNOTSUPP; unsigned int xid; - __le64 eof; + loff_t new_eof; xid = get_xid(); @@ -3578,14 +3575,14 @@ static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon, if (cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) smb2_set_sparse(xid, tcon, cfile, inode, false); - eof = cpu_to_le64(off + len); + new_eof = off + len; rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid, - cfile->fid.volatile_fid, cfile->pid, &eof); + cfile->fid.volatile_fid, cfile->pid, new_eof); if (rc == 0) { - cifsi->server_eof = off + len; - cifs_setsize(inode, off + len); + cifsi->server_eof = new_eof; + cifs_setsize(inode, new_eof); cifs_truncate_page(inode->i_mapping, inode->i_size); - truncate_setsize(inode, off + len); + truncate_setsize(inode, new_eof); } goto out; } @@ -3676,8 +3673,7 @@ static long smb3_collapse_range(struct file *file, struct cifs_tcon *tcon, struct inode *inode = file_inode(file); struct cifsFileInfo *cfile = file->private_data; struct cifsInodeInfo *cifsi = CIFS_I(inode); - __le64 eof; - loff_t old_eof; + loff_t old_eof, new_eof; xid = get_xid(); @@ -3702,9 +3698,9 @@ static long smb3_collapse_range(struct file *file, struct cifs_tcon *tcon, if (rc < 0) goto out_2; - eof = cpu_to_le64(old_eof - len); + new_eof = old_eof - len; rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid, - cfile->fid.volatile_fid, cfile->pid, &eof); + cfile->fid.volatile_fid, cfile->pid, new_eof); if (rc < 0) goto out_2; @@ -3728,8 +3724,7 @@ static long smb3_insert_range(struct file *file, struct cifs_tcon *tcon, unsigned int xid; struct cifsFileInfo *cfile = file->private_data; struct inode *inode = file_inode(file); - __le64 eof; - __u64 count, old_eof; + __u64 count, old_eof, new_eof; xid = get_xid(); @@ -3742,20 +3737,20 @@ static long smb3_insert_range(struct file *file, struct cifs_tcon *tcon, } count = old_eof - off; - eof = cpu_to_le64(old_eof + len); + new_eof = old_eof + len; filemap_invalidate_lock(inode->i_mapping); - rc = filemap_write_and_wait_range(inode->i_mapping, off, old_eof + len - 1); + rc = filemap_write_and_wait_range(inode->i_mapping, off, new_eof - 1); if (rc < 0) goto out_2; truncate_pagecache_range(inode, off, old_eof); rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid, - cfile->fid.volatile_fid, cfile->pid, &eof); + cfile->fid.volatile_fid, cfile->pid, new_eof); if (rc < 0) goto out_2; - truncate_setsize(inode, old_eof + len); + truncate_setsize(inode, new_eof); fscache_resize_cookie(cifs_inode_cookie(inode), i_size_read(inode)); rc = smb2_copychunk_range(xid, cfile, cfile, off, count, off + len); diff --git a/fs/smb/client/smb2pdu.c b/fs/smb/client/smb2pdu.c index 4f971c1061f0..bd25c34dc398 100644 --- a/fs/smb/client/smb2pdu.c +++ b/fs/smb/client/smb2pdu.c @@ -5347,18 +5347,18 @@ send_set_info(const unsigned int xid, struct cifs_tcon *tcon, int SMB2_set_eof(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid, - u64 volatile_fid, u32 pid, __le64 *eof) + u64 volatile_fid, u32 pid, loff_t new_eof) { struct smb2_file_eof_info info; void *data; unsigned int size; - info.EndOfFile = *eof; + info.EndOfFile = cpu_to_le64(new_eof); data = &info; size = sizeof(struct smb2_file_eof_info); - trace_smb3_set_eof(xid, persistent_fid, tcon->tid, tcon->ses->Suid, le64_to_cpu(*eof)); + trace_smb3_set_eof(xid, persistent_fid, tcon->tid, tcon->ses->Suid, new_eof); return send_set_info(xid, tcon, persistent_fid, volatile_fid, pid, FILE_END_OF_FILE_INFORMATION, SMB2_O_INFO_FILE, diff --git a/fs/smb/client/smb2proto.h b/fs/smb/client/smb2proto.h index 0e371f7e2854..95e5ca69fdf3 100644 --- a/fs/smb/client/smb2proto.h +++ b/fs/smb/client/smb2proto.h @@ -205,7 +205,7 @@ extern int SMB2_query_directory_init(unsigned int xid, struct cifs_tcon *tcon, extern void SMB2_query_directory_free(struct smb_rqst *rqst); extern int SMB2_set_eof(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid, u64 volatile_fid, u32 pid, - __le64 *eof); + loff_t new_eof); extern int SMB2_set_info_init(struct cifs_tcon *tcon, struct TCP_Server_Info *server, struct smb_rqst *rqst,
Hi Steve, How about something like the attached? David --- cifs: Pass unbyteswapped eof value into SMB2_set_eof() Change SMB2_set_eof() to take eof as CPU order rather than __le64 and pass it directly rather than by pointer. This moves the conversion down into SMB_set_eof() rather than all of its callers and means we don't need to undo it for the traceline. Signed-off-by: David Howells <dhowells@redhat.com> cc: Steve French <sfrench@samba.org> cc: Shyam Prasad N <nspmangalore@gmail.com> cc: Rohith Surabattula <rohiths.msft@gmail.com> cc: Jeff Layton <jlayton@kernel.org> cc: linux-cifs@vger.kernel.org --- fs/smb/client/smb2ops.c | 37 ++++++++++++++++--------------------- fs/smb/client/smb2pdu.c | 6 +++--- fs/smb/client/smb2proto.h | 2 +- 3 files changed, 20 insertions(+), 25 deletions(-)