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