Skip to contentSkip to conversation

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

PATCH In review Ronnie Sahlberg 3 participants 5 messages Aug 27, 2019

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

PATCH 1/2 cifs: create a helper to find a writeable handle py 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 | 83 +++++++++++++++++++++++++++++++++++++----------------
 3 files changed, 96 insertions(+), 24 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 +59 -24

195 lines not on this page · raw message

Signature · 1 line
2.13.6
#1 lore raw

PATCH 2/2 cifs: fix incorrect error return in build_unc_path_to_root

---
 fs/cifs/connect.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/cifs/connect.c +1 -1
index 1ed449f4a8ec..c5dc8265b671 100644
@@ -4232,7 +4232,7 @@ build_unc_path_to_root(const struct smb_vol *vol,
 	unsigned int unc_len = strnlen(vol->UNC, MAX_TREE_SIZE + 1);
 
 	if (unc_len > MAX_TREE_SIZE)
-		return -EINVAL;
+		return ERR_PTR(-EINVAL);
 
 	full_path = kmalloc(unc_len + pplen + 1, GFP_KERNEL);
 	if (full_path == NULL)
Signature · 1 line
2.13.6
#2 lore raw

Re: [PATCH 2/2] cifs: fix incorrect error return in build_unc_path_to_root

Do you have a simple repro for this one that would lead us to want to cc:stable

Quoted 22 lines · Ronnie Sahlberg
---
 fs/cifs/connect.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/cifs/connect.c +1 -2
index 1ed449f4a8ec..c5dc8265b671 100644
@@ -4232,7 +4232,7 @@ build_unc_path_to_root(const struct smb_vol *vol,
        unsigned int unc_len = strnlen(vol->UNC, MAX_TREE_SIZE + 1);
 
        if (unc_len > MAX_TREE_SIZE)
-               return -EINVAL;
+               return ERR_PTR(-EINVAL);
 
        full_path = kmalloc(unc_len + pplen + 1, GFP_KERNEL);
        if (full_path == NULL)
--

2.13.6

Signature · 3 lines
Thanks,

Steve
#3 lore raw

Re: [PATCH 2/2] cifs: fix incorrect error return in build_unc_path_to_root

Quoted 2 lines · Steve French

Do you have a simple repro for this one that would lead us to want to cc:stable

I don't have a reproducer.

Quoted 30 lines · Ronnie Sahlberg
Quoted 20 lines
---
 fs/cifs/connect.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/cifs/connect.c +1 -2
index 1ed449f4a8ec..c5dc8265b671 100644
@@ -4232,7 +4232,7 @@ build_unc_path_to_root(const struct smb_vol *vol,
        unsigned int unc_len = strnlen(vol->UNC, MAX_TREE_SIZE + 1);
 
        if (unc_len > MAX_TREE_SIZE)
-               return -EINVAL;
+               return ERR_PTR(-EINVAL);
 
        full_path = kmalloc(unc_len + pplen + 1, GFP_KERNEL);
        if (full_path == NULL)
--
Quoted 2 lines

2.13.6

--
Thanks,

Steve

#4 lore raw

Re: [PATCH 2/2] cifs: fix incorrect error return in build_unc_path_to_root

In reply to Ronnie Sahlberg

I fixed this in an earlier patch of yours

Quoted 22 lines · Ronnie Sahlberg
---
 fs/cifs/connect.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/cifs/connect.c +1 -2
index 1ed449f4a8ec..c5dc8265b671 100644
@@ -4232,7 +4232,7 @@ build_unc_path_to_root(const struct smb_vol *vol,
        unsigned int unc_len = strnlen(vol->UNC, MAX_TREE_SIZE + 1);
 
        if (unc_len > MAX_TREE_SIZE)
-               return -EINVAL;
+               return ERR_PTR(-EINVAL);
 
        full_path = kmalloc(unc_len + pplen + 1, GFP_KERNEL);
        if (full_path == NULL)
--

2.13.6

Signature · 3 lines
Thanks,

Steve