From: Bharath SM <bharathsm.hsk@gmail.com>
To: linux-cifs@vger.kernel.org, smfrench@gmail.com,
sprasad@microsoft.com, pc@manguebit.com, ematsumiya@suse.de,
henrique.carvalho@suse.com, bharathsm@microsoft.com
Subject: [PATCH 1/4] smb: client: add tracepoints for lock operations
Date: Tue, 14 Apr 2026 21:48:02 +0530 [thread overview]
Message-ID: <20260414161805.233686-1-bharathsm@microsoft.com> (raw)
Add tracepoints when lock operations are sent to the
server with details including lock offset, length, and flags.
smb3_lock_enter: before sending lock request
smb3_lock_done: lock acquired successfully
smb3_lock_err: lock request failed
smb3_lock_cached: lock granted from local cache (no server roundtrip)
Signed-off-by: Bharath SM <bharathsm@microsoft.com>
---
fs/smb/client/file.c | 10 +++++--
fs/smb/client/smb2pdu.c | 15 ++++++++++-
fs/smb/client/trace.h | 58 ++++++++++++++++++++++++++++++++++++++++-
3 files changed, 79 insertions(+), 4 deletions(-)
diff --git a/fs/smb/client/file.c b/fs/smb/client/file.c
index 5d5b49468aff..66a678a0e89f 100644
--- a/fs/smb/client/file.c
+++ b/fs/smb/client/file.c
@@ -1712,7 +1712,7 @@ cifs_lock_add(struct cifsFileInfo *cfile, struct cifsLockInfo *lock)
*/
static int
cifs_lock_add_if(struct cifsFileInfo *cfile, struct cifsLockInfo *lock,
- bool wait)
+ bool wait, unsigned int xid)
{
struct cifsLockInfo *conf_lock;
struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry));
@@ -1727,7 +1727,13 @@ cifs_lock_add_if(struct cifsFileInfo *cfile, struct cifsLockInfo *lock,
lock->type, lock->flags, &conf_lock,
CIFS_LOCK_OP);
if (!exist && cinode->can_cache_brlcks) {
+ struct cifs_tcon *tcon = tlink_tcon(cfile->tlink);
+
list_add_tail(&lock->llist, &cfile->llist->locks);
+ trace_smb3_lock_cached(xid, cfile->fid.persistent_fid,
+ tcon->tid, tcon->ses->Suid,
+ lock->offset, lock->length,
+ lock->type, 1, 0);
up_write(&cinode->lock_sem);
return rc;
}
@@ -2342,7 +2348,7 @@ cifs_setlk(struct file *file, struct file_lock *flock, __u32 type,
if (!lock)
return -ENOMEM;
- rc = cifs_lock_add_if(cfile, lock, wait_flag);
+ rc = cifs_lock_add_if(cfile, lock, wait_flag, xid);
if (rc < 0) {
kfree(lock);
return rc;
diff --git a/fs/smb/client/smb2pdu.c b/fs/smb/client/smb2pdu.c
index 5188218c25be..61bae531959a 100644
--- a/fs/smb/client/smb2pdu.c
+++ b/fs/smb/client/smb2pdu.c
@@ -6277,6 +6277,11 @@ smb2_lockv(const unsigned int xid, struct cifs_tcon *tcon,
smb2_set_replay(server, &rqst);
}
+ trace_smb3_lock_enter(xid, persist_fid, tcon->tid, tcon->ses->Suid,
+ le64_to_cpu(buf[0].Offset),
+ le64_to_cpu(buf[0].Length),
+ le32_to_cpu(buf[0].Flags), num_lock, 0);
+
rc = cifs_send_recv(xid, tcon->ses, server,
&rqst, &resp_buf_type, flags,
&rsp_iov);
@@ -6285,7 +6290,15 @@ smb2_lockv(const unsigned int xid, struct cifs_tcon *tcon,
cifs_dbg(FYI, "Send error in smb2_lockv = %d\n", rc);
cifs_stats_fail_inc(tcon, SMB2_LOCK_HE);
trace_smb3_lock_err(xid, persist_fid, tcon->tid,
- tcon->ses->Suid, rc);
+ tcon->ses->Suid,
+ le64_to_cpu(buf[0].Offset),
+ le64_to_cpu(buf[0].Length),
+ le32_to_cpu(buf[0].Flags), num_lock, rc);
+ } else {
+ trace_smb3_lock_done(xid, persist_fid, tcon->tid, tcon->ses->Suid,
+ le64_to_cpu(buf[0].Offset),
+ le64_to_cpu(buf[0].Length),
+ le32_to_cpu(buf[0].Flags), num_lock, 0);
}
if (is_replayable_error(rc) &&
diff --git a/fs/smb/client/trace.h b/fs/smb/client/trace.h
index acfbb63086ea..242c9da0283e 100644
--- a/fs/smb/client/trace.h
+++ b/fs/smb/client/trace.h
@@ -670,9 +670,65 @@ DEFINE_EVENT(smb3_fd_err_class, smb3_##name, \
TP_ARGS(xid, fid, tid, sesid, rc))
DEFINE_SMB3_FD_ERR_EVENT(flush_err);
-DEFINE_SMB3_FD_ERR_EVENT(lock_err);
DEFINE_SMB3_FD_ERR_EVENT(close_err);
+DECLARE_EVENT_CLASS(smb3_lock_class,
+ TP_PROTO(unsigned int xid,
+ __u64 fid,
+ __u32 tid,
+ __u64 sesid,
+ __u64 offset,
+ __u64 len,
+ __u32 flags,
+ __u32 num_lock,
+ int rc),
+ TP_ARGS(xid, fid, tid, sesid, offset, len, flags, num_lock, rc),
+ TP_STRUCT__entry(
+ __field(unsigned int, xid)
+ __field(__u64, fid)
+ __field(__u32, tid)
+ __field(__u64, sesid)
+ __field(__u64, offset)
+ __field(__u64, len)
+ __field(__u32, flags)
+ __field(__u32, num_lock)
+ __field(int, rc)
+ ),
+ TP_fast_assign(
+ __entry->xid = xid;
+ __entry->fid = fid;
+ __entry->tid = tid;
+ __entry->sesid = sesid;
+ __entry->offset = offset;
+ __entry->len = len;
+ __entry->flags = flags;
+ __entry->num_lock = num_lock;
+ __entry->rc = rc;
+ ),
+ TP_printk("xid=%u sid=0x%llx tid=0x%x fid=0x%llx offset=0x%llx len=0x%llx flags=0x%x num_lock=%u rc=%d",
+ __entry->xid, __entry->sesid, __entry->tid, __entry->fid,
+ __entry->offset, __entry->len, __entry->flags, __entry->num_lock,
+ __entry->rc)
+)
+
+#define DEFINE_SMB3_LOCK_EVENT(name) \
+DEFINE_EVENT(smb3_lock_class, smb3_##name, \
+ TP_PROTO(unsigned int xid, \
+ __u64 fid, \
+ __u32 tid, \
+ __u64 sesid, \
+ __u64 offset, \
+ __u64 len, \
+ __u32 flags, \
+ __u32 num_lock, \
+ int rc), \
+ TP_ARGS(xid, fid, tid, sesid, offset, len, flags, num_lock, rc))
+
+DEFINE_SMB3_LOCK_EVENT(lock_enter);
+DEFINE_SMB3_LOCK_EVENT(lock_done);
+DEFINE_SMB3_LOCK_EVENT(lock_err);
+DEFINE_SMB3_LOCK_EVENT(lock_cached);
+
/*
* For handle based query/set info calls
*/
--
2.48.1
next reply other threads:[~2026-04-14 16:18 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-14 16:18 Bharath SM [this message]
2026-04-14 16:18 ` [PATCH 2/4] smb: client: add tracepoint for local lock conflicts Bharath SM
2026-04-14 16:18 ` [PATCH 3/4] smb: client: add oplock level to smb3_open_done tracepoint Bharath SM
2026-04-14 16:18 ` [PATCH 4/4] smb: client: add tracepoints for deferred handle caching Bharath SM
2026-04-14 23:10 ` [PATCH 1/4] smb: client: add tracepoints for lock operations Steve French
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=20260414161805.233686-1-bharathsm@microsoft.com \
--to=bharathsm.hsk@gmail.com \
--cc=bharathsm@microsoft.com \
--cc=ematsumiya@suse.de \
--cc=henrique.carvalho@suse.com \
--cc=linux-cifs@vger.kernel.org \
--cc=pc@manguebit.com \
--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