]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
smb: client: add tracepoints for lock operations
authorBharath SM <bharathsm@microsoft.com>
Tue, 14 Apr 2026 16:18:02 +0000 (21:48 +0530)
committerSteve French <stfrench@microsoft.com>
Tue, 14 Apr 2026 18:04:21 +0000 (13:04 -0500)
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>
Signed-off-by: Steve French <stfrench@microsoft.com>
fs/smb/client/file.c
fs/smb/client/smb2pdu.c
fs/smb/client/trace.h

index 5d5b49468aff9bd5718a5b36a589c5dc64f0bb3f..66a678a0e89f48ca92465a06badd76d76b60f4f0 100644 (file)
@@ -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 @@ try_again:
                                        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;
index 5188218c25be4202b631a37df7cb06f831abf674..61bae531959a491baacdd6a95e24b3386c4d9161 100644 (file)
@@ -6277,6 +6277,11 @@ replay_again:
                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 @@ replay_again:
                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) &&
index acfbb63086ea23eecc2ef5f19751fffd0c414c20..242c9da0283ea94c682b5c0586d22c172e36866f 100644 (file)
@@ -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
  */