Skip to contentSkip to conversation

smb: enable reuse of deferred file handles for write operations

PATCH In review Bharath SM 4 participants 6 messages Dec 16, 2024 – Dec 23, 2024

Subsystems (2)
lore
Share & tools
lore

Bharath SM

author
#0 lore raw

PATCH 1/1 smb: enable reuse of deferred file handles for write operations

Previously, deferred file handles were reused only for read operations, this commit extends to reusing deferred handles for write operations.

---
 fs/smb/client/file.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
fs/smb/client/file.c +5 -1
index a58a3333ecc3..98deff1de74c 100644
@@ -990,7 +990,11 @@ int cifs_open(struct inode *inode, struct file *file)
 	}
 
 	/* Get the cached handle as SMB2 close is deferred */
-	rc = cifs_get_readable_path(tcon, full_path, &cfile);
+	if (OPEN_FMODE(file->f_flags) & FMODE_WRITE) {
+		rc = cifs_get_writable_path(tcon, full_path, FIND_WR_ANY, &cfile);
+	} else {
+		rc = cifs_get_readable_path(tcon, full_path, &cfile);
+	}
 	if (rc == 0) {
 		if (file->f_flags == cfile->f_flags) {
 			file->private_data = cfile;
Signature · 1 line
2.43.0
#1 lore raw

merged into cifs-2.6.git for-next pending review and more testing

Quoted 31 lines · Bharath SM

Previously, deferred file handles were reused only for read operations, this commit extends to reusing deferred handles for write operations.

---
 fs/smb/client/file.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
fs/smb/client/file.c +5 -2
index a58a3333ecc3..98deff1de74c 100644
@@ -990,7 +990,11 @@ int cifs_open(struct inode *inode, struct file *file)
        }
 
        /* Get the cached handle as SMB2 close is deferred */
-       rc = cifs_get_readable_path(tcon, full_path, &cfile);
+       if (OPEN_FMODE(file->f_flags) & FMODE_WRITE) {
+               rc = cifs_get_writable_path(tcon, full_path, FIND_WR_ANY, &cfile);
+       } else {
+               rc = cifs_get_readable_path(tcon, full_path, &cfile);
+       }
        if (rc == 0) {
                if (file->f_flags == cfile->f_flags) {
                        file->private_data = cfile;
--

2.43.0

Signature · 3 lines
Thanks,

Steve
#2 lore raw
Quoted 21 lines · Steve French

merged into cifs-2.6.git for-next pending review and more testing

Quoted 17 lines · Bharath SM

Previously, deferred file handles were reused only for read operations, this commit extends to reusing deferred handles for write operations.

---
 fs/smb/client/file.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
fs/smb/client/file.c +0 -0
index a58a3333ecc3..98deff1de74c 100644
@@ -990,7 +990,11 @@ int cifs_open(struct inode *inode, struct file *file)
        }
 
Quoted 4 lines

fs/smb/client/file.c int cifs_open(struct inode *inode, struct file *file) · line 994

Quoted 4 lines
fs/smb/client/file.c +2 -1
        /* Get the cached handle as SMB2 close is deferred */
-       rc = cifs_get_readable_path(tcon, full_path, &cfile);
+       if (OPEN_FMODE(file->f_flags) & FMODE_WRITE) {
+               rc = cifs_get_writable_path(tcon, full_path, FIND_WR_ANY, &cfile);

Wondering if FIND_WR_ANY is okay for all use cases? Specifically, I'm checking where FIND_WR_FSUID_ONLY is relevant. @Steve French Is this for multiuser mounts? I don't think so, since multiuser mounts come with their own tcon, and we search writable files in our tcon's open list.

Quoted 12 lines
Quoted 10 lines
fs/smb/client/file.c +3 -1
+       } else {
+               rc = cifs_get_readable_path(tcon, full_path, &cfile);
+       }
        if (rc == 0) {
                if (file->f_flags == cfile->f_flags) {
                        file->private_data = cfile;
--

2.43.0

Quoted 5 lines

--
Thanks,

Steve

Other than that one thing to look at, the changes look good to me.

Signature · 2 lines
Regards,
Shyam
#3 lore raw
Quoted 22 lines · Shyam Prasad N
Quoted 21 lines · Steve French

merged into cifs-2.6.git for-next pending review and more testing

Quoted 17 lines · Bharath SM

Previously, deferred file handles were reused only for read operations, this commit extends to reusing deferred handles for write operations.

---
 fs/smb/client/file.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
fs/smb/client/file.c +0 -0
index a58a3333ecc3..98deff1de74c 100644
@@ -990,7 +990,11 @@ int cifs_open(struct inode *inode, struct file *file)
        }
 
Quoted 10 lines
Quoted 4 lines

fs/smb/client/file.c int cifs_open(struct inode *inode, struct file *file) · line 994

Quoted 4 lines
fs/smb/client/file.c +2 -1
        /* Get the cached handle as SMB2 close is deferred */
-       rc = cifs_get_readable_path(tcon, full_path, &cfile);
+       if (OPEN_FMODE(file->f_flags) & FMODE_WRITE) {
+               rc = cifs_get_writable_path(tcon, full_path, FIND_WR_ANY, &cfile);

Wondering if FIND_WR_ANY is okay for all use cases? Specifically, I'm checking where FIND_WR_FSUID_ONLY is relevant. @Steve French Is this for multiuser mounts? I don't think so, since multiuser mounts come with their own tcon, and we search writable files in our tcon's open list.

I think this should be FIND_WR_FSUID_ONLY, yeah. (IMHO, that should be the default, and FIND_WR_ANY should be renamed something indicating it should only be used in specific situations and it's probably not what the caller wants.)

I have a series I need to resurrect and polish that fixes a few problems along these lines, but it doesn't touch the 'writable file' path.

Quoted 12 lines
Quoted 12 lines
Quoted 10 lines
fs/smb/client/file.c +3 -1
+       } else {
+               rc = cifs_get_readable_path(tcon, full_path, &cfile);
+       }
        if (rc == 0) {
                if (file->f_flags == cfile->f_flags) {
                        file->private_data = cfile;
--

2.43.0

Quoted 10 lines
Quoted 5 lines

--
Thanks,

Steve

Other than that one thing to look at, the changes look good to me.

Signature · 2 lines
Regards,
Shyam

~Paul

author
#4 lore raw

Thanks Shyam and Paul Aurich for reviewing and sharing comments.! I have attached an updated patch.

Quoted 59 lines · Paul Aurich
Quoted 22 lines · Shyam Prasad N
Quoted 21 lines · Steve French

merged into cifs-2.6.git for-next pending review and more testing

Quoted 17 lines · Bharath SM

Previously, deferred file handles were reused only for read operations, this commit extends to reusing deferred handles for write operations.

---
 fs/smb/client/file.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
fs/smb/client/file.c +0 -0
index a58a3333ecc3..98deff1de74c 100644
@@ -990,7 +990,11 @@ int cifs_open(struct inode *inode, struct file *file)
        }
 
Quoted 10 lines
Quoted 4 lines

fs/smb/client/file.c int cifs_open(struct inode *inode, struct file *file) · line 994

Quoted 4 lines
fs/smb/client/file.c +2 -1
        /* Get the cached handle as SMB2 close is deferred */
-       rc = cifs_get_readable_path(tcon, full_path, &cfile);
+       if (OPEN_FMODE(file->f_flags) & FMODE_WRITE) {
+               rc = cifs_get_writable_path(tcon, full_path, FIND_WR_ANY, &cfile);

Wondering if FIND_WR_ANY is okay for all use cases? Specifically, I'm checking where FIND_WR_FSUID_ONLY is relevant. @Steve French Is this for multiuser mounts? I don't think so, since multiuser mounts come with their own tcon, and we search writable files in our tcon's open list.

I think this should be FIND_WR_FSUID_ONLY, yeah. (IMHO, that should be the default, and FIND_WR_ANY should be renamed something indicating it should only be used in specific situations and it's probably not what the caller wants.)

I have a series I need to resurrect and polish that fixes a few problems along these lines, but it doesn't touch the 'writable file' path.

Quoted 17 lines
Quoted 17 lines
Quoted 10 lines
fs/smb/client/file.c +3 -1
+       } else {
+               rc = cifs_get_readable_path(tcon, full_path, &cfile);
+       }
        if (rc == 0) {
                if (file->f_flags == cfile->f_flags) {
                        file->private_data = cfile;
--

2.43.0

--
Thanks,

Steve

Quoted 8 lines
Quoted 5 lines

Other than that one thing to look at, the changes look good to me.

--
Regards,
Shyam

~Paul

From 8643af77857e3129924e788b4def9872798c1772 Mon Sep 17 00:00:00 2001
From: Bharath SM <[email protected]>
Date: Fri, 13 Dec 2024 22:50:21 +0530
Subject: [PATCH] smb: enable reuse of deferred file handles for write
operations

Previously, deferred file handles were reused only for read operations, this commit extends to reusing deferred handles for write operations. By reusing these handles we can reduce the need for open/close operations over the wire.

---
 fs/smb/client/file.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
fs/smb/client/file.c +5 -1
index a58a3333ecc3..3b2d33291a7e 100644
@@ -990,7 +990,11 @@ int cifs_open(struct inode *inode, struct file *file)
 	}
 
 	/* Get the cached handle as SMB2 close is deferred */
-	rc = cifs_get_readable_path(tcon, full_path, &cfile);
+	if (OPEN_FMODE(file->f_flags) & FMODE_WRITE) {
+		rc = cifs_get_writable_path(tcon, full_path, FIND_WR_FSUID_ONLY, &cfile);
+	} else {
+		rc = cifs_get_readable_path(tcon, full_path, &cfile);
+	}
 	if (rc == 0) {
 		if (file->f_flags == cfile->f_flags) {
 			file->private_data = cfile;
Signature · 1 line
2.43.0
#5 lore raw

Merged into cifs-2.6.git for-next pending more testing

Quoted 72 lines · Bharath SM

Thanks Shyam and Paul Aurich for reviewing and sharing comments.! I have attached an updated patch.

Quoted 67 lines · Paul Aurich
Quoted 22 lines · Shyam Prasad N
Quoted 21 lines · Steve French

merged into cifs-2.6.git for-next pending review and more testing

Quoted 17 lines · Bharath SM

Previously, deferred file handles were reused only for read operations, this commit extends to reusing deferred handles for write operations.

---
 fs/smb/client/file.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
fs/smb/client/file.c +0 -0
index a58a3333ecc3..98deff1de74c 100644
@@ -990,7 +990,11 @@ int cifs_open(struct inode *inode, struct file *file)
        }
 
Quoted 10 lines
Quoted 4 lines

fs/smb/client/file.c int cifs_open(struct inode *inode, struct file *file)

Quoted 4 lines
fs/smb/client/file.c +2 -1
        /* Get the cached handle as SMB2 close is deferred */
-       rc = cifs_get_readable_path(tcon, full_path, &cfile);
+       if (OPEN_FMODE(file->f_flags) & FMODE_WRITE) {
+               rc = cifs_get_writable_path(tcon, full_path, FIND_WR_ANY, &cfile);

Wondering if FIND_WR_ANY is okay for all use cases? Specifically, I'm checking where FIND_WR_FSUID_ONLY is relevant. @Steve French Is this for multiuser mounts? I don't think so, since multiuser mounts come with their own tcon, and we search writable files in our tcon's open list.

I think this should be FIND_WR_FSUID_ONLY, yeah. (IMHO, that should be the default, and FIND_WR_ANY should be renamed something indicating it should only be used in specific situations and it's probably not what the caller wants.)

I have a series I need to resurrect and polish that fixes a few problems along these lines, but it doesn't touch the 'writable file' path.

Quoted 15 lines
Quoted 15 lines
Quoted 10 lines
fs/smb/client/file.c +3 -1
+       } else {
+               rc = cifs_get_readable_path(tcon, full_path, &cfile);
+       }
        if (rc == 0) {
                if (file->f_flags == cfile->f_flags) {
                        file->private_data = cfile;
--

2.43.0

--
Thanks,

Quoted 7 lines
Quoted 2 lines

Steve

Other than that one thing to look at, the changes look good to me.

--
Regards,
Shyam

~Paul

Signature · 3 lines
Thanks,

Steve