Linux CIFS filesystem development
 help / color / mirror / Atom feed
From: Bharath SM <bharathsm.hsk@gmail.com>
To: linux-cifs@vger.kernel.org, sprasad@microsoft.com, smfrench@gmail.com
Cc: Bharath SM <bharathsm@microsoft.com>
Subject: [PATCH 3/3] smb: client: show directory lease state in /proc/fs/cifs/open_dirs
Date: Thu, 30 Oct 2025 22:31:16 +0530	[thread overview]
Message-ID: <20251030170116.31239-3-bharathsm@microsoft.com> (raw)
In-Reply-To: <20251030170116.31239-1-bharathsm@microsoft.com>

Expose the SMB directory lease bits in the cached-dir proc
output for debugging purposes.

Signed-off-by: Bharath SM <bharathsm@microsoft.com>
---
 fs/smb/client/cached_dir.c |  7 +++++++
 fs/smb/client/cached_dir.h |  1 +
 fs/smb/client/cifs_debug.c | 23 +++++++++++++++++++----
 3 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/fs/smb/client/cached_dir.c b/fs/smb/client/cached_dir.c
index b8ac7b7faf61..1703b5477fec 100644
--- a/fs/smb/client/cached_dir.c
+++ b/fs/smb/client/cached_dir.c
@@ -66,6 +66,7 @@ static struct cached_fid *find_or_create_cached_dir(struct cached_fids *cfids,
 	 * zero.
 	 */
 	cfid->has_lease = true;
+	cfid->lease_state = 0;
 
 	return cfid;
 }
@@ -350,6 +351,7 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,
 		spin_unlock(&cfids->cfid_list_lock);
 		goto oshr_free;
 	}
+	cfid->lease_state = oplock;
 	qi_rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base;
 	if (le32_to_cpu(qi_rsp->OutputBufferLength) < sizeof(struct smb2_file_all_info)) {
 		spin_unlock(&cfids->cfid_list_lock);
@@ -388,6 +390,7 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,
 			 * lease. Release one here, and the second below.
 			 */
 			cfid->has_lease = false;
+			cfid->lease_state = 0;
 			kref_put(&cfid->refcount, smb2_close_cached_fid);
 		}
 		spin_unlock(&cfids->cfid_list_lock);
@@ -478,6 +481,7 @@ void drop_cached_dir_by_name(const unsigned int xid, struct cifs_tcon *tcon,
 	spin_lock(&cfid->cfids->cfid_list_lock);
 	if (cfid->has_lease) {
 		cfid->has_lease = false;
+		cfid->lease_state = 0;
 		kref_put(&cfid->refcount, smb2_close_cached_fid);
 	}
 	spin_unlock(&cfid->cfids->cfid_list_lock);
@@ -577,6 +581,7 @@ void invalidate_all_cached_dirs(struct cifs_tcon *tcon)
 			 * so steal that reference.
 			 */
 			cfid->has_lease = false;
+			cfid->lease_state = 0;
 		} else
 			kref_get(&cfid->refcount);
 	}
@@ -632,6 +637,7 @@ bool cached_dir_lease_break(struct cifs_tcon *tcon, __u8 lease_key[16])
 			    cfid->fid.lease_key,
 			    SMB2_LEASE_KEY_SIZE)) {
 			cfid->has_lease = false;
+			cfid->lease_state = 0;
 			cfid->time = 0;
 			/*
 			 * We found a lease remove it from the list
@@ -738,6 +744,7 @@ static void cfids_laundromat_worker(struct work_struct *work)
 				 * server. Steal that reference.
 				 */
 				cfid->has_lease = false;
+				cfid->lease_state = 0;
 			} else
 				kref_get(&cfid->refcount);
 		}
diff --git a/fs/smb/client/cached_dir.h b/fs/smb/client/cached_dir.h
index 1e383db7c337..dd12e67870be 100644
--- a/fs/smb/client/cached_dir.h
+++ b/fs/smb/client/cached_dir.h
@@ -40,6 +40,7 @@ struct cached_fid {
 	bool is_open:1;
 	bool on_list:1;
 	bool file_all_info_is_valid:1;
+	u8 lease_state;
 	unsigned long time; /* jiffies of when lease was taken */
 	unsigned long last_access_time; /* jiffies of when last accessed */
 	struct kref refcount;
diff --git a/fs/smb/client/cifs_debug.c b/fs/smb/client/cifs_debug.c
index 7fdcaf9feb16..3ff17513f363 100644
--- a/fs/smb/client/cifs_debug.c
+++ b/fs/smb/client/cifs_debug.c
@@ -19,6 +19,7 @@
 #include "cifs_debug.h"
 #include "cifsfs.h"
 #include "fs_context.h"
+#include "smb2pdu.h"
 #ifdef CONFIG_CIFS_DFS_UPCALL
 #include "dfs_cache.h"
 #endif
@@ -320,11 +321,14 @@ static int cifs_debug_dirs_proc_show(struct seq_file *m, void *v)
 	struct cifs_tcon *tcon;
 	struct cached_fids *cfids;
 	struct cached_fid *cfid;
+	char lease[4];
+	int n;
+	u8 lease_state;
 	LIST_HEAD(entry);
 
 	seq_puts(m, "# Version:1\n");
 	seq_puts(m, "# Format:\n");
-	seq_puts(m, "# <tree id> <sess id> <persistent fid> <lease-key> <path>\n");
+	seq_puts(m, "# <tree id> <sess id> <persistent fid> <lease> <lease-key> <path>\n");
 
 	spin_lock(&cifs_tcp_ses_lock);
 	list_for_each(stmp, &cifs_tcp_ses_list) {
@@ -343,17 +347,28 @@ static int cifs_debug_dirs_proc_show(struct seq_file *m, void *v)
 						(unsigned long)atomic_long_read(&cfids->total_dirents_entries),
 						(unsigned long long)atomic64_read(&cfids->total_dirents_bytes));
 				list_for_each_entry(cfid, &cfids->entries, entry) {
-					seq_printf(m, "0x%x 0x%llx 0x%llx ",
+					lease_state = cfid->has_lease ? cfid->lease_state : 0;
+					n = 0;
+					if (lease_state & SMB2_LEASE_READ_CACHING_HE)
+						lease[n++] = 'R';
+					if (lease_state & SMB2_LEASE_HANDLE_CACHING_HE)
+						lease[n++] = 'H';
+					if (lease_state & SMB2_LEASE_WRITE_CACHING_HE)
+						lease[n++] = 'W';
+					lease[n] = '\0';
+
+					seq_printf(m, "0x%x 0x%llx 0x%llx %s ",
 						tcon->tid,
 						ses->Suid,
-						cfid->fid.persistent_fid);
+						cfid->fid.persistent_fid,
+						n ? lease : "NONE");
 					if (cfid->has_lease)
 						seq_printf(m, "%pUl ", cfid->fid.lease_key);
 					else
 						seq_puts(m, "- ");
 					seq_printf(m, "%s", cfid->path);
 					if (cfid->file_all_info_is_valid)
-						seq_printf(m, "\tvalid file info");
+						seq_puts(m, " valid file info");
 					if (cfid->dirents.is_valid)
 						seq_printf(m, ", valid dirents");
 					if (!list_empty(&cfid->dirents.entries))
-- 
2.48.1


  parent reply	other threads:[~2025-10-30 17:01 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-30 17:01 [PATCH 1/3] smb: client: show smb lease key in open_files output Bharath SM
2025-10-30 17:01 ` [PATCH 2/3] smb: client: show smb lease key in open_dirs output Bharath SM
2025-10-30 17:01 ` Bharath SM [this message]
2025-10-30 21:56   ` [PATCH 3/3] smb: client: show directory lease state in /proc/fs/cifs/open_dirs Paulo Alcantara
2025-10-30 22:08     ` Enzo Matsumiya
2025-10-30 22:14       ` Paulo Alcantara
2025-10-31  3:18       ` Shyam Prasad N
2025-10-31 12:55         ` Enzo Matsumiya
2025-10-31 17:32           ` Steve French
2025-10-31  3:19     ` Shyam Prasad N
2025-10-31  7:31       ` Bharath SM

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251030170116.31239-3-bharathsm@microsoft.com \
    --to=bharathsm.hsk@gmail.com \
    --cc=bharathsm@microsoft.com \
    --cc=linux-cifs@vger.kernel.org \
    --cc=smfrench@gmail.com \
    --cc=sprasad@microsoft.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox