Skip to content

Commit d60622e

Browse files
committed
CIFS: Allow SMB2 statistics to be tracked
Since there are only 19 command codes, it also is easier to track by exact command code than it was for cifs. Signed-off-by: Pavel Shilovsky <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 44c5818 commit d60622e

File tree

3 files changed

+91
-3
lines changed

3 files changed

+91
-3
lines changed

fs/cifs/cifsglob.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
#include "cifsacl.h"
2929
#include <crypto/internal/hash.h>
3030
#include <linux/scatterlist.h>
31+
#ifdef CONFIG_CIFS_SMB2
32+
#include "smb2pdu.h"
33+
#endif
3134

3235
/*
3336
* The sizes of various internal tables and strings
@@ -592,6 +595,12 @@ struct cifs_tcon {
592595
atomic_t num_acl_get;
593596
atomic_t num_acl_set;
594597
} cifs_stats;
598+
#ifdef CONFIG_CIFS_SMB2
599+
struct {
600+
atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
601+
atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
602+
} smb2_stats;
603+
#endif /* CONFIG_CIFS_SMB2 */
595604
} stats;
596605
#ifdef CONFIG_CIFS_STATS2
597606
unsigned long long time_writes;

fs/cifs/smb2ops.c

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,85 @@ smb2_can_echo(struct TCP_Server_Info *server)
213213
return server->echoes;
214214
}
215215

216+
static void
217+
smb2_clear_stats(struct cifs_tcon *tcon)
218+
{
219+
#ifdef CONFIG_CIFS_STATS
220+
int i;
221+
for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
222+
atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
223+
atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
224+
}
225+
#endif
226+
}
227+
228+
static void
229+
smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
230+
{
231+
#ifdef CONFIG_CIFS_STATS
232+
atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
233+
atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
234+
seq_printf(m, "\nNegotiates: %d sent %d failed",
235+
atomic_read(&sent[SMB2_NEGOTIATE_HE]),
236+
atomic_read(&failed[SMB2_NEGOTIATE_HE]));
237+
seq_printf(m, "\nSessionSetups: %d sent %d failed",
238+
atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
239+
atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
240+
#define SMB2LOGOFF 0x0002 /* trivial request/resp */
241+
seq_printf(m, "\nLogoffs: %d sent %d failed",
242+
atomic_read(&sent[SMB2_LOGOFF_HE]),
243+
atomic_read(&failed[SMB2_LOGOFF_HE]));
244+
seq_printf(m, "\nTreeConnects: %d sent %d failed",
245+
atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
246+
atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
247+
seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
248+
atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
249+
atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
250+
seq_printf(m, "\nCreates: %d sent %d failed",
251+
atomic_read(&sent[SMB2_CREATE_HE]),
252+
atomic_read(&failed[SMB2_CREATE_HE]));
253+
seq_printf(m, "\nCloses: %d sent %d failed",
254+
atomic_read(&sent[SMB2_CLOSE_HE]),
255+
atomic_read(&failed[SMB2_CLOSE_HE]));
256+
seq_printf(m, "\nFlushes: %d sent %d failed",
257+
atomic_read(&sent[SMB2_FLUSH_HE]),
258+
atomic_read(&failed[SMB2_FLUSH_HE]));
259+
seq_printf(m, "\nReads: %d sent %d failed",
260+
atomic_read(&sent[SMB2_READ_HE]),
261+
atomic_read(&failed[SMB2_READ_HE]));
262+
seq_printf(m, "\nWrites: %d sent %d failed",
263+
atomic_read(&sent[SMB2_WRITE_HE]),
264+
atomic_read(&failed[SMB2_WRITE_HE]));
265+
seq_printf(m, "\nLocks: %d sent %d failed",
266+
atomic_read(&sent[SMB2_LOCK_HE]),
267+
atomic_read(&failed[SMB2_LOCK_HE]));
268+
seq_printf(m, "\nIOCTLs: %d sent %d failed",
269+
atomic_read(&sent[SMB2_IOCTL_HE]),
270+
atomic_read(&failed[SMB2_IOCTL_HE]));
271+
seq_printf(m, "\nCancels: %d sent %d failed",
272+
atomic_read(&sent[SMB2_CANCEL_HE]),
273+
atomic_read(&failed[SMB2_CANCEL_HE]));
274+
seq_printf(m, "\nEchos: %d sent %d failed",
275+
atomic_read(&sent[SMB2_ECHO_HE]),
276+
atomic_read(&failed[SMB2_ECHO_HE]));
277+
seq_printf(m, "\nQueryDirectories: %d sent %d failed",
278+
atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
279+
atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
280+
seq_printf(m, "\nChangeNotifies: %d sent %d failed",
281+
atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
282+
atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
283+
seq_printf(m, "\nQueryInfos: %d sent %d failed",
284+
atomic_read(&sent[SMB2_QUERY_INFO_HE]),
285+
atomic_read(&failed[SMB2_QUERY_INFO_HE]));
286+
seq_printf(m, "\nSetInfos: %d sent %d failed",
287+
atomic_read(&sent[SMB2_SET_INFO_HE]),
288+
atomic_read(&failed[SMB2_SET_INFO_HE]));
289+
seq_printf(m, "\nOplockBreaks: %d sent %d failed",
290+
atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
291+
atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
292+
#endif
293+
}
294+
216295
struct smb_version_operations smb21_operations = {
217296
.setup_request = smb2_setup_request,
218297
.setup_async_request = smb2_setup_async_request,
@@ -225,6 +304,8 @@ struct smb_version_operations smb21_operations = {
225304
.find_mid = smb2_find_mid,
226305
.check_message = smb2_check_message,
227306
.dump_detail = smb2_dump_detail,
307+
.clear_stats = smb2_clear_stats,
308+
.print_stats = smb2_print_stats,
228309
.need_neg = smb2_need_neg,
229310
.negotiate = smb2_negotiate,
230311
.sess_setup = SMB2_sess_setup,

fs/cifs/smb2pdu.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,10 +282,8 @@ small_smb2_init(__le16 smb2_command, struct cifs_tcon *tcon,
282282

283283
if (tcon != NULL) {
284284
#ifdef CONFIG_CIFS_STATS2
285-
/*
286285
uint16_t com_code = le16_to_cpu(smb2_command);
287286
cifs_stats_inc(&tcon->stats.smb2_stats.smb2_com_sent[com_code]);
288-
*/
289287
#endif
290288
cifs_stats_inc(&tcon->num_smbs_sent);
291289
}
@@ -677,7 +675,7 @@ SMB2_logoff(const unsigned int xid, struct cifs_ses *ses)
677675

678676
static inline void cifs_stats_fail_inc(struct cifs_tcon *tcon, uint16_t code)
679677
{
680-
/* cifs_stats_inc(&tcon->stats.smb2_stats.smb2_com_fail[code]); */
678+
cifs_stats_inc(&tcon->stats.smb2_stats.smb2_com_failed[code]);
681679
}
682680

683681
#define MAX_SHARENAME_LENGTH (255 /* server */ + 80 /* share */ + 1 /* NULL */)

0 commit comments

Comments
 (0)