xref: /illumos-gate/usr/src/cmd/smbsrv/dtrace/smb2-trace.d (revision b69c34dad3717624ff6b4f32b71014ee05b6a678)
1 #!/usr/sbin/dtrace -s
2 /*
3  * This file and its contents are supplied under the terms of the
4  * Common Development and Distribution License ("CDDL"), version 1.0.
5  * You may only use this file in accordance with the terms of version
6  * 1.0 of the CDDL.
7  *
8  * A full copy of the text of the CDDL should have accompanied this
9  * source.  A copy of the CDDL is also available via the Internet at
10  * http://www.illumos.org/license/CDDL.
11  */
12 
13 /*
14  * Copyright 2018 Nexenta Systems, Inc.  All rights reserved.
15  */
16 
17 /*
18  * Example using the "smb2" dtrace provider.
19  * Traces all SMB commands.
20  *
21  * All these probes provide:
22  *	args[0]  conninfo_t
23  *	args[1]  smb2opinfo_t
24  * Some also provide one of: (not used here)
25  *	args[2]  smb_open_args_t
26  *	args[2]  smb_rw_args_t
27  *
28  * Usage: smb2-trace.d [<client ip>|all [<share path>|all] [<zone id>]]]
29  *
30  * example: smb2_trace.d 192.168.012.001 mypool_fs1  0
31  *
32  * It is valid to specify <client ip> or <share path> as "all" to
33  * print data for all clients and/or all shares.
34  * Omitting <zone id> will print data for all zones.
35  */
36 
37 #pragma D option defaultargs
38 
39 dtrace:::BEGIN
40 {
41 	all_clients = (($$1 == NULL) || ($$1 == "all")) ? 1 : 0;
42 	all_shares = (($$2 == NULL) || ($$2 == "all")) ? 1 : 0;
43 	all_zones = ($$3 == NULL) ? 1 : 0;
44 
45 	client = $$1;
46 	share = $$2;
47 	zoneid = $3;
48 
49 	printf("%Y - client=%s share=%s zone=%s)\n", walltimestamp,
50 	    (all_clients) ? "all" : client,
51 	    (all_shares) ? "all" : share,
52 	    (all_zones) ? "all" : $$3);
53 }
54 
55 smb2:::op-*-start
56 / ((all_clients == 1) || (args[0]->ci_remote == client)) &&
57    ((all_shares == 1) || (args[1]->soi_share == share)) &&
58    ((all_zones == 1) || (args[1]->soi_zoneid == zoneid)) /
59 {
60 	printf("clnt=%s mid=0x%x uid=0x%x tid=0x%x\n",
61 	       args[0]->ci_remote,
62 	       args[1]->soi_mid,
63 	       args[1]->soi_uid,
64 	       args[1]->soi_tid);
65 }
66 
67 smb2:::op-*-done
68 / ((all_clients == 1) || (args[0]->ci_remote == client)) &&
69    ((all_shares == 1) || (args[1]->soi_share == share)) &&
70    ((all_zones == 1) || (args[1]->soi_zoneid == zoneid)) /
71 {
72 	printf("clnt=%s mid=0x%x status=0x%x\n",
73 	       args[0]->ci_remote,
74 	       args[1]->soi_mid,
75 	       args[1]->soi_status);
76 }
77 
78 dtrace:::END
79 {
80 }
81