10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
53406Sth199096 * Common Development and Distribution License (the "License").
63406Sth199096 * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
213406Sth199096
220Sstevel@tonic-gate /* LINTLIBRARY */
230Sstevel@tonic-gate /* PROTOLIB1 */
240Sstevel@tonic-gate
250Sstevel@tonic-gate /*
2610265SKrishnendu.Sadhukhan@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
270Sstevel@tonic-gate * Use is subject to license terms.
280Sstevel@tonic-gate */
290Sstevel@tonic-gate
300Sstevel@tonic-gate /*
310Sstevel@tonic-gate * nfsstat: Network File System statistics
320Sstevel@tonic-gate *
330Sstevel@tonic-gate */
340Sstevel@tonic-gate
350Sstevel@tonic-gate #include <stdio.h>
360Sstevel@tonic-gate #include <stdlib.h>
370Sstevel@tonic-gate #include <unistd.h>
380Sstevel@tonic-gate #include <stdarg.h>
390Sstevel@tonic-gate #include <string.h>
400Sstevel@tonic-gate #include <errno.h>
410Sstevel@tonic-gate #include <fcntl.h>
420Sstevel@tonic-gate #include <kvm.h>
430Sstevel@tonic-gate #include <kstat.h>
440Sstevel@tonic-gate #include <sys/param.h>
450Sstevel@tonic-gate #include <sys/types.h>
460Sstevel@tonic-gate #include <sys/t_lock.h>
470Sstevel@tonic-gate #include <sys/tiuser.h>
480Sstevel@tonic-gate #include <sys/statvfs.h>
490Sstevel@tonic-gate #include <sys/mntent.h>
500Sstevel@tonic-gate #include <sys/mnttab.h>
510Sstevel@tonic-gate #include <sys/sysmacros.h>
520Sstevel@tonic-gate #include <sys/mkdev.h>
530Sstevel@tonic-gate #include <rpc/types.h>
540Sstevel@tonic-gate #include <rpc/xdr.h>
550Sstevel@tonic-gate #include <rpc/auth.h>
560Sstevel@tonic-gate #include <rpc/clnt.h>
570Sstevel@tonic-gate #include <nfs/nfs.h>
580Sstevel@tonic-gate #include <nfs/nfs_clnt.h>
590Sstevel@tonic-gate #include <nfs/nfs_sec.h>
600Sstevel@tonic-gate #include <inttypes.h>
610Sstevel@tonic-gate #include <signal.h>
620Sstevel@tonic-gate #include <time.h>
630Sstevel@tonic-gate #include <sys/time.h>
640Sstevel@tonic-gate #include <strings.h>
650Sstevel@tonic-gate #include <ctype.h>
6610265SKrishnendu.Sadhukhan@Sun.COM #include <locale.h>
670Sstevel@tonic-gate
6810265SKrishnendu.Sadhukhan@Sun.COM #include "statcommon.h"
690Sstevel@tonic-gate
700Sstevel@tonic-gate static kstat_ctl_t *kc = NULL; /* libkstat cookie */
710Sstevel@tonic-gate static kstat_t *rpc_clts_client_kstat, *rpc_clts_server_kstat;
720Sstevel@tonic-gate static kstat_t *rpc_cots_client_kstat, *rpc_cots_server_kstat;
730Sstevel@tonic-gate static kstat_t *rpc_rdma_client_kstat, *rpc_rdma_server_kstat;
740Sstevel@tonic-gate static kstat_t *nfs_client_kstat, *nfs_server_v2_kstat, *nfs_server_v3_kstat;
750Sstevel@tonic-gate static kstat_t *nfs4_client_kstat, *nfs_server_v4_kstat;
760Sstevel@tonic-gate static kstat_t *rfsproccnt_v2_kstat, *rfsproccnt_v3_kstat, *rfsproccnt_v4_kstat;
770Sstevel@tonic-gate static kstat_t *rfsreqcnt_v2_kstat, *rfsreqcnt_v3_kstat, *rfsreqcnt_v4_kstat;
780Sstevel@tonic-gate static kstat_t *aclproccnt_v2_kstat, *aclproccnt_v3_kstat;
790Sstevel@tonic-gate static kstat_t *aclreqcnt_v2_kstat, *aclreqcnt_v3_kstat;
800Sstevel@tonic-gate static kstat_t *ksum_kstat;
810Sstevel@tonic-gate
820Sstevel@tonic-gate static void handle_sig(int);
830Sstevel@tonic-gate static int getstats_rpc(void);
840Sstevel@tonic-gate static int getstats_nfs(void);
850Sstevel@tonic-gate static int getstats_rfsproc(int);
860Sstevel@tonic-gate static int getstats_rfsreq(int);
870Sstevel@tonic-gate static int getstats_aclproc(void);
880Sstevel@tonic-gate static int getstats_aclreq(void);
890Sstevel@tonic-gate static void putstats(void);
900Sstevel@tonic-gate static void setup(void);
910Sstevel@tonic-gate static void cr_print(int);
920Sstevel@tonic-gate static void sr_print(int);
930Sstevel@tonic-gate static void cn_print(int, int);
940Sstevel@tonic-gate static void sn_print(int, int);
950Sstevel@tonic-gate static void ca_print(int, int);
960Sstevel@tonic-gate static void sa_print(int, int);
970Sstevel@tonic-gate static void req_print(kstat_t *, kstat_t *, int, int, int);
980Sstevel@tonic-gate static void req_print_v4(kstat_t *, kstat_t *, int, int);
990Sstevel@tonic-gate static void stat_print(const char *, kstat_t *, kstat_t *, int, int);
10010265SKrishnendu.Sadhukhan@Sun.COM static void nfsstat_kstat_sum(kstat_t *, kstat_t *, kstat_t *);
1010Sstevel@tonic-gate static void stats_timer(int);
1020Sstevel@tonic-gate static void safe_zalloc(void **, uint_t, int);
1030Sstevel@tonic-gate static int safe_strtoi(char const *, char *);
1040Sstevel@tonic-gate
1050Sstevel@tonic-gate
10610265SKrishnendu.Sadhukhan@Sun.COM static void nfsstat_kstat_copy(kstat_t *, kstat_t *, int);
1070Sstevel@tonic-gate static kid_t safe_kstat_read(kstat_ctl_t *, kstat_t *, void *);
1080Sstevel@tonic-gate static kid_t safe_kstat_write(kstat_ctl_t *, kstat_t *, void *);
1090Sstevel@tonic-gate
1100Sstevel@tonic-gate static void usage(void);
1110Sstevel@tonic-gate static void mi_print(void);
1120Sstevel@tonic-gate static int ignore(char *);
1130Sstevel@tonic-gate static int interval; /* interval between stats */
1140Sstevel@tonic-gate static int count; /* number of iterations the stat is printed */
1150Sstevel@tonic-gate #define MAX_COLUMNS 80
1160Sstevel@tonic-gate #define MAX_PATHS 50 /* max paths that can be taken by -m */
1170Sstevel@tonic-gate
1185302Sth199096 /*
1195302Sth199096 * MI4_MIRRORMOUNT is canonically defined in nfs4_clnt.h, but we cannot
120*11291SRobert.Thurlow@Sun.COM * include that file here. Same with MI4_REFERRAL.
1215302Sth199096 */
1225302Sth199096 #define MI4_MIRRORMOUNT 0x4000
123*11291SRobert.Thurlow@Sun.COM #define MI4_REFERRAL 0x8000
1245302Sth199096 #define NFS_V4 4
1255302Sth199096
1260Sstevel@tonic-gate static int req_width(kstat_t *, int);
1270Sstevel@tonic-gate static int stat_width(kstat_t *, int);
1280Sstevel@tonic-gate static char *path [MAX_PATHS] = {NULL}; /* array to store the multiple paths */
1290Sstevel@tonic-gate
1300Sstevel@tonic-gate /*
1310Sstevel@tonic-gate * Struct holds the previous kstat values so
1320Sstevel@tonic-gate * we can compute deltas when using the -i flag
1330Sstevel@tonic-gate */
1340Sstevel@tonic-gate typedef struct old_kstat
1350Sstevel@tonic-gate {
1360Sstevel@tonic-gate kstat_t kst;
1370Sstevel@tonic-gate int tot;
1380Sstevel@tonic-gate } old_kstat_t;
1390Sstevel@tonic-gate
1400Sstevel@tonic-gate static old_kstat_t old_rpc_clts_client_kstat, old_rpc_clts_server_kstat;
1410Sstevel@tonic-gate static old_kstat_t old_rpc_cots_client_kstat, old_rpc_cots_server_kstat;
1420Sstevel@tonic-gate static old_kstat_t old_rpc_rdma_client_kstat, old_rpc_rdma_server_kstat;
1430Sstevel@tonic-gate static old_kstat_t old_nfs_client_kstat, old_nfs_server_v2_kstat;
1440Sstevel@tonic-gate static old_kstat_t old_nfs_server_v3_kstat, old_ksum_kstat;
1450Sstevel@tonic-gate static old_kstat_t old_nfs4_client_kstat, old_nfs_server_v4_kstat;
1460Sstevel@tonic-gate static old_kstat_t old_rfsproccnt_v2_kstat, old_rfsproccnt_v3_kstat;
1470Sstevel@tonic-gate static old_kstat_t old_rfsproccnt_v4_kstat, old_rfsreqcnt_v2_kstat;
1480Sstevel@tonic-gate static old_kstat_t old_rfsreqcnt_v3_kstat, old_rfsreqcnt_v4_kstat;
1490Sstevel@tonic-gate static old_kstat_t old_aclproccnt_v2_kstat, old_aclproccnt_v3_kstat;
1500Sstevel@tonic-gate static old_kstat_t old_aclreqcnt_v2_kstat, old_aclreqcnt_v3_kstat;
1510Sstevel@tonic-gate
15210265SKrishnendu.Sadhukhan@Sun.COM static uint_t timestamp_fmt = NODATE;
1530Sstevel@tonic-gate
15410265SKrishnendu.Sadhukhan@Sun.COM #if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
15510265SKrishnendu.Sadhukhan@Sun.COM #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it isn't */
15610265SKrishnendu.Sadhukhan@Sun.COM #endif
1570Sstevel@tonic-gate
158249Sjwahlig int
main(int argc,char * argv[])1590Sstevel@tonic-gate main(int argc, char *argv[])
1600Sstevel@tonic-gate {
1610Sstevel@tonic-gate int c, go_forever, j;
1620Sstevel@tonic-gate int cflag = 0; /* client stats */
1630Sstevel@tonic-gate int sflag = 0; /* server stats */
1640Sstevel@tonic-gate int nflag = 0; /* nfs stats */
1650Sstevel@tonic-gate int rflag = 0; /* rpc stats */
1660Sstevel@tonic-gate int mflag = 0; /* mount table stats */
1670Sstevel@tonic-gate int aflag = 0; /* print acl statistics */
1680Sstevel@tonic-gate int vflag = 0; /* version specified, 0 specifies all */
1690Sstevel@tonic-gate int zflag = 0; /* zero stats after printing */
1700Sstevel@tonic-gate char *split_line = "*******************************************"
1715302Sth199096 "*************************************";
1720Sstevel@tonic-gate
1730Sstevel@tonic-gate interval = 0;
1740Sstevel@tonic-gate count = 0;
1750Sstevel@tonic-gate go_forever = 0;
1760Sstevel@tonic-gate
17710265SKrishnendu.Sadhukhan@Sun.COM (void) setlocale(LC_ALL, "");
17810265SKrishnendu.Sadhukhan@Sun.COM (void) textdomain(TEXT_DOMAIN);
17910265SKrishnendu.Sadhukhan@Sun.COM
18010265SKrishnendu.Sadhukhan@Sun.COM while ((c = getopt(argc, argv, "cnrsmzav:T:")) != EOF) {
1810Sstevel@tonic-gate switch (c) {
1820Sstevel@tonic-gate case 'c':
1830Sstevel@tonic-gate cflag++;
1840Sstevel@tonic-gate break;
1850Sstevel@tonic-gate case 'n':
1860Sstevel@tonic-gate nflag++;
1870Sstevel@tonic-gate break;
1880Sstevel@tonic-gate case 'r':
1890Sstevel@tonic-gate rflag++;
1900Sstevel@tonic-gate break;
1910Sstevel@tonic-gate case 's':
1920Sstevel@tonic-gate sflag++;
1930Sstevel@tonic-gate break;
1940Sstevel@tonic-gate case 'm':
1950Sstevel@tonic-gate mflag++;
1960Sstevel@tonic-gate break;
1970Sstevel@tonic-gate case 'z':
1980Sstevel@tonic-gate if (geteuid())
1990Sstevel@tonic-gate fail(0, "Must be root for z flag\n");
2000Sstevel@tonic-gate zflag++;
2010Sstevel@tonic-gate break;
2020Sstevel@tonic-gate case 'a':
2030Sstevel@tonic-gate aflag++;
2040Sstevel@tonic-gate break;
2050Sstevel@tonic-gate case 'v':
2060Sstevel@tonic-gate vflag = atoi(optarg);
2070Sstevel@tonic-gate if ((vflag < 2) || (vflag > 4))
2080Sstevel@tonic-gate fail(0, "Invalid version number\n");
2090Sstevel@tonic-gate break;
21010265SKrishnendu.Sadhukhan@Sun.COM case 'T':
21110265SKrishnendu.Sadhukhan@Sun.COM if (optarg) {
21210265SKrishnendu.Sadhukhan@Sun.COM if (*optarg == 'u')
21310265SKrishnendu.Sadhukhan@Sun.COM timestamp_fmt = UDATE;
21410265SKrishnendu.Sadhukhan@Sun.COM else if (*optarg == 'd')
21510265SKrishnendu.Sadhukhan@Sun.COM timestamp_fmt = DDATE;
21610265SKrishnendu.Sadhukhan@Sun.COM else
21710265SKrishnendu.Sadhukhan@Sun.COM usage();
21810265SKrishnendu.Sadhukhan@Sun.COM } else {
21910265SKrishnendu.Sadhukhan@Sun.COM usage();
22010265SKrishnendu.Sadhukhan@Sun.COM }
22110265SKrishnendu.Sadhukhan@Sun.COM break;
2220Sstevel@tonic-gate case '?':
2230Sstevel@tonic-gate default:
2240Sstevel@tonic-gate usage();
2250Sstevel@tonic-gate }
2260Sstevel@tonic-gate }
2270Sstevel@tonic-gate
2280Sstevel@tonic-gate if (((argc - optind) > 0) && !mflag) {
2290Sstevel@tonic-gate
2300Sstevel@tonic-gate interval = safe_strtoi(argv[optind], "invalid interval");
2310Sstevel@tonic-gate if (interval < 1)
2320Sstevel@tonic-gate fail(0, "invalid interval\n");
2330Sstevel@tonic-gate optind++;
2340Sstevel@tonic-gate
2350Sstevel@tonic-gate if ((argc - optind) > 0) {
2360Sstevel@tonic-gate count = safe_strtoi(argv[optind], "invalid count");
2370Sstevel@tonic-gate if ((count <= 0) || (count == NULL))
2380Sstevel@tonic-gate fail(0, "invalid count\n");
2390Sstevel@tonic-gate }
2400Sstevel@tonic-gate optind++;
2410Sstevel@tonic-gate
2420Sstevel@tonic-gate if ((argc - optind) > 0)
2430Sstevel@tonic-gate usage();
2440Sstevel@tonic-gate
2450Sstevel@tonic-gate /*
2460Sstevel@tonic-gate * no count number was set, so we will loop infinitely
2470Sstevel@tonic-gate * at interval specified
2480Sstevel@tonic-gate */
2490Sstevel@tonic-gate if (!count)
2500Sstevel@tonic-gate go_forever = 1;
2510Sstevel@tonic-gate stats_timer(interval);
2520Sstevel@tonic-gate } else if (mflag) {
2530Sstevel@tonic-gate
2540Sstevel@tonic-gate if (cflag || rflag || sflag || zflag || nflag || aflag || vflag)
2555302Sth199096 fail(0,
2565302Sth199096 "The -m flag may not be used with any other flags");
2570Sstevel@tonic-gate
2580Sstevel@tonic-gate for (j = 0; (argc - optind > 0) && (j < (MAX_PATHS - 1)); j++) {
2590Sstevel@tonic-gate path[j] = argv[optind];
2600Sstevel@tonic-gate if (*path[j] != '/')
2610Sstevel@tonic-gate fail(0, "Please fully qualify your pathname "
2620Sstevel@tonic-gate "with a leading '/'");
2630Sstevel@tonic-gate optind++;
2640Sstevel@tonic-gate }
2650Sstevel@tonic-gate path[j] = NULL;
2660Sstevel@tonic-gate if (argc - optind > 0)
2670Sstevel@tonic-gate fprintf(stderr, "Only the first 50 paths "
2685302Sth199096 "will be searched for\n");
2690Sstevel@tonic-gate }
2700Sstevel@tonic-gate
2710Sstevel@tonic-gate setup();
2720Sstevel@tonic-gate
2730Sstevel@tonic-gate do {
2740Sstevel@tonic-gate if (mflag) {
2750Sstevel@tonic-gate mi_print();
2760Sstevel@tonic-gate } else {
27710265SKrishnendu.Sadhukhan@Sun.COM if (timestamp_fmt != NODATE)
27810265SKrishnendu.Sadhukhan@Sun.COM print_timestamp(timestamp_fmt);
2790Sstevel@tonic-gate
2800Sstevel@tonic-gate if (sflag &&
2810Sstevel@tonic-gate (rpc_clts_server_kstat == NULL ||
2820Sstevel@tonic-gate nfs_server_v4_kstat == NULL)) {
2830Sstevel@tonic-gate fprintf(stderr,
2840Sstevel@tonic-gate "nfsstat: kernel is not configured with "
2850Sstevel@tonic-gate "the server nfs and rpc code.\n");
2860Sstevel@tonic-gate }
2870Sstevel@tonic-gate
2880Sstevel@tonic-gate /* if s and nothing else, all 3 prints are called */
2890Sstevel@tonic-gate if (sflag || (!sflag && !cflag)) {
2900Sstevel@tonic-gate if (rflag || (!rflag && !nflag && !aflag))
2910Sstevel@tonic-gate sr_print(zflag);
2920Sstevel@tonic-gate if (nflag || (!rflag && !nflag && !aflag))
2930Sstevel@tonic-gate sn_print(zflag, vflag);
2940Sstevel@tonic-gate if (aflag || (!rflag && !nflag && !aflag))
2950Sstevel@tonic-gate sa_print(zflag, vflag);
2960Sstevel@tonic-gate }
2970Sstevel@tonic-gate if (cflag &&
2980Sstevel@tonic-gate (rpc_clts_client_kstat == NULL ||
2990Sstevel@tonic-gate nfs_client_kstat == NULL)) {
3000Sstevel@tonic-gate fprintf(stderr,
3015302Sth199096 "nfsstat: kernel is not configured with"
3025302Sth199096 " the client nfs and rpc code.\n");
3030Sstevel@tonic-gate }
3040Sstevel@tonic-gate if (cflag || (!sflag && !cflag)) {
3050Sstevel@tonic-gate if (rflag || (!rflag && !nflag && !aflag))
3060Sstevel@tonic-gate cr_print(zflag);
3070Sstevel@tonic-gate if (nflag || (!rflag && !nflag && !aflag))
3080Sstevel@tonic-gate cn_print(zflag, vflag);
3090Sstevel@tonic-gate if (aflag || (!rflag && !nflag && !aflag))
3100Sstevel@tonic-gate ca_print(zflag, vflag);
3110Sstevel@tonic-gate }
3120Sstevel@tonic-gate }
3130Sstevel@tonic-gate
3140Sstevel@tonic-gate if (zflag)
3150Sstevel@tonic-gate putstats();
3160Sstevel@tonic-gate if (interval)
3170Sstevel@tonic-gate printf("%s\n", split_line);
3180Sstevel@tonic-gate
3190Sstevel@tonic-gate if (interval > 0)
3200Sstevel@tonic-gate (void) pause();
3210Sstevel@tonic-gate } while ((--count > 0) || go_forever);
3220Sstevel@tonic-gate
3230Sstevel@tonic-gate kstat_close(kc);
3240Sstevel@tonic-gate free(ksum_kstat);
3250Sstevel@tonic-gate return (0);
3260Sstevel@tonic-gate }
3270Sstevel@tonic-gate
3280Sstevel@tonic-gate
3290Sstevel@tonic-gate static int
getstats_rpc(void)3300Sstevel@tonic-gate getstats_rpc(void)
3310Sstevel@tonic-gate {
3320Sstevel@tonic-gate int field_width = 0;
3330Sstevel@tonic-gate
3340Sstevel@tonic-gate if (rpc_clts_client_kstat != NULL) {
3350Sstevel@tonic-gate safe_kstat_read(kc, rpc_clts_client_kstat, NULL);
3360Sstevel@tonic-gate field_width = stat_width(rpc_clts_client_kstat, field_width);
3370Sstevel@tonic-gate }
3380Sstevel@tonic-gate
3390Sstevel@tonic-gate if (rpc_cots_client_kstat != NULL) {
3400Sstevel@tonic-gate safe_kstat_read(kc, rpc_cots_client_kstat, NULL);
3410Sstevel@tonic-gate field_width = stat_width(rpc_cots_client_kstat, field_width);
3420Sstevel@tonic-gate }
3430Sstevel@tonic-gate
3440Sstevel@tonic-gate if (rpc_rdma_client_kstat != NULL) {
3450Sstevel@tonic-gate safe_kstat_read(kc, rpc_rdma_client_kstat, NULL);
3460Sstevel@tonic-gate field_width = stat_width(rpc_rdma_client_kstat, field_width);
3470Sstevel@tonic-gate }
3480Sstevel@tonic-gate
3490Sstevel@tonic-gate if (rpc_clts_server_kstat != NULL) {
3500Sstevel@tonic-gate safe_kstat_read(kc, rpc_clts_server_kstat, NULL);
3510Sstevel@tonic-gate field_width = stat_width(rpc_clts_server_kstat, field_width);
3520Sstevel@tonic-gate }
3530Sstevel@tonic-gate if (rpc_cots_server_kstat != NULL) {
3540Sstevel@tonic-gate safe_kstat_read(kc, rpc_cots_server_kstat, NULL);
3550Sstevel@tonic-gate field_width = stat_width(rpc_cots_server_kstat, field_width);
3560Sstevel@tonic-gate }
3570Sstevel@tonic-gate if (rpc_rdma_server_kstat != NULL) {
3580Sstevel@tonic-gate safe_kstat_read(kc, rpc_rdma_server_kstat, NULL);
3590Sstevel@tonic-gate field_width = stat_width(rpc_rdma_server_kstat, field_width);
3600Sstevel@tonic-gate }
3610Sstevel@tonic-gate return (field_width);
3620Sstevel@tonic-gate }
3630Sstevel@tonic-gate
3640Sstevel@tonic-gate static int
getstats_nfs(void)3650Sstevel@tonic-gate getstats_nfs(void)
3660Sstevel@tonic-gate {
3670Sstevel@tonic-gate int field_width = 0;
3680Sstevel@tonic-gate
3690Sstevel@tonic-gate if (nfs_client_kstat != NULL) {
3700Sstevel@tonic-gate safe_kstat_read(kc, nfs_client_kstat, NULL);
3710Sstevel@tonic-gate field_width = stat_width(nfs_client_kstat, field_width);
3720Sstevel@tonic-gate }
3730Sstevel@tonic-gate if (nfs4_client_kstat != NULL) {
3740Sstevel@tonic-gate safe_kstat_read(kc, nfs4_client_kstat, NULL);
3750Sstevel@tonic-gate field_width = stat_width(nfs4_client_kstat, field_width);
3760Sstevel@tonic-gate }
3770Sstevel@tonic-gate if (nfs_server_v2_kstat != NULL) {
3780Sstevel@tonic-gate safe_kstat_read(kc, nfs_server_v2_kstat, NULL);
3790Sstevel@tonic-gate field_width = stat_width(nfs_server_v2_kstat, field_width);
3800Sstevel@tonic-gate }
3810Sstevel@tonic-gate if (nfs_server_v3_kstat != NULL) {
3820Sstevel@tonic-gate safe_kstat_read(kc, nfs_server_v3_kstat, NULL);
3830Sstevel@tonic-gate field_width = stat_width(nfs_server_v3_kstat, field_width);
3840Sstevel@tonic-gate }
3850Sstevel@tonic-gate if (nfs_server_v4_kstat != NULL) {
3860Sstevel@tonic-gate safe_kstat_read(kc, nfs_server_v4_kstat, NULL);
3870Sstevel@tonic-gate field_width = stat_width(nfs_server_v4_kstat, field_width);
3880Sstevel@tonic-gate }
3890Sstevel@tonic-gate return (field_width);
3900Sstevel@tonic-gate }
3910Sstevel@tonic-gate
3920Sstevel@tonic-gate static int
getstats_rfsproc(int ver)3930Sstevel@tonic-gate getstats_rfsproc(int ver)
3940Sstevel@tonic-gate {
3950Sstevel@tonic-gate int field_width = 0;
3960Sstevel@tonic-gate
3970Sstevel@tonic-gate if ((ver == 2) && (rfsproccnt_v2_kstat != NULL)) {
3980Sstevel@tonic-gate safe_kstat_read(kc, rfsproccnt_v2_kstat, NULL);
3990Sstevel@tonic-gate field_width = req_width(rfsproccnt_v2_kstat, field_width);
4000Sstevel@tonic-gate }
4010Sstevel@tonic-gate if ((ver == 3) && (rfsproccnt_v3_kstat != NULL)) {
4020Sstevel@tonic-gate safe_kstat_read(kc, rfsproccnt_v3_kstat, NULL);
4030Sstevel@tonic-gate field_width = req_width(rfsproccnt_v3_kstat, field_width);
4040Sstevel@tonic-gate }
4050Sstevel@tonic-gate if ((ver == 4) && (rfsproccnt_v4_kstat != NULL)) {
4060Sstevel@tonic-gate safe_kstat_read(kc, rfsproccnt_v4_kstat, NULL);
4070Sstevel@tonic-gate field_width = req_width(rfsproccnt_v4_kstat, field_width);
4080Sstevel@tonic-gate }
4090Sstevel@tonic-gate return (field_width);
4100Sstevel@tonic-gate }
4110Sstevel@tonic-gate
4120Sstevel@tonic-gate static int
getstats_rfsreq(int ver)4130Sstevel@tonic-gate getstats_rfsreq(int ver)
4140Sstevel@tonic-gate {
4150Sstevel@tonic-gate int field_width = 0;
4160Sstevel@tonic-gate if ((ver == 2) && (rfsreqcnt_v2_kstat != NULL)) {
4170Sstevel@tonic-gate safe_kstat_read(kc, rfsreqcnt_v2_kstat, NULL);
4180Sstevel@tonic-gate field_width = req_width(rfsreqcnt_v2_kstat, field_width);
4190Sstevel@tonic-gate }
4200Sstevel@tonic-gate if ((ver == 3) && (rfsreqcnt_v3_kstat != NULL)) {
4210Sstevel@tonic-gate safe_kstat_read(kc, rfsreqcnt_v3_kstat, NULL);
4220Sstevel@tonic-gate field_width = req_width(rfsreqcnt_v3_kstat, field_width);
4230Sstevel@tonic-gate }
4240Sstevel@tonic-gate if ((ver == 4) && (rfsreqcnt_v4_kstat != NULL)) {
4250Sstevel@tonic-gate safe_kstat_read(kc, rfsreqcnt_v4_kstat, NULL);
4260Sstevel@tonic-gate field_width = req_width(rfsreqcnt_v4_kstat, field_width);
4270Sstevel@tonic-gate }
4280Sstevel@tonic-gate return (field_width);
4290Sstevel@tonic-gate }
4300Sstevel@tonic-gate
4310Sstevel@tonic-gate static int
getstats_aclproc(void)4320Sstevel@tonic-gate getstats_aclproc(void)
4330Sstevel@tonic-gate {
4340Sstevel@tonic-gate int field_width = 0;
4350Sstevel@tonic-gate if (aclproccnt_v2_kstat != NULL) {
4360Sstevel@tonic-gate safe_kstat_read(kc, aclproccnt_v2_kstat, NULL);
4370Sstevel@tonic-gate field_width = req_width(aclproccnt_v2_kstat, field_width);
4380Sstevel@tonic-gate }
4390Sstevel@tonic-gate if (aclproccnt_v3_kstat != NULL) {
4400Sstevel@tonic-gate safe_kstat_read(kc, aclproccnt_v3_kstat, NULL);
4410Sstevel@tonic-gate field_width = req_width(aclproccnt_v3_kstat, field_width);
4420Sstevel@tonic-gate }
4430Sstevel@tonic-gate return (field_width);
4440Sstevel@tonic-gate }
4450Sstevel@tonic-gate
4460Sstevel@tonic-gate static int
getstats_aclreq(void)4470Sstevel@tonic-gate getstats_aclreq(void)
4480Sstevel@tonic-gate {
4490Sstevel@tonic-gate int field_width = 0;
4500Sstevel@tonic-gate if (aclreqcnt_v2_kstat != NULL) {
4510Sstevel@tonic-gate safe_kstat_read(kc, aclreqcnt_v2_kstat, NULL);
4520Sstevel@tonic-gate field_width = req_width(aclreqcnt_v2_kstat, field_width);
4530Sstevel@tonic-gate }
4540Sstevel@tonic-gate if (aclreqcnt_v3_kstat != NULL) {
4550Sstevel@tonic-gate safe_kstat_read(kc, aclreqcnt_v3_kstat, NULL);
4560Sstevel@tonic-gate field_width = req_width(aclreqcnt_v3_kstat, field_width);
4570Sstevel@tonic-gate }
4580Sstevel@tonic-gate return (field_width);
4590Sstevel@tonic-gate }
4600Sstevel@tonic-gate
4610Sstevel@tonic-gate static void
putstats(void)4620Sstevel@tonic-gate putstats(void)
4630Sstevel@tonic-gate {
4640Sstevel@tonic-gate if (rpc_clts_client_kstat != NULL)
4650Sstevel@tonic-gate safe_kstat_write(kc, rpc_clts_client_kstat, NULL);
4660Sstevel@tonic-gate if (rpc_cots_client_kstat != NULL)
4670Sstevel@tonic-gate safe_kstat_write(kc, rpc_cots_client_kstat, NULL);
4680Sstevel@tonic-gate if (rpc_rdma_client_kstat != NULL)
4690Sstevel@tonic-gate safe_kstat_write(kc, rpc_rdma_client_kstat, NULL);
4700Sstevel@tonic-gate if (nfs_client_kstat != NULL)
4710Sstevel@tonic-gate safe_kstat_write(kc, nfs_client_kstat, NULL);
4720Sstevel@tonic-gate if (nfs4_client_kstat != NULL)
4730Sstevel@tonic-gate safe_kstat_write(kc, nfs4_client_kstat, NULL);
4740Sstevel@tonic-gate if (rpc_clts_server_kstat != NULL)
4750Sstevel@tonic-gate safe_kstat_write(kc, rpc_clts_server_kstat, NULL);
4760Sstevel@tonic-gate if (rpc_cots_server_kstat != NULL)
4770Sstevel@tonic-gate safe_kstat_write(kc, rpc_cots_server_kstat, NULL);
4780Sstevel@tonic-gate if (rpc_rdma_server_kstat != NULL)
4790Sstevel@tonic-gate safe_kstat_write(kc, rpc_rdma_server_kstat, NULL);
4800Sstevel@tonic-gate if (nfs_server_v2_kstat != NULL)
4810Sstevel@tonic-gate safe_kstat_write(kc, nfs_server_v2_kstat, NULL);
4820Sstevel@tonic-gate if (nfs_server_v3_kstat != NULL)
4830Sstevel@tonic-gate safe_kstat_write(kc, nfs_server_v3_kstat, NULL);
4840Sstevel@tonic-gate if (nfs_server_v4_kstat != NULL)
4850Sstevel@tonic-gate safe_kstat_write(kc, nfs_server_v4_kstat, NULL);
4860Sstevel@tonic-gate if (rfsproccnt_v2_kstat != NULL)
4870Sstevel@tonic-gate safe_kstat_write(kc, rfsproccnt_v2_kstat, NULL);
4880Sstevel@tonic-gate if (rfsproccnt_v3_kstat != NULL)
4890Sstevel@tonic-gate safe_kstat_write(kc, rfsproccnt_v3_kstat, NULL);
4900Sstevel@tonic-gate if (rfsproccnt_v4_kstat != NULL)
4910Sstevel@tonic-gate safe_kstat_write(kc, rfsproccnt_v4_kstat, NULL);
4920Sstevel@tonic-gate if (rfsreqcnt_v2_kstat != NULL)
4930Sstevel@tonic-gate safe_kstat_write(kc, rfsreqcnt_v2_kstat, NULL);
4940Sstevel@tonic-gate if (rfsreqcnt_v3_kstat != NULL)
4950Sstevel@tonic-gate safe_kstat_write(kc, rfsreqcnt_v3_kstat, NULL);
4960Sstevel@tonic-gate if (rfsreqcnt_v4_kstat != NULL)
4970Sstevel@tonic-gate safe_kstat_write(kc, rfsreqcnt_v4_kstat, NULL);
4980Sstevel@tonic-gate if (aclproccnt_v2_kstat != NULL)
4990Sstevel@tonic-gate safe_kstat_write(kc, aclproccnt_v2_kstat, NULL);
5000Sstevel@tonic-gate if (aclproccnt_v3_kstat != NULL)
5010Sstevel@tonic-gate safe_kstat_write(kc, aclproccnt_v3_kstat, NULL);
5020Sstevel@tonic-gate if (aclreqcnt_v2_kstat != NULL)
5030Sstevel@tonic-gate safe_kstat_write(kc, aclreqcnt_v2_kstat, NULL);
5040Sstevel@tonic-gate if (aclreqcnt_v3_kstat != NULL)
5050Sstevel@tonic-gate safe_kstat_write(kc, aclreqcnt_v3_kstat, NULL);
5060Sstevel@tonic-gate }
5070Sstevel@tonic-gate
5080Sstevel@tonic-gate static void
setup(void)5090Sstevel@tonic-gate setup(void)
5100Sstevel@tonic-gate {
5110Sstevel@tonic-gate if ((kc = kstat_open()) == NULL)
5120Sstevel@tonic-gate fail(1, "kstat_open(): can't open /dev/kstat");
5130Sstevel@tonic-gate
51410429SMarcel.Telka@Sun.COM /* alloc space for our temporary kstat */
51510429SMarcel.Telka@Sun.COM safe_zalloc((void **)&ksum_kstat, sizeof (kstat_t), 0);
5160Sstevel@tonic-gate rpc_clts_client_kstat = kstat_lookup(kc, "unix", 0, "rpc_clts_client");
5170Sstevel@tonic-gate rpc_clts_server_kstat = kstat_lookup(kc, "unix", 0, "rpc_clts_server");
5180Sstevel@tonic-gate rpc_cots_client_kstat = kstat_lookup(kc, "unix", 0, "rpc_cots_client");
5190Sstevel@tonic-gate rpc_cots_server_kstat = kstat_lookup(kc, "unix", 0, "rpc_cots_server");
5200Sstevel@tonic-gate rpc_rdma_client_kstat = kstat_lookup(kc, "unix", 0, "rpc_rdma_client");
5210Sstevel@tonic-gate rpc_rdma_server_kstat = kstat_lookup(kc, "unix", 0, "rpc_rdma_server");
5220Sstevel@tonic-gate nfs_client_kstat = kstat_lookup(kc, "nfs", 0, "nfs_client");
5230Sstevel@tonic-gate nfs4_client_kstat = kstat_lookup(kc, "nfs", 0, "nfs4_client");
5240Sstevel@tonic-gate nfs_server_v2_kstat = kstat_lookup(kc, "nfs", 2, "nfs_server");
5250Sstevel@tonic-gate nfs_server_v3_kstat = kstat_lookup(kc, "nfs", 3, "nfs_server");
5260Sstevel@tonic-gate nfs_server_v4_kstat = kstat_lookup(kc, "nfs", 4, "nfs_server");
5270Sstevel@tonic-gate rfsproccnt_v2_kstat = kstat_lookup(kc, "nfs", 0, "rfsproccnt_v2");
5280Sstevel@tonic-gate rfsproccnt_v3_kstat = kstat_lookup(kc, "nfs", 0, "rfsproccnt_v3");
5290Sstevel@tonic-gate rfsproccnt_v4_kstat = kstat_lookup(kc, "nfs", 0, "rfsproccnt_v4");
5300Sstevel@tonic-gate rfsreqcnt_v2_kstat = kstat_lookup(kc, "nfs", 0, "rfsreqcnt_v2");
5310Sstevel@tonic-gate rfsreqcnt_v3_kstat = kstat_lookup(kc, "nfs", 0, "rfsreqcnt_v3");
5320Sstevel@tonic-gate rfsreqcnt_v4_kstat = kstat_lookup(kc, "nfs", 0, "rfsreqcnt_v4");
5330Sstevel@tonic-gate aclproccnt_v2_kstat = kstat_lookup(kc, "nfs_acl", 0, "aclproccnt_v2");
5340Sstevel@tonic-gate aclproccnt_v3_kstat = kstat_lookup(kc, "nfs_acl", 0, "aclproccnt_v3");
5350Sstevel@tonic-gate aclreqcnt_v2_kstat = kstat_lookup(kc, "nfs_acl", 0, "aclreqcnt_v2");
5360Sstevel@tonic-gate aclreqcnt_v3_kstat = kstat_lookup(kc, "nfs_acl", 0, "aclreqcnt_v3");
5370Sstevel@tonic-gate if (rpc_clts_client_kstat == NULL && rpc_cots_server_kstat == NULL &&
5380Sstevel@tonic-gate rfsproccnt_v2_kstat == NULL && rfsreqcnt_v3_kstat == NULL)
5390Sstevel@tonic-gate fail(0, "Multiple kstat lookups failed."
5403406Sth199096 "Your kernel module may not be loaded\n");
5410Sstevel@tonic-gate }
5420Sstevel@tonic-gate
5430Sstevel@tonic-gate static int
req_width(kstat_t * req,int field_width)5440Sstevel@tonic-gate req_width(kstat_t *req, int field_width)
5450Sstevel@tonic-gate {
5460Sstevel@tonic-gate int i, nreq, per, len;
5470Sstevel@tonic-gate char fixlen[128];
5480Sstevel@tonic-gate kstat_named_t *knp;
5490Sstevel@tonic-gate uint64_t tot;
5500Sstevel@tonic-gate
5510Sstevel@tonic-gate tot = 0;
5520Sstevel@tonic-gate knp = KSTAT_NAMED_PTR(req);
5530Sstevel@tonic-gate for (i = 0; i < req->ks_ndata; i++)
5540Sstevel@tonic-gate tot += knp[i].value.ui64;
5550Sstevel@tonic-gate
5560Sstevel@tonic-gate knp = kstat_data_lookup(req, "null");
5570Sstevel@tonic-gate nreq = req->ks_ndata - (knp - KSTAT_NAMED_PTR(req));
5580Sstevel@tonic-gate
5590Sstevel@tonic-gate for (i = 0; i < nreq; i++) {
5600Sstevel@tonic-gate len = strlen(knp[i].name) + 1;
5610Sstevel@tonic-gate if (field_width < len)
5620Sstevel@tonic-gate field_width = len;
5630Sstevel@tonic-gate if (tot)
5640Sstevel@tonic-gate per = (int)(knp[i].value.ui64 * 100 / tot);
5650Sstevel@tonic-gate else
5660Sstevel@tonic-gate per = 0;
5670Sstevel@tonic-gate (void) sprintf(fixlen, "%" PRIu64 " %d%%",
5685302Sth199096 knp[i].value.ui64, per);
5690Sstevel@tonic-gate len = strlen(fixlen) + 1;
5700Sstevel@tonic-gate if (field_width < len)
5710Sstevel@tonic-gate field_width = len;
5720Sstevel@tonic-gate }
5730Sstevel@tonic-gate return (field_width);
5740Sstevel@tonic-gate }
5750Sstevel@tonic-gate
5760Sstevel@tonic-gate static int
stat_width(kstat_t * req,int field_width)5770Sstevel@tonic-gate stat_width(kstat_t *req, int field_width)
5780Sstevel@tonic-gate {
5790Sstevel@tonic-gate int i, nreq, len;
5800Sstevel@tonic-gate char fixlen[128];
5810Sstevel@tonic-gate kstat_named_t *knp;
5820Sstevel@tonic-gate
5830Sstevel@tonic-gate knp = KSTAT_NAMED_PTR(req);
5840Sstevel@tonic-gate nreq = req->ks_ndata;
5850Sstevel@tonic-gate
5860Sstevel@tonic-gate for (i = 0; i < nreq; i++) {
5870Sstevel@tonic-gate len = strlen(knp[i].name) + 1;
5880Sstevel@tonic-gate if (field_width < len)
5890Sstevel@tonic-gate field_width = len;
5900Sstevel@tonic-gate (void) sprintf(fixlen, "%" PRIu64, knp[i].value.ui64);
5910Sstevel@tonic-gate len = strlen(fixlen) + 1;
5920Sstevel@tonic-gate if (field_width < len)
5930Sstevel@tonic-gate field_width = len;
5940Sstevel@tonic-gate }
5950Sstevel@tonic-gate return (field_width);
5960Sstevel@tonic-gate }
5970Sstevel@tonic-gate
5980Sstevel@tonic-gate static void
cr_print(int zflag)5990Sstevel@tonic-gate cr_print(int zflag)
6000Sstevel@tonic-gate {
6010Sstevel@tonic-gate int field_width;
6020Sstevel@tonic-gate
6030Sstevel@tonic-gate field_width = getstats_rpc();
6043406Sth199096 if (field_width == 0)
6053406Sth199096 return;
6063406Sth199096
6070Sstevel@tonic-gate stat_print("\nClient rpc:\nConnection oriented:",
6085302Sth199096 rpc_cots_client_kstat,
6095302Sth199096 &old_rpc_cots_client_kstat.kst, field_width, zflag);
6100Sstevel@tonic-gate stat_print("Connectionless:", rpc_clts_client_kstat,
6115302Sth199096 &old_rpc_clts_client_kstat.kst, field_width, zflag);
6120Sstevel@tonic-gate stat_print("RDMA based:", rpc_rdma_client_kstat,
6135302Sth199096 &old_rpc_rdma_client_kstat.kst, field_width, zflag);
6140Sstevel@tonic-gate }
6150Sstevel@tonic-gate
6160Sstevel@tonic-gate static void
sr_print(int zflag)6170Sstevel@tonic-gate sr_print(int zflag)
6180Sstevel@tonic-gate {
6190Sstevel@tonic-gate int field_width;
6200Sstevel@tonic-gate
6210Sstevel@tonic-gate field_width = getstats_rpc();
6223406Sth199096 if (field_width == 0)
6233406Sth199096 return;
6243406Sth199096
6250Sstevel@tonic-gate stat_print("\nServer rpc:\nConnection oriented:", rpc_cots_server_kstat,
6265302Sth199096 &old_rpc_cots_server_kstat.kst, field_width, zflag);
6270Sstevel@tonic-gate stat_print("Connectionless:", rpc_clts_server_kstat,
6285302Sth199096 &old_rpc_clts_server_kstat.kst, field_width, zflag);
6290Sstevel@tonic-gate stat_print("RDMA based:", rpc_rdma_server_kstat,
6305302Sth199096 &old_rpc_rdma_server_kstat.kst, field_width, zflag);
6310Sstevel@tonic-gate }
6320Sstevel@tonic-gate
6330Sstevel@tonic-gate static void
cn_print(int zflag,int vflag)6340Sstevel@tonic-gate cn_print(int zflag, int vflag)
6350Sstevel@tonic-gate {
6360Sstevel@tonic-gate int field_width;
6370Sstevel@tonic-gate
6380Sstevel@tonic-gate field_width = getstats_nfs();
6393406Sth199096 if (field_width == 0)
6403406Sth199096 return;
6410Sstevel@tonic-gate
6420Sstevel@tonic-gate if (vflag == 0) {
64310265SKrishnendu.Sadhukhan@Sun.COM nfsstat_kstat_sum(nfs_client_kstat, nfs4_client_kstat,
64410265SKrishnendu.Sadhukhan@Sun.COM ksum_kstat);
6450Sstevel@tonic-gate stat_print("\nClient nfs:", ksum_kstat, &old_ksum_kstat.kst,
6465302Sth199096 field_width, zflag);
6470Sstevel@tonic-gate }
6480Sstevel@tonic-gate
6490Sstevel@tonic-gate if (vflag == 2 || vflag == 3) {
6500Sstevel@tonic-gate stat_print("\nClient nfs:", nfs_client_kstat,
6515302Sth199096 &old_nfs_client_kstat.kst, field_width, zflag);
6520Sstevel@tonic-gate }
6530Sstevel@tonic-gate
6540Sstevel@tonic-gate if (vflag == 4) {
6550Sstevel@tonic-gate stat_print("\nClient nfs:", nfs4_client_kstat,
6565302Sth199096 &old_nfs4_client_kstat.kst, field_width, zflag);
6570Sstevel@tonic-gate }
6580Sstevel@tonic-gate
6590Sstevel@tonic-gate if (vflag == 2 || vflag == 0) {
6600Sstevel@tonic-gate field_width = getstats_rfsreq(2);
6610Sstevel@tonic-gate req_print(rfsreqcnt_v2_kstat, &old_rfsreqcnt_v2_kstat.kst,
6625302Sth199096 2, field_width, zflag);
6630Sstevel@tonic-gate }
6640Sstevel@tonic-gate
6650Sstevel@tonic-gate if (vflag == 3 || vflag == 0) {
6660Sstevel@tonic-gate field_width = getstats_rfsreq(3);
6670Sstevel@tonic-gate req_print(rfsreqcnt_v3_kstat, &old_rfsreqcnt_v3_kstat.kst, 3,
6685302Sth199096 field_width, zflag);
6690Sstevel@tonic-gate }
6700Sstevel@tonic-gate
6710Sstevel@tonic-gate if (vflag == 4 || vflag == 0) {
6720Sstevel@tonic-gate field_width = getstats_rfsreq(4);
6730Sstevel@tonic-gate req_print_v4(rfsreqcnt_v4_kstat, &old_rfsreqcnt_v4_kstat.kst,
6745302Sth199096 field_width, zflag);
6750Sstevel@tonic-gate }
6760Sstevel@tonic-gate }
6770Sstevel@tonic-gate
6780Sstevel@tonic-gate static void
sn_print(int zflag,int vflag)6790Sstevel@tonic-gate sn_print(int zflag, int vflag)
6800Sstevel@tonic-gate {
6810Sstevel@tonic-gate int field_width;
6820Sstevel@tonic-gate
6830Sstevel@tonic-gate field_width = getstats_nfs();
6843406Sth199096 if (field_width == 0)
6853406Sth199096 return;
6863406Sth199096
6870Sstevel@tonic-gate if (vflag == 2 || vflag == 0) {
6880Sstevel@tonic-gate stat_print("\nServer NFSv2:", nfs_server_v2_kstat,
6895302Sth199096 &old_nfs_server_v2_kstat.kst, field_width, zflag);
6900Sstevel@tonic-gate }
6910Sstevel@tonic-gate
6920Sstevel@tonic-gate if (vflag == 3 || vflag == 0) {
6930Sstevel@tonic-gate stat_print("\nServer NFSv3:", nfs_server_v3_kstat,
6945302Sth199096 &old_nfs_server_v3_kstat.kst, field_width, zflag);
6950Sstevel@tonic-gate }
6960Sstevel@tonic-gate
6970Sstevel@tonic-gate if (vflag == 4 || vflag == 0) {
6980Sstevel@tonic-gate stat_print("\nServer NFSv4:", nfs_server_v4_kstat,
6995302Sth199096 &old_nfs_server_v4_kstat.kst, field_width, zflag);
7000Sstevel@tonic-gate }
7010Sstevel@tonic-gate
7020Sstevel@tonic-gate if (vflag == 2 || vflag == 0) {
7030Sstevel@tonic-gate field_width = getstats_rfsproc(2);
7040Sstevel@tonic-gate req_print(rfsproccnt_v2_kstat, &old_rfsproccnt_v2_kstat.kst,
7055302Sth199096 2, field_width, zflag);
7060Sstevel@tonic-gate }
7070Sstevel@tonic-gate
7080Sstevel@tonic-gate if (vflag == 3 || vflag == 0) {
7090Sstevel@tonic-gate field_width = getstats_rfsproc(3);
7100Sstevel@tonic-gate req_print(rfsproccnt_v3_kstat, &old_rfsproccnt_v3_kstat.kst,
7115302Sth199096 3, field_width, zflag);
7120Sstevel@tonic-gate }
7130Sstevel@tonic-gate
7140Sstevel@tonic-gate if (vflag == 4 || vflag == 0) {
7150Sstevel@tonic-gate field_width = getstats_rfsproc(4);
7160Sstevel@tonic-gate req_print_v4(rfsproccnt_v4_kstat, &old_rfsproccnt_v4_kstat.kst,
7175302Sth199096 field_width, zflag);
7180Sstevel@tonic-gate }
7190Sstevel@tonic-gate }
7200Sstevel@tonic-gate
7210Sstevel@tonic-gate static void
ca_print(int zflag,int vflag)7220Sstevel@tonic-gate ca_print(int zflag, int vflag)
7230Sstevel@tonic-gate {
7240Sstevel@tonic-gate int field_width;
7250Sstevel@tonic-gate
7260Sstevel@tonic-gate field_width = getstats_aclreq();
7273406Sth199096 if (field_width == 0)
7283406Sth199096 return;
7293406Sth199096
7300Sstevel@tonic-gate printf("\nClient nfs_acl:\n");
7310Sstevel@tonic-gate
7320Sstevel@tonic-gate if (vflag == 2 || vflag == 0) {
7330Sstevel@tonic-gate req_print(aclreqcnt_v2_kstat, &old_aclreqcnt_v2_kstat.kst, 2,
7345302Sth199096 field_width, zflag);
7350Sstevel@tonic-gate }
7360Sstevel@tonic-gate
7370Sstevel@tonic-gate if (vflag == 3 || vflag == 0) {
7380Sstevel@tonic-gate req_print(aclreqcnt_v3_kstat, &old_aclreqcnt_v3_kstat.kst,
7395302Sth199096 3, field_width, zflag);
7400Sstevel@tonic-gate }
7410Sstevel@tonic-gate }
7420Sstevel@tonic-gate
7430Sstevel@tonic-gate static void
sa_print(int zflag,int vflag)7440Sstevel@tonic-gate sa_print(int zflag, int vflag)
7450Sstevel@tonic-gate {
7460Sstevel@tonic-gate int field_width;
7470Sstevel@tonic-gate
7480Sstevel@tonic-gate field_width = getstats_aclproc();
7493406Sth199096 if (field_width == 0)
7503406Sth199096 return;
7510Sstevel@tonic-gate
7520Sstevel@tonic-gate printf("\nServer nfs_acl:\n");
7530Sstevel@tonic-gate
7540Sstevel@tonic-gate if (vflag == 2 || vflag == 0) {
7550Sstevel@tonic-gate req_print(aclproccnt_v2_kstat, &old_aclproccnt_v2_kstat.kst,
7565302Sth199096 2, field_width, zflag);
7570Sstevel@tonic-gate }
7580Sstevel@tonic-gate
7590Sstevel@tonic-gate if (vflag == 3 || vflag == 0) {
7600Sstevel@tonic-gate req_print(aclproccnt_v3_kstat, &old_aclproccnt_v3_kstat.kst,
7615302Sth199096 3, field_width, zflag);
7620Sstevel@tonic-gate }
7630Sstevel@tonic-gate }
7640Sstevel@tonic-gate
7650Sstevel@tonic-gate #define MIN(a, b) ((a) < (b) ? (a) : (b))
7660Sstevel@tonic-gate
7670Sstevel@tonic-gate static void
req_print(kstat_t * req,kstat_t * req_old,int ver,int field_width,int zflag)7680Sstevel@tonic-gate req_print(kstat_t *req, kstat_t *req_old, int ver, int field_width,
7695302Sth199096 int zflag)
7700Sstevel@tonic-gate {
7710Sstevel@tonic-gate int i, j, nreq, per, ncolumns;
7720Sstevel@tonic-gate uint64_t tot, old_tot;
7730Sstevel@tonic-gate char fixlen[128];
7740Sstevel@tonic-gate kstat_named_t *knp;
7750Sstevel@tonic-gate kstat_named_t *kptr;
7760Sstevel@tonic-gate kstat_named_t *knp_old;
7770Sstevel@tonic-gate
7780Sstevel@tonic-gate if (req == NULL)
7790Sstevel@tonic-gate return;
7800Sstevel@tonic-gate
7813406Sth199096 if (field_width == 0)
7823406Sth199096 return;
7833406Sth199096
7840Sstevel@tonic-gate ncolumns = (MAX_COLUMNS -1)/field_width;
7850Sstevel@tonic-gate knp = kstat_data_lookup(req, "null");
7860Sstevel@tonic-gate knp_old = KSTAT_NAMED_PTR(req_old);
7870Sstevel@tonic-gate
7880Sstevel@tonic-gate kptr = KSTAT_NAMED_PTR(req);
7890Sstevel@tonic-gate nreq = req->ks_ndata - (knp - KSTAT_NAMED_PTR(req));
7900Sstevel@tonic-gate
7910Sstevel@tonic-gate tot = 0;
7920Sstevel@tonic-gate old_tot = 0;
7930Sstevel@tonic-gate
7940Sstevel@tonic-gate if (knp_old == NULL) {
7950Sstevel@tonic-gate old_tot = 0;
7960Sstevel@tonic-gate }
7970Sstevel@tonic-gate
7980Sstevel@tonic-gate for (i = 0; i < req->ks_ndata; i++)
7990Sstevel@tonic-gate tot += kptr[i].value.ui64;
8000Sstevel@tonic-gate
8010Sstevel@tonic-gate if (interval && knp_old != NULL) {
8020Sstevel@tonic-gate for (i = 0; i < req_old->ks_ndata; i++)
8030Sstevel@tonic-gate old_tot += knp_old[i].value.ui64;
8040Sstevel@tonic-gate tot -= old_tot;
8050Sstevel@tonic-gate }
8060Sstevel@tonic-gate
8070Sstevel@tonic-gate printf("Version %d: (%" PRIu64 " calls)\n", ver, tot);
8080Sstevel@tonic-gate
8090Sstevel@tonic-gate for (i = 0; i < nreq; i += ncolumns) {
8100Sstevel@tonic-gate for (j = i; j < MIN(i + ncolumns, nreq); j++) {
8110Sstevel@tonic-gate printf("%-*s", field_width, knp[j].name);
8120Sstevel@tonic-gate }
8130Sstevel@tonic-gate printf("\n");
8140Sstevel@tonic-gate for (j = i; j < MIN(i + ncolumns, nreq); j++) {
8150Sstevel@tonic-gate if (tot && interval && knp_old != NULL)
8160Sstevel@tonic-gate per = (int)((knp[j].value.ui64 -
8170Sstevel@tonic-gate knp_old[j].value.ui64) * 100 / tot);
8180Sstevel@tonic-gate else if (tot)
8190Sstevel@tonic-gate per = (int)(knp[j].value.ui64 * 100 / tot);
8200Sstevel@tonic-gate else
8210Sstevel@tonic-gate per = 0;
8220Sstevel@tonic-gate (void) sprintf(fixlen, "%" PRIu64 " %d%% ",
8235302Sth199096 ((interval && knp_old != NULL) ?
8245302Sth199096 (knp[j].value.ui64 - knp_old[j].value.ui64)
8255302Sth199096 : knp[j].value.ui64), per);
8260Sstevel@tonic-gate printf("%-*s", field_width, fixlen);
8270Sstevel@tonic-gate }
8280Sstevel@tonic-gate printf("\n");
8295998Sgt29601 }
8305998Sgt29601 if (zflag) {
8315998Sgt29601 for (i = 0; i < req->ks_ndata; i++)
8325998Sgt29601 knp[i].value.ui64 = 0;
8330Sstevel@tonic-gate }
8345998Sgt29601 if (knp_old != NULL)
83510265SKrishnendu.Sadhukhan@Sun.COM nfsstat_kstat_copy(req, req_old, 1);
8365998Sgt29601 else
83710265SKrishnendu.Sadhukhan@Sun.COM nfsstat_kstat_copy(req, req_old, 0);
8380Sstevel@tonic-gate }
8390Sstevel@tonic-gate
8400Sstevel@tonic-gate /*
8410Sstevel@tonic-gate * Separate version of the req_print() to deal with V4 and its use of
8420Sstevel@tonic-gate * procedures and operations. It looks odd to have the counts for
8430Sstevel@tonic-gate * both of those lumped into the same set of statistics so this
8440Sstevel@tonic-gate * function (copy of req_print() does the separation and titles).
8450Sstevel@tonic-gate */
8460Sstevel@tonic-gate
8470Sstevel@tonic-gate #define COUNT 2
8480Sstevel@tonic-gate
8490Sstevel@tonic-gate static void
req_print_v4(kstat_t * req,kstat_t * req_old,int field_width,int zflag)8500Sstevel@tonic-gate req_print_v4(kstat_t *req, kstat_t *req_old, int field_width, int zflag)
8510Sstevel@tonic-gate {
8520Sstevel@tonic-gate int i, j, nreq, per, ncolumns;
8530Sstevel@tonic-gate uint64_t tot, tot_ops, old_tot, old_tot_ops;
8540Sstevel@tonic-gate char fixlen[128];
8550Sstevel@tonic-gate kstat_named_t *kptr;
8560Sstevel@tonic-gate kstat_named_t *knp;
8570Sstevel@tonic-gate kstat_named_t *kptr_old;
8580Sstevel@tonic-gate
8590Sstevel@tonic-gate if (req == NULL)
8600Sstevel@tonic-gate return;
8610Sstevel@tonic-gate
8623406Sth199096 if (field_width == 0)
8633406Sth199096 return;
8643406Sth199096
8650Sstevel@tonic-gate ncolumns = (MAX_COLUMNS)/field_width;
8660Sstevel@tonic-gate kptr = KSTAT_NAMED_PTR(req);
8670Sstevel@tonic-gate kptr_old = KSTAT_NAMED_PTR(req_old);
8680Sstevel@tonic-gate
8690Sstevel@tonic-gate if (kptr_old == NULL) {
8700Sstevel@tonic-gate old_tot_ops = 0;
8710Sstevel@tonic-gate old_tot = 0;
8720Sstevel@tonic-gate } else {
8730Sstevel@tonic-gate old_tot = kptr_old[0].value.ui64 + kptr_old[1].value.ui64;
8740Sstevel@tonic-gate for (i = 2, old_tot_ops = 0; i < req_old->ks_ndata; i++)
8750Sstevel@tonic-gate old_tot_ops += kptr_old[i].value.ui64;
8760Sstevel@tonic-gate }
8770Sstevel@tonic-gate
8780Sstevel@tonic-gate /* Count the number of operations sent */
8790Sstevel@tonic-gate for (i = 2, tot_ops = 0; i < req->ks_ndata; i++)
8800Sstevel@tonic-gate tot_ops += kptr[i].value.ui64;
8810Sstevel@tonic-gate /* For v4 NULL/COMPOUND are the only procedures */
8820Sstevel@tonic-gate tot = kptr[0].value.ui64 + kptr[1].value.ui64;
8830Sstevel@tonic-gate
8840Sstevel@tonic-gate if (interval) {
8850Sstevel@tonic-gate tot -= old_tot;
8860Sstevel@tonic-gate tot_ops -= old_tot_ops;
8870Sstevel@tonic-gate }
8880Sstevel@tonic-gate
8890Sstevel@tonic-gate printf("Version 4: (%" PRIu64 " calls)\n", tot);
8900Sstevel@tonic-gate
8910Sstevel@tonic-gate knp = kstat_data_lookup(req, "null");
8920Sstevel@tonic-gate nreq = req->ks_ndata - (knp - KSTAT_NAMED_PTR(req));
8930Sstevel@tonic-gate
8940Sstevel@tonic-gate for (i = 0; i < COUNT; i += ncolumns) {
8950Sstevel@tonic-gate for (j = i; j < MIN(i + ncolumns, 2); j++) {
8960Sstevel@tonic-gate printf("%-*s", field_width, knp[j].name);
8970Sstevel@tonic-gate }
8980Sstevel@tonic-gate printf("\n");
8990Sstevel@tonic-gate for (j = i; j < MIN(i + ncolumns, 2); j++) {
9000Sstevel@tonic-gate if (tot && interval && kptr_old != NULL)
9010Sstevel@tonic-gate per = (int)((knp[j].value.ui64 -
9020Sstevel@tonic-gate kptr_old[j].value.ui64) * 100 / tot);
9030Sstevel@tonic-gate else if (tot)
9040Sstevel@tonic-gate per = (int)(knp[j].value.ui64 * 100 / tot);
9050Sstevel@tonic-gate else
9060Sstevel@tonic-gate per = 0;
9070Sstevel@tonic-gate (void) sprintf(fixlen, "%" PRIu64 " %d%% ",
9085302Sth199096 ((interval && kptr_old != NULL) ?
9095302Sth199096 (knp[j].value.ui64 - kptr_old[j].value.ui64)
9105302Sth199096 : knp[j].value.ui64), per);
9110Sstevel@tonic-gate printf("%-*s", field_width, fixlen);
9120Sstevel@tonic-gate }
9130Sstevel@tonic-gate printf("\n");
9140Sstevel@tonic-gate }
9150Sstevel@tonic-gate
9160Sstevel@tonic-gate printf("Version 4: (%" PRIu64 " operations)\n", tot_ops);
9170Sstevel@tonic-gate for (i = 2; i < nreq; i += ncolumns) {
9180Sstevel@tonic-gate for (j = i; j < MIN(i + ncolumns, nreq); j++) {
9190Sstevel@tonic-gate printf("%-*s", field_width, knp[j].name);
9200Sstevel@tonic-gate }
9210Sstevel@tonic-gate printf("\n");
9220Sstevel@tonic-gate for (j = i; j < MIN(i + ncolumns, nreq); j++) {
9230Sstevel@tonic-gate if (tot_ops && interval && kptr_old != NULL)
9240Sstevel@tonic-gate per = (int)((knp[j].value.ui64 -
9250Sstevel@tonic-gate kptr_old[j].value.ui64) * 100 / tot_ops);
9260Sstevel@tonic-gate else if (tot_ops)
9270Sstevel@tonic-gate per = (int)(knp[j].value.ui64 * 100 / tot_ops);
9280Sstevel@tonic-gate else
9290Sstevel@tonic-gate per = 0;
9300Sstevel@tonic-gate (void) sprintf(fixlen, "%" PRIu64 " %d%% ",
9315302Sth199096 ((interval && kptr_old != NULL) ?
9325302Sth199096 (knp[j].value.ui64 - kptr_old[j].value.ui64)
9335302Sth199096 : knp[j].value.ui64), per);
9340Sstevel@tonic-gate printf("%-*s", field_width, fixlen);
9350Sstevel@tonic-gate }
9360Sstevel@tonic-gate printf("\n");
9370Sstevel@tonic-gate }
9380Sstevel@tonic-gate if (zflag) {
9390Sstevel@tonic-gate for (i = 0; i < req->ks_ndata; i++)
9400Sstevel@tonic-gate kptr[i].value.ui64 = 0;
9410Sstevel@tonic-gate }
9420Sstevel@tonic-gate if (kptr_old != NULL)
94310265SKrishnendu.Sadhukhan@Sun.COM nfsstat_kstat_copy(req, req_old, 1);
9440Sstevel@tonic-gate else
94510265SKrishnendu.Sadhukhan@Sun.COM nfsstat_kstat_copy(req, req_old, 0);
9460Sstevel@tonic-gate }
9470Sstevel@tonic-gate
9480Sstevel@tonic-gate static void
stat_print(const char * title_string,kstat_t * req,kstat_t * req_old,int field_width,int zflag)9490Sstevel@tonic-gate stat_print(const char *title_string, kstat_t *req, kstat_t *req_old,
9505302Sth199096 int field_width, int zflag)
9510Sstevel@tonic-gate {
9520Sstevel@tonic-gate int i, j, nreq, ncolumns;
9530Sstevel@tonic-gate char fixlen[128];
9540Sstevel@tonic-gate kstat_named_t *knp;
9550Sstevel@tonic-gate kstat_named_t *knp_old;
9560Sstevel@tonic-gate
9570Sstevel@tonic-gate if (req == NULL)
9580Sstevel@tonic-gate return;
9590Sstevel@tonic-gate
9603406Sth199096 if (field_width == 0)
9613406Sth199096 return;
9623406Sth199096
9630Sstevel@tonic-gate printf("%s\n", title_string);
9640Sstevel@tonic-gate ncolumns = (MAX_COLUMNS -1)/field_width;
9650Sstevel@tonic-gate
9660Sstevel@tonic-gate /* MEANS knp = (kstat_named_t *)req->ks_data */
9670Sstevel@tonic-gate knp = KSTAT_NAMED_PTR(req);
9680Sstevel@tonic-gate nreq = req->ks_ndata;
9690Sstevel@tonic-gate knp_old = KSTAT_NAMED_PTR(req_old);
9700Sstevel@tonic-gate
9710Sstevel@tonic-gate for (i = 0; i < nreq; i += ncolumns) {
9720Sstevel@tonic-gate /* prints out the titles of the columns */
9730Sstevel@tonic-gate for (j = i; j < MIN(i + ncolumns, nreq); j++) {
9740Sstevel@tonic-gate printf("%-*s", field_width, knp[j].name);
9750Sstevel@tonic-gate }
9760Sstevel@tonic-gate printf("\n");
9770Sstevel@tonic-gate /* prints out the stat numbers */
9780Sstevel@tonic-gate for (j = i; j < MIN(i + ncolumns, nreq); j++) {
9790Sstevel@tonic-gate (void) sprintf(fixlen, "%" PRIu64 " ",
9805302Sth199096 (interval && knp_old != NULL) ?
9815302Sth199096 (knp[j].value.ui64 - knp_old[j].value.ui64)
9825302Sth199096 : knp[j].value.ui64);
9830Sstevel@tonic-gate printf("%-*s", field_width, fixlen);
9840Sstevel@tonic-gate }
9850Sstevel@tonic-gate printf("\n");
9860Sstevel@tonic-gate
9870Sstevel@tonic-gate }
9880Sstevel@tonic-gate if (zflag) {
9890Sstevel@tonic-gate for (i = 0; i < req->ks_ndata; i++)
9900Sstevel@tonic-gate knp[i].value.ui64 = 0;
9910Sstevel@tonic-gate }
9920Sstevel@tonic-gate
9930Sstevel@tonic-gate if (knp_old != NULL)
99410265SKrishnendu.Sadhukhan@Sun.COM nfsstat_kstat_copy(req, req_old, 1);
9950Sstevel@tonic-gate else
99610265SKrishnendu.Sadhukhan@Sun.COM nfsstat_kstat_copy(req, req_old, 0);
9970Sstevel@tonic-gate }
9983406Sth199096
9990Sstevel@tonic-gate static void
nfsstat_kstat_sum(kstat_t * kstat1,kstat_t * kstat2,kstat_t * sum)100010265SKrishnendu.Sadhukhan@Sun.COM nfsstat_kstat_sum(kstat_t *kstat1, kstat_t *kstat2, kstat_t *sum)
10010Sstevel@tonic-gate {
10020Sstevel@tonic-gate int i;
10030Sstevel@tonic-gate kstat_named_t *knp1, *knp2, *knpsum;
10040Sstevel@tonic-gate if (kstat1 == NULL || kstat2 == NULL)
10050Sstevel@tonic-gate return;
10060Sstevel@tonic-gate
10070Sstevel@tonic-gate knp1 = KSTAT_NAMED_PTR(kstat1);
10080Sstevel@tonic-gate knp2 = KSTAT_NAMED_PTR(kstat2);
10090Sstevel@tonic-gate if (sum->ks_data == NULL)
101010265SKrishnendu.Sadhukhan@Sun.COM nfsstat_kstat_copy(kstat1, sum, 0);
10110Sstevel@tonic-gate knpsum = KSTAT_NAMED_PTR(sum);
10120Sstevel@tonic-gate
10130Sstevel@tonic-gate for (i = 0; i < (kstat1->ks_ndata); i++)
10140Sstevel@tonic-gate knpsum[i].value.ui64 = knp1[i].value.ui64 + knp2[i].value.ui64;
10150Sstevel@tonic-gate }
10160Sstevel@tonic-gate
10170Sstevel@tonic-gate /*
10180Sstevel@tonic-gate * my_dir and my_path could be pointers
10190Sstevel@tonic-gate */
10200Sstevel@tonic-gate struct myrec {
10210Sstevel@tonic-gate ulong_t my_fsid;
10220Sstevel@tonic-gate char my_dir[MAXPATHLEN];
10230Sstevel@tonic-gate char *my_path;
10240Sstevel@tonic-gate char *ig_path;
10250Sstevel@tonic-gate struct myrec *next;
10260Sstevel@tonic-gate };
10270Sstevel@tonic-gate
10280Sstevel@tonic-gate /*
10290Sstevel@tonic-gate * Print the mount table info
10300Sstevel@tonic-gate */
10310Sstevel@tonic-gate static void
mi_print(void)10320Sstevel@tonic-gate mi_print(void)
10330Sstevel@tonic-gate {
10340Sstevel@tonic-gate FILE *mt;
10350Sstevel@tonic-gate struct extmnttab m;
10360Sstevel@tonic-gate struct myrec *list, *mrp, *pmrp;
10370Sstevel@tonic-gate char *flavor;
10380Sstevel@tonic-gate int ignored = 0;
10390Sstevel@tonic-gate seconfig_t nfs_sec;
10400Sstevel@tonic-gate kstat_t *ksp;
10410Sstevel@tonic-gate struct mntinfo_kstat mik;
10420Sstevel@tonic-gate int transport_flag = 0;
10430Sstevel@tonic-gate int path_count;
10440Sstevel@tonic-gate int found;
10450Sstevel@tonic-gate char *timer_name[] = {
10460Sstevel@tonic-gate "Lookups",
10470Sstevel@tonic-gate "Reads",
10480Sstevel@tonic-gate "Writes",
10490Sstevel@tonic-gate "All"
10500Sstevel@tonic-gate };
10510Sstevel@tonic-gate
10520Sstevel@tonic-gate mt = fopen(MNTTAB, "r");
10530Sstevel@tonic-gate if (mt == NULL) {
10540Sstevel@tonic-gate perror(MNTTAB);
10550Sstevel@tonic-gate exit(0);
10560Sstevel@tonic-gate }
10570Sstevel@tonic-gate
10580Sstevel@tonic-gate list = NULL;
10590Sstevel@tonic-gate resetmnttab(mt);
10600Sstevel@tonic-gate
10610Sstevel@tonic-gate while (getextmntent(mt, &m, sizeof (struct extmnttab)) == 0) {
10620Sstevel@tonic-gate /* ignore non "nfs" and save the "ignore" entries */
10630Sstevel@tonic-gate if (strcmp(m.mnt_fstype, MNTTYPE_NFS) != 0)
10640Sstevel@tonic-gate continue;
10650Sstevel@tonic-gate /*
10660Sstevel@tonic-gate * Check to see here if user gave a path(s) to
10670Sstevel@tonic-gate * only show the mount point they wanted
10680Sstevel@tonic-gate * Iterate through the list of paths the user gave and see
10695302Sth199096 * if any of them match our current nfs mount
10700Sstevel@tonic-gate */
10710Sstevel@tonic-gate if (path[0] != NULL) {
10720Sstevel@tonic-gate found = 0;
10730Sstevel@tonic-gate for (path_count = 0; path[path_count] != NULL;
10740Sstevel@tonic-gate path_count++) {
10750Sstevel@tonic-gate if (strcmp(path[path_count], m.mnt_mountp)
10760Sstevel@tonic-gate == 0) {
10770Sstevel@tonic-gate found = 1;
10780Sstevel@tonic-gate break;
10790Sstevel@tonic-gate }
10800Sstevel@tonic-gate }
10810Sstevel@tonic-gate if (!found)
10820Sstevel@tonic-gate continue;
10830Sstevel@tonic-gate }
10840Sstevel@tonic-gate
10850Sstevel@tonic-gate if ((mrp = malloc(sizeof (struct myrec))) == 0) {
10860Sstevel@tonic-gate fprintf(stderr, "nfsstat: not enough memory\n");
10870Sstevel@tonic-gate exit(1);
10880Sstevel@tonic-gate }
10890Sstevel@tonic-gate mrp->my_fsid = makedev(m.mnt_major, m.mnt_minor);
10900Sstevel@tonic-gate if (ignore(m.mnt_mntopts)) {
10910Sstevel@tonic-gate /*
10920Sstevel@tonic-gate * ignored entries cannot be ignored for this
10930Sstevel@tonic-gate * option. We have to display the info for this
10940Sstevel@tonic-gate * nfs mount. The ignore is an indication
10950Sstevel@tonic-gate * that the actual mount point is different and
10960Sstevel@tonic-gate * something is in between the nfs mount.
10970Sstevel@tonic-gate * So save the mount point now
10980Sstevel@tonic-gate */
10990Sstevel@tonic-gate if ((mrp->ig_path = malloc(
11005302Sth199096 strlen(m.mnt_mountp) + 1)) == 0) {
11010Sstevel@tonic-gate fprintf(stderr, "nfsstat: not enough memory\n");
11020Sstevel@tonic-gate exit(1);
11030Sstevel@tonic-gate }
11040Sstevel@tonic-gate (void) strcpy(mrp->ig_path, m.mnt_mountp);
11050Sstevel@tonic-gate ignored++;
11060Sstevel@tonic-gate } else {
11070Sstevel@tonic-gate mrp->ig_path = 0;
11080Sstevel@tonic-gate (void) strcpy(mrp->my_dir, m.mnt_mountp);
11090Sstevel@tonic-gate }
11100Sstevel@tonic-gate if ((mrp->my_path = strdup(m.mnt_special)) == NULL) {
11110Sstevel@tonic-gate fprintf(stderr, "nfsstat: not enough memory\n");
11120Sstevel@tonic-gate exit(1);
11130Sstevel@tonic-gate }
11140Sstevel@tonic-gate mrp->next = list;
11150Sstevel@tonic-gate list = mrp;
11160Sstevel@tonic-gate }
11170Sstevel@tonic-gate
11180Sstevel@tonic-gate /*
11190Sstevel@tonic-gate * If something got ignored, go to the beginning of the mnttab
11200Sstevel@tonic-gate * and look for the cachefs entries since they are the one
11210Sstevel@tonic-gate * causing this. The mount point saved for the ignored entries
11220Sstevel@tonic-gate * is matched against the special to get the actual mount point.
11230Sstevel@tonic-gate * We are interested in the acutal mount point so that the output
11240Sstevel@tonic-gate * look nice too.
11250Sstevel@tonic-gate */
11260Sstevel@tonic-gate if (ignored) {
11270Sstevel@tonic-gate rewind(mt);
11280Sstevel@tonic-gate resetmnttab(mt);
11290Sstevel@tonic-gate while (getextmntent(mt, &m, sizeof (struct extmnttab)) == 0) {
11300Sstevel@tonic-gate
11310Sstevel@tonic-gate /* ignore non "cachefs" */
11320Sstevel@tonic-gate if (strcmp(m.mnt_fstype, MNTTYPE_CACHEFS) != 0)
11330Sstevel@tonic-gate continue;
11340Sstevel@tonic-gate
11350Sstevel@tonic-gate for (mrp = list; mrp; mrp = mrp->next) {
11360Sstevel@tonic-gate if (mrp->ig_path == 0)
11370Sstevel@tonic-gate continue;
11380Sstevel@tonic-gate if (strcmp(mrp->ig_path, m.mnt_special) == 0) {
11390Sstevel@tonic-gate mrp->ig_path = 0;
11400Sstevel@tonic-gate (void) strcpy(mrp->my_dir,
11415302Sth199096 m.mnt_mountp);
11420Sstevel@tonic-gate }
11430Sstevel@tonic-gate }
11440Sstevel@tonic-gate }
11450Sstevel@tonic-gate /*
11460Sstevel@tonic-gate * Now ignored entries which do not have
11470Sstevel@tonic-gate * the my_dir initialized are really ignored; This never
11480Sstevel@tonic-gate * happens unless the mnttab is corrupted.
11490Sstevel@tonic-gate */
11500Sstevel@tonic-gate for (pmrp = 0, mrp = list; mrp; mrp = mrp->next) {
11510Sstevel@tonic-gate if (mrp->ig_path == 0)
11520Sstevel@tonic-gate pmrp = mrp;
11530Sstevel@tonic-gate else if (pmrp)
11540Sstevel@tonic-gate pmrp->next = mrp->next;
11550Sstevel@tonic-gate else
11560Sstevel@tonic-gate list = mrp->next;
11570Sstevel@tonic-gate }
11580Sstevel@tonic-gate }
11590Sstevel@tonic-gate
11600Sstevel@tonic-gate (void) fclose(mt);
11610Sstevel@tonic-gate
11620Sstevel@tonic-gate
11630Sstevel@tonic-gate for (ksp = kc->kc_chain; ksp; ksp = ksp->ks_next) {
11640Sstevel@tonic-gate int i;
11650Sstevel@tonic-gate
11660Sstevel@tonic-gate if (ksp->ks_type != KSTAT_TYPE_RAW)
11670Sstevel@tonic-gate continue;
11680Sstevel@tonic-gate if (strcmp(ksp->ks_module, "nfs") != 0)
11690Sstevel@tonic-gate continue;
11700Sstevel@tonic-gate if (strcmp(ksp->ks_name, "mntinfo") != 0)
11710Sstevel@tonic-gate continue;
11720Sstevel@tonic-gate
11730Sstevel@tonic-gate for (mrp = list; mrp; mrp = mrp->next) {
11740Sstevel@tonic-gate if ((mrp->my_fsid & MAXMIN) == ksp->ks_instance)
11750Sstevel@tonic-gate break;
11760Sstevel@tonic-gate }
11770Sstevel@tonic-gate if (mrp == 0)
11780Sstevel@tonic-gate continue;
11790Sstevel@tonic-gate
11800Sstevel@tonic-gate if (safe_kstat_read(kc, ksp, &mik) == -1)
11810Sstevel@tonic-gate continue;
11820Sstevel@tonic-gate
11830Sstevel@tonic-gate printf("%s from %s\n", mrp->my_dir, mrp->my_path);
11840Sstevel@tonic-gate
11850Sstevel@tonic-gate /*
11860Sstevel@tonic-gate * for printing rdma transport and provider string.
11870Sstevel@tonic-gate * This way we avoid modifying the kernel mntinfo_kstat
11880Sstevel@tonic-gate * struct for protofmly.
11890Sstevel@tonic-gate */
11900Sstevel@tonic-gate if (strcmp(mik.mik_proto, "ibtf") == 0) {
11910Sstevel@tonic-gate printf(" Flags: vers=%u,proto=rdma",
11920Sstevel@tonic-gate mik.mik_vers);
11930Sstevel@tonic-gate transport_flag = 1;
11940Sstevel@tonic-gate } else {
11950Sstevel@tonic-gate printf(" Flags: vers=%u,proto=%s",
11960Sstevel@tonic-gate mik.mik_vers, mik.mik_proto);
11970Sstevel@tonic-gate transport_flag = 0;
11980Sstevel@tonic-gate }
11990Sstevel@tonic-gate
12000Sstevel@tonic-gate /*
12010Sstevel@tonic-gate * get the secmode name from /etc/nfssec.conf.
12020Sstevel@tonic-gate */
12030Sstevel@tonic-gate if (!nfs_getseconfig_bynumber(mik.mik_secmod, &nfs_sec)) {
12040Sstevel@tonic-gate flavor = nfs_sec.sc_name;
12050Sstevel@tonic-gate } else
12060Sstevel@tonic-gate flavor = NULL;
12070Sstevel@tonic-gate
12080Sstevel@tonic-gate if (flavor != NULL)
12090Sstevel@tonic-gate printf(",sec=%s", flavor);
12100Sstevel@tonic-gate else
12110Sstevel@tonic-gate printf(",sec#=%d", mik.mik_secmod);
12120Sstevel@tonic-gate
12130Sstevel@tonic-gate printf(",%s", (mik.mik_flags & MI_HARD) ? "hard" : "soft");
12140Sstevel@tonic-gate if (mik.mik_flags & MI_PRINTED)
12150Sstevel@tonic-gate printf(",printed");
12160Sstevel@tonic-gate printf(",%s", (mik.mik_flags & MI_INT) ? "intr" : "nointr");
12170Sstevel@tonic-gate if (mik.mik_flags & MI_DOWN)
12180Sstevel@tonic-gate printf(",down");
12190Sstevel@tonic-gate if (mik.mik_flags & MI_NOAC)
12200Sstevel@tonic-gate printf(",noac");
12210Sstevel@tonic-gate if (mik.mik_flags & MI_NOCTO)
12220Sstevel@tonic-gate printf(",nocto");
12230Sstevel@tonic-gate if (mik.mik_flags & MI_DYNAMIC)
12240Sstevel@tonic-gate printf(",dynamic");
12250Sstevel@tonic-gate if (mik.mik_flags & MI_LLOCK)
12260Sstevel@tonic-gate printf(",llock");
12270Sstevel@tonic-gate if (mik.mik_flags & MI_GRPID)
12280Sstevel@tonic-gate printf(",grpid");
12290Sstevel@tonic-gate if (mik.mik_flags & MI_RPCTIMESYNC)
12300Sstevel@tonic-gate printf(",rpctimesync");
12310Sstevel@tonic-gate if (mik.mik_flags & MI_LINK)
12320Sstevel@tonic-gate printf(",link");
12330Sstevel@tonic-gate if (mik.mik_flags & MI_SYMLINK)
12340Sstevel@tonic-gate printf(",symlink");
12355897Sth199096 if (mik.mik_vers < NFS_V4 && mik.mik_flags & MI_READDIRONLY)
12360Sstevel@tonic-gate printf(",readdironly");
12370Sstevel@tonic-gate if (mik.mik_flags & MI_ACL)
12380Sstevel@tonic-gate printf(",acl");
123910924SMarcel.Telka@Sun.COM if (mik.mik_flags & MI_DIRECTIO)
124010924SMarcel.Telka@Sun.COM printf(",forcedirectio");
12410Sstevel@tonic-gate
12425302Sth199096 if (mik.mik_vers >= NFS_V4) {
12435302Sth199096 if (mik.mik_flags & MI4_MIRRORMOUNT)
12445302Sth199096 printf(",mirrormount");
1245*11291SRobert.Thurlow@Sun.COM if (mik.mik_flags & MI4_REFERRAL)
1246*11291SRobert.Thurlow@Sun.COM printf(",referral");
12475302Sth199096 }
12485302Sth199096
12490Sstevel@tonic-gate printf(",rsize=%d,wsize=%d,retrans=%d,timeo=%d",
12505302Sth199096 mik.mik_curread, mik.mik_curwrite, mik.mik_retrans,
12515302Sth199096 mik.mik_timeo);
12520Sstevel@tonic-gate printf("\n");
12530Sstevel@tonic-gate printf(" Attr cache: acregmin=%d,acregmax=%d"
12545302Sth199096 ",acdirmin=%d,acdirmax=%d\n", mik.mik_acregmin,
12555302Sth199096 mik.mik_acregmax, mik.mik_acdirmin, mik.mik_acdirmax);
12560Sstevel@tonic-gate
12570Sstevel@tonic-gate if (transport_flag) {
12580Sstevel@tonic-gate printf(" Transport: proto=rdma, plugin=%s\n",
12590Sstevel@tonic-gate mik.mik_proto);
12600Sstevel@tonic-gate }
12610Sstevel@tonic-gate
12620Sstevel@tonic-gate #define srtt_to_ms(x) x, (x * 2 + x / 2)
12630Sstevel@tonic-gate #define dev_to_ms(x) x, (x * 5)
12640Sstevel@tonic-gate
12650Sstevel@tonic-gate for (i = 0; i < NFS_CALLTYPES + 1; i++) {
12660Sstevel@tonic-gate int j;
12670Sstevel@tonic-gate
12680Sstevel@tonic-gate j = (i == NFS_CALLTYPES ? i - 1 : i);
12690Sstevel@tonic-gate if (mik.mik_timers[j].srtt ||
12700Sstevel@tonic-gate mik.mik_timers[j].rtxcur) {
12715302Sth199096 printf(" %s: srtt=%d (%dms), "
12725302Sth199096 "dev=%d (%dms), cur=%u (%ums)\n",
12735302Sth199096 timer_name[i],
12745302Sth199096 srtt_to_ms(mik.mik_timers[i].srtt),
12755302Sth199096 dev_to_ms(mik.mik_timers[i].deviate),
12765302Sth199096 mik.mik_timers[i].rtxcur,
12775302Sth199096 mik.mik_timers[i].rtxcur * 20);
12780Sstevel@tonic-gate }
12790Sstevel@tonic-gate }
12800Sstevel@tonic-gate
12810Sstevel@tonic-gate if (strchr(mrp->my_path, ','))
12820Sstevel@tonic-gate printf(
12830Sstevel@tonic-gate " Failover: noresponse=%d,failover=%d,"
12840Sstevel@tonic-gate "remap=%d,currserver=%s\n",
12850Sstevel@tonic-gate mik.mik_noresponse, mik.mik_failover,
12860Sstevel@tonic-gate mik.mik_remap, mik.mik_curserver);
12870Sstevel@tonic-gate printf("\n");
12880Sstevel@tonic-gate }
12890Sstevel@tonic-gate }
12900Sstevel@tonic-gate
12910Sstevel@tonic-gate static char *mntopts[] = { MNTOPT_IGNORE, MNTOPT_DEV, NULL };
12920Sstevel@tonic-gate #define IGNORE 0
12930Sstevel@tonic-gate #define DEV 1
12940Sstevel@tonic-gate
12950Sstevel@tonic-gate /*
12960Sstevel@tonic-gate * Return 1 if "ignore" appears in the options string
12970Sstevel@tonic-gate */
12980Sstevel@tonic-gate static int
ignore(char * opts)12990Sstevel@tonic-gate ignore(char *opts)
13000Sstevel@tonic-gate {
13010Sstevel@tonic-gate char *value;
13020Sstevel@tonic-gate char *s;
13030Sstevel@tonic-gate
13040Sstevel@tonic-gate if (opts == NULL)
13050Sstevel@tonic-gate return (0);
13060Sstevel@tonic-gate s = strdup(opts);
13070Sstevel@tonic-gate if (s == NULL)
13080Sstevel@tonic-gate return (0);
13090Sstevel@tonic-gate opts = s;
13100Sstevel@tonic-gate
13110Sstevel@tonic-gate while (*opts != '\0') {
13120Sstevel@tonic-gate if (getsubopt(&opts, mntopts, &value) == IGNORE) {
13130Sstevel@tonic-gate free(s);
13140Sstevel@tonic-gate return (1);
13150Sstevel@tonic-gate }
13160Sstevel@tonic-gate }
13170Sstevel@tonic-gate
13180Sstevel@tonic-gate free(s);
13190Sstevel@tonic-gate return (0);
13200Sstevel@tonic-gate }
13210Sstevel@tonic-gate
13220Sstevel@tonic-gate void
usage(void)13230Sstevel@tonic-gate usage(void)
13240Sstevel@tonic-gate {
13250Sstevel@tonic-gate fprintf(stderr, "Usage: nfsstat [-cnrsza [-v version] "
132610265SKrishnendu.Sadhukhan@Sun.COM "[-T d|u] [interval [count]]\n");
13270Sstevel@tonic-gate fprintf(stderr, "Usage: nfsstat -m [pathname..]\n");
13280Sstevel@tonic-gate exit(1);
13290Sstevel@tonic-gate }
13300Sstevel@tonic-gate
133110265SKrishnendu.Sadhukhan@Sun.COM void
fail(int do_perror,char * message,...)13320Sstevel@tonic-gate fail(int do_perror, char *message, ...)
13330Sstevel@tonic-gate {
13340Sstevel@tonic-gate va_list args;
13350Sstevel@tonic-gate
13360Sstevel@tonic-gate va_start(args, message);
13370Sstevel@tonic-gate fprintf(stderr, "nfsstat: ");
13380Sstevel@tonic-gate vfprintf(stderr, message, args);
13390Sstevel@tonic-gate va_end(args);
13400Sstevel@tonic-gate if (do_perror)
13410Sstevel@tonic-gate fprintf(stderr, ": %s", strerror(errno));
13420Sstevel@tonic-gate fprintf(stderr, "\n");
13430Sstevel@tonic-gate exit(1);
13440Sstevel@tonic-gate }
13450Sstevel@tonic-gate
13460Sstevel@tonic-gate kid_t
safe_kstat_read(kstat_ctl_t * kc,kstat_t * ksp,void * data)13470Sstevel@tonic-gate safe_kstat_read(kstat_ctl_t *kc, kstat_t *ksp, void *data)
13480Sstevel@tonic-gate {
13490Sstevel@tonic-gate kid_t kstat_chain_id = kstat_read(kc, ksp, data);
13500Sstevel@tonic-gate
13510Sstevel@tonic-gate if (kstat_chain_id == -1)
13520Sstevel@tonic-gate fail(1, "kstat_read(%x, '%s') failed", kc, ksp->ks_name);
13530Sstevel@tonic-gate return (kstat_chain_id);
13540Sstevel@tonic-gate }
13550Sstevel@tonic-gate
13560Sstevel@tonic-gate kid_t
safe_kstat_write(kstat_ctl_t * kc,kstat_t * ksp,void * data)13570Sstevel@tonic-gate safe_kstat_write(kstat_ctl_t *kc, kstat_t *ksp, void *data)
13580Sstevel@tonic-gate {
13590Sstevel@tonic-gate kid_t kstat_chain_id = 0;
13600Sstevel@tonic-gate
13610Sstevel@tonic-gate if (ksp->ks_data != NULL) {
13620Sstevel@tonic-gate kstat_chain_id = kstat_write(kc, ksp, data);
13630Sstevel@tonic-gate
13640Sstevel@tonic-gate if (kstat_chain_id == -1)
13650Sstevel@tonic-gate fail(1, "kstat_write(%x, '%s') failed", kc,
13660Sstevel@tonic-gate ksp->ks_name);
13670Sstevel@tonic-gate }
13680Sstevel@tonic-gate return (kstat_chain_id);
13690Sstevel@tonic-gate }
13700Sstevel@tonic-gate
13710Sstevel@tonic-gate void
stats_timer(int interval)13720Sstevel@tonic-gate stats_timer(int interval)
13730Sstevel@tonic-gate {
13740Sstevel@tonic-gate timer_t t_id;
13750Sstevel@tonic-gate itimerspec_t time_struct;
13760Sstevel@tonic-gate struct sigevent sig_struct;
13770Sstevel@tonic-gate struct sigaction act;
13780Sstevel@tonic-gate
13790Sstevel@tonic-gate bzero(&sig_struct, sizeof (struct sigevent));
13800Sstevel@tonic-gate bzero(&act, sizeof (struct sigaction));
13810Sstevel@tonic-gate
13820Sstevel@tonic-gate /* Create timer */
13830Sstevel@tonic-gate sig_struct.sigev_notify = SIGEV_SIGNAL;
13840Sstevel@tonic-gate sig_struct.sigev_signo = SIGUSR1;
13850Sstevel@tonic-gate sig_struct.sigev_value.sival_int = 0;
13860Sstevel@tonic-gate
13870Sstevel@tonic-gate if (timer_create(CLOCK_REALTIME, &sig_struct, &t_id) != 0) {
13880Sstevel@tonic-gate fail(1, "Timer creation failed");
13890Sstevel@tonic-gate }
13900Sstevel@tonic-gate
13910Sstevel@tonic-gate act.sa_handler = handle_sig;
13920Sstevel@tonic-gate
13930Sstevel@tonic-gate if (sigaction(SIGUSR1, &act, NULL) != 0) {
13940Sstevel@tonic-gate fail(1, "Could not set up signal handler");
13950Sstevel@tonic-gate }
13960Sstevel@tonic-gate
13970Sstevel@tonic-gate time_struct.it_value.tv_sec = interval;
13980Sstevel@tonic-gate time_struct.it_value.tv_nsec = 0;
13990Sstevel@tonic-gate time_struct.it_interval.tv_sec = interval;
14000Sstevel@tonic-gate time_struct.it_interval.tv_nsec = 0;
14010Sstevel@tonic-gate
14020Sstevel@tonic-gate /* Arm timer */
14030Sstevel@tonic-gate if ((timer_settime(t_id, 0, &time_struct, NULL)) != 0) {
14040Sstevel@tonic-gate fail(1, "Setting timer failed");
14050Sstevel@tonic-gate }
14060Sstevel@tonic-gate }
14070Sstevel@tonic-gate
14080Sstevel@tonic-gate void
handle_sig(int x)14090Sstevel@tonic-gate handle_sig(int x)
14100Sstevel@tonic-gate {
14110Sstevel@tonic-gate }
14120Sstevel@tonic-gate
14130Sstevel@tonic-gate static void
nfsstat_kstat_copy(kstat_t * src,kstat_t * dst,int fr)141410265SKrishnendu.Sadhukhan@Sun.COM nfsstat_kstat_copy(kstat_t *src, kstat_t *dst, int fr)
14150Sstevel@tonic-gate {
14160Sstevel@tonic-gate
14170Sstevel@tonic-gate if (fr)
14180Sstevel@tonic-gate free(dst->ks_data);
14190Sstevel@tonic-gate
14200Sstevel@tonic-gate *dst = *src;
14210Sstevel@tonic-gate
14220Sstevel@tonic-gate if (src->ks_data != NULL) {
14230Sstevel@tonic-gate safe_zalloc(&dst->ks_data, src->ks_data_size, 0);
14240Sstevel@tonic-gate (void) memcpy(dst->ks_data, src->ks_data, src->ks_data_size);
14250Sstevel@tonic-gate } else {
14260Sstevel@tonic-gate dst->ks_data = NULL;
14270Sstevel@tonic-gate dst->ks_data_size = 0;
14280Sstevel@tonic-gate }
14290Sstevel@tonic-gate }
14300Sstevel@tonic-gate
14310Sstevel@tonic-gate /*
143210429SMarcel.Telka@Sun.COM * "Safe" allocators - if we return we're guaranteed to have the desired space
143310429SMarcel.Telka@Sun.COM * allocated and zero-filled. We exit via fail if we can't get the space.
14340Sstevel@tonic-gate */
14350Sstevel@tonic-gate void
safe_zalloc(void ** ptr,uint_t size,int free_first)14360Sstevel@tonic-gate safe_zalloc(void **ptr, uint_t size, int free_first)
14370Sstevel@tonic-gate {
143810429SMarcel.Telka@Sun.COM if (ptr == NULL)
14390Sstevel@tonic-gate fail(1, "invalid pointer");
14400Sstevel@tonic-gate if (free_first && *ptr != NULL)
14410Sstevel@tonic-gate free(*ptr);
14420Sstevel@tonic-gate if ((*ptr = (void *)malloc(size)) == NULL)
14430Sstevel@tonic-gate fail(1, "malloc failed");
14440Sstevel@tonic-gate (void) memset(*ptr, 0, size);
14450Sstevel@tonic-gate }
14460Sstevel@tonic-gate
14470Sstevel@tonic-gate static int
safe_strtoi(char const * val,char * errmsg)14480Sstevel@tonic-gate safe_strtoi(char const *val, char *errmsg)
14490Sstevel@tonic-gate {
14500Sstevel@tonic-gate char *end;
14510Sstevel@tonic-gate long tmp;
14520Sstevel@tonic-gate errno = 0;
14530Sstevel@tonic-gate tmp = strtol(val, &end, 10);
14540Sstevel@tonic-gate if (*end != '\0' || errno)
14550Sstevel@tonic-gate fail(0, "%s %s", errmsg, val);
14560Sstevel@tonic-gate return ((int)tmp);
14570Sstevel@tonic-gate }
1458