smb: client: add tracepoints for lock operations

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>
This commit is contained in:
Bharath SM 2026-04-14 21:48:02 +05:30 committed by Steve French
parent 15e9e00a5a
commit eb4d3691fc
3 changed files with 79 additions and 4 deletions

View 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 @@ 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;

View File

@ -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) &&

View 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
*/