Skip to content

Commit eb4d369

Browse files
bharathsm-mssmfrench
authored andcommitted
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>
1 parent 15e9e00 commit eb4d369

3 files changed

Lines changed: 79 additions & 4 deletions

File tree

fs/smb/client/file.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1712,7 +1712,7 @@ cifs_lock_add(struct cifsFileInfo *cfile, struct cifsLockInfo *lock)
17121712
*/
17131713
static int
17141714
cifs_lock_add_if(struct cifsFileInfo *cfile, struct cifsLockInfo *lock,
1715-
bool wait)
1715+
bool wait, unsigned int xid)
17161716
{
17171717
struct cifsLockInfo *conf_lock;
17181718
struct cifsInodeInfo *cinode = CIFS_I(d_inode(cfile->dentry));
@@ -1727,7 +1727,13 @@ cifs_lock_add_if(struct cifsFileInfo *cfile, struct cifsLockInfo *lock,
17271727
lock->type, lock->flags, &conf_lock,
17281728
CIFS_LOCK_OP);
17291729
if (!exist && cinode->can_cache_brlcks) {
1730+
struct cifs_tcon *tcon = tlink_tcon(cfile->tlink);
1731+
17301732
list_add_tail(&lock->llist, &cfile->llist->locks);
1733+
trace_smb3_lock_cached(xid, cfile->fid.persistent_fid,
1734+
tcon->tid, tcon->ses->Suid,
1735+
lock->offset, lock->length,
1736+
lock->type, 1, 0);
17311737
up_write(&cinode->lock_sem);
17321738
return rc;
17331739
}
@@ -2342,7 +2348,7 @@ cifs_setlk(struct file *file, struct file_lock *flock, __u32 type,
23422348
if (!lock)
23432349
return -ENOMEM;
23442350

2345-
rc = cifs_lock_add_if(cfile, lock, wait_flag);
2351+
rc = cifs_lock_add_if(cfile, lock, wait_flag, xid);
23462352
if (rc < 0) {
23472353
kfree(lock);
23482354
return rc;

fs/smb/client/smb2pdu.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6277,6 +6277,11 @@ smb2_lockv(const unsigned int xid, struct cifs_tcon *tcon,
62776277
smb2_set_replay(server, &rqst);
62786278
}
62796279

6280+
trace_smb3_lock_enter(xid, persist_fid, tcon->tid, tcon->ses->Suid,
6281+
le64_to_cpu(buf[0].Offset),
6282+
le64_to_cpu(buf[0].Length),
6283+
le32_to_cpu(buf[0].Flags), num_lock, 0);
6284+
62806285
rc = cifs_send_recv(xid, tcon->ses, server,
62816286
&rqst, &resp_buf_type, flags,
62826287
&rsp_iov);
@@ -6285,7 +6290,15 @@ smb2_lockv(const unsigned int xid, struct cifs_tcon *tcon,
62856290
cifs_dbg(FYI, "Send error in smb2_lockv = %d\n", rc);
62866291
cifs_stats_fail_inc(tcon, SMB2_LOCK_HE);
62876292
trace_smb3_lock_err(xid, persist_fid, tcon->tid,
6288-
tcon->ses->Suid, rc);
6293+
tcon->ses->Suid,
6294+
le64_to_cpu(buf[0].Offset),
6295+
le64_to_cpu(buf[0].Length),
6296+
le32_to_cpu(buf[0].Flags), num_lock, rc);
6297+
} else {
6298+
trace_smb3_lock_done(xid, persist_fid, tcon->tid, tcon->ses->Suid,
6299+
le64_to_cpu(buf[0].Offset),
6300+
le64_to_cpu(buf[0].Length),
6301+
le32_to_cpu(buf[0].Flags), num_lock, 0);
62896302
}
62906303

62916304
if (is_replayable_error(rc) &&

fs/smb/client/trace.h

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,9 +670,65 @@ DEFINE_EVENT(smb3_fd_err_class, smb3_##name, \
670670
TP_ARGS(xid, fid, tid, sesid, rc))
671671

672672
DEFINE_SMB3_FD_ERR_EVENT(flush_err);
673-
DEFINE_SMB3_FD_ERR_EVENT(lock_err);
674673
DEFINE_SMB3_FD_ERR_EVENT(close_err);
675674

675+
DECLARE_EVENT_CLASS(smb3_lock_class,
676+
TP_PROTO(unsigned int xid,
677+
__u64 fid,
678+
__u32 tid,
679+
__u64 sesid,
680+
__u64 offset,
681+
__u64 len,
682+
__u32 flags,
683+
__u32 num_lock,
684+
int rc),
685+
TP_ARGS(xid, fid, tid, sesid, offset, len, flags, num_lock, rc),
686+
TP_STRUCT__entry(
687+
__field(unsigned int, xid)
688+
__field(__u64, fid)
689+
__field(__u32, tid)
690+
__field(__u64, sesid)
691+
__field(__u64, offset)
692+
__field(__u64, len)
693+
__field(__u32, flags)
694+
__field(__u32, num_lock)
695+
__field(int, rc)
696+
),
697+
TP_fast_assign(
698+
__entry->xid = xid;
699+
__entry->fid = fid;
700+
__entry->tid = tid;
701+
__entry->sesid = sesid;
702+
__entry->offset = offset;
703+
__entry->len = len;
704+
__entry->flags = flags;
705+
__entry->num_lock = num_lock;
706+
__entry->rc = rc;
707+
),
708+
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",
709+
__entry->xid, __entry->sesid, __entry->tid, __entry->fid,
710+
__entry->offset, __entry->len, __entry->flags, __entry->num_lock,
711+
__entry->rc)
712+
)
713+
714+
#define DEFINE_SMB3_LOCK_EVENT(name) \
715+
DEFINE_EVENT(smb3_lock_class, smb3_##name, \
716+
TP_PROTO(unsigned int xid, \
717+
__u64 fid, \
718+
__u32 tid, \
719+
__u64 sesid, \
720+
__u64 offset, \
721+
__u64 len, \
722+
__u32 flags, \
723+
__u32 num_lock, \
724+
int rc), \
725+
TP_ARGS(xid, fid, tid, sesid, offset, len, flags, num_lock, rc))
726+
727+
DEFINE_SMB3_LOCK_EVENT(lock_enter);
728+
DEFINE_SMB3_LOCK_EVENT(lock_done);
729+
DEFINE_SMB3_LOCK_EVENT(lock_err);
730+
DEFINE_SMB3_LOCK_EVENT(lock_cached);
731+
676732
/*
677733
* For handle based query/set info calls
678734
*/

0 commit comments

Comments
 (0)