8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / avs / dsstat / multi_stats.c
blobcac76d4cd6046a9cdf46f5dd816ae4af65d0d332
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #include <stdio.h>
27 #include <unistd.h>
28 #include <errno.h>
30 #include <kstat.h>
32 #include "ii_stats.h"
33 #include "sdbc_stats.h"
34 #include "sndr_stats.h"
36 #include "multi_stats.h"
38 #include "dsstat.h"
39 #include "common.h"
40 #include "report.h"
43 * do_stats() - called by main() to start monitoring
46 int
47 do_stats()
49 int error;
50 int pass;
52 /* Collection/reporting loop */
53 for (pass = 0; ; pass++) { /* CSTYLED */
54 if (iterations != -1 && pass >= iterations)
55 return (0);
57 error = discover();
59 if (error == ENOMEM || error == EINVAL)
60 return (error);
62 if (error == EAGAIN && pass == 0)
63 return (error);
65 (void) sleep(interval);
67 if ((error = update()) != 0)
68 return (error);
70 if (report())
71 break;
74 /* No stats on this system */
75 return (EAGAIN);
78 int
79 discover()
81 int err = 0;
83 int sdbc_err = 0;
84 int sndr_err = 0;
85 int ii_err = 0;
87 kstat_ctl_t *kc;
89 if ((kc = kstat_open()) == NULL)
90 return (ENOMEM);
92 if (mode & SDBC) {
93 sdbc_err = sdbc_discover(kc);
94 err = sdbc_err;
95 if (sdbc_err && !(mode & MULTI))
96 goto fail;
97 if (sdbc_err && (mode & MULTI) && sdbc_err != EAGAIN)
98 goto fail;
101 if (mode & SNDR) {
102 sndr_err = sndr_discover(kc);
103 err = sndr_err;
104 if (sndr_err && !(mode & MULTI))
105 goto fail;
106 if (sndr_err && (mode & MULTI) && sndr_err != EAGAIN)
107 goto fail;
110 if (mode & IIMG) {
111 ii_err = ii_discover(kc);
112 err = ii_err;
113 if (ii_err && !(mode & MULTI))
114 goto fail;
115 if (ii_err && ii_err != EAGAIN && (mode & MULTI))
116 goto fail;
119 (void) kstat_close(kc);
120 if (sdbc_err && sndr_err && ii_err)
121 return (err);
122 else
123 return (0);
125 fail:
126 (void) kstat_close(kc);
127 return (err);
131 update()
133 int err = 0;
135 int sdbc_err = 0;
136 int sndr_err = 0;
137 int ii_err = 0;
139 kstat_ctl_t *kc;
141 if ((kc = kstat_open()) == NULL)
142 goto fail;
144 if (mode & SDBC) {
145 sdbc_err = sdbc_update(kc);
146 err = sdbc_err;
147 if (sdbc_err && !(mode & MULTI))
148 goto fail;
149 if (sdbc_err && (mode & MULTI) && sdbc_err != EAGAIN)
150 goto fail;
153 if (mode & SNDR) {
154 sndr_err = sndr_update(kc);
155 err = sndr_err;
156 if (sndr_err && !(mode & MULTI))
157 goto fail;
158 if (sndr_err && (mode & MULTI) && sndr_err != EAGAIN)
159 goto fail;
162 if (mode & IIMG) {
163 ii_err = ii_update(kc);
164 err = ii_err;
165 if (ii_err && !(mode & MULTI))
166 goto fail;
167 if (ii_err && (mode & MULTI) && ii_err != EAGAIN)
168 goto fail;
171 (void) kstat_close(kc);
172 if (sdbc_err && sndr_err && ii_err)
173 return (err);
174 else
175 return (0);
177 fail:
178 (void) kstat_close(kc);
179 return (err);
183 report()
185 int err = 0;
187 int sdbc_err = 0;
188 int sndr_err = 0;
189 int ii_err = 0;
191 hflags &= (HEADERS_EXL | HEADERS_ATT | HEADERS_BOR);
193 if (mode & SNDR)
194 if (sndr_err = sndr_report())
195 err = sndr_err;
197 if (mode & IIMG)
198 if (ii_err = ii_report())
199 err = ii_err;
201 if ((mode & SDBC) && !(mode & MULTI))
202 if (sdbc_err = sdbc_report())
203 err = sdbc_err;
205 return (err);