1*fcf3ce44SJohn Forte /* 2*fcf3ce44SJohn Forte * CDDL HEADER START 3*fcf3ce44SJohn Forte * 4*fcf3ce44SJohn Forte * The contents of this file are subject to the terms of the 5*fcf3ce44SJohn Forte * Common Development and Distribution License (the "License"). 6*fcf3ce44SJohn Forte * You may not use this file except in compliance with the License. 7*fcf3ce44SJohn Forte * 8*fcf3ce44SJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*fcf3ce44SJohn Forte * or http://www.opensolaris.org/os/licensing. 10*fcf3ce44SJohn Forte * See the License for the specific language governing permissions 11*fcf3ce44SJohn Forte * and limitations under the License. 12*fcf3ce44SJohn Forte * 13*fcf3ce44SJohn Forte * When distributing Covered Code, include this CDDL HEADER in each 14*fcf3ce44SJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*fcf3ce44SJohn Forte * If applicable, add the following below this CDDL HEADER, with the 16*fcf3ce44SJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying 17*fcf3ce44SJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner] 18*fcf3ce44SJohn Forte * 19*fcf3ce44SJohn Forte * CDDL HEADER END 20*fcf3ce44SJohn Forte */ 21*fcf3ce44SJohn Forte /* 22*fcf3ce44SJohn Forte * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 23*fcf3ce44SJohn Forte * Use is subject to license terms. 24*fcf3ce44SJohn Forte */ 25*fcf3ce44SJohn Forte 26*fcf3ce44SJohn Forte #include <stdio.h> 27*fcf3ce44SJohn Forte #include <unistd.h> 28*fcf3ce44SJohn Forte #include <errno.h> 29*fcf3ce44SJohn Forte 30*fcf3ce44SJohn Forte #include <kstat.h> 31*fcf3ce44SJohn Forte 32*fcf3ce44SJohn Forte #include "ii_stats.h" 33*fcf3ce44SJohn Forte #include "sdbc_stats.h" 34*fcf3ce44SJohn Forte #include "sndr_stats.h" 35*fcf3ce44SJohn Forte 36*fcf3ce44SJohn Forte #include "multi_stats.h" 37*fcf3ce44SJohn Forte 38*fcf3ce44SJohn Forte #include "dsstat.h" 39*fcf3ce44SJohn Forte #include "common.h" 40*fcf3ce44SJohn Forte #include "report.h" 41*fcf3ce44SJohn Forte 42*fcf3ce44SJohn Forte /* 43*fcf3ce44SJohn Forte * do_stats() - called by main() to start monitoring 44*fcf3ce44SJohn Forte * 45*fcf3ce44SJohn Forte */ 46*fcf3ce44SJohn Forte int 47*fcf3ce44SJohn Forte do_stats() 48*fcf3ce44SJohn Forte { 49*fcf3ce44SJohn Forte int error; 50*fcf3ce44SJohn Forte int pass; 51*fcf3ce44SJohn Forte 52*fcf3ce44SJohn Forte /* Collection/reporting loop */ 53*fcf3ce44SJohn Forte for (pass = 0; ; pass++) { /* CSTYLED */ 54*fcf3ce44SJohn Forte if (iterations != -1 && pass >= iterations) 55*fcf3ce44SJohn Forte return (0); 56*fcf3ce44SJohn Forte 57*fcf3ce44SJohn Forte error = discover(); 58*fcf3ce44SJohn Forte 59*fcf3ce44SJohn Forte if (error == ENOMEM || error == EINVAL) 60*fcf3ce44SJohn Forte return (error); 61*fcf3ce44SJohn Forte 62*fcf3ce44SJohn Forte if (error == EAGAIN && pass == 0) 63*fcf3ce44SJohn Forte return (error); 64*fcf3ce44SJohn Forte 65*fcf3ce44SJohn Forte (void) sleep(interval); 66*fcf3ce44SJohn Forte 67*fcf3ce44SJohn Forte if ((error = update()) != 0) 68*fcf3ce44SJohn Forte return (error); 69*fcf3ce44SJohn Forte 70*fcf3ce44SJohn Forte if (report()) 71*fcf3ce44SJohn Forte break; 72*fcf3ce44SJohn Forte } 73*fcf3ce44SJohn Forte 74*fcf3ce44SJohn Forte /* No stats on this system */ 75*fcf3ce44SJohn Forte return (EAGAIN); 76*fcf3ce44SJohn Forte } 77*fcf3ce44SJohn Forte 78*fcf3ce44SJohn Forte int 79*fcf3ce44SJohn Forte discover() 80*fcf3ce44SJohn Forte { 81*fcf3ce44SJohn Forte int err = 0; 82*fcf3ce44SJohn Forte 83*fcf3ce44SJohn Forte int sdbc_err = 0; 84*fcf3ce44SJohn Forte int sndr_err = 0; 85*fcf3ce44SJohn Forte int ii_err = 0; 86*fcf3ce44SJohn Forte 87*fcf3ce44SJohn Forte kstat_ctl_t *kc; 88*fcf3ce44SJohn Forte 89*fcf3ce44SJohn Forte if ((kc = kstat_open()) == NULL) 90*fcf3ce44SJohn Forte return (ENOMEM); 91*fcf3ce44SJohn Forte 92*fcf3ce44SJohn Forte if (mode & SDBC) { 93*fcf3ce44SJohn Forte sdbc_err = sdbc_discover(kc); 94*fcf3ce44SJohn Forte err = sdbc_err; 95*fcf3ce44SJohn Forte if (sdbc_err && !(mode & MULTI)) 96*fcf3ce44SJohn Forte goto fail; 97*fcf3ce44SJohn Forte if (sdbc_err && (mode & MULTI) && sdbc_err != EAGAIN) 98*fcf3ce44SJohn Forte goto fail; 99*fcf3ce44SJohn Forte } 100*fcf3ce44SJohn Forte 101*fcf3ce44SJohn Forte if (mode & SNDR) { 102*fcf3ce44SJohn Forte sndr_err = sndr_discover(kc); 103*fcf3ce44SJohn Forte err = sndr_err; 104*fcf3ce44SJohn Forte if (sndr_err && !(mode & MULTI)) 105*fcf3ce44SJohn Forte goto fail; 106*fcf3ce44SJohn Forte if (sndr_err && (mode & MULTI) && sndr_err != EAGAIN) 107*fcf3ce44SJohn Forte goto fail; 108*fcf3ce44SJohn Forte } 109*fcf3ce44SJohn Forte 110*fcf3ce44SJohn Forte if (mode & IIMG) { 111*fcf3ce44SJohn Forte ii_err = ii_discover(kc); 112*fcf3ce44SJohn Forte err = ii_err; 113*fcf3ce44SJohn Forte if (ii_err && !(mode & MULTI)) 114*fcf3ce44SJohn Forte goto fail; 115*fcf3ce44SJohn Forte if (ii_err && ii_err != EAGAIN && (mode & MULTI)) 116*fcf3ce44SJohn Forte goto fail; 117*fcf3ce44SJohn Forte } 118*fcf3ce44SJohn Forte 119*fcf3ce44SJohn Forte (void) kstat_close(kc); 120*fcf3ce44SJohn Forte if (sdbc_err && sndr_err && ii_err) 121*fcf3ce44SJohn Forte return (err); 122*fcf3ce44SJohn Forte else 123*fcf3ce44SJohn Forte return (0); 124*fcf3ce44SJohn Forte 125*fcf3ce44SJohn Forte fail: 126*fcf3ce44SJohn Forte (void) kstat_close(kc); 127*fcf3ce44SJohn Forte return (err); 128*fcf3ce44SJohn Forte } 129*fcf3ce44SJohn Forte 130*fcf3ce44SJohn Forte int 131*fcf3ce44SJohn Forte update() 132*fcf3ce44SJohn Forte { 133*fcf3ce44SJohn Forte int err = 0; 134*fcf3ce44SJohn Forte 135*fcf3ce44SJohn Forte int sdbc_err = 0; 136*fcf3ce44SJohn Forte int sndr_err = 0; 137*fcf3ce44SJohn Forte int ii_err = 0; 138*fcf3ce44SJohn Forte 139*fcf3ce44SJohn Forte kstat_ctl_t *kc; 140*fcf3ce44SJohn Forte 141*fcf3ce44SJohn Forte if ((kc = kstat_open()) == NULL) 142*fcf3ce44SJohn Forte goto fail; 143*fcf3ce44SJohn Forte 144*fcf3ce44SJohn Forte if (mode & SDBC) { 145*fcf3ce44SJohn Forte sdbc_err = sdbc_update(kc); 146*fcf3ce44SJohn Forte err = sdbc_err; 147*fcf3ce44SJohn Forte if (sdbc_err && !(mode & MULTI)) 148*fcf3ce44SJohn Forte goto fail; 149*fcf3ce44SJohn Forte if (sdbc_err && (mode & MULTI) && sdbc_err != EAGAIN) 150*fcf3ce44SJohn Forte goto fail; 151*fcf3ce44SJohn Forte } 152*fcf3ce44SJohn Forte 153*fcf3ce44SJohn Forte if (mode & SNDR) { 154*fcf3ce44SJohn Forte sndr_err = sndr_update(kc); 155*fcf3ce44SJohn Forte err = sndr_err; 156*fcf3ce44SJohn Forte if (sndr_err && !(mode & MULTI)) 157*fcf3ce44SJohn Forte goto fail; 158*fcf3ce44SJohn Forte if (sndr_err && (mode & MULTI) && sndr_err != EAGAIN) 159*fcf3ce44SJohn Forte goto fail; 160*fcf3ce44SJohn Forte } 161*fcf3ce44SJohn Forte 162*fcf3ce44SJohn Forte if (mode & IIMG) { 163*fcf3ce44SJohn Forte ii_err = ii_update(kc); 164*fcf3ce44SJohn Forte err = ii_err; 165*fcf3ce44SJohn Forte if (ii_err && !(mode & MULTI)) 166*fcf3ce44SJohn Forte goto fail; 167*fcf3ce44SJohn Forte if (ii_err && (mode & MULTI) && ii_err != EAGAIN) 168*fcf3ce44SJohn Forte goto fail; 169*fcf3ce44SJohn Forte } 170*fcf3ce44SJohn Forte 171*fcf3ce44SJohn Forte (void) kstat_close(kc); 172*fcf3ce44SJohn Forte if (sdbc_err && sndr_err && ii_err) 173*fcf3ce44SJohn Forte return (err); 174*fcf3ce44SJohn Forte else 175*fcf3ce44SJohn Forte return (0); 176*fcf3ce44SJohn Forte 177*fcf3ce44SJohn Forte fail: 178*fcf3ce44SJohn Forte (void) kstat_close(kc); 179*fcf3ce44SJohn Forte return (err); 180*fcf3ce44SJohn Forte } 181*fcf3ce44SJohn Forte 182*fcf3ce44SJohn Forte int 183*fcf3ce44SJohn Forte report() 184*fcf3ce44SJohn Forte { 185*fcf3ce44SJohn Forte int err = 0; 186*fcf3ce44SJohn Forte 187*fcf3ce44SJohn Forte int sdbc_err = 0; 188*fcf3ce44SJohn Forte int sndr_err = 0; 189*fcf3ce44SJohn Forte int ii_err = 0; 190*fcf3ce44SJohn Forte 191*fcf3ce44SJohn Forte hflags &= (HEADERS_EXL | HEADERS_ATT | HEADERS_BOR); 192*fcf3ce44SJohn Forte 193*fcf3ce44SJohn Forte if (mode & SNDR) 194*fcf3ce44SJohn Forte if (sndr_err = sndr_report()) 195*fcf3ce44SJohn Forte err = sndr_err; 196*fcf3ce44SJohn Forte 197*fcf3ce44SJohn Forte if (mode & IIMG) 198*fcf3ce44SJohn Forte if (ii_err = ii_report()) 199*fcf3ce44SJohn Forte err = ii_err; 200*fcf3ce44SJohn Forte 201*fcf3ce44SJohn Forte if ((mode & SDBC) && !(mode & MULTI)) 202*fcf3ce44SJohn Forte if (sdbc_err = sdbc_report()) 203*fcf3ce44SJohn Forte err = sdbc_err; 204*fcf3ce44SJohn Forte 205*fcf3ce44SJohn Forte return (err); 206*fcf3ce44SJohn Forte } 207