Skip to contentSkip to conversation

SMB3: Do not send lease break acknowledgment if all file handles have been closed

PATCH In review Bharath SM 4 participants 10 messages Jun 19, 2023 – Jun 21, 2023

Subsystems (2)
lore
Share & tools
lore

Bharath SM

author
#0 lore raw

PATCH 1/1 SMB3: Do not send lease break acknowledgment if all file handles have been closed

In case if all existing file handles are deferred handles and if all of them gets closed due to handle lease break then we dont need to send lease break acknowledgment to server, because last handle close will be considered as lease break ack.
After closing deferred handels, we check for openfile list of inode, if its empty then we skip sending lease break ack.

Fixes 59a556aebc43 ("SMB3: drop reference to cfile before sending oplock break")
---
 fs/smb/client/file.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
fs/smb/client/file.c +5 -2
index 051283386e22..b8a3d60e7ac4 100644
@@ -4941,7 +4941,9 @@ void cifs_oplock_break(struct work_struct *work)
 	 * not bother sending an oplock release if session to server still is
 	 * disconnected since oplock already released by the server
 	 */
-	if (!oplock_break_cancelled) {
+	spin_lock(&cinode->open_file_lock);
+	if (!oplock_break_cancelled && !list_empty(&cinode->openFileList)) {
+		spin_unlock(&cinode->open_file_lock);
 		/* check for server null since can race with kill_sb calling tree disconnect */
 		if (tcon->ses && tcon->ses->server) {
 			rc = tcon->ses->server->ops->oplock_response(tcon, persistent_fid,
@@ -4949,7 +4951,8 @@ void cifs_oplock_break(struct work_struct *work)
 			cifs_dbg(FYI, "Oplock release rc = %d\n", rc);
 		} else
 			pr_warn_once("lease break not sent for unmounted share\n");
-	}
+	} else
+		spin_unlock(&cinode->open_file_lock);
 
 	cifs_done_oplock_break(cinode);
 }
Signature · 1 line
2.34.1
#1 lore raw

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

Quoted 42 lines · Bharath SM

In case if all existing file handles are deferred handles and if all of them gets closed due to handle lease break then we dont need to send lease break acknowledgment to server, because last handle close will be considered as lease break ack.
After closing deferred handels, we check for openfile list of inode, if its empty then we skip sending lease break ack.

Fixes 59a556aebc43 ("SMB3: drop reference to cfile before sending oplock break")
---
 fs/smb/client/file.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
fs/smb/client/file.c +5 -3
index 051283386e22..b8a3d60e7ac4 100644
@@ -4941,7 +4941,9 @@ void cifs_oplock_break(struct work_struct *work)
         * not bother sending an oplock release if session to server still is
         * disconnected since oplock already released by the server
         */
-       if (!oplock_break_cancelled) {
+       spin_lock(&cinode->open_file_lock);
+       if (!oplock_break_cancelled && !list_empty(&cinode->openFileList)) {
+               spin_unlock(&cinode->open_file_lock);
                /* check for server null since can race with kill_sb calling tree disconnect */
                if (tcon->ses && tcon->ses->server) {
                        rc = tcon->ses->server->ops->oplock_response(tcon, persistent_fid,
@@ -4949,7 +4951,8 @@ void cifs_oplock_break(struct work_struct *work)
                        cifs_dbg(FYI, "Oplock release rc = %d\n", rc);
                } else
                        pr_warn_once("lease break not sent for unmounted share\n");
-       }
+       } else
+               spin_unlock(&cinode->open_file_lock);
 
        cifs_done_oplock_break(cinode);
 }
--

2.34.1

Signature · 3 lines
Thanks,

Steve
reviewer Reviewed-by
#2 lore raw
Quoted 17 lines · Steve French

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

Quoted 14 lines · Bharath SM

In case if all existing file handles are deferred handles and if all of them gets closed due to handle lease break then we dont need to send lease break acknowledgment to server, because last handle close will be considered as lease break ack.
After closing deferred handels, we check for openfile list of inode, if its empty then we skip sending lease break ack.

Fixes 59a556aebc43 ("SMB3: drop reference to cfile before sending oplock break")
---
  fs/smb/client/file.c | 7 +++++--
  1 file changed, 5 insertions(+), 2 deletions(-)
Quoted 8 lines

fs/smb/client/file.c void cifs_oplock_break(struct work_struct *work) · line 4943

Quoted 8 lines
fs/smb/client/file.c +0 -0
index 051283386e22..b8a3d60e7ac4 100644
@@ -4941,7 +4941,9 @@ void cifs_oplock_break(struct work_struct *work)
          * not bother sending an oplock release if session to server still is
          * disconnected since oplock already released by the server
          */

The comment just above is a woefully incorrect SMB1 artifact, and it's even worse now.

Here's what it currently says:

Quoted 6 lines

/*
* releasing stale oplock after recent reconnect of smb session using
* a now incorrect file handle is not a data integrity issue but do
* not bother sending an oplock release if session to server still is
* disconnected since oplock already released by the server */

One option is deleting it entirely, but I suggest:

"MS-SMB2 3.2.5.19.1 and 3.2.5.19.2 (and MS-CIFS 3.2.5.42) do not require
an acknowledgement to be sent when the file has already been closed."

Quoted 11 lines

fs/smb/client/file.c void cifs_oplock_break(struct work_struct *work) · line 4953

Quoted 11 lines
fs/smb/client/file.c +3 -1
-       if (!oplock_break_cancelled) {
+       spin_lock(&cinode->open_file_lock);
+       if (!oplock_break_cancelled && !list_empty(&cinode->openFileList)) {
+               spin_unlock(&cinode->open_file_lock);
                 /* check for server null since can race with kill_sb calling tree disconnect */
                 if (tcon->ses && tcon->ses->server) {
                         rc = tcon->ses->server->ops->oplock_response(tcon, persistent_fid,
@@ -4949,7 +4951,8 @@ void cifs_oplock_break(struct work_struct *work)
                         cifs_dbg(FYI, "Oplock release rc = %d\n", rc);
                 } else
                         pr_warn_once("lease break not sent for unmounted share\n");

Also, I think this warning is entirely pointless, in addition to being similarly incorrect post-SMB1. Delete it. You will be able to refactor the if/else branches more clearly in this case too.

With those changes considered,

Tom.

Quoted 11 lines
Quoted 9 lines
fs/smb/client/file.c +2 -2
-       }
+       } else
+               spin_unlock(&cinode->open_file_lock);
 
         cifs_done_oplock_break(cinode);
  }
--

2.34.1

author
#3 lore raw

Please find the attached patch with suggested changes.

Quoted 61 lines · Tom Talpey
Quoted 17 lines · Steve French

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

Quoted 14 lines · Bharath SM

In case if all existing file handles are deferred handles and if all of them gets closed due to handle lease break then we dont need to send lease break acknowledgment to server, because last handle close will be considered as lease break ack.
After closing deferred handels, we check for openfile list of inode, if its empty then we skip sending lease break ack.

Fixes 59a556aebc43 ("SMB3: drop reference to cfile before sending oplock break")
---
  fs/smb/client/file.c | 7 +++++--
  1 file changed, 5 insertions(+), 2 deletions(-)
Quoted 8 lines

fs/smb/client/file.c void cifs_oplock_break(struct work_struct *work) · line 4943

Quoted 8 lines
fs/smb/client/file.c +0 -0
index 051283386e22..b8a3d60e7ac4 100644
@@ -4941,7 +4941,9 @@ void cifs_oplock_break(struct work_struct *work)
          * not bother sending an oplock release if session to server still is
          * disconnected since oplock already released by the server
          */

The comment just above is a woefully incorrect SMB1 artifact, and it's even worse now.

Here's what it currently says:

Quoted 6 lines

/*
* releasing stale oplock after recent reconnect of smb session using
* a now incorrect file handle is not a data integrity issue but do
* not bother sending an oplock release if session to server still is
* disconnected since oplock already released by the server */

One option is deleting it entirely, but I suggest:

"MS-SMB2 3.2.5.19.1 and 3.2.5.19.2 (and MS-CIFS 3.2.5.42) do not require
an acknowledgement to be sent when the file has already been closed."

Quoted 11 lines

fs/smb/client/file.c void cifs_oplock_break(struct work_struct *work) · line 4953

Quoted 11 lines
fs/smb/client/file.c +3 -1
-       if (!oplock_break_cancelled) {
+       spin_lock(&cinode->open_file_lock);
+       if (!oplock_break_cancelled && !list_empty(&cinode->openFileList)) {
+               spin_unlock(&cinode->open_file_lock);
                 /* check for server null since can race with kill_sb calling tree disconnect */
                 if (tcon->ses && tcon->ses->server) {
                         rc = tcon->ses->server->ops->oplock_response(tcon, persistent_fid,
@@ -4949,7 +4951,8 @@ void cifs_oplock_break(struct work_struct *work)
                         cifs_dbg(FYI, "Oplock release rc = %d\n", rc);
                 } else
                         pr_warn_once("lease break not sent for unmounted share\n");

Also, I think this warning is entirely pointless, in addition to being similarly incorrect post-SMB1. Delete it. You will be able to refactor the if/else branches more clearly in this case too.

Quoted 16 lines

With those changes considered,

Tom.

Quoted 11 lines
Quoted 9 lines
fs/smb/client/file.c +2 -2
-       }
+       } else
+               spin_unlock(&cinode->open_file_lock);
 
         cifs_done_oplock_break(cinode);
  }
--

2.34.1

From d792b8885bc17885fcc713976aa863b4dd1314b2 Mon Sep 17 00:00:00 2001
From: Bharath SM <[email protected]>
Date: Sun, 18 Jun 2023 19:02:24 +0000
Subject: [PATCH] SMB3: Do not send lease break acknowledgment if all file
handles have been closed

In case if all existing file handles are deferred handles and if all of them gets closed due to handle lease break then we dont need to send lease break acknowledgment to server, because last handle close will be considered as lease break ack.
After closing deferred handels, we check for openfile list of inode, if its empty then we skip sending lease break ack.

Fixes 59a556aebc43 ("SMB3: drop reference to cfile before sending oplock break")
---
 fs/smb/client/file.c | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)
fs/smb/client/file.c +12 -13
index 051283386e22..1a854dc20482 100644
@@ -4936,20 +4936,19 @@ void cifs_oplock_break(struct work_struct *work)
 
 	_cifsFileInfo_put(cfile, false /* do not wait for ourself */, false);
 	/*
-	 * releasing stale oplock after recent reconnect of smb session using
-	 * a now incorrect file handle is not a data integrity issue but do
-	 * not bother sending an oplock release if session to server still is
-	 * disconnected since oplock already released by the server
+	 * MS-SMB2 3.2.5.19.1 and 3.2.5.19.2 (and MS-CIFS 3.2.5.42) do not require
+	 * an acknowledgment to be sent when the file has already been closed.
+	 * check for server null, since can race with kill_sb calling tree disconnect.
 	 */
-	if (!oplock_break_cancelled) {
-		/* check for server null since can race with kill_sb calling tree disconnect */
-		if (tcon->ses && tcon->ses->server) {
-			rc = tcon->ses->server->ops->oplock_response(tcon, persistent_fid,
-				volatile_fid, net_fid, cinode);
-			cifs_dbg(FYI, "Oplock release rc = %d\n", rc);
-		} else
-			pr_warn_once("lease break not sent for unmounted share\n");
-	}
+	spin_lock(&cinode->open_file_lock);
+	if (tcon->ses && tcon->ses->server && !oplock_break_cancelled &&
+					!list_empty(&cinode->openFileList)) {
+		spin_unlock(&cinode->open_file_lock);
+		rc = tcon->ses->server->ops->oplock_response(tcon, persistent_fid,
+						volatile_fid, net_fid, cinode);
+		cifs_dbg(FYI, "Oplock release rc = %d\n", rc);
+	} else
+		spin_unlock(&cinode->open_file_lock);
 
 	cifs_done_oplock_break(cinode);
 }
Signature · 1 line
2.34.1
reviewer
#4 lore raw
Quoted 1 line · Bharath SM

Please find the attached patch with suggested changes.

LGTM, feel free to add my previous R-B.

Tom.

Quoted 78 lines · Tom Talpey
Quoted 77 lines · Steve French
Quoted 17 lines

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

Quoted 14 lines · Bharath SM

In case if all existing file handles are deferred handles and if all of them gets closed due to handle lease break then we dont need to send lease break acknowledgment to server, because last handle close will be considered as lease break ack.
After closing deferred handels, we check for openfile list of inode, if its empty then we skip sending lease break ack.

Fixes 59a556aebc43 ("SMB3: drop reference to cfile before sending oplock break")
---
   fs/smb/client/file.c | 7 +++++--
   1 file changed, 5 insertions(+), 2 deletions(-)
Quoted 8 lines

fs/smb/client/file.c void cifs_oplock_break(struct work_struct *work) · line 4943

Quoted 8 lines
fs/smb/client/file.c +0 -0
index 051283386e22..b8a3d60e7ac4 100644
@@ -4941,7 +4941,9 @@ void cifs_oplock_break(struct work_struct *work)
           * not bother sending an oplock release if session to server still is
           * disconnected since oplock already released by the server
           */

The comment just above is a woefully incorrect SMB1 artifact, and it's even worse now.

Here's what it currently says:

Quoted 6 lines

/*
* releasing stale oplock after recent reconnect of smb session using
* a now incorrect file handle is not a data integrity issue but do
* not bother sending an oplock release if session to server still is
* disconnected since oplock already released by the server */

One option is deleting it entirely, but I suggest:

"MS-SMB2 3.2.5.19.1 and 3.2.5.19.2 (and MS-CIFS 3.2.5.42) do not require
an acknowledgement to be sent when the file has already been closed."

Quoted 11 lines

fs/smb/client/file.c void cifs_oplock_break(struct work_struct *work) · line 4953

Quoted 11 lines
fs/smb/client/file.c +3 -1
-       if (!oplock_break_cancelled) {
+       spin_lock(&cinode->open_file_lock);
+       if (!oplock_break_cancelled && !list_empty(&cinode->openFileList)) {
+               spin_unlock(&cinode->open_file_lock);
                  /* check for server null since can race with kill_sb calling tree disconnect */
                  if (tcon->ses && tcon->ses->server) {
                          rc = tcon->ses->server->ops->oplock_response(tcon, persistent_fid,
@@ -4949,7 +4951,8 @@ void cifs_oplock_break(struct work_struct *work)
                          cifs_dbg(FYI, "Oplock release rc = %d\n", rc);
                  } else
                          pr_warn_once("lease break not sent for unmounted share\n");

Also, I think this warning is entirely pointless, in addition to being similarly incorrect post-SMB1. Delete it. You will be able to refactor the if/else branches more clearly in this case too.

With those changes considered,

Tom.

Quoted 11 lines
Quoted 9 lines
fs/smb/client/file.c +2 -2
-       }
+       } else
+               spin_unlock(&cinode->open_file_lock);
 
          cifs_done_oplock_break(cinode);
   }
--

2.34.1

#5 lore raw
Quoted 73 lines · Tom Talpey
Quoted 1 line · Bharath SM

Please find the attached patch with suggested changes.

LGTM, feel free to add my previous R-B.

Tom.

Quoted 65 lines · Tom Talpey
Quoted 64 lines · Steve French
Quoted 17 lines

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

Quoted 14 lines · Bharath SM

In case if all existing file handles are deferred handles and if all of them gets closed due to handle lease break then we dont need to send lease break acknowledgment to server, because last handle close will be considered as lease break ack.
After closing deferred handels, we check for openfile list of inode, if its empty then we skip sending lease break ack.

Fixes 59a556aebc43 ("SMB3: drop reference to cfile before sending oplock break")
---
   fs/smb/client/file.c | 7 +++++--
   1 file changed, 5 insertions(+), 2 deletions(-)
Quoted 8 lines

fs/smb/client/file.c void cifs_oplock_break(struct work_struct *work) · line 4943

Quoted 8 lines
fs/smb/client/file.c +0 -0
index 051283386e22..b8a3d60e7ac4 100644
@@ -4941,7 +4941,9 @@ void cifs_oplock_break(struct work_struct *work)
           * not bother sending an oplock release if session to server still is
           * disconnected since oplock already released by the server
           */

The comment just above is a woefully incorrect SMB1 artifact, and it's even worse now.

Here's what it currently says:

Quoted 6 lines

/*
* releasing stale oplock after recent reconnect of smb session using
* a now incorrect file handle is not a data integrity issue but do
* not bother sending an oplock release if session to server still is
* disconnected since oplock already released by the server */

One option is deleting it entirely, but I suggest:

"MS-SMB2 3.2.5.19.1 and 3.2.5.19.2 (and MS-CIFS 3.2.5.42) do not require
an acknowledgement to be sent when the file has already been closed."

Quoted 11 lines

fs/smb/client/file.c void cifs_oplock_break(struct work_struct *work) · line 4953

Quoted 11 lines
fs/smb/client/file.c +3 -1
-       if (!oplock_break_cancelled) {
+       spin_lock(&cinode->open_file_lock);
+       if (!oplock_break_cancelled && !list_empty(&cinode->openFileList)) {
+               spin_unlock(&cinode->open_file_lock);
                  /* check for server null since can race with kill_sb calling tree disconnect */
                  if (tcon->ses && tcon->ses->server) {
                          rc = tcon->ses->server->ops->oplock_response(tcon, persistent_fid,
@@ -4949,7 +4951,8 @@ void cifs_oplock_break(struct work_struct *work)
                          cifs_dbg(FYI, "Oplock release rc = %d\n", rc);
                  } else
                          pr_warn_once("lease break not sent for unmounted share\n");

Also, I think this warning is entirely pointless, in addition to being similarly incorrect post-SMB1. Delete it. You will be able to refactor the if/else branches more clearly in this case too.

With those changes considered,

Hi Tom,

I'm leaning towards having the warning statement here. Although with more useful details about the inode/lease etc.
If this condition is reached, it means that the cifs_inode still has at least one handle open.
If that is the case, can the tcon/ses/server ever be NULL?

Regards,
Shyam

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines

Tom.

Quoted 11 lines
Quoted 9 lines
fs/smb/client/file.c +2 -2
-       }
+       } else
+               spin_unlock(&cinode->open_file_lock);
 
          cifs_done_oplock_break(cinode);
   }
--

2.34.1

Signature · 2 lines
Regards,
Shyam
reviewer
#6 lore raw
Quoted 75 lines · Shyam Prasad N
Quoted 73 lines · Tom Talpey
Quoted 1 line · Bharath SM

Please find the attached patch with suggested changes.

LGTM, feel free to add my previous R-B.

Tom.

Quoted 65 lines · Tom Talpey
Quoted 64 lines · Steve French
Quoted 17 lines

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

Quoted 14 lines · Bharath SM

In case if all existing file handles are deferred handles and if all of them gets closed due to handle lease break then we dont need to send lease break acknowledgment to server, because last handle close will be considered as lease break ack.
After closing deferred handels, we check for openfile list of inode, if its empty then we skip sending lease break ack.

Fixes 59a556aebc43 ("SMB3: drop reference to cfile before sending oplock break")
---
    fs/smb/client/file.c | 7 +++++--
    1 file changed, 5 insertions(+), 2 deletions(-)
Quoted 8 lines

fs/smb/client/file.c void cifs_oplock_break(struct work_struct *work) · line 4943

Quoted 8 lines
fs/smb/client/file.c +0 -0
index 051283386e22..b8a3d60e7ac4 100644
@@ -4941,7 +4941,9 @@ void cifs_oplock_break(struct work_struct *work)
            * not bother sending an oplock release if session to server still is
            * disconnected since oplock already released by the server
            */

The comment just above is a woefully incorrect SMB1 artifact, and it's even worse now.

Here's what it currently says:

Quoted 6 lines

/*
* releasing stale oplock after recent reconnect of smb session using
* a now incorrect file handle is not a data integrity issue but do
* not bother sending an oplock release if session to server still is
* disconnected since oplock already released by the server */

One option is deleting it entirely, but I suggest:

"MS-SMB2 3.2.5.19.1 and 3.2.5.19.2 (and MS-CIFS 3.2.5.42) do not require
an acknowledgement to be sent when the file has already been closed."

Quoted 11 lines

fs/smb/client/file.c void cifs_oplock_break(struct work_struct *work) · line 4953

Quoted 11 lines
fs/smb/client/file.c +3 -1
-       if (!oplock_break_cancelled) {
+       spin_lock(&cinode->open_file_lock);
+       if (!oplock_break_cancelled && !list_empty(&cinode->openFileList)) {
+               spin_unlock(&cinode->open_file_lock);
                   /* check for server null since can race with kill_sb calling tree disconnect */
                   if (tcon->ses && tcon->ses->server) {
                           rc = tcon->ses->server->ops->oplock_response(tcon, persistent_fid,
@@ -4949,7 +4951,8 @@ void cifs_oplock_break(struct work_struct *work)
                           cifs_dbg(FYI, "Oplock release rc = %d\n", rc);
                   } else
                           pr_warn_once("lease break not sent for unmounted share\n");

Also, I think this warning is entirely pointless, in addition to being similarly incorrect post-SMB1. Delete it. You will be able to refactor the if/else branches more clearly in this case too.

With those changes considered,

Quoted 7 lines

Hi Tom,

I'm leaning towards having the warning statement here. Although with more useful details about the inode/lease etc.
If this condition is reached, it means that the cifs_inode still has at least one handle open.
If that is the case, can the tcon/ses/server ever be NULL?

I don't agree, my reading is that this is a race condition with an unmount, and the tree connect and/or session is being torn down. So I don't see the point in whining to the syslog.

Besides, there's nothing the client can do to recover, or prevent the situation. Why alarm the admin? What "useful" details would impact this?

Tom.

Quoted 20 lines

Regards,
Shyam

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines

Tom.

Quoted 11 lines
Quoted 9 lines
fs/smb/client/file.c +2 -2
-       }
+       } else
+               spin_unlock(&cinode->open_file_lock);
 
           cifs_done_oplock_break(cinode);
    }
--

2.34.1

#7 lore raw

We could make the unlikely error condition (lease break race with umount) log as cifsFYI so no one would see it by default?

Quoted 115 lines · Tom Talpey
Quoted 75 lines · Shyam Prasad N
Quoted 73 lines · Tom Talpey
Quoted 1 line · Bharath SM

Please find the attached patch with suggested changes.

LGTM, feel free to add my previous R-B.

Tom.

Quoted 65 lines · Tom Talpey
Quoted 64 lines · Steve French
Quoted 17 lines

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

Quoted 14 lines · Bharath SM

In case if all existing file handles are deferred handles and if all of them gets closed due to handle lease break then we dont need to send lease break acknowledgment to server, because last handle close will be considered as lease break ack.
After closing deferred handels, we check for openfile list of inode, if its empty then we skip sending lease break ack.

Fixes 59a556aebc43 ("SMB3: drop reference to cfile before sending oplock break")
---
    fs/smb/client/file.c | 7 +++++--
    1 file changed, 5 insertions(+), 2 deletions(-)
Quoted 8 lines

fs/smb/client/file.c void cifs_oplock_break(struct work_struct *work) · line 4943

Quoted 8 lines
fs/smb/client/file.c +0 -0
index 051283386e22..b8a3d60e7ac4 100644
@@ -4941,7 +4941,9 @@ void cifs_oplock_break(struct work_struct *work)
            * not bother sending an oplock release if session to server still is
            * disconnected since oplock already released by the server
            */

The comment just above is a woefully incorrect SMB1 artifact, and it's even worse now.

Here's what it currently says:

Quoted 6 lines

/*
* releasing stale oplock after recent reconnect of smb session using
* a now incorrect file handle is not a data integrity issue but do
* not bother sending an oplock release if session to server still is
* disconnected since oplock already released by the server */

One option is deleting it entirely, but I suggest:

"MS-SMB2 3.2.5.19.1 and 3.2.5.19.2 (and MS-CIFS 3.2.5.42) do not require
an acknowledgement to be sent when the file has already been closed."

Quoted 11 lines

fs/smb/client/file.c void cifs_oplock_break(struct work_struct *work) · line 4953

Quoted 11 lines
fs/smb/client/file.c +3 -1
-       if (!oplock_break_cancelled) {
+       spin_lock(&cinode->open_file_lock);
+       if (!oplock_break_cancelled && !list_empty(&cinode->openFileList)) {
+               spin_unlock(&cinode->open_file_lock);
                   /* check for server null since can race with kill_sb calling tree disconnect */
                   if (tcon->ses && tcon->ses->server) {
                           rc = tcon->ses->server->ops->oplock_response(tcon, persistent_fid,
@@ -4949,7 +4951,8 @@ void cifs_oplock_break(struct work_struct *work)
                           cifs_dbg(FYI, "Oplock release rc = %d\n", rc);
                   } else
                           pr_warn_once("lease break not sent for unmounted share\n");

Also, I think this warning is entirely pointless, in addition to being similarly incorrect post-SMB1. Delete it. You will be able to refactor the if/else branches more clearly in this case too.

With those changes considered,

Quoted 7 lines

Hi Tom,

I'm leaning towards having the warning statement here. Although with more useful details about the inode/lease etc.
If this condition is reached, it means that the cifs_inode still has at least one handle open.
If that is the case, can the tcon/ses/server ever be NULL?

I don't agree, my reading is that this is a race condition with an unmount, and the tree connect and/or session is being torn down. So I don't see the point in whining to the syslog.

Besides, there's nothing the client can do to recover, or prevent the situation. Why alarm the admin? What "useful" details would impact this?

Tom.

Quoted 20 lines

Regards,
Shyam

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines

Tom.

Quoted 11 lines
Quoted 9 lines
fs/smb/client/file.c +2 -2
-       }
+       } else
+               spin_unlock(&cinode->open_file_lock);
 
           cifs_done_oplock_break(cinode);
    }
--

2.34.1

Signature · 3 lines
Thanks,

Steve
reviewer
#8 lore raw
Quoted 2 lines · Steve French

We could make the unlikely error condition (lease break race with umount) log as cifsFYI so no one would see it by default?

You guys obviously want the noise to stay. So, yes I'd agree that a cifsFYI is better than a pr_warn_once. The FYI is silenced by default, and it will appear every time if wanted.

Tom.

Quoted 119 lines · Tom Talpey
Quoted 115 lines · Shyam Prasad N
Quoted 75 lines · Tom Talpey
Quoted 73 lines · Bharath SM
Quoted 1 line

Please find the attached patch with suggested changes.

LGTM, feel free to add my previous R-B.

Tom.

Quoted 65 lines · Tom Talpey
Quoted 64 lines · Steve French
Quoted 17 lines

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

Quoted 14 lines · Bharath SM

In case if all existing file handles are deferred handles and if all of them gets closed due to handle lease break then we dont need to send lease break acknowledgment to server, because last handle close will be considered as lease break ack.
After closing deferred handels, we check for openfile list of inode, if its empty then we skip sending lease break ack.

Fixes 59a556aebc43 ("SMB3: drop reference to cfile before sending oplock break")
---
     fs/smb/client/file.c | 7 +++++--
     1 file changed, 5 insertions(+), 2 deletions(-)
Quoted 8 lines

fs/smb/client/file.c void cifs_oplock_break(struct work_struct *work) · line 4943

Quoted 8 lines
fs/smb/client/file.c +0 -0
index 051283386e22..b8a3d60e7ac4 100644
@@ -4941,7 +4941,9 @@ void cifs_oplock_break(struct work_struct *work)
             * not bother sending an oplock release if session to server still is
             * disconnected since oplock already released by the server
             */

The comment just above is a woefully incorrect SMB1 artifact, and it's even worse now.

Here's what it currently says:

Quoted 6 lines

/*
* releasing stale oplock after recent reconnect of smb session using
* a now incorrect file handle is not a data integrity issue but do
* not bother sending an oplock release if session to server still is
* disconnected since oplock already released by the server */

One option is deleting it entirely, but I suggest:

"MS-SMB2 3.2.5.19.1 and 3.2.5.19.2 (and MS-CIFS 3.2.5.42) do not require
an acknowledgement to be sent when the file has already been closed."

Quoted 11 lines

fs/smb/client/file.c void cifs_oplock_break(struct work_struct *work) · line 4953

Quoted 11 lines
fs/smb/client/file.c +3 -1
-       if (!oplock_break_cancelled) {
+       spin_lock(&cinode->open_file_lock);
+       if (!oplock_break_cancelled && !list_empty(&cinode->openFileList)) {
+               spin_unlock(&cinode->open_file_lock);
                    /* check for server null since can race with kill_sb calling tree disconnect */
                    if (tcon->ses && tcon->ses->server) {
                            rc = tcon->ses->server->ops->oplock_response(tcon, persistent_fid,
@@ -4949,7 +4951,8 @@ void cifs_oplock_break(struct work_struct *work)
                            cifs_dbg(FYI, "Oplock release rc = %d\n", rc);
                    } else
                            pr_warn_once("lease break not sent for unmounted share\n");

Also, I think this warning is entirely pointless, in addition to being similarly incorrect post-SMB1. Delete it. You will be able to refactor the if/else branches more clearly in this case too.

With those changes considered,

Quoted 7 lines

Hi Tom,

I'm leaning towards having the warning statement here. Although with more useful details about the inode/lease etc.
If this condition is reached, it means that the cifs_inode still has at least one handle open.
If that is the case, can the tcon/ses/server ever be NULL?

I don't agree, my reading is that this is a race condition with an unmount, and the tree connect and/or session is being torn down. So I don't see the point in whining to the syslog.

Besides, there's nothing the client can do to recover, or prevent the situation. Why alarm the admin? What "useful" details would impact this?

Tom.

Quoted 20 lines

Regards,
Shyam

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines

Tom.

Quoted 11 lines
Quoted 9 lines
fs/smb/client/file.c +2 -2
-       }
+       } else
+               spin_unlock(&cinode->open_file_lock);
 
            cifs_done_oplock_break(cinode);
     }
--

2.34.1

#9 lore raw

In discussing with Bharath today he reminded me that the message would be noisier than for unmount races - so I lean toward leaving it as is (ie no extra debug message for this path - ie the current version of the patch in for-next, which matches Tom's suggestion)

Quoted 130 lines · Tom Talpey
Quoted 2 lines · Steve French

We could make the unlikely error condition (lease break race with umount) log as cifsFYI so no one would see it by default?

You guys obviously want the noise to stay. So, yes I'd agree that a cifsFYI is better than a pr_warn_once. The FYI is silenced by default, and it will appear every time if wanted.

Tom.

Quoted 119 lines · Tom Talpey
Quoted 115 lines · Shyam Prasad N
Quoted 75 lines · Tom Talpey
Quoted 73 lines · Bharath SM
Quoted 1 line

Please find the attached patch with suggested changes.

LGTM, feel free to add my previous R-B.

Tom.

Quoted 65 lines · Tom Talpey
Quoted 64 lines · Steve French
Quoted 17 lines

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

Quoted 14 lines · Bharath SM

In case if all existing file handles are deferred handles and if all of them gets closed due to handle lease break then we dont need to send lease break acknowledgment to server, because last handle close will be considered as lease break ack.
After closing deferred handels, we check for openfile list of inode, if its empty then we skip sending lease break ack.

Fixes 59a556aebc43 ("SMB3: drop reference to cfile before sending oplock break")
---
     fs/smb/client/file.c | 7 +++++--
     1 file changed, 5 insertions(+), 2 deletions(-)
Quoted 8 lines

fs/smb/client/file.c void cifs_oplock_break(struct work_struct *work) · line 4943

Quoted 8 lines
fs/smb/client/file.c +0 -0
index 051283386e22..b8a3d60e7ac4 100644
@@ -4941,7 +4941,9 @@ void cifs_oplock_break(struct work_struct *work)
             * not bother sending an oplock release if session to server still is
             * disconnected since oplock already released by the server
             */

The comment just above is a woefully incorrect SMB1 artifact, and it's even worse now.

Here's what it currently says:

Quoted 6 lines

/*
* releasing stale oplock after recent reconnect of smb session using
* a now incorrect file handle is not a data integrity issue but do
* not bother sending an oplock release if session to server still is
* disconnected since oplock already released by the server */

One option is deleting it entirely, but I suggest:

"MS-SMB2 3.2.5.19.1 and 3.2.5.19.2 (and MS-CIFS 3.2.5.42) do not require
an acknowledgement to be sent when the file has already been closed."

Quoted 11 lines

fs/smb/client/file.c void cifs_oplock_break(struct work_struct *work) · line 4953

Quoted 11 lines
fs/smb/client/file.c +3 -1
-       if (!oplock_break_cancelled) {
+       spin_lock(&cinode->open_file_lock);
+       if (!oplock_break_cancelled && !list_empty(&cinode->openFileList)) {
+               spin_unlock(&cinode->open_file_lock);
                    /* check for server null since can race with kill_sb calling tree disconnect */
                    if (tcon->ses && tcon->ses->server) {
                            rc = tcon->ses->server->ops->oplock_response(tcon, persistent_fid,
@@ -4949,7 +4951,8 @@ void cifs_oplock_break(struct work_struct *work)
                            cifs_dbg(FYI, "Oplock release rc = %d\n", rc);
                    } else
                            pr_warn_once("lease break not sent for unmounted share\n");

Also, I think this warning is entirely pointless, in addition to being similarly incorrect post-SMB1. Delete it. You will be able to refactor the if/else branches more clearly in this case too.

With those changes considered,

Quoted 7 lines

Hi Tom,

I'm leaning towards having the warning statement here. Although with more useful details about the inode/lease etc.
If this condition is reached, it means that the cifs_inode still has at least one handle open.
If that is the case, can the tcon/ses/server ever be NULL?

I don't agree, my reading is that this is a race condition with an unmount, and the tree connect and/or session is being torn down. So I don't see the point in whining to the syslog.

Besides, there's nothing the client can do to recover, or prevent the situation. Why alarm the admin? What "useful" details would impact this?

Tom.

Quoted 20 lines

Regards,
Shyam

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines

Tom.

Quoted 11 lines
Quoted 9 lines
fs/smb/client/file.c +2 -2
-       }
+       } else
+               spin_unlock(&cinode->open_file_lock);
 
            cifs_done_oplock_break(cinode);
     }
--

2.34.1

Signature · 3 lines
Thanks,

Steve