cifs: create a helper to find a writeable handle by path name
Subsystems (2)
PATCH 1/1 cifs: create a helper to find a writeable handle by path name
rename() takes a path for old_file and in SMB2 we used to just create a compound for create(old_path)/rename/close().
If we already have a writable handle we can avoid the create() and close() altogether and just use the existing handle.
For this situation, as we avoid doing the create()
we also avoid triggering an oplock break for the existing handle.
--- fs/cifs/cifsproto.h | 2 ++ fs/cifs/dir.c | 2 +- fs/cifs/file.c | 35 ++++++++++++++++++++ fs/cifs/smb2inode.c | 94 ++++++++++++++++++++++++++++++++++++++--------------- 4 files changed, 106 insertions(+), 27 deletions(-)
fs/cifs/cifsproto.h +2 -0
@@ -137,6 +137,8 @@ extern struct cifsFileInfo *find_writable_file(struct cifsInodeInfo *, bool);extern int cifs_get_writable_file (struct cifsInodeInfo *cifs_inode,bool fsuid_only,struct cifsFileInfo **ret_file); +extern int cifs_get_writable_path (struct cifs_tcon *tcon,const char *name, +struct cifsFileInfo **ret_file);extern struct cifsFileInfo *find_readable_file (struct cifsInodeInfo *,bool );extern unsigned int smbCalcSize (void *buf,struct TCP_Server_Info *server); extern int decode_negTokenInit(unsigned char *security_blob, int length,
fs/cifs/dir.c +1 -1
@@ -125,7 +125,7 @@ build_path_from_dentry_optional_prefix(struct dentry *direntry, bool prefix) }rcu_read_unlock (); - full_path =kmalloc (namelen+1 ,GFP_KERNEL ); + full_path =kmalloc (namelen+1 ,GFP_ATOMIC );if (full_path ==NULL )return full_path; full_path[namelen] =0 ;/* trailing null */
fs/cifs/file.c +35 -0
@@ -1980,6 +1980,41 @@ find_writable_file(struct cifsInodeInfo *cifs_inode, bool fsuid_only)return cfile; } +int +cifs_get_writable_path (struct cifs_tcon *tcon,const char *name, +struct cifsFileInfo **ret_file) +{ +struct list_head *tmp; +struct cifsFileInfo *cfile; +struct cifsInodeInfo *cinode; +char *full_path; + + *ret_file =NULL ; + +spin_lock (&tcon->open_file_lock); +list_for_each (tmp, &tcon->openFileList) { + cfile = list_entry(tmp, struct cifsFileInfo, + tlist); + full_path =build_path_from_dentry (cfile->dentry); +if (full_path ==NULL ) { +spin_unlock (&tcon->open_file_lock); +return -ENOMEM ; + } +if (strcmp (full_path, name)) { +kfree (full_path); +continue ; + } + +kfree (full_path); + cinode =CIFS_I (d_inode (cfile->dentry)); +spin_unlock (&tcon->open_file_lock); +return cifs_get_writable_file (cinode,0 , ret_file); + } + +spin_unlock (&tcon->open_file_lock); +return -ENOENT ; +} +static int cifs_partialpagewrite (struct page *page,unsigned from,unsigned to) {struct address_space *mapping = page->mapping;
fs/cifs/smb2inode.c +68 -26
210 lines not on this page · raw message
Signature · 1 line
2.13.6
чт, 29 авг. 2019 г. в 15:26, Ronnie Sahlberg <[email protected]>:
Quoted 8 lines
rename()takes a path forold_fileand in SMB2 we used to just create a compound for create(old_path)/rename/close().
If we already have a writable handle we can avoid thecreate()andclose()altogether and just use the existing handle.For this situation, as we avoid doing the
create()
we also avoid triggering an oplock break for the existing handle.
Hi Ronnie,
Another SMB2_CREATE from the same client shouldn't cause a lease break if we ask for a lease with the same lease key. The lease key is associated with the inode, all opens that can cause a break should ask for the lease with the lease key.
Currently smb2_compound_op doesn't ask for a lease: see at the beginning of the function:
oplock = SMB2_OPLOCK_LEVEL_NONE
What we need to do is to change this to SMB2_OPLOCK_LEVEL_BATCH for operation that modifies the file like SET_EOF and SET_INFO. In this case the lower layer will map it to the appropriate lease state. Note that parms->fid->lease_key should be populated.
--
Best regards,
Pavel Shilovsky
Even so ... we shouldn't ask for open/query/close or open/setinfo/close if just a query-info or set-info (no open/close) is possible - it will make server's lives much easier ...
Quoted 31 lines · Pavel Shilovsky
чт, 29 авг. 2019 г. в 15:26, Ronnie Sahlberg <[email protected]>:
Quoted 8 lines
rename()takes a path forold_fileand in SMB2 we used to just create a compound for create(old_path)/rename/close().
If we already have a writable handle we can avoid thecreate()andclose()altogether and just use the existing handle.For this situation, as we avoid doing the
create()
we also avoid triggering an oplock break for the existing handle.Hi Ronnie,
Another
SMB2_CREATEfrom the same client shouldn't cause a lease break if we ask for a lease with the same lease key. The lease key is associated with the inode, all opens that can cause a break should ask for the lease with the lease key.Currently
smb2_compound_opdoesn't ask for a lease: see at the beginning of the function:oplock =
SMB2_OPLOCK_LEVEL_NONEWhat we need to do is to change this to
SMB2_OPLOCK_LEVEL_BATCHfor operation that modifies the file likeSET_EOFandSET_INFO. In this case the lower layer will map it to the appropriate lease state. Note thatparms->fid->lease_keyshould be populated.--
Best regards,
Pavel Shilovsky
Signature · 3 lines
Thanks, Steve