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