xref: /illumos-gate/usr/src/cmd/smbsrv/dtrace/smb-trace.d (revision c686756220120076a07be0dcce54be698101a3d1)
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 "smb" dtrace provider.
19  * Traces all SMB commands.
20  *
21  * All these probes provide:
22  *	args[0]  conninfo_t
23  *	args[1]  smbopinfo_t
24  * Some also provide one of: (not used here)
25  *	args[2]  smb_name_args_t
26  *	args[2]  smb_open_args_t
27  *	args[2]  smb_rw_args_t
28  *
29  * Usage: smb-trace.d [<client ip>|all [<share path>|all] [<zone id>]]]
30  *
31  * example: smb_trace.d 192.168.012.001 mypool_fs1  0
32  *
33  * It is valid to specify <client ip> or <share path> as "all" to
34  * print data for all clients and/or all shares.
35  * Omitting <zone id> will print data for all zones.
36  */
37 
38 #pragma D option defaultargs
39 
40 dtrace:::BEGIN
41 {
42 	all_clients = (($$1 == NULL) || ($$1 == "all")) ? 1 : 0;
43 	all_shares = (($$2 == NULL) || ($$2 == "all")) ? 1 : 0;
44 	all_zones = ($$3 == NULL) ? 1 : 0;
45 
46 	client = $$1;
47 	share = $$2;
48 	zoneid = $3;
49 
50 	printf("%Y - client=%s share=%s zone=%s)\n", walltimestamp,
51 	    (all_clients) ? "all" : client,
52 	    (all_shares) ? "all" : share,
53 	    (all_zones) ? "all" : $$3);
54 }
55 
56 smb:::op-*-start
57 / ((all_clients) || (args[0]->ci_remote == client)) &&
58    ((all_shares) || (args[1]->soi_share == share)) &&
59    ((all_zones) || (args[1]->soi_zoneid == zoneid)) /
60 {
61 	printf("clnt=%s mid=0x%x uid=0x%x tid=0x%x\n",
62 	       args[0]->ci_remote,
63 	       args[1]->soi_mid,
64 	       args[1]->soi_uid,
65 	       args[1]->soi_tid);
66 }
67 
68 smb:::op-*-done
69 / ((all_clients) || (args[0]->ci_remote == client)) &&
70    ((all_shares) || (args[1]->soi_share == share)) &&
71    ((all_zones) || (args[1]->soi_zoneid == zoneid)) /
72 {
73 	printf("clnt=%s mid=0x%x status=0x%x\n",
74 	       args[0]->ci_remote,
75 	       args[1]->soi_mid,
76 	       args[1]->soi_status);
77 }
78 
79 dtrace:::END
80 {
81 }
82