1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 *
25 * Copyright 2020 RackTop Systems, Inc.
26 */
27
28 #include <sys/types.h>
29 #include <sys/kstat.h>
30 #include <sys/zone.h>
31 #include <sys/kmem.h>
32 #include <sys/systm.h>
33
34 #include <nfs/nfs.h>
35 #include <nfs/nfs4_kprot.h>
36
37 /*
38 * Key to retrieve per-zone data corresponding to NFS kstats consumed by
39 * nfsstat(8).
40 */
41 zone_key_t nfsstat_zone_key;
42
43 /*
44 * Convenience routine to create a named kstat associated with zoneid, named
45 * module:0:name:"misc", using the provided template to initialize the names
46 * and values of the stats.
47 */
48 static kstat_named_t *
nfsstat_zone_init_common(zoneid_t zoneid,const char * module,int vers,const char * name,const kstat_named_t * template,size_t template_size)49 nfsstat_zone_init_common(zoneid_t zoneid, const char *module, int vers,
50 const char *name, const kstat_named_t *template,
51 size_t template_size)
52 {
53 kstat_t *ksp;
54 kstat_named_t *ks_data;
55
56 ks_data = kmem_alloc(template_size, KM_SLEEP);
57 bcopy(template, ks_data, template_size);
58 if ((ksp = kstat_create_zone(module, vers, name, "misc",
59 KSTAT_TYPE_NAMED, template_size / sizeof (kstat_named_t),
60 KSTAT_FLAG_VIRTUAL | KSTAT_FLAG_WRITABLE, zoneid)) != NULL) {
61 ksp->ks_data = ks_data;
62 kstat_install(ksp);
63 }
64 return (ks_data);
65 }
66
67 /*
68 * Convenience routine to remove a kstat in specified zone with name
69 * module:0:name.
70 */
71 static void
nfsstat_zone_fini_common(zoneid_t zoneid,const char * module,int vers,const char * name)72 nfsstat_zone_fini_common(zoneid_t zoneid, const char *module, int vers,
73 const char *name)
74 {
75 kstat_delete_byname_zone(module, vers, name, zoneid);
76 }
77
78 /*
79 * Server statistics. These are defined here, rather than in the server
80 * code, so that they can be referenced before the nfssrv kmod is loaded.
81 *
82 * The "calls" counter is a Contract Private interface covered by
83 * PSARC/2001/357. Please contact contract-2001-357-01@eng.sun.com before
84 * making any changes.
85 */
86
87 static const kstat_named_t svstat_tmpl[] = {
88 { "calls", KSTAT_DATA_UINT64 },
89 { "badcalls", KSTAT_DATA_UINT64 },
90 { "referrals", KSTAT_DATA_UINT64 },
91 { "referlinks", KSTAT_DATA_UINT64 },
92 };
93
94 static void
nfsstat_zone_init_server(zoneid_t zoneid,kstat_named_t * svstatp[])95 nfsstat_zone_init_server(zoneid_t zoneid, kstat_named_t *svstatp[])
96 {
97 int vers;
98
99 for (vers = NFS_VERSION; vers <= NFS_V4; vers++) {
100 svstatp[vers] = nfsstat_zone_init_common(zoneid, "nfs", vers,
101 "nfs_server", svstat_tmpl, sizeof (svstat_tmpl));
102 }
103 }
104
105 static void
nfsstat_zone_fini_server(zoneid_t zoneid,kstat_named_t * svstatp[])106 nfsstat_zone_fini_server(zoneid_t zoneid, kstat_named_t *svstatp[])
107 {
108 int vers;
109 for (vers = NFS_VERSION; vers <= NFS_V4; vers++) {
110 nfsstat_zone_fini_common(zoneid, "nfs", vers, "nfs_server");
111 kmem_free(svstatp[vers], sizeof (svstat_tmpl));
112 }
113 }
114
115 /*
116 * NFSv2 client stats
117 */
118 static const kstat_named_t rfsreqcnt_v2_tmpl[] = {
119 { "null", KSTAT_DATA_UINT64 },
120 { "getattr", KSTAT_DATA_UINT64 },
121 { "setattr", KSTAT_DATA_UINT64 },
122 { "root", KSTAT_DATA_UINT64 },
123 { "lookup", KSTAT_DATA_UINT64 },
124 { "readlink", KSTAT_DATA_UINT64 },
125 { "read", KSTAT_DATA_UINT64 },
126 { "wrcache", KSTAT_DATA_UINT64 },
127 { "write", KSTAT_DATA_UINT64 },
128 { "create", KSTAT_DATA_UINT64 },
129 { "remove", KSTAT_DATA_UINT64 },
130 { "rename", KSTAT_DATA_UINT64 },
131 { "link", KSTAT_DATA_UINT64 },
132 { "symlink", KSTAT_DATA_UINT64 },
133 { "mkdir", KSTAT_DATA_UINT64 },
134 { "rmdir", KSTAT_DATA_UINT64 },
135 { "readdir", KSTAT_DATA_UINT64 },
136 { "statfs", KSTAT_DATA_UINT64 }
137 };
138
139 static void
nfsstat_zone_init_rfsreq_v2(zoneid_t zoneid,struct nfs_version_stats * statsp)140 nfsstat_zone_init_rfsreq_v2(zoneid_t zoneid, struct nfs_version_stats *statsp)
141 {
142 statsp->rfsreqcnt_ptr = nfsstat_zone_init_common(zoneid, "nfs", 0,
143 "rfsreqcnt_v2", rfsreqcnt_v2_tmpl, sizeof (rfsreqcnt_v2_tmpl));
144 }
145
146 static void
nfsstat_zone_fini_rfsreq_v2(zoneid_t zoneid,struct nfs_version_stats * statsp)147 nfsstat_zone_fini_rfsreq_v2(zoneid_t zoneid, struct nfs_version_stats *statsp)
148 {
149 nfsstat_zone_fini_common(zoneid, "nfs", 0, "rfsreqcnt_v2");
150 kmem_free(statsp->rfsreqcnt_ptr, sizeof (rfsreqcnt_v2_tmpl));
151 }
152
153 /*
154 * NFSv2 server stats
155 */
156 static const kstat_named_t rfsproccnt_v2_tmpl[] = {
157 { "null", KSTAT_DATA_UINT64 },
158 { "getattr", KSTAT_DATA_UINT64 },
159 { "setattr", KSTAT_DATA_UINT64 },
160 { "root", KSTAT_DATA_UINT64 },
161 { "lookup", KSTAT_DATA_UINT64 },
162 { "readlink", KSTAT_DATA_UINT64 },
163 { "read", KSTAT_DATA_UINT64 },
164 { "wrcache", KSTAT_DATA_UINT64 },
165 { "write", KSTAT_DATA_UINT64 },
166 { "create", KSTAT_DATA_UINT64 },
167 { "remove", KSTAT_DATA_UINT64 },
168 { "rename", KSTAT_DATA_UINT64 },
169 { "link", KSTAT_DATA_UINT64 },
170 { "symlink", KSTAT_DATA_UINT64 },
171 { "mkdir", KSTAT_DATA_UINT64 },
172 { "rmdir", KSTAT_DATA_UINT64 },
173 { "readdir", KSTAT_DATA_UINT64 },
174 { "statfs", KSTAT_DATA_UINT64 }
175 };
176
177 /*
178 * NFSv2 client ACL stats
179 */
180 static const kstat_named_t aclreqcnt_v2_tmpl[] = {
181 { "null", KSTAT_DATA_UINT64 },
182 { "getacl", KSTAT_DATA_UINT64 },
183 { "setacl", KSTAT_DATA_UINT64 },
184 { "getattr", KSTAT_DATA_UINT64 },
185 { "access", KSTAT_DATA_UINT64 },
186 { "getxattrdir", KSTAT_DATA_UINT64 }
187 };
188
189 static void
nfsstat_zone_init_aclreq_v2(zoneid_t zoneid,struct nfs_version_stats * statsp)190 nfsstat_zone_init_aclreq_v2(zoneid_t zoneid, struct nfs_version_stats *statsp)
191 {
192 statsp->aclreqcnt_ptr = nfsstat_zone_init_common(zoneid, "nfs_acl", 0,
193 "aclreqcnt_v2", aclreqcnt_v2_tmpl, sizeof (aclreqcnt_v2_tmpl));
194 }
195
196 static void
nfsstat_zone_fini_aclreq_v2(zoneid_t zoneid,struct nfs_version_stats * statsp)197 nfsstat_zone_fini_aclreq_v2(zoneid_t zoneid, struct nfs_version_stats *statsp)
198 {
199 nfsstat_zone_fini_common(zoneid, "nfs_acl", 0, "aclreqcnt_v2");
200 kmem_free(statsp->aclreqcnt_ptr, sizeof (aclreqcnt_v2_tmpl));
201 }
202
203 /*
204 * NFSv2 server ACL stats
205 */
206 static const kstat_named_t aclproccnt_v2_tmpl[] = {
207 { "null", KSTAT_DATA_UINT64 },
208 { "getacl", KSTAT_DATA_UINT64 },
209 { "setacl", KSTAT_DATA_UINT64 },
210 { "getattr", KSTAT_DATA_UINT64 },
211 { "access", KSTAT_DATA_UINT64 },
212 { "getxattrdir", KSTAT_DATA_UINT64 }
213 };
214
215 /*
216 * NFSv3 client stats
217 */
218 static const kstat_named_t rfsreqcnt_v3_tmpl[] = {
219 { "null", KSTAT_DATA_UINT64 },
220 { "getattr", KSTAT_DATA_UINT64 },
221 { "setattr", KSTAT_DATA_UINT64 },
222 { "lookup", KSTAT_DATA_UINT64 },
223 { "access", KSTAT_DATA_UINT64 },
224 { "readlink", KSTAT_DATA_UINT64 },
225 { "read", KSTAT_DATA_UINT64 },
226 { "write", KSTAT_DATA_UINT64 },
227 { "create", KSTAT_DATA_UINT64 },
228 { "mkdir", KSTAT_DATA_UINT64 },
229 { "symlink", KSTAT_DATA_UINT64 },
230 { "mknod", KSTAT_DATA_UINT64 },
231 { "remove", KSTAT_DATA_UINT64 },
232 { "rmdir", KSTAT_DATA_UINT64 },
233 { "rename", KSTAT_DATA_UINT64 },
234 { "link", KSTAT_DATA_UINT64 },
235 { "readdir", KSTAT_DATA_UINT64 },
236 { "readdirplus", KSTAT_DATA_UINT64 },
237 { "fsstat", KSTAT_DATA_UINT64 },
238 { "fsinfo", KSTAT_DATA_UINT64 },
239 { "pathconf", KSTAT_DATA_UINT64 },
240 { "commit", KSTAT_DATA_UINT64 }
241 };
242
243 static void
nfsstat_zone_init_rfsreq_v3(zoneid_t zoneid,struct nfs_version_stats * statsp)244 nfsstat_zone_init_rfsreq_v3(zoneid_t zoneid, struct nfs_version_stats *statsp)
245 {
246 statsp->rfsreqcnt_ptr = nfsstat_zone_init_common(zoneid, "nfs", 0,
247 "rfsreqcnt_v3", rfsreqcnt_v3_tmpl, sizeof (rfsreqcnt_v3_tmpl));
248 }
249
250 static void
nfsstat_zone_fini_rfsreq_v3(zoneid_t zoneid,struct nfs_version_stats * statsp)251 nfsstat_zone_fini_rfsreq_v3(zoneid_t zoneid, struct nfs_version_stats *statsp)
252 {
253 nfsstat_zone_fini_common(zoneid, "nfs", 0, "rfsreqcnt_v3");
254 kmem_free(statsp->rfsreqcnt_ptr, sizeof (rfsreqcnt_v3_tmpl));
255 }
256
257 /*
258 * NFSv3 server stats
259 */
260 static const kstat_named_t rfsproccnt_v3_tmpl[] = {
261 { "null", KSTAT_DATA_UINT64 },
262 { "getattr", KSTAT_DATA_UINT64 },
263 { "setattr", KSTAT_DATA_UINT64 },
264 { "lookup", KSTAT_DATA_UINT64 },
265 { "access", KSTAT_DATA_UINT64 },
266 { "readlink", KSTAT_DATA_UINT64 },
267 { "read", KSTAT_DATA_UINT64 },
268 { "write", KSTAT_DATA_UINT64 },
269 { "create", KSTAT_DATA_UINT64 },
270 { "mkdir", KSTAT_DATA_UINT64 },
271 { "symlink", KSTAT_DATA_UINT64 },
272 { "mknod", KSTAT_DATA_UINT64 },
273 { "remove", KSTAT_DATA_UINT64 },
274 { "rmdir", KSTAT_DATA_UINT64 },
275 { "rename", KSTAT_DATA_UINT64 },
276 { "link", KSTAT_DATA_UINT64 },
277 { "readdir", KSTAT_DATA_UINT64 },
278 { "readdirplus", KSTAT_DATA_UINT64 },
279 { "fsstat", KSTAT_DATA_UINT64 },
280 { "fsinfo", KSTAT_DATA_UINT64 },
281 { "pathconf", KSTAT_DATA_UINT64 },
282 { "commit", KSTAT_DATA_UINT64 }
283 };
284
285 /*
286 * NFSv3 client ACL stats
287 */
288 static const kstat_named_t aclreqcnt_v3_tmpl[] = {
289 { "null", KSTAT_DATA_UINT64 },
290 { "getacl", KSTAT_DATA_UINT64 },
291 { "setacl", KSTAT_DATA_UINT64 },
292 { "getxattrdir", KSTAT_DATA_UINT64 }
293 };
294
295 static void
nfsstat_zone_init_aclreq_v3(zoneid_t zoneid,struct nfs_version_stats * statsp)296 nfsstat_zone_init_aclreq_v3(zoneid_t zoneid, struct nfs_version_stats *statsp)
297 {
298 statsp->aclreqcnt_ptr = nfsstat_zone_init_common(zoneid, "nfs_acl", 0,
299 "aclreqcnt_v3", aclreqcnt_v3_tmpl, sizeof (aclreqcnt_v3_tmpl));
300 }
301
302 static void
nfsstat_zone_fini_aclreq_v3(zoneid_t zoneid,struct nfs_version_stats * statsp)303 nfsstat_zone_fini_aclreq_v3(zoneid_t zoneid, struct nfs_version_stats *statsp)
304 {
305 nfsstat_zone_fini_common(zoneid, "nfs_acl", 0, "aclreqcnt_v3");
306 kmem_free(statsp->aclreqcnt_ptr, sizeof (aclreqcnt_v3_tmpl));
307 }
308
309 /*
310 * NFSv3 server ACL stats
311 */
312 static const kstat_named_t aclproccnt_v3_tmpl[] = {
313 { "null", KSTAT_DATA_UINT64 },
314 { "getacl", KSTAT_DATA_UINT64 },
315 { "setacl", KSTAT_DATA_UINT64 },
316 { "getxattrdir", KSTAT_DATA_UINT64 }
317 };
318
319 /*
320 * NFSv4 client stats
321 */
322 static const kstat_named_t rfsreqcnt_v4_tmpl[] = {
323 { "null", KSTAT_DATA_UINT64 },
324 { "compound", KSTAT_DATA_UINT64 },
325 { "reserved", KSTAT_DATA_UINT64 },
326 { "access", KSTAT_DATA_UINT64 },
327 { "close", KSTAT_DATA_UINT64 },
328 { "commit", KSTAT_DATA_UINT64 },
329 { "create", KSTAT_DATA_UINT64 },
330 { "delegpurge", KSTAT_DATA_UINT64 },
331 { "delegreturn", KSTAT_DATA_UINT64 },
332 { "getattr", KSTAT_DATA_UINT64 },
333 { "getfh", KSTAT_DATA_UINT64 },
334 { "link", KSTAT_DATA_UINT64 },
335 { "lock", KSTAT_DATA_UINT64 },
336 { "lockt", KSTAT_DATA_UINT64 },
337 { "locku", KSTAT_DATA_UINT64 },
338 { "lookup", KSTAT_DATA_UINT64 },
339 { "lookupp", KSTAT_DATA_UINT64 },
340 { "nverify", KSTAT_DATA_UINT64 },
341 { "open", KSTAT_DATA_UINT64 },
342 { "openattr", KSTAT_DATA_UINT64 },
343 { "open_confirm", KSTAT_DATA_UINT64 },
344 { "open_downgrade", KSTAT_DATA_UINT64 },
345 { "putfh", KSTAT_DATA_UINT64 },
346 { "putpubfh", KSTAT_DATA_UINT64 },
347 { "putrootfh", KSTAT_DATA_UINT64 },
348 { "read", KSTAT_DATA_UINT64 },
349 { "readdir", KSTAT_DATA_UINT64 },
350 { "readlink", KSTAT_DATA_UINT64 },
351 { "remove", KSTAT_DATA_UINT64 },
352 { "rename", KSTAT_DATA_UINT64 },
353 { "renew", KSTAT_DATA_UINT64 },
354 { "restorefh", KSTAT_DATA_UINT64 },
355 { "savefh", KSTAT_DATA_UINT64 },
356 { "secinfo", KSTAT_DATA_UINT64 },
357 { "setattr", KSTAT_DATA_UINT64 },
358 { "setclientid", KSTAT_DATA_UINT64 },
359 { "setclientid_confirm", KSTAT_DATA_UINT64 },
360 { "verify", KSTAT_DATA_UINT64 },
361 { "write", KSTAT_DATA_UINT64 }
362 };
363
364 static void
nfsstat_zone_init_rfsreq_v4(zoneid_t zoneid,struct nfs_version_stats * statsp)365 nfsstat_zone_init_rfsreq_v4(zoneid_t zoneid, struct nfs_version_stats *statsp)
366 {
367 statsp->rfsreqcnt_ptr = nfsstat_zone_init_common(zoneid, "nfs", 0,
368 "rfsreqcnt_v4", rfsreqcnt_v4_tmpl, sizeof (rfsreqcnt_v4_tmpl));
369 }
370
371 static void
nfsstat_zone_fini_rfsreq_v4(zoneid_t zoneid,struct nfs_version_stats * statsp)372 nfsstat_zone_fini_rfsreq_v4(zoneid_t zoneid, struct nfs_version_stats *statsp)
373 {
374 nfsstat_zone_fini_common(zoneid, "nfs", 0, "rfsreqcnt_v4");
375 kmem_free(statsp->rfsreqcnt_ptr, sizeof (rfsreqcnt_v4_tmpl));
376 }
377
378 /*
379 * NFSv4 server stats
380 */
381 static const kstat_named_t rfsproccnt_v4_tmpl[] = {
382 { "null", KSTAT_DATA_UINT64 },
383 { "compound", KSTAT_DATA_UINT64 },
384 { "reserved", KSTAT_DATA_UINT64 },
385 { "access", KSTAT_DATA_UINT64 },
386 { "close", KSTAT_DATA_UINT64 },
387 { "commit", KSTAT_DATA_UINT64 },
388 { "create", KSTAT_DATA_UINT64 },
389 { "delegpurge", KSTAT_DATA_UINT64 },
390 { "delegreturn", KSTAT_DATA_UINT64 },
391 { "getattr", KSTAT_DATA_UINT64 },
392 { "getfh", KSTAT_DATA_UINT64 },
393 { "link", KSTAT_DATA_UINT64 },
394 { "lock", KSTAT_DATA_UINT64 },
395 { "lockt", KSTAT_DATA_UINT64 },
396 { "locku", KSTAT_DATA_UINT64 },
397 { "lookup", KSTAT_DATA_UINT64 },
398 { "lookupp", KSTAT_DATA_UINT64 },
399 { "nverify", KSTAT_DATA_UINT64 },
400 { "open", KSTAT_DATA_UINT64 },
401 { "openattr", KSTAT_DATA_UINT64 },
402 { "open_confirm", KSTAT_DATA_UINT64 },
403 { "open_downgrade", KSTAT_DATA_UINT64 },
404 { "putfh", KSTAT_DATA_UINT64 },
405 { "putpubfh", KSTAT_DATA_UINT64 },
406 { "putrootfh", KSTAT_DATA_UINT64 },
407 { "read", KSTAT_DATA_UINT64 },
408 { "readdir", KSTAT_DATA_UINT64 },
409 { "readlink", KSTAT_DATA_UINT64 },
410 { "remove", KSTAT_DATA_UINT64 },
411 { "rename", KSTAT_DATA_UINT64 },
412 { "renew", KSTAT_DATA_UINT64 },
413 { "restorefh", KSTAT_DATA_UINT64 },
414 { "savefh", KSTAT_DATA_UINT64 },
415 { "secinfo", KSTAT_DATA_UINT64 },
416 { "setattr", KSTAT_DATA_UINT64 },
417 { "setclientid", KSTAT_DATA_UINT64 },
418 { "setclientid_confirm", KSTAT_DATA_UINT64 },
419 { "verify", KSTAT_DATA_UINT64 },
420 { "write", KSTAT_DATA_UINT64 },
421 { "release_lockowner", KSTAT_DATA_UINT64 },
422 { "backchannel_ctl", KSTAT_DATA_UINT64 },
423 { "bind_conn_to_session", KSTAT_DATA_UINT64 },
424 { "exchange_id", KSTAT_DATA_UINT64 },
425 { "create_session", KSTAT_DATA_UINT64 },
426 { "destroy_session", KSTAT_DATA_UINT64 },
427 { "free_stateid", KSTAT_DATA_UINT64 },
428 { "get_dir_delegation", KSTAT_DATA_UINT64 },
429 { "getdeviceinfo", KSTAT_DATA_UINT64 },
430 { "getdevicelist", KSTAT_DATA_UINT64 },
431 { "layoutcommit", KSTAT_DATA_UINT64 },
432 { "layoutget", KSTAT_DATA_UINT64 },
433 { "layoutreturn", KSTAT_DATA_UINT64 },
434 { "secinfo_no_name", KSTAT_DATA_UINT64 },
435 { "sequence", KSTAT_DATA_UINT64 },
436 { "set_ssv", KSTAT_DATA_UINT64 },
437 { "test_stateid", KSTAT_DATA_UINT64 },
438 { "want_delegation", KSTAT_DATA_UINT64 },
439 { "destroy_clientid", KSTAT_DATA_UINT64 },
440 { "reclaim_complete", KSTAT_DATA_UINT64 },
441 { "illegal", KSTAT_DATA_UINT64 },
442 };
443
444 /*
445 * NFSv4 client ACL stats
446 */
447 static const kstat_named_t aclreqcnt_v4_tmpl[] = {
448 { "null", KSTAT_DATA_UINT64 },
449 { "getacl", KSTAT_DATA_UINT64 },
450 { "setacl", KSTAT_DATA_UINT64 },
451 };
452
453 static void
nfsstat_zone_init_aclreq_v4(zoneid_t zoneid,struct nfs_version_stats * statsp)454 nfsstat_zone_init_aclreq_v4(zoneid_t zoneid, struct nfs_version_stats *statsp)
455 {
456 statsp->aclreqcnt_ptr = nfsstat_zone_init_common(zoneid, "nfs_acl", 0,
457 "aclreqcnt_v4", aclreqcnt_v4_tmpl, sizeof (aclreqcnt_v4_tmpl));
458 }
459
460 static void
nfsstat_zone_fini_aclreq_v4(zoneid_t zoneid,struct nfs_version_stats * statsp)461 nfsstat_zone_fini_aclreq_v4(zoneid_t zoneid, struct nfs_version_stats *statsp)
462 {
463 nfsstat_zone_fini_common(zoneid, "nfs_acl", 0, "aclreqcnt_v4");
464 kmem_free(statsp->aclreqcnt_ptr, sizeof (aclreqcnt_v4_tmpl));
465 }
466
467 /*
468 * Zone initializer callback to setup the kstats.
469 */
470 void *
nfsstat_zone_init(zoneid_t zoneid)471 nfsstat_zone_init(zoneid_t zoneid)
472 {
473 struct nfs_stats *nfs_stats_ptr;
474
475 nfs_stats_ptr = kmem_zalloc(sizeof (*nfs_stats_ptr), KM_SLEEP);
476
477 /*
478 * Initialize v2 stats
479 */
480 nfsstat_zone_init_rfsreq_v2(zoneid, &nfs_stats_ptr->nfs_stats_v2);
481 nfsstat_zone_init_aclreq_v2(zoneid, &nfs_stats_ptr->nfs_stats_v2);
482 /*
483 * Initialize v3 stats
484 */
485 nfsstat_zone_init_rfsreq_v3(zoneid, &nfs_stats_ptr->nfs_stats_v3);
486 nfsstat_zone_init_aclreq_v3(zoneid, &nfs_stats_ptr->nfs_stats_v3);
487 /*
488 * Initialize v4 stats
489 */
490 nfsstat_zone_init_rfsreq_v4(zoneid, &nfs_stats_ptr->nfs_stats_v4);
491 nfsstat_zone_init_aclreq_v4(zoneid, &nfs_stats_ptr->nfs_stats_v4);
492
493 return (nfs_stats_ptr);
494 }
495
496 /*
497 * Zone destructor callback to tear down the various kstats.
498 */
499 void
nfsstat_zone_fini(zoneid_t zoneid,void * data)500 nfsstat_zone_fini(zoneid_t zoneid, void *data)
501 {
502 struct nfs_stats *nfs_stats_ptr = data;
503
504 /*
505 * Free v2 stats
506 */
507 nfsstat_zone_fini_rfsreq_v2(zoneid, &nfs_stats_ptr->nfs_stats_v2);
508 nfsstat_zone_fini_aclreq_v2(zoneid, &nfs_stats_ptr->nfs_stats_v2);
509 /*
510 * Free v3 stats
511 */
512 nfsstat_zone_fini_rfsreq_v3(zoneid, &nfs_stats_ptr->nfs_stats_v3);
513 nfsstat_zone_fini_aclreq_v3(zoneid, &nfs_stats_ptr->nfs_stats_v3);
514 /*
515 * Free v4 stats
516 */
517 nfsstat_zone_fini_rfsreq_v4(zoneid, &nfs_stats_ptr->nfs_stats_v4);
518 nfsstat_zone_fini_aclreq_v4(zoneid, &nfs_stats_ptr->nfs_stats_v4);
519
520 kmem_free(nfs_stats_ptr, sizeof (*nfs_stats_ptr));
521 }
522
523 void
rfs_stat_zone_init(nfs_globals_t * ng)524 rfs_stat_zone_init(nfs_globals_t *ng)
525 {
526 zoneid_t zoneid = ng->nfs_zoneid;
527
528 /* Initialize all versions of the nfs_server */
529 nfsstat_zone_init_server(zoneid, ng->svstat);
530
531 /* NFS proc */
532 ng->rfsproccnt[NFS_V2] = nfsstat_zone_init_common(zoneid, "nfs", 0,
533 "rfsproccnt_v2", rfsproccnt_v2_tmpl, sizeof (rfsproccnt_v2_tmpl));
534
535 ng->rfsproccnt[NFS_V3] = nfsstat_zone_init_common(zoneid, "nfs", 0,
536 "rfsproccnt_v3", rfsproccnt_v3_tmpl, sizeof (rfsproccnt_v3_tmpl));
537
538 ng->rfsproccnt[NFS_V4] = nfsstat_zone_init_common(zoneid, "nfs", 0,
539 "rfsproccnt_v4", rfsproccnt_v4_tmpl, sizeof (rfsproccnt_v4_tmpl));
540
541 /* ACL proc */
542 ng->aclproccnt[NFS_V2] = nfsstat_zone_init_common(zoneid, "nfs_acl", 0,
543 "aclproccnt_v2", aclproccnt_v2_tmpl, sizeof (aclproccnt_v2_tmpl));
544
545 ng->aclproccnt[NFS_V3] = nfsstat_zone_init_common(zoneid, "nfs_acl", 0,
546 "aclproccnt_v3", aclproccnt_v3_tmpl, sizeof (aclproccnt_v3_tmpl));
547
548 }
549
550 void
rfs_stat_zone_fini(nfs_globals_t * ng)551 rfs_stat_zone_fini(nfs_globals_t *ng)
552 {
553 zoneid_t zoneid = ng->nfs_zoneid;
554
555 /* Free nfs:x:nfs_server stats */
556 nfsstat_zone_fini_server(zoneid, ng->svstat);
557
558 /* NFS */
559 nfsstat_zone_fini_common(zoneid, "nfs", 0, "rfsproccnt_v2");
560 kmem_free(ng->rfsproccnt[NFS_V2], sizeof (rfsproccnt_v2_tmpl));
561
562 nfsstat_zone_fini_common(zoneid, "nfs", 0, "rfsproccnt_v3");
563 kmem_free(ng->rfsproccnt[NFS_V3], sizeof (rfsproccnt_v3_tmpl));
564
565 nfsstat_zone_fini_common(zoneid, "nfs", 0, "rfsproccnt_v4");
566 kmem_free(ng->rfsproccnt[NFS_V4], sizeof (rfsproccnt_v4_tmpl));
567
568 /* ACL */
569 nfsstat_zone_fini_common(zoneid, "nfs_acl", 0, "aclproccnt_v2");
570 kmem_free(ng->aclproccnt[NFS_V2], sizeof (aclproccnt_v2_tmpl));
571
572 nfsstat_zone_fini_common(zoneid, "nfs_acl", 0, "aclproccnt_v3");
573 kmem_free(ng->aclproccnt[NFS_V3], sizeof (aclproccnt_v3_tmpl));
574
575 }
576