Skip to contentSkip to conversation

smb: client: add tracepoints for lock operations

PATCH Applied Bharath SM 2 participants 5 messages Apr 14

Subsystems (2)
lore
Share & tools
lore

Bharath SM

author
#0 lore raw

PATCH 1/4 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)

---
 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(-)
fs/smb/client/file.c +8 -2
index 5d5b49468aff..66a678a0e89f 100644
@@ -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;
fs/smb/client/smb2pdu.c +14 -1
index 5188218c25be..61bae531959a 100644
@@ -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) &&
fs/smb/client/trace.h +57 -1

66 lines not on this page · raw message

Signature · 1 line
2.48.1
author
#1 lore raw

PATCH 2/4 smb: client: add tracepoint for local lock conflicts

Add smb3_lock_conflict tracepoint that fires when a byte-range lock request conflicts with an existing cached lock. This helps debug lock contention issues when locks are cached locally due to oplocks/leases.

The trace includes both the requested and conflicting lock details:
- Requested: offset, length, type
- Conflicting: offset, length, type, pid (lock holder)

---
 fs/smb/client/file.c  |  3 +++
 fs/smb/client/trace.h | 35 +++++++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+)
fs/smb/client/file.c +3 -0
index 66a678a0e89f..4662592801b0 100644
@@ -1631,6 +1631,9 @@ cifs_find_fid_lock_conflict(struct cifs_fid_locks *fdlocks, __u64 offset,
 			continue;
 		if (conf_lock)
 			*conf_lock = li;
+		trace_smb3_lock_conflict(cfile->fid.persistent_fid,
+					 offset, length, type,
+					 li->offset, li->length, li->type, li->pid);
 		return true;
 	}
 	return false;
fs/smb/client/trace.h +35 -0
index 242c9da0283e..cb5ce1316eba 100644
@@ -729,6 +729,41 @@ DEFINE_SMB3_LOCK_EVENT(lock_done);
 DEFINE_SMB3_LOCK_EVENT(lock_err);
 DEFINE_SMB3_LOCK_EVENT(lock_cached);
 
+TRACE_EVENT(smb3_lock_conflict,
+	TP_PROTO(__u64 fid,
+		__u64 req_offset,
+		__u64 req_len,
+		__u8 req_type,
+		__u64 conf_offset,
+		__u64 conf_len,
+		__u16 conf_type,
+		__u32 conf_pid),
+	TP_ARGS(fid, req_offset, req_len, req_type, conf_offset, conf_len, conf_type, conf_pid),
+	TP_STRUCT__entry(
+		__field(__u64, fid)
+		__field(__u64, req_offset)
+		__field(__u64, req_len)
+		__field(__u8, req_type)
+		__field(__u64, conf_offset)
+		__field(__u64, conf_len)
+		__field(__u16, conf_type)
+		__field(__u32, conf_pid)
+	),
+	TP_fast_assign(
+		__entry->fid = fid;
+		__entry->req_offset = req_offset;
+		__entry->req_len = req_len;
+		__entry->req_type = req_type;
+		__entry->conf_offset = conf_offset;
+		__entry->conf_len = conf_len;
+		__entry->conf_type = conf_type;
+		__entry->conf_pid = conf_pid;
+	),
+	TP_printk("fid=0x%llx req=[0x%llx:0x%llx] type=0x%x conflicts with [0x%llx:0x%llx] type=0x%x pid=%u",
+		__entry->fid, __entry->req_offset, __entry->req_len, __entry->req_type,
+		__entry->conf_offset, __entry->conf_len, __entry->conf_type, __entry->conf_pid)
+);
+
 /*
  * For handle based query/set info calls
  */
Signature · 1 line
2.48.1
author
#2 lore raw

PATCH 3/4 smb: client: add oplock level to smb3_open_done tracepoint

In reply to Bharath SM

Add an oplock field to the smb3_open_done_class trace event to show the granted oplock/lease level. Move the trace_smb3_open_done call after smb2_parse_contexts() so the oplock value reflects the parsed lease state (R/W/H flags).

---
 fs/smb/client/smb2pdu.c | 10 ++++++----
 fs/smb/client/trace.h   | 16 ++++++++++------
 2 files changed, 16 insertions(+), 10 deletions(-)
fs/smb/client/smb2pdu.c +6 -4
index 61bae531959a..96140f6d30b5 100644
@@ -3044,7 +3044,8 @@ int smb311_posix_mkdir(const unsigned int xid, struct inode *inode,
 	}
 
 	trace_smb3_posix_mkdir_done(xid, rsp->PersistentFileId, tcon->tid, ses->Suid,
-				    CREATE_NOT_FILE, FILE_WRITE_ATTRIBUTES);
+				    CREATE_NOT_FILE, FILE_WRITE_ATTRIBUTES,
+				    rsp->OplockLevel);
 
 	SMB2_close(xid, tcon, rsp->PersistentFileId, rsp->VolatileFileId);
 
@@ -3321,9 +3322,6 @@ SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path,
 		goto creat_exit;
 	} else if (rsp == NULL) /* unlikely to happen, but safer to check */
 		goto creat_exit;
-	else
-		trace_smb3_open_done(xid, rsp->PersistentFileId, tcon->tid, ses->Suid,
-				     oparms->create_options, oparms->desired_access);
 
 	atomic_inc(&tcon->num_remote_opens);
 	oparms->fid->persistent_fid = rsp->PersistentFileId;
@@ -3348,6 +3346,10 @@ SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path,
 
 	rc = smb2_parse_contexts(server, &rsp_iov, &oparms->fid->epoch,
 				 oparms->fid->lease_key, oplock, buf, posix);
+
+	trace_smb3_open_done(xid, rsp->PersistentFileId, tcon->tid, ses->Suid,
+			     oparms->create_options, oparms->desired_access,
+			     *oplock);
 creat_exit:
 	SMB2_open_free(&rqst);
 	free_rsp_buf(resp_buftype, rsp);
fs/smb/client/trace.h +10 -6
index cb5ce1316eba..57abf5fca26c 100644
@@ -1321,8 +1321,9 @@ DECLARE_EVENT_CLASS(smb3_open_done_class,
 		__u32	tid,
 		__u64	sesid,
 		int	create_options,
-		int	desired_access),
-	TP_ARGS(xid, fid, tid, sesid, create_options, desired_access),
+		int	desired_access,
+		__u8	oplock),
+	TP_ARGS(xid, fid, tid, sesid, create_options, desired_access, oplock),
 	TP_STRUCT__entry(
 		__field(unsigned int, xid)
 		__field(__u64, fid)
@@ -1330,6 +1331,7 @@ DECLARE_EVENT_CLASS(smb3_open_done_class,
 		__field(__u64, sesid)
 		__field(int, create_options)
 		__field(int, desired_access)
+		__field(__u8, oplock)
 	),
 	TP_fast_assign(
 		__entry->xid = xid;
@@ -1338,10 +1340,11 @@ DECLARE_EVENT_CLASS(smb3_open_done_class,
 		__entry->sesid = sesid;
 		__entry->create_options = create_options;
 		__entry->desired_access = desired_access;
+		__entry->oplock = oplock;
 	),
-	TP_printk("xid=%u sid=0x%llx tid=0x%x fid=0x%llx cr_opts=0x%x des_access=0x%x",
+	TP_printk("xid=%u sid=0x%llx tid=0x%x fid=0x%llx cr_opts=0x%x des_access=0x%x oplock=0x%x",
 		__entry->xid, __entry->sesid, __entry->tid, __entry->fid,
-		__entry->create_options, __entry->desired_access)
+		__entry->create_options, __entry->desired_access, __entry->oplock)
 )
 
 #define DEFINE_SMB3_OPEN_DONE_EVENT(name)        \
@@ -1351,8 +1354,9 @@ DEFINE_EVENT(smb3_open_done_class, smb3_##name,  \
 		__u32	tid,			\
 		__u64	sesid,			\
 		int	create_options,		\
-		int	desired_access),	\
-	TP_ARGS(xid, fid, tid, sesid, create_options, desired_access))
+		int	desired_access,		\
+		__u8	oplock),		\
+	TP_ARGS(xid, fid, tid, sesid, create_options, desired_access, oplock))
 
 DEFINE_SMB3_OPEN_DONE_EVENT(open_done);
 DEFINE_SMB3_OPEN_DONE_EVENT(posix_mkdir_done);
Signature · 1 line
2.48.1
author
#3 lore raw

PATCH 4/4 smb: client: add tracepoints for deferred handle caching

In reply to Bharath SM

Add tracepoints to observe handle caching behavior.

smb3_open_cached: emitted when an open reuses a cached handle from a previous deferred close, avoiding a network round-trip

smb3_close_cached: emitted when a close is deferred (handle cached for potential reuse by subsequent opens)

---
 fs/smb/client/file.c  |  8 +++++++
 fs/smb/client/trace.h | 51 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 59 insertions(+)
fs/smb/client/file.c +8 -0
index 4662592801b0..79819241ebfd 100644
@@ -1083,6 +1083,9 @@ int cifs_open(struct inode *inode, struct file *file)
 		rc = cfile ? 0 : -ENOENT;
 	}
 	if (rc == 0) {
+		trace_smb3_open_cached(xid, tcon->tid, tcon->ses->Suid,
+				       cfile->fid.persistent_fid,
+				       file->f_flags, cfile->f_flags);
 		file->private_data = cfile;
 		spin_lock(&CIFS_I(inode)->deferred_lock);
 		cifs_del_deferred_close(cfile);
@@ -1442,6 +1445,7 @@ int cifs_close(struct inode *inode, struct file *file)
 	struct cifsInodeInfo *cinode = CIFS_I(inode);
 	struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
 	struct cifs_deferred_close *dclose;
+	struct cifs_tcon *tcon;
 
 	cifs_fscache_unuse_inode_cookie(inode, file->f_mode & FMODE_WRITE);
 
@@ -1468,6 +1472,10 @@ int cifs_close(struct inode *inode, struct file *file)
 					cifsFileInfo_get(cfile);
 			} else {
 				/* Deferred close for files */
+				tcon = tlink_tcon(cfile->tlink);
+				trace_smb3_close_cached(tcon->tid, tcon->ses->Suid,
+						cfile->fid.persistent_fid,
+						cifs_sb->ctx->closetimeo);
 				queue_delayed_work(deferredclose_wq,
 						&cfile->deferred, cifs_sb->ctx->closetimeo);
 				cfile->deferred_close_scheduled = true;
fs/smb/client/trace.h +51 -0

57 lines not on this page · raw message

Signature · 1 line
2.48.1
Applied
#4 lore raw
In reply to Bharath SM

merged into cifs-2.6.git for-next

Quoted 159 lines · Bharath SM

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)

---
 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(-)
fs/smb/client/file.c +8 -2
index 5d5b49468aff..66a678a0e89f 100644
@@ -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;
fs/smb/client/smb2pdu.c +14 -1
index 5188218c25be..61bae531959a 100644
@@ -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) &&
fs/smb/client/trace.h +57 -2
index acfbb63086ea..242c9da0283e 100644
@@ -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

Signature · 3 lines
Thanks,

Steve