smb3: show beginning time for per share stats
authorSteve French <stfrench@microsoft.com>
Wed, 17 Jan 2024 22:15:18 +0000 (16:15 -0600)
committerSteve French <stfrench@microsoft.com>
Fri, 26 Apr 2024 16:55:38 +0000 (11:55 -0500)
[ Upstream commit d8392c203e84ec7daa2afecdb8f4db69bc32416a ]

In analyzing problems, one missing piece of debug data is when the
mount occurred.  A related problem is when collecting stats we don't
know the  period of time the stats covered, ie when this set of stats
for the tcon started to be collected.  To make debugging easier track
the stats begin time. Set it when the mount occurred at mount time,
and reset it to current time whenever stats are reset. For example,

...
1) \\localhost\test
SMBs: 14 since 2024-01-17 22:17:30 UTC
Bytes read: 0  Bytes written: 0
Open files: 0 total (local), 0 open on server
TreeConnects: 1 total 0 failed
TreeDisconnects: 0 total 0 failed
...
2) \\localhost\scratch
SMBs: 24 since 2024-01-17 22:16:04 UTC
Bytes read: 0  Bytes written: 0
Open files: 0 total (local), 0 open on server
TreeConnects: 1 total 0 failed
TreeDisconnects: 0 total 0 failed
...

Note the time "since ... UTC" is now displayed in /proc/fs/cifs/Stats
for each share that is mounted.

Suggested-by: Shyam Prasad N <sprasad@microsoft.com>
Reviewed-by: Bharath SM <bharathsm@microsoft.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
Stable-dep-of: 062a7f0ff46e ("smb: client: guarantee refcounted children from parent session")
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/smb/client/cifs_debug.c
fs/smb/client/cifsglob.h
fs/smb/client/misc.c

index 6c85edb8635d01daaccb2fb2cb8c2fda2f1a1d8c..c53d516459fc45311bcdccc54c2e412d033ddba5 100644 (file)
@@ -663,6 +663,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
                                        spin_lock(&tcon->stat_lock);
                                        tcon->bytes_read = 0;
                                        tcon->bytes_written = 0;
+                                       tcon->stats_from_time = ktime_get_real_seconds();
                                        spin_unlock(&tcon->stat_lock);
                                        if (server->ops->clear_stats)
                                                server->ops->clear_stats(tcon);
@@ -743,8 +744,9 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
                                seq_printf(m, "\n%d) %s", i, tcon->tree_name);
                                if (tcon->need_reconnect)
                                        seq_puts(m, "\tDISCONNECTED ");
-                               seq_printf(m, "\nSMBs: %d",
-                                          atomic_read(&tcon->num_smbs_sent));
+                               seq_printf(m, "\nSMBs: %d since %ptTs UTC",
+                                          atomic_read(&tcon->num_smbs_sent),
+                                          &tcon->stats_from_time);
                                if (server->ops->print_stats)
                                        server->ops->print_stats(m, tcon);
                        }
index a878b1e5aa313a2ea35811652822baca6112c8b5..01d7031194671d6d99bdc0c451e51f031bd4f9d1 100644 (file)
@@ -1208,6 +1208,7 @@ struct cifs_tcon {
        __u64    bytes_read;
        __u64    bytes_written;
        spinlock_t stat_lock;  /* protects the two fields above */
+       time64_t stats_from_time;
        FILE_SYSTEM_DEVICE_INFO fsDevInfo;
        FILE_SYSTEM_ATTRIBUTE_INFO fsAttrInfo; /* ok if fs name truncated */
        FILE_SYSTEM_UNIX_INFO fsUnixInfo;
index ef573e3f8e52ab0e2feed7e6054a18246ccb9c0f..51413cb00e1998e6c8e075888aca068fe8cd336c 100644 (file)
@@ -140,6 +140,7 @@ tcon_info_alloc(bool dir_leases_enabled)
        spin_lock_init(&ret_buf->stat_lock);
        atomic_set(&ret_buf->num_local_opens, 0);
        atomic_set(&ret_buf->num_remote_opens, 0);
+       ret_buf->stats_from_time = ktime_get_real_seconds();
 #ifdef CONFIG_CIFS_DFS_UPCALL
        INIT_LIST_HEAD(&ret_buf->dfs_ses_list);
 #endif