1 #!/usr/sbin/dtrace -s
   2 
   3 /*
   4  * This file and its contents are supplied under the terms of the
   5  * Common Development and Distribution License ("CDDL"), version 1.0.
   6  * You may only use this file in accordance with the terms of version
   7  * 1.0 of the CDDL.
   8  *
   9  * A full copy of the text of the CDDL should have accompanied this
  10  * source.  A copy of the CDDL is also available via the Internet at
  11  * http://www.illumos.org/license/CDDL.
  12  */
  13 
  14 /*
  15  * Copyright 2018 Nexenta Systems, Inc.  All rights reserved.
  16  */
  17 
  18 /*
  19  * Print input and output values for each NFSv3 andf NFSv4 operation,
  20  * optionally for a specified client and share.
  21  *
  22  * usage:   nfs_test.d
  23  * usage:   nfs_test.d <client ip>   <share path>
  24  * example: nfs_test.d 192.168.123.1 /mypool/fs1
  25  *
  26  * It is valid to specify <client ip> or <share path> as "all" to
  27  * print data for all clients and/or all shares.
  28  * example: nfs_test.d 192.168.123.1 all
  29  * example: nfs_test.d all /mypool/fs1
  30  * example: nfs_test.d all all
  31  */
  32 
  33 /*
  34  * Unfortunately, trying to write this script using wildcards, for example:
  35  *      nfsv3:::op-*-start {}
  36  *      nfsv3:::op-*-done {}
  37  * prints the operation-specific args[2] structure as the incorrect type.
  38  * Until this is resolved it is necessary to explicitly list each operation.
  39  *
  40  * See nfs-time.d for an example of using the wildcard format when there are
  41  * no operation-specific args (args[2]) being traced.
  42  */
  43 
  44 #pragma D option flowindent
  45 #pragma D option defaultargs
  46 
  47 dtrace:::BEGIN
  48 {
  49         client = ($$1 == NULL) ? "all" : $$1;
  50         share = ($$2 == NULL) ? "all" : $$2;
  51         printf("%Y - client=%s share=%s\n", walltimestamp, client, share);
  52 }
  53 
  54 nfsv3:::op-getattr-start,
  55 nfsv3:::op-setattr-start,
  56 nfsv3:::op-lookup-start,
  57 nfsv3:::op-access-start,
  58 nfsv3:::op-commit-start,
  59 nfsv3:::op-create-start,
  60 nfsv3:::op-fsinfo-start,
  61 nfsv3:::op-fsstat-start,
  62 nfsv3:::op-link-start,
  63 nfsv3:::op-mkdir-start,
  64 nfsv3:::op-mknod-start,
  65 nfsv3:::op-pathconf-start,
  66 nfsv3:::op-read-start,
  67 nfsv3:::op-readdir-start,
  68 nfsv3:::op-readdirplus-start,
  69 nfsv3:::op-readlink-start,
  70 nfsv3:::op-remove-start,
  71 nfsv3:::op-rename-start,
  72 nfsv3:::op-rmdir-start,
  73 nfsv3:::op-symlink-start,
  74 nfsv3:::op-write-start
  75 / ((client == "all") || (args[0]->ci_remote == client)) &&
  76    ((share == "all") || (args[1]->noi_shrpath == share)) /
  77 {
  78         printf("\n");
  79         print(*args[0]);
  80         printf("\n");
  81         print(*args[1]);
  82         printf("\n");
  83         print(*args[2]);
  84         printf("\n");
  85 }
  86 
  87 nfsv3:::op-getattr-done,
  88 nfsv3:::op-setattr-done,
  89 nfsv3:::op-lookup-done,
  90 nfsv3:::op-access-done,
  91 nfsv3:::op-commit-done,
  92 nfsv3:::op-create-done,
  93 nfsv3:::op-fsinfo-done,
  94 nfsv3:::op-fsstat-done,
  95 nfsv3:::op-link-done,
  96 nfsv3:::op-mkdir-done,
  97 nfsv3:::op-mknod-done,
  98 nfsv3:::op-pathconf-done,
  99 nfsv3:::op-read-done,
 100 nfsv3:::op-readdir-done,
 101 nfsv3:::op-readdirplus-done,
 102 nfsv3:::op-readlink-done,
 103 nfsv3:::op-remove-done,
 104 nfsv3:::op-rename-done,
 105 nfsv3:::op-rmdir-done,
 106 nfsv3:::op-symlink-done,
 107 nfsv3:::op-write-done
 108 / ((client == "all") || (args[0]->ci_remote == client)) &&
 109    ((share == "all") || (args[1]->noi_shrpath == share)) /
 110 {
 111         /*
 112         printf("\n");
 113         print(*args[0]);
 114         printf("\n");
 115         print(*args[1]);
 116         */
 117         printf("\n");
 118         print(*args[2]);
 119         printf("\n");
 120 }
 121 
 122 nfsv4:::op-access-start,
 123 nfsv4:::op-close-start,
 124 nfsv4:::op-commit-start,
 125 nfsv4:::op-create-start,
 126 nfsv4:::op-delegpurge-start,
 127 nfsv4:::op-delegreturn-start,
 128 nfsv4:::op-getattr-start,
 129 nfsv4:::op-link-start,
 130 nfsv4:::op-lock-start,
 131 nfsv4:::op-lockt-start,
 132 nfsv4:::op-locku-start,
 133 nfsv4:::op-lookup-start,
 134 nfsv4:::op-nverify-start,
 135 nfsv4:::op-open-start,
 136 nfsv4:::op-open-confirm-start,
 137 nfsv4:::op-open-downgrade-start,
 138 nfsv4:::op-openattr-start,
 139 nfsv4:::op-putfh-start,
 140 nfsv4:::op-read-start,
 141 nfsv4:::op-readdir-start,
 142 nfsv4:::op-release-lockowner-start,
 143 nfsv4:::op-remove-start,
 144 nfsv4:::op-rename-start,
 145 nfsv4:::op-renew-start,
 146 nfsv4:::op-secinfo-start,
 147 nfsv4:::op-setattr-start,
 148 nfsv4:::op-setclientid-start,
 149 nfsv4:::op-setclientid-confirm-start,
 150 nfsv4:::op-verify-start,
 151 nfsv4:::op-write-start
 152 / ((client == "all") || (args[0]->ci_remote == client)) &&
 153    ((share == "all") || (args[1]->noi_shrpath == share)) /
 154 {
 155         printf("\n");
 156         print(*args[0]);
 157         printf("\n");
 158         print(*args[1]);
 159         printf("\n");
 160         print(*args[2]);
 161         printf("\n");
 162 }
 163 
 164 /* These operations do not have args[2] */
 165 nfsv4:::op-getfh-start,
 166 nfsv4:::op-lookupp-start,
 167 nfsv4:::op-putpubfh-start,
 168 nfsv4:::op-putrootfh-start,
 169 nfsv4:::op-readlink-start,
 170 nfsv4:::op-restorefh-start,
 171 nfsv4:::op-savefh-start
 172 / ((client == "all") || (args[0]->ci_remote == client)) &&
 173    ((share == "all") || (args[1]->noi_shrpath == share)) /
 174 {
 175         printf("\n");
 176         print(*args[0]);
 177         printf("\n");
 178         print(*args[1]);
 179         printf("\n");
 180 }
 181 
 182 
 183 nfsv4:::op-access-done,
 184 nfsv4:::op-close-done,
 185 nfsv4:::op-commit-done,
 186 nfsv4:::op-create-done,
 187 nfsv4:::op-delegpurge-done,
 188 nfsv4:::op-delegreturn-done,
 189 nfsv4:::op-getattr-done,
 190 nfsv4:::op-getfh-done,
 191 nfsv4:::op-link-done,
 192 nfsv4:::op-lock-done,
 193 nfsv4:::op-lockt-done,
 194 nfsv4:::op-locku-done,
 195 nfsv4:::op-lookup-done,
 196 nfsv4:::op-lookupp-done,
 197 nfsv4:::op-nverify-done,
 198 nfsv4:::op-open-done,
 199 nfsv4:::op-open-confirm-done,
 200 nfsv4:::op-open-downgrade-done,
 201 nfsv4:::op-openattr-done,
 202 nfsv4:::op-putfh-done,
 203 nfsv4:::op-putpubfh-done,
 204 nfsv4:::op-putrootfh-done,
 205 nfsv4:::op-read-done,
 206 nfsv4:::op-readdir-done,
 207 nfsv4:::op-readlink-done,
 208 nfsv4:::op-release-lockowner-done,
 209 nfsv4:::op-remove-done,
 210 nfsv4:::op-rename-done,
 211 nfsv4:::op-renew-done,
 212 nfsv4:::op-restorefh-done,
 213 nfsv4:::op-savefh-done,
 214 nfsv4:::op-secinfo-done,
 215 nfsv4:::op-setattr-done,
 216 nfsv4:::op-setclientid-done,
 217 nfsv4:::op-setclientid-confirm-done,
 218 nfsv4:::op-verify-done,
 219 nfsv4:::op-write-done
 220 / ((client == "all") || (args[0]->ci_remote == client)) &&
 221    ((share == "all") || (args[1]->noi_shrpath == share)) /
 222 {
 223         /*
 224         printf("\n");
 225         print(*args[0]);
 226         printf("\n");
 227         print(*args[1]);
 228         */
 229         printf("\n");
 230         print(*args[2]);
 231         printf("\n");
 232 }
 233 
 234 dtrace:::END
 235 {
 236 }