Skip to contentSkip to conversation

cifs: create a helper to find a writeable handle by path name

PATCH New Ronnie Sahlberg 1 participant 1 message Aug 27, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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/file.c      | 35 ++++++++++++++++++++
 fs/cifs/smb2inode.c | 93 ++++++++++++++++++++++++++++++++++++++---------------
 3 files changed, 104 insertions(+), 26 deletions(-)
fs/cifs/cifsproto.h +2 -0
index 592a6cea2b79..be206744407c 100644
@@ -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/file.c +35 -0
index 97090693d182..b67f17b06bcd 100644
@@ -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 +67 -26

209 lines not on this page · raw message

Signature · 1 line
2.13.6