[PATCH] cifs: add lease tracking to the cached root fid

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Use a read lease for the cached root fid so that we can detect
when the fid changes and thus we should not longer keep it cached.

We detect the lease break in the context of the demultiplex loop
when we receive an unsolicited lease break that matches the lease key
for the root fid and setting a flag to indicate the fid is no longer
valid.

On next call to open_shroot() we forcibly close the fid and eventually
re-open it, getting a new lease.

Signed-off-by: Ronnie Sahlberg <lsahlber@xxxxxxxxxx>
---
 fs/cifs/cifsglob.h |  1 +
 fs/cifs/smb2misc.c |  9 +++++++++
 fs/cifs/smb2ops.c  | 10 +++++++++-
 3 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
index 4f674b75bbc8..b9ec91ef3cba 100644
--- a/fs/cifs/cifsglob.h
+++ b/fs/cifs/cifsglob.h
@@ -982,6 +982,7 @@ struct cifs_tcon {
 #endif
 	struct list_head pending_opens;	/* list of incomplete opens */
 	bool valid_root_fid:1;	/* Do we have a useable root fid */
+	bool broken_root_fid:1;	/* Has the lease been broken? */
 	struct mutex prfid_mutex; /* prevents reopen race after dead ses*/
 	struct cifs_fid *prfid;	/* handle to the directory at top of share */
 	/* BB add field for back pointer to sb struct(s)? */
diff --git a/fs/cifs/smb2misc.c b/fs/cifs/smb2misc.c
index f7f3ad760401..33b82de50540 100644
--- a/fs/cifs/smb2misc.c
+++ b/fs/cifs/smb2misc.c
@@ -608,6 +608,15 @@ smb2_is_valid_lease_break(char *buffer)
 					spin_unlock(&cifs_tcp_ses_lock);
 					return true;
 				}
+				if (tcon->valid_root_fid &&
+				    !memcmp(rsp->LeaseKey,
+					    tcon->prfid->lease_key,
+					    SMB2_LEASE_KEY_SIZE)) {
+				  tcon->broken_root_fid = true;
+				  spin_unlock(&tcon->open_file_lock);
+				  spin_unlock(&cifs_tcp_ses_lock);
+				  return true;
+				}
 				spin_unlock(&tcon->open_file_lock);
 			}
 		}
diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
index ceaa358723f0..c6edc99faac7 100644
--- a/fs/cifs/smb2ops.c
+++ b/fs/cifs/smb2ops.c
@@ -331,9 +331,16 @@ int open_shroot(unsigned int xid, struct cifs_tcon *tcon, struct cifs_fid *pfid)
 	struct cifs_open_parms oparams;
 	int rc;
 	__le16 srch_path = 0; /* Null - since an open of top of share */
-	u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
+	u8 oplock = SMB2_OPLOCK_LEVEL_II;
 
 	mutex_lock(&tcon->prfid_mutex);
+	if (tcon->valid_root_fid && tcon->broken_root_fid) {
+		cifs_dbg(FYI, "clear cached root file handle\n");
+		SMB2_close(0, tcon, pfid->persistent_fid, pfid->volatile_fid);
+		tcon->valid_root_fid = false;
+		tcon->broken_root_fid = false;
+	}
+
 	if (tcon->valid_root_fid) {
 		cifs_dbg(FYI, "found a cached root file handle\n");
 		memcpy(pfid, tcon->prfid, sizeof(struct cifs_fid));
@@ -352,6 +359,7 @@ int open_shroot(unsigned int xid, struct cifs_tcon *tcon, struct cifs_fid *pfid)
 	if (rc == 0) {
 		memcpy(tcon->prfid, pfid, sizeof(struct cifs_fid));
 		tcon->valid_root_fid = true;
+		tcon->broken_root_fid = false;
 	}
 	mutex_unlock(&tcon->prfid_mutex);
 	return rc;
-- 
2.13.3

--
To unsubscribe from this list: send the line "unsubscribe linux-cifs" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux