diff options
author | Ronnie Sahlberg <lsahlber@redhat.com> | 2019-08-30 00:25:46 +0200 |
---|---|---|
committer | Steve French <stfrench@microsoft.com> | 2019-09-16 18:43:37 +0200 |
commit | 8de9e86c67baa71c661b9ba59a4e23210d98bc79 (patch) | |
tree | bbcca0ff9e4b61fbedbdfec6d28f04580506adf7 /fs/cifs/file.c | |
parent | cifs: remove set but not used variables (diff) | |
download | linux-8de9e86c67baa71c661b9ba59a4e23210d98bc79.tar.xz linux-8de9e86c67baa71c661b9ba59a4e23210d98bc79.zip |
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.
Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
Diffstat (limited to 'fs/cifs/file.c')
-rw-r--r-- | fs/cifs/file.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/fs/cifs/file.c b/fs/cifs/file.c index f16f6d2b5217..6124b1d1ab05 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c @@ -1973,6 +1973,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; |