17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5f5cd957fSRobert Harris * Common Development and Distribution License (the "License").
6f5cd957fSRobert Harris * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217c478bd9Sstevel@tonic-gate /*
2226fd7700SKrishnendu Sadhukhan - Sun Microsystems * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
237c478bd9Sstevel@tonic-gate * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate */
257c478bd9Sstevel@tonic-gate
267c478bd9Sstevel@tonic-gate /*
277c478bd9Sstevel@tonic-gate * poolstat - report active pool statistics
287c478bd9Sstevel@tonic-gate */
297c478bd9Sstevel@tonic-gate #include <stdio.h>
307c478bd9Sstevel@tonic-gate #include <unistd.h>
317c478bd9Sstevel@tonic-gate #include <stdlib.h>
327c478bd9Sstevel@tonic-gate #include <unistd.h>
337c478bd9Sstevel@tonic-gate #include <locale.h>
347c478bd9Sstevel@tonic-gate #include <string.h>
357c478bd9Sstevel@tonic-gate #include <ctype.h>
367c478bd9Sstevel@tonic-gate #include <limits.h>
377c478bd9Sstevel@tonic-gate #include <errno.h>
38*c5d54b67SRichard Lowe #include <stddef.h>
397c478bd9Sstevel@tonic-gate
407c478bd9Sstevel@tonic-gate #include <pool.h>
417c478bd9Sstevel@tonic-gate #include "utils.h"
427c478bd9Sstevel@tonic-gate #include "poolstat.h"
437c478bd9Sstevel@tonic-gate #include "poolstat_utils.h"
4426fd7700SKrishnendu Sadhukhan - Sun Microsystems #include "statcommon.h"
457c478bd9Sstevel@tonic-gate
467c478bd9Sstevel@tonic-gate #ifndef TEXT_DOMAIN
477c478bd9Sstevel@tonic-gate #define TEXT_DOMAIN "SYS_TEST"
487c478bd9Sstevel@tonic-gate #endif
497c478bd9Sstevel@tonic-gate
507c478bd9Sstevel@tonic-gate #define addrof(s) ((char **)&(s))
517c478bd9Sstevel@tonic-gate
527c478bd9Sstevel@tonic-gate /* verify if a field is printable in respect of the current option flags */
537c478bd9Sstevel@tonic-gate #define PRINTABLE(i) ((lf->plf_ffs[(i)].pff_prt & D_FIELD) || \
547c478bd9Sstevel@tonic-gate (lf->plf_ffs[(i)].pff_prt & X_FIELD))
557c478bd9Sstevel@tonic-gate
567c478bd9Sstevel@tonic-gate typedef int (* formatter) (char *, int, int, poolstat_field_format_t *, char *);
577c478bd9Sstevel@tonic-gate
5826fd7700SKrishnendu Sadhukhan - Sun Microsystems static uint_t timestamp_fmt = NODATE;
5926fd7700SKrishnendu Sadhukhan - Sun Microsystems
607c478bd9Sstevel@tonic-gate /* available field formatters */
617c478bd9Sstevel@tonic-gate static int default_f(char *, int, int, poolstat_field_format_t *, char *);
627c478bd9Sstevel@tonic-gate static int bigno_f(char *, int, int, poolstat_field_format_t *, char *);
637c478bd9Sstevel@tonic-gate static int used_stat_f(char *, int, int, poolstat_field_format_t *, char *);
647c478bd9Sstevel@tonic-gate static int header_f(char *, int, int, poolstat_field_format_t *, char *);
657c478bd9Sstevel@tonic-gate
667c478bd9Sstevel@tonic-gate /* statistics bags used to collect data from various provider */
677c478bd9Sstevel@tonic-gate static statistic_bag_t pool_sbag_s;
687c478bd9Sstevel@tonic-gate static statistic_bag_t pset_sbag_s;
697c478bd9Sstevel@tonic-gate static statistic_bag_t *pool_sbag = &pool_sbag_s;
707c478bd9Sstevel@tonic-gate static statistic_bag_t *pset_sbag = &pset_sbag_s;
717c478bd9Sstevel@tonic-gate
727c478bd9Sstevel@tonic-gate /* formatter objects for pset, defined in a default printing sequence */
737c478bd9Sstevel@tonic-gate static poolstat_field_format_t pset_ffs[] = {
747c478bd9Sstevel@tonic-gate /* prt flags,name,header,type,width,minwidth,offset,formatter */
757c478bd9Sstevel@tonic-gate { DX_FIELD, "id", "id", LL, 3, 1, addrof(pool_sbag),
767c478bd9Sstevel@tonic-gate offsetof(statistic_bag_t, sb_sysid),
777c478bd9Sstevel@tonic-gate (formatter)default_f },
787c478bd9Sstevel@tonic-gate { DX_FIELD, "pool", "pool", STR, 20, 14, addrof(pool_sbag),
797c478bd9Sstevel@tonic-gate offsetof(statistic_bag_t, sb_name),
807c478bd9Sstevel@tonic-gate (formatter)default_f },
817c478bd9Sstevel@tonic-gate { DX_FIELD, "type", "type", STR, 4, 5, addrof(pset_sbag),
827c478bd9Sstevel@tonic-gate offsetof(statistic_bag_t, sb_type),
837c478bd9Sstevel@tonic-gate (formatter)default_f },
847c478bd9Sstevel@tonic-gate { D_FIELD, "rid", "rid", LL, 3, 1, addrof(pset_sbag_s.bag),
857c478bd9Sstevel@tonic-gate offsetof(pset_statistic_bag_t, pset_sb_sysid),
867c478bd9Sstevel@tonic-gate (formatter)default_f },
877c478bd9Sstevel@tonic-gate { DX_FIELD, "rset", "rset", STR, 20, 14, addrof(pset_sbag),
887c478bd9Sstevel@tonic-gate offsetof(statistic_bag_t, sb_name),
897c478bd9Sstevel@tonic-gate (formatter)default_f },
907c478bd9Sstevel@tonic-gate { DX_FIELD, "min", "min", ULL, 4, 1, addrof(pset_sbag_s.bag),
917c478bd9Sstevel@tonic-gate offsetof(pset_statistic_bag_t, pset_sb_min),
927c478bd9Sstevel@tonic-gate (formatter)bigno_f },
937c478bd9Sstevel@tonic-gate { DX_FIELD, "max", "max", ULL, 4, 1, addrof(pset_sbag_s.bag),
947c478bd9Sstevel@tonic-gate offsetof(pset_statistic_bag_t, pset_sb_max),
957c478bd9Sstevel@tonic-gate (formatter)bigno_f },
967c478bd9Sstevel@tonic-gate { DX_FIELD, "size", "size", ULL, 4, 1, addrof(pset_sbag_s.bag),
977c478bd9Sstevel@tonic-gate offsetof(pset_statistic_bag_t, pset_sb_size),
987c478bd9Sstevel@tonic-gate (formatter)default_f },
997c478bd9Sstevel@tonic-gate { DX_FIELD, "used", "used", FL, 4, -1, addrof(pset_sbag_s.bag),
1007c478bd9Sstevel@tonic-gate offsetof(pset_statistic_bag_t, pset_sb_used),
1017c478bd9Sstevel@tonic-gate (formatter)used_stat_f },
1027c478bd9Sstevel@tonic-gate { DX_FIELD, "load", "load", FL, 4, -1, addrof(pset_sbag_s.bag),
1037c478bd9Sstevel@tonic-gate offsetof(pset_statistic_bag_t, pset_sb_load),
1047c478bd9Sstevel@tonic-gate (formatter)default_f }
1057c478bd9Sstevel@tonic-gate };
1067c478bd9Sstevel@tonic-gate
1077c478bd9Sstevel@tonic-gate /* formatter objects for pool, defined in a default printing sequence */
1087c478bd9Sstevel@tonic-gate static poolstat_field_format_t pool_ffs[] = {
1097c478bd9Sstevel@tonic-gate /* prt flags,name,header,type,width,minwidth,offset,formatter */
1107c478bd9Sstevel@tonic-gate { D_FIELD, "id", "id", LL, 3, 1, addrof(pool_sbag),
1117c478bd9Sstevel@tonic-gate offsetof(statistic_bag_t, sb_sysid),
1127c478bd9Sstevel@tonic-gate (formatter)default_f },
1137c478bd9Sstevel@tonic-gate { D_FIELD, "pool", "pool", STR, 20, 13, addrof(pool_sbag),
1147c478bd9Sstevel@tonic-gate offsetof(statistic_bag_t, sb_name),
1157c478bd9Sstevel@tonic-gate (formatter)default_f },
1167c478bd9Sstevel@tonic-gate { D_FIELD, "p_size", "size", ULL, 4, 1, addrof(pset_sbag_s.bag),
1177c478bd9Sstevel@tonic-gate offsetof(pset_statistic_bag_t, pset_sb_size),
1187c478bd9Sstevel@tonic-gate (formatter)default_f },
1197c478bd9Sstevel@tonic-gate { D_FIELD, "p_used", "used", FL, 4, -1, addrof(pset_sbag_s.bag),
1207c478bd9Sstevel@tonic-gate offsetof(pset_statistic_bag_t, pset_sb_used),
1217c478bd9Sstevel@tonic-gate (formatter)default_f },
1227c478bd9Sstevel@tonic-gate { D_FIELD, "p_load", "load", FL, 4, -1, addrof(pset_sbag_s.bag),
1237c478bd9Sstevel@tonic-gate offsetof(pset_statistic_bag_t, pset_sb_load),
1247c478bd9Sstevel@tonic-gate (formatter)default_f },
1257c478bd9Sstevel@tonic-gate };
1267c478bd9Sstevel@tonic-gate
1277c478bd9Sstevel@tonic-gate /* lists with formatter objects, one for each statistics field */
1287c478bd9Sstevel@tonic-gate static poolstat_line_format_t pool_lf; /* formatting list in default mode */
1297c478bd9Sstevel@tonic-gate static poolstat_line_format_t pset_lf; /* formatting list for psets */
1307c478bd9Sstevel@tonic-gate
1317c478bd9Sstevel@tonic-gate /* name of pools to be shown */
1327c478bd9Sstevel@tonic-gate static poolstat_list_element_t *pnames;
1337c478bd9Sstevel@tonic-gate /*
1347c478bd9Sstevel@tonic-gate * type of resources to be shown, currently we only have one type 'pset'
1357c478bd9Sstevel@tonic-gate * but, poolstat can be extended to handle new upcoming resource types.
1367c478bd9Sstevel@tonic-gate */
1377c478bd9Sstevel@tonic-gate static poolstat_list_element_t *rtypes;
1387c478bd9Sstevel@tonic-gate
1397c478bd9Sstevel@tonic-gate /* a handle to the pool configuration */
1407c478bd9Sstevel@tonic-gate static pool_conf_t *conf;
1417c478bd9Sstevel@tonic-gate
1427c478bd9Sstevel@tonic-gate /* option flags */
1437c478bd9Sstevel@tonic-gate static int rflag;
1447c478bd9Sstevel@tonic-gate static int pflag;
1457c478bd9Sstevel@tonic-gate static int oflag;
1467c478bd9Sstevel@tonic-gate
1477c478bd9Sstevel@tonic-gate /* operands */
1487c478bd9Sstevel@tonic-gate static int interval = 0; /* update interval */
1497c478bd9Sstevel@tonic-gate static long count = 1; /* one run */
1507c478bd9Sstevel@tonic-gate
1517c478bd9Sstevel@tonic-gate /* data structure handlers */
1527c478bd9Sstevel@tonic-gate static poolstat_list_element_t *
1537c478bd9Sstevel@tonic-gate create_prt_sequence_list(char *, poolstat_line_format_t *);
1547c478bd9Sstevel@tonic-gate static poolstat_list_element_t *
1557c478bd9Sstevel@tonic-gate create_args_list(char *, poolstat_list_element_t *, const char *);
1567c478bd9Sstevel@tonic-gate
1577c478bd9Sstevel@tonic-gate /* statistics update function */
1587c478bd9Sstevel@tonic-gate static void sa_update(statistic_bag_t *, int);
1597c478bd9Sstevel@tonic-gate
1607c478bd9Sstevel@tonic-gate /* statistics printing function */
1617c478bd9Sstevel@tonic-gate static void prt_pool_stats(poolstat_list_element_t *);
1627c478bd9Sstevel@tonic-gate
1637c478bd9Sstevel@tonic-gate static void
usage(void)1647c478bd9Sstevel@tonic-gate usage(void)
1657c478bd9Sstevel@tonic-gate {
1667c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(
1677c478bd9Sstevel@tonic-gate "Usage:\n"
16826fd7700SKrishnendu Sadhukhan - Sun Microsystems "poolstat [-p pool-list] [-r rset-list] [-T d|u] [interval [count]]\n"
16926fd7700SKrishnendu Sadhukhan - Sun Microsystems "poolstat [-p pool-list] [-o format -r rset-list] [-T d|u] [interval [count]]\n"
1707c478bd9Sstevel@tonic-gate " \'pool-list\' is a space-separated list of pool IDs or names\n"
1717c478bd9Sstevel@tonic-gate " \'rset-list\' is \'all\' or \'pset\'\n"
1727c478bd9Sstevel@tonic-gate " \'format\' for all resource types is one or more of:\n"
1737c478bd9Sstevel@tonic-gate "\tid pool type rid rset min max size used load\n"));
1747c478bd9Sstevel@tonic-gate (void) exit(E_USAGE);
1757c478bd9Sstevel@tonic-gate }
1767c478bd9Sstevel@tonic-gate
1777c478bd9Sstevel@tonic-gate static int
Atoi(char * p,int * errp)1787c478bd9Sstevel@tonic-gate Atoi(char *p, int *errp)
1797c478bd9Sstevel@tonic-gate {
1807c478bd9Sstevel@tonic-gate int i;
1817c478bd9Sstevel@tonic-gate char *q;
1827c478bd9Sstevel@tonic-gate errno = 0;
1837c478bd9Sstevel@tonic-gate i = strtol(p, &q, 10);
1847c478bd9Sstevel@tonic-gate if (errno != 0 || q == p || *q != '\0')
1857c478bd9Sstevel@tonic-gate *errp = -1;
1867c478bd9Sstevel@tonic-gate else
1877c478bd9Sstevel@tonic-gate *errp = 0;
1887c478bd9Sstevel@tonic-gate return (i);
1897c478bd9Sstevel@tonic-gate }
1907c478bd9Sstevel@tonic-gate
1917c478bd9Sstevel@tonic-gate int
main(int argc,char * argv[])1927c478bd9Sstevel@tonic-gate main(int argc, char *argv[])
1937c478bd9Sstevel@tonic-gate {
1947c478bd9Sstevel@tonic-gate char c;
1957c478bd9Sstevel@tonic-gate int error = 0;
1967c478bd9Sstevel@tonic-gate
1977c478bd9Sstevel@tonic-gate (void) getpname(argv[0]);
1987c478bd9Sstevel@tonic-gate (void) setlocale(LC_ALL, "");
1997c478bd9Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN);
2007c478bd9Sstevel@tonic-gate
2017c478bd9Sstevel@tonic-gate /* pset_sbag_s is used to collect pset statistics */
2027c478bd9Sstevel@tonic-gate pset_sbag_s.sb_type = PSET_TYPE_NAME;
2037c478bd9Sstevel@tonic-gate pset_sbag_s.bag = ZALLOC(sizeof (pset_statistic_bag_t));
2047c478bd9Sstevel@tonic-gate pool_sbag_s.sb_type = POOL_TYPE_NAME;
2057c478bd9Sstevel@tonic-gate
2067c478bd9Sstevel@tonic-gate pset_lf.plf_ffs = pset_ffs;
2077c478bd9Sstevel@tonic-gate pset_lf.plf_ff_len = sizeof (pset_ffs) /
2087c478bd9Sstevel@tonic-gate sizeof (poolstat_field_format_t);
2097c478bd9Sstevel@tonic-gate pool_lf.plf_ffs = pool_ffs;
2107c478bd9Sstevel@tonic-gate pool_lf.plf_ff_len = sizeof (pool_ffs) /
2117c478bd9Sstevel@tonic-gate sizeof (poolstat_field_format_t);
2127c478bd9Sstevel@tonic-gate
213f5cd957fSRobert Harris /* Don't let buffering interfere with piped output. */
214f5cd957fSRobert Harris (void) setvbuf(stdout, NULL, _IOLBF, 0);
215f5cd957fSRobert Harris
21626fd7700SKrishnendu Sadhukhan - Sun Microsystems while ((c = getopt(argc, argv, ":p:r:o:T:")) != EOF) {
2177c478bd9Sstevel@tonic-gate switch (c) {
2187c478bd9Sstevel@tonic-gate case 'p': /* pool name specification */
2197c478bd9Sstevel@tonic-gate pflag++;
2207c478bd9Sstevel@tonic-gate pnames = create_args_list(optarg, pnames,
2217c478bd9Sstevel@tonic-gate " \t");
2227c478bd9Sstevel@tonic-gate break;
2237c478bd9Sstevel@tonic-gate case 'r': { /* resource type */
2247c478bd9Sstevel@tonic-gate rflag++;
2257c478bd9Sstevel@tonic-gate rtypes = create_args_list(optarg, rtypes,
2267c478bd9Sstevel@tonic-gate " \t,");
2277c478bd9Sstevel@tonic-gate break;
2287c478bd9Sstevel@tonic-gate }
2297c478bd9Sstevel@tonic-gate case 'o': { /* format specification */
2307c478bd9Sstevel@tonic-gate oflag++;
2317c478bd9Sstevel@tonic-gate if (create_prt_sequence_list(optarg, &pset_lf) == NULL)
2327c478bd9Sstevel@tonic-gate usage();
2337c478bd9Sstevel@tonic-gate break;
2347c478bd9Sstevel@tonic-gate }
23526fd7700SKrishnendu Sadhukhan - Sun Microsystems case 'T':
23626fd7700SKrishnendu Sadhukhan - Sun Microsystems if (optarg) {
23726fd7700SKrishnendu Sadhukhan - Sun Microsystems if (*optarg == 'u')
23826fd7700SKrishnendu Sadhukhan - Sun Microsystems timestamp_fmt = UDATE;
23926fd7700SKrishnendu Sadhukhan - Sun Microsystems else if (*optarg == 'd')
24026fd7700SKrishnendu Sadhukhan - Sun Microsystems timestamp_fmt = DDATE;
24126fd7700SKrishnendu Sadhukhan - Sun Microsystems else
24226fd7700SKrishnendu Sadhukhan - Sun Microsystems usage();
24326fd7700SKrishnendu Sadhukhan - Sun Microsystems } else {
24426fd7700SKrishnendu Sadhukhan - Sun Microsystems usage();
24526fd7700SKrishnendu Sadhukhan - Sun Microsystems }
24626fd7700SKrishnendu Sadhukhan - Sun Microsystems break;
2477c478bd9Sstevel@tonic-gate case ':': {
2487c478bd9Sstevel@tonic-gate (void) fprintf(stderr,
2497c478bd9Sstevel@tonic-gate gettext(ERR_OPTION_ARGS), optopt);
2507c478bd9Sstevel@tonic-gate usage();
2517c478bd9Sstevel@tonic-gate /*NOTREACHED*/
2527c478bd9Sstevel@tonic-gate }
2537c478bd9Sstevel@tonic-gate default:
2547c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(ERR_OPTION), optopt);
2557c478bd9Sstevel@tonic-gate usage();
2567c478bd9Sstevel@tonic-gate /*NOTREACHED*/
2577c478bd9Sstevel@tonic-gate }
2587c478bd9Sstevel@tonic-gate }
2597c478bd9Sstevel@tonic-gate
2607c478bd9Sstevel@tonic-gate /* get operands */
2617c478bd9Sstevel@tonic-gate if (argc > optind) {
2627c478bd9Sstevel@tonic-gate if ((interval = Atoi(argv[optind++], &error)) < 1 || error != 0)
2637c478bd9Sstevel@tonic-gate usage();
2647c478bd9Sstevel@tonic-gate count = -1;
2657c478bd9Sstevel@tonic-gate }
2667c478bd9Sstevel@tonic-gate if (argc > optind) {
2677c478bd9Sstevel@tonic-gate if ((count = Atoi(argv[optind++], &error)) < 1 || error != 0)
2687c478bd9Sstevel@tonic-gate usage();
2697c478bd9Sstevel@tonic-gate }
2707c478bd9Sstevel@tonic-gate /* check for extra options/operands */
2717c478bd9Sstevel@tonic-gate if (argc > optind)
2727c478bd9Sstevel@tonic-gate usage();
2737c478bd9Sstevel@tonic-gate
2747c478bd9Sstevel@tonic-gate /* check options */
2757c478bd9Sstevel@tonic-gate if (oflag && !rflag)
2767c478bd9Sstevel@tonic-gate usage();
2777c478bd9Sstevel@tonic-gate
2787c478bd9Sstevel@tonic-gate /* global initializations */
2797c478bd9Sstevel@tonic-gate if (!oflag) {
2807c478bd9Sstevel@tonic-gate /* create the default print sequences */
2817c478bd9Sstevel@tonic-gate (void) create_prt_sequence_list(NULL, &pool_lf);
2827c478bd9Sstevel@tonic-gate (void) create_prt_sequence_list(NULL, &pset_lf);
2837c478bd9Sstevel@tonic-gate }
2847c478bd9Sstevel@tonic-gate
2857c478bd9Sstevel@tonic-gate if (rtypes == NULL || strcmp(rtypes->ple_obj, "all") == 0) {
2867c478bd9Sstevel@tonic-gate /* crate a default resource list */
2877c478bd9Sstevel@tonic-gate FREE(rtypes);
2887c478bd9Sstevel@tonic-gate rtypes = create_args_list("pset", NULL, " \t,");
2897c478bd9Sstevel@tonic-gate }
2907c478bd9Sstevel@tonic-gate
2917c478bd9Sstevel@tonic-gate if ((conf = pool_conf_alloc()) == NULL)
2927c478bd9Sstevel@tonic-gate die(gettext(ERR_NOMEM));
2937c478bd9Sstevel@tonic-gate if (pool_conf_open(conf, pool_dynamic_location(), PO_RDONLY)
2947c478bd9Sstevel@tonic-gate != PO_SUCCESS)
2957c478bd9Sstevel@tonic-gate die(gettext(ERR_OPEN_DYNAMIC), get_errstr());
2967c478bd9Sstevel@tonic-gate
2977c478bd9Sstevel@tonic-gate /* initialize statistic adapters */
2987c478bd9Sstevel@tonic-gate sa_libpool_init(conf);
2997c478bd9Sstevel@tonic-gate sa_kstat_init(NULL);
3007c478bd9Sstevel@tonic-gate
3017c478bd9Sstevel@tonic-gate /* collect and print out statistics */
3027c478bd9Sstevel@tonic-gate while (count-- != 0) {
3037c478bd9Sstevel@tonic-gate sa_update(pool_sbag, SA_REFRESH);
30426fd7700SKrishnendu Sadhukhan - Sun Microsystems if (timestamp_fmt != NODATE)
30526fd7700SKrishnendu Sadhukhan - Sun Microsystems print_timestamp(timestamp_fmt);
3067c478bd9Sstevel@tonic-gate if (pool_sbag->sb_changed & POU_POOL)
3077c478bd9Sstevel@tonic-gate (void) printf(
3087c478bd9Sstevel@tonic-gate "<<State change>>\n");
3097c478bd9Sstevel@tonic-gate prt_pool_stats(pnames);
3107c478bd9Sstevel@tonic-gate if (count != 0) {
3117c478bd9Sstevel@tonic-gate (void) sleep(interval);
3127c478bd9Sstevel@tonic-gate if (rflag)
3137c478bd9Sstevel@tonic-gate (void) printf("\n");
3147c478bd9Sstevel@tonic-gate }
3157c478bd9Sstevel@tonic-gate }
3167c478bd9Sstevel@tonic-gate
3177c478bd9Sstevel@tonic-gate return (E_PO_SUCCESS);
3187c478bd9Sstevel@tonic-gate }
3197c478bd9Sstevel@tonic-gate
3207c478bd9Sstevel@tonic-gate /*
3217c478bd9Sstevel@tonic-gate * Take the arguments and create/append a string list to the 'le' list.
3227c478bd9Sstevel@tonic-gate */
3237c478bd9Sstevel@tonic-gate static poolstat_list_element_t *
create_args_list(char * arg,poolstat_list_element_t * le,const char * delim)3247c478bd9Sstevel@tonic-gate create_args_list(char *arg, poolstat_list_element_t *le, const char *delim)
3257c478bd9Sstevel@tonic-gate {
3267c478bd9Sstevel@tonic-gate poolstat_list_element_t *head = le;
3277c478bd9Sstevel@tonic-gate
3287c478bd9Sstevel@tonic-gate while (arg != NULL && *arg != '\0') {
3297c478bd9Sstevel@tonic-gate char *name = arg;
3307c478bd9Sstevel@tonic-gate arg = strpbrk(arg, delim);
3317c478bd9Sstevel@tonic-gate if (arg != NULL) {
3327c478bd9Sstevel@tonic-gate *arg++ = '\0';
3337c478bd9Sstevel@tonic-gate }
3347c478bd9Sstevel@tonic-gate if (le == NULL) {
3357c478bd9Sstevel@tonic-gate /* create first element */
3367c478bd9Sstevel@tonic-gate NEW0(le);
3377c478bd9Sstevel@tonic-gate head = le;
3387c478bd9Sstevel@tonic-gate } else {
3397c478bd9Sstevel@tonic-gate /* find last and append */
3407c478bd9Sstevel@tonic-gate while (le->ple_next != NULL)
3417c478bd9Sstevel@tonic-gate le = le->ple_next;
3427c478bd9Sstevel@tonic-gate NEW0(le->ple_next);
3437c478bd9Sstevel@tonic-gate le = le->ple_next;
3447c478bd9Sstevel@tonic-gate }
3457c478bd9Sstevel@tonic-gate le->ple_obj = (void *)name;
3467c478bd9Sstevel@tonic-gate }
3477c478bd9Sstevel@tonic-gate
3487c478bd9Sstevel@tonic-gate return (head);
3497c478bd9Sstevel@tonic-gate }
3507c478bd9Sstevel@tonic-gate
3517c478bd9Sstevel@tonic-gate /*
3527c478bd9Sstevel@tonic-gate * Take the arguments to the -o option, and create a format field list in order
3537c478bd9Sstevel@tonic-gate * specified by 'arg'.
3547c478bd9Sstevel@tonic-gate * If 'arg' is NULL a list in a default printing order is created.
3557c478bd9Sstevel@tonic-gate */
3567c478bd9Sstevel@tonic-gate static poolstat_list_element_t *
create_prt_sequence_list(char * arg,poolstat_line_format_t * lf)3577c478bd9Sstevel@tonic-gate create_prt_sequence_list(char *arg, poolstat_line_format_t *lf)
3587c478bd9Sstevel@tonic-gate {
3597c478bd9Sstevel@tonic-gate /*
3607c478bd9Sstevel@tonic-gate * Create a default print sequence. It is the sequence defined
3617c478bd9Sstevel@tonic-gate * statically in the format list. At the same time mark the fields
3627c478bd9Sstevel@tonic-gate * printable according to the current option settings.
3637c478bd9Sstevel@tonic-gate */
3647c478bd9Sstevel@tonic-gate if (arg == NULL) {
3657c478bd9Sstevel@tonic-gate int i;
3667c478bd9Sstevel@tonic-gate NEW0(lf->plf_prt_seq);
3677c478bd9Sstevel@tonic-gate lf->plf_ffs[0].pff_prt |= PRINTABLE(0) ? PABLE_FIELD : 0;
3687c478bd9Sstevel@tonic-gate lf->plf_last = lf->plf_prt_seq;
3697c478bd9Sstevel@tonic-gate lf->plf_last->ple_obj = &(lf->plf_ffs[0]);
3707c478bd9Sstevel@tonic-gate for (i = 1; i < lf->plf_ff_len; i++) {
3717c478bd9Sstevel@tonic-gate lf->plf_ffs[i].pff_prt |=
3727c478bd9Sstevel@tonic-gate PRINTABLE(i) ? PABLE_FIELD : 0;
3737c478bd9Sstevel@tonic-gate NEW0(lf->plf_last->ple_next);
3747c478bd9Sstevel@tonic-gate lf->plf_last = lf->plf_last->ple_next;
3757c478bd9Sstevel@tonic-gate lf->plf_last->ple_obj = &(lf->plf_ffs[i]);
3767c478bd9Sstevel@tonic-gate }
3777c478bd9Sstevel@tonic-gate return (lf->plf_prt_seq);
3787c478bd9Sstevel@tonic-gate }
3797c478bd9Sstevel@tonic-gate
3807c478bd9Sstevel@tonic-gate while (arg != NULL && *arg != '\0') {
3817c478bd9Sstevel@tonic-gate poolstat_field_format_t *ff; /* current format field */
3827c478bd9Sstevel@tonic-gate int ffIdx; /* format field index */
3837c478bd9Sstevel@tonic-gate char *name; /* name of field */
3847c478bd9Sstevel@tonic-gate int n; /* no. of chars to strip */
3857c478bd9Sstevel@tonic-gate
3867c478bd9Sstevel@tonic-gate n = strspn(arg, " ,\t\r\v\f\n");
3877c478bd9Sstevel@tonic-gate arg += n; /* strip multiples separator */
3887c478bd9Sstevel@tonic-gate name = arg;
3897c478bd9Sstevel@tonic-gate
3907c478bd9Sstevel@tonic-gate if (strlen(name) < 1)
3917c478bd9Sstevel@tonic-gate break;
3927c478bd9Sstevel@tonic-gate
3937c478bd9Sstevel@tonic-gate if ((arg = strpbrk(arg, " ,\t\r\v\f\n")) != NULL)
3947c478bd9Sstevel@tonic-gate *arg++ = '\0';
3957c478bd9Sstevel@tonic-gate
3967c478bd9Sstevel@tonic-gate /* search for a named format field */
3977c478bd9Sstevel@tonic-gate for (ffIdx = 0; ffIdx < lf->plf_ff_len; ffIdx++) {
3987c478bd9Sstevel@tonic-gate ff = lf->plf_ffs + ffIdx;
3997c478bd9Sstevel@tonic-gate if (strcmp(ff->pff_name, name) == 0) {
4007c478bd9Sstevel@tonic-gate ff->pff_prt |= PABLE_FIELD;
4017c478bd9Sstevel@tonic-gate break;
4027c478bd9Sstevel@tonic-gate }
4037c478bd9Sstevel@tonic-gate }
4047c478bd9Sstevel@tonic-gate /* if the name wasn't found */
4057c478bd9Sstevel@tonic-gate if (ffIdx == lf->plf_ff_len) {
4067c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext(ERR_UNSUPP_STAT_FIELD),
4077c478bd9Sstevel@tonic-gate name);
4087c478bd9Sstevel@tonic-gate usage();
4097c478bd9Sstevel@tonic-gate }
4107c478bd9Sstevel@tonic-gate if (lf->plf_last == NULL) {
4117c478bd9Sstevel@tonic-gate /* create first print handle */
4127c478bd9Sstevel@tonic-gate NEW0(lf->plf_prt_seq);
4137c478bd9Sstevel@tonic-gate lf->plf_last = lf->plf_prt_seq;
4147c478bd9Sstevel@tonic-gate } else {
4157c478bd9Sstevel@tonic-gate NEW0(lf->plf_last->ple_next);
4167c478bd9Sstevel@tonic-gate lf->plf_last = lf->plf_last->ple_next;
4177c478bd9Sstevel@tonic-gate }
4187c478bd9Sstevel@tonic-gate lf->plf_last->ple_obj = ff; /* refer to the format field */
4197c478bd9Sstevel@tonic-gate }
4207c478bd9Sstevel@tonic-gate
4217c478bd9Sstevel@tonic-gate return (lf->plf_prt_seq);
4227c478bd9Sstevel@tonic-gate }
4237c478bd9Sstevel@tonic-gate
4247c478bd9Sstevel@tonic-gate /* update the statistic data by adapters */
4257c478bd9Sstevel@tonic-gate static void
sa_update(statistic_bag_t * sbag,int flags)4267c478bd9Sstevel@tonic-gate sa_update(statistic_bag_t *sbag, int flags)
4277c478bd9Sstevel@tonic-gate {
4287c478bd9Sstevel@tonic-gate sa_libpool_update(sbag, flags);
4297c478bd9Sstevel@tonic-gate sa_kstat_update(sbag, flags);
4307c478bd9Sstevel@tonic-gate }
4317c478bd9Sstevel@tonic-gate
4327c478bd9Sstevel@tonic-gate /*
4337c478bd9Sstevel@tonic-gate * Format one statistic field and put it into the 'str' buffer. 'ff' contains
4347c478bd9Sstevel@tonic-gate * the field formatting parameters. Return the number of used bytes.
4357c478bd9Sstevel@tonic-gate */
4367c478bd9Sstevel@tonic-gate static int
default_f(char * str,int pos,int left,poolstat_field_format_t * ff,char * data)4377c478bd9Sstevel@tonic-gate default_f(char *str, int pos, int left, poolstat_field_format_t *ff, char *data)
4387c478bd9Sstevel@tonic-gate {
4397c478bd9Sstevel@tonic-gate int used;
4407c478bd9Sstevel@tonic-gate
4417c478bd9Sstevel@tonic-gate switch (ff->pff_type) {
4427c478bd9Sstevel@tonic-gate case LL: {
4437c478bd9Sstevel@tonic-gate int64_t v;
4447c478bd9Sstevel@tonic-gate v = *((int64_t *)(void *)(data + ff->pff_offset));
4457c478bd9Sstevel@tonic-gate used = snprintf(str + pos, left, "%*.*lld",
4467c478bd9Sstevel@tonic-gate ff->pff_width, ff->pff_minwidth, v);
4477c478bd9Sstevel@tonic-gate }
4487c478bd9Sstevel@tonic-gate break;
4497c478bd9Sstevel@tonic-gate case ULL: {
4507c478bd9Sstevel@tonic-gate uint64_t v;
4517c478bd9Sstevel@tonic-gate v = *((uint64_t *)(void *)(data + ff->pff_offset));
4527c478bd9Sstevel@tonic-gate used = snprintf(str + pos, left, "%*.*llu",
4537c478bd9Sstevel@tonic-gate ff->pff_width, ff->pff_minwidth, v);
4547c478bd9Sstevel@tonic-gate };
4557c478bd9Sstevel@tonic-gate break;
4567c478bd9Sstevel@tonic-gate case FL: {
4577c478bd9Sstevel@tonic-gate int pw = 0;
4587c478bd9Sstevel@tonic-gate double v = *((double *)(void *)(data + ff->pff_offset));
4597c478bd9Sstevel@tonic-gate if (v < 10) {
4607c478bd9Sstevel@tonic-gate pw = ff->pff_width - 2;
4617c478bd9Sstevel@tonic-gate } else if (v < 100) {
4627c478bd9Sstevel@tonic-gate pw = ff->pff_width - 3;
4637c478bd9Sstevel@tonic-gate } else if (v < 1000) {
4647c478bd9Sstevel@tonic-gate pw = ff->pff_width - 4;
4657c478bd9Sstevel@tonic-gate }
4667c478bd9Sstevel@tonic-gate if (pw < 0)
4677c478bd9Sstevel@tonic-gate pw = 0;
4687c478bd9Sstevel@tonic-gate used = snprintf(str + pos, left, "%*.*f",
4697c478bd9Sstevel@tonic-gate ff->pff_width, pw, v);
4707c478bd9Sstevel@tonic-gate };
4717c478bd9Sstevel@tonic-gate break;
4727c478bd9Sstevel@tonic-gate case STR: {
4737c478bd9Sstevel@tonic-gate char *v;
4747c478bd9Sstevel@tonic-gate int sl;
4757c478bd9Sstevel@tonic-gate v = *((char **)(void *)(data + ff->pff_offset));
4767c478bd9Sstevel@tonic-gate sl = strlen(v);
4777c478bd9Sstevel@tonic-gate /* truncate if it doesn't fit */
4787c478bd9Sstevel@tonic-gate if (sl > ff->pff_width) {
4797c478bd9Sstevel@tonic-gate char *cp = v + ff->pff_width - 1;
4807c478bd9Sstevel@tonic-gate if (ff->pff_width < 4)
4817c478bd9Sstevel@tonic-gate die(gettext(ERR_STATS_FORMAT),
4827c478bd9Sstevel@tonic-gate ff->pff_header);
4837c478bd9Sstevel@tonic-gate *cp-- = 0;
4847c478bd9Sstevel@tonic-gate *cp-- = '.';
4857c478bd9Sstevel@tonic-gate *cp-- = '.';
4867c478bd9Sstevel@tonic-gate *cp-- = '.';
4877c478bd9Sstevel@tonic-gate }
4887c478bd9Sstevel@tonic-gate used = snprintf(str + pos, left, "%-*s", ff->pff_width,
4897c478bd9Sstevel@tonic-gate v);
4907c478bd9Sstevel@tonic-gate }
4917c478bd9Sstevel@tonic-gate break;
4927c478bd9Sstevel@tonic-gate }
4937c478bd9Sstevel@tonic-gate
4947c478bd9Sstevel@tonic-gate return (used);
4957c478bd9Sstevel@tonic-gate }
4967c478bd9Sstevel@tonic-gate
4977c478bd9Sstevel@tonic-gate /* format big numbers */
4987c478bd9Sstevel@tonic-gate static int
bigno_f(char * str,int pos,int left,poolstat_field_format_t * ff,char * data)4997c478bd9Sstevel@tonic-gate bigno_f(char *str, int pos, int left, poolstat_field_format_t *ff, char *data)
5007c478bd9Sstevel@tonic-gate {
5017c478bd9Sstevel@tonic-gate uint64_t v;
5027c478bd9Sstevel@tonic-gate char tag;
5037c478bd9Sstevel@tonic-gate int pw = ff->pff_width - 4;
5047c478bd9Sstevel@tonic-gate double pv;
5057c478bd9Sstevel@tonic-gate int used;
5067c478bd9Sstevel@tonic-gate
5077c478bd9Sstevel@tonic-gate v = *((uint64_t *)(void *)(data + ff->pff_offset));
5087c478bd9Sstevel@tonic-gate /*
5097c478bd9Sstevel@tonic-gate * the max value can be ULONG_MAX, which is formatted as:
5107c478bd9Sstevel@tonic-gate * E P T G M K
5117c478bd9Sstevel@tonic-gate * 18 446 744 073 709 551 615
5127c478bd9Sstevel@tonic-gate * As a result ULONG_MAX is displayed as 18E
5137c478bd9Sstevel@tonic-gate */
5147c478bd9Sstevel@tonic-gate pv = v;
5157c478bd9Sstevel@tonic-gate if (v < 1000) {
5167c478bd9Sstevel@tonic-gate pw = 0;
5177c478bd9Sstevel@tonic-gate } else if (v < KILO * 10) {
5187c478bd9Sstevel@tonic-gate pv = (double)v / KILO;
5197c478bd9Sstevel@tonic-gate tag = 'K';
5207c478bd9Sstevel@tonic-gate } else if (v < KILO * 100) {
5217c478bd9Sstevel@tonic-gate pv = (double)v / KILO;
5227c478bd9Sstevel@tonic-gate tag = 'K'; pw -= 1;
5237c478bd9Sstevel@tonic-gate } else if (v < KILO * 1000) {
5247c478bd9Sstevel@tonic-gate pv = (double)v / KILO;
5257c478bd9Sstevel@tonic-gate tag = 'K'; pw -= 2;
5267c478bd9Sstevel@tonic-gate } else if (v < MEGA * 10) {
5277c478bd9Sstevel@tonic-gate pv = (double)v / MEGA;
5287c478bd9Sstevel@tonic-gate tag = 'M';
5297c478bd9Sstevel@tonic-gate } else if (v < MEGA * 100) {
5307c478bd9Sstevel@tonic-gate pv = (double)v / MEGA;
5317c478bd9Sstevel@tonic-gate tag = 'M'; pw -= 1;
5327c478bd9Sstevel@tonic-gate } else if (v < MEGA * 1000) {
5337c478bd9Sstevel@tonic-gate pv = (double)v / MEGA;
5347c478bd9Sstevel@tonic-gate tag = 'M'; pw -= 2;
5357c478bd9Sstevel@tonic-gate } else if (v < GIGA * 10) {
5367c478bd9Sstevel@tonic-gate pv = (double)v / GIGA;
5377c478bd9Sstevel@tonic-gate tag = 'G';
5387c478bd9Sstevel@tonic-gate } else if (v < GIGA * 100) {
5397c478bd9Sstevel@tonic-gate pv = (double)v / GIGA;
5407c478bd9Sstevel@tonic-gate tag = 'G'; pw -= 1;
5417c478bd9Sstevel@tonic-gate } else if (v < GIGA * 1000) {
5427c478bd9Sstevel@tonic-gate pv = (double)v / GIGA;
5437c478bd9Sstevel@tonic-gate tag = 'G'; pw -= 2;
5447c478bd9Sstevel@tonic-gate } else if (v < TERA * 10) {
5457c478bd9Sstevel@tonic-gate pv = (double)v / TERA;
5467c478bd9Sstevel@tonic-gate tag = 'T';
5477c478bd9Sstevel@tonic-gate } else if (v < TERA * 100) {
5487c478bd9Sstevel@tonic-gate pv = (double)v / TERA;
5497c478bd9Sstevel@tonic-gate tag = 'T'; pw -= 1;
5507c478bd9Sstevel@tonic-gate } else if (v < TERA * 1000) {
5517c478bd9Sstevel@tonic-gate pv = (double)v / TERA;
5527c478bd9Sstevel@tonic-gate tag = 'T'; pw -= 2;
5537c478bd9Sstevel@tonic-gate } else if (v < PETA * 10) {
5547c478bd9Sstevel@tonic-gate pv = (double)v / PETA;
5557c478bd9Sstevel@tonic-gate tag = 'P';
5567c478bd9Sstevel@tonic-gate } else if (v < PETA * 100) {
5577c478bd9Sstevel@tonic-gate pv = (double)v / PETA;
5587c478bd9Sstevel@tonic-gate tag = 'P'; pw -= 1;
5597c478bd9Sstevel@tonic-gate } else if (v < PETA * 1000) {
5607c478bd9Sstevel@tonic-gate pv = (double)v / PETA;
5617c478bd9Sstevel@tonic-gate tag = 'P'; pw -= 2;
5627c478bd9Sstevel@tonic-gate } else if (v < EXA * 10) {
5637c478bd9Sstevel@tonic-gate pv = (double)v / EXA;
5647c478bd9Sstevel@tonic-gate tag = 'E';
5657c478bd9Sstevel@tonic-gate } else if (v < EXA * 100) {
5667c478bd9Sstevel@tonic-gate pv = (double)v / EXA;
5677c478bd9Sstevel@tonic-gate tag = 'E'; pw -= 1;
5687c478bd9Sstevel@tonic-gate } else {
5697c478bd9Sstevel@tonic-gate pv = (double)v / EXA;
5707c478bd9Sstevel@tonic-gate tag = 'E'; pw -= 2;
5717c478bd9Sstevel@tonic-gate }
5727c478bd9Sstevel@tonic-gate if (pw < 0)
5737c478bd9Sstevel@tonic-gate pw = 0;
5747c478bd9Sstevel@tonic-gate if (v < 1000)
5757c478bd9Sstevel@tonic-gate used = snprintf(str + pos, left, "%*.*f",
5767c478bd9Sstevel@tonic-gate ff->pff_width, pw, pv);
5777c478bd9Sstevel@tonic-gate else
5787c478bd9Sstevel@tonic-gate used = snprintf(str + pos, left, "%*.*f%c",
5797c478bd9Sstevel@tonic-gate ff->pff_width - 1, pw, pv, tag);
5807c478bd9Sstevel@tonic-gate
5817c478bd9Sstevel@tonic-gate return (used);
5827c478bd9Sstevel@tonic-gate }
5837c478bd9Sstevel@tonic-gate
5847c478bd9Sstevel@tonic-gate /* format usage statistic, if configuration has changed print '-'. */
5857c478bd9Sstevel@tonic-gate static int
used_stat_f(char * str,int pos,int left,poolstat_field_format_t * ff,char * data)5867c478bd9Sstevel@tonic-gate used_stat_f(char *str, int pos, int left, poolstat_field_format_t *ff,
5877c478bd9Sstevel@tonic-gate char *data)
5887c478bd9Sstevel@tonic-gate {
5897c478bd9Sstevel@tonic-gate int pw = 0;
5907c478bd9Sstevel@tonic-gate double v = *((double *)(void *)(data + ff->pff_offset));
5917c478bd9Sstevel@tonic-gate int used;
5927c478bd9Sstevel@tonic-gate
5937c478bd9Sstevel@tonic-gate if (pool_sbag->sb_changed & POU_POOL) {
5947c478bd9Sstevel@tonic-gate used = snprintf(str + pos, left, "%*c", ff->pff_width, '-');
5957c478bd9Sstevel@tonic-gate } else {
5967c478bd9Sstevel@tonic-gate if (v < 10) {
5977c478bd9Sstevel@tonic-gate pw = ff->pff_width - 2;
5987c478bd9Sstevel@tonic-gate } else if (v < 100) {
5997c478bd9Sstevel@tonic-gate pw = ff->pff_width - 3;
6007c478bd9Sstevel@tonic-gate } else if (v < 1000) {
6017c478bd9Sstevel@tonic-gate pw = ff->pff_width - 4;
6027c478bd9Sstevel@tonic-gate }
6037c478bd9Sstevel@tonic-gate if (pw < 0)
6047c478bd9Sstevel@tonic-gate pw = 0;
6057c478bd9Sstevel@tonic-gate used = snprintf(str + pos, left, "%*.*f",
6067c478bd9Sstevel@tonic-gate ff->pff_width, pw, v);
6077c478bd9Sstevel@tonic-gate }
6087c478bd9Sstevel@tonic-gate return (used);
6097c478bd9Sstevel@tonic-gate }
6107c478bd9Sstevel@tonic-gate
6117c478bd9Sstevel@tonic-gate /*
6127c478bd9Sstevel@tonic-gate * Format one header field and put it into the 'str' buffer.
6137c478bd9Sstevel@tonic-gate */
6147c478bd9Sstevel@tonic-gate /*ARGSUSED*/
6157c478bd9Sstevel@tonic-gate static int
header_f(char * str,int pos,int left,poolstat_field_format_t * ff,char * data)6167c478bd9Sstevel@tonic-gate header_f(char *str, int pos, int left, poolstat_field_format_t *ff, char *data)
6177c478bd9Sstevel@tonic-gate {
6187c478bd9Sstevel@tonic-gate int used = 0;
6197c478bd9Sstevel@tonic-gate
6207c478bd9Sstevel@tonic-gate if (ff->pff_type == STR)
6217c478bd9Sstevel@tonic-gate /* strings are left justified */
6227c478bd9Sstevel@tonic-gate used = snprintf(str + pos, left, "%-*s",
6237c478bd9Sstevel@tonic-gate ff->pff_width, ff->pff_header);
6247c478bd9Sstevel@tonic-gate else
6257c478bd9Sstevel@tonic-gate used = snprintf(str + pos, left, "%*s",
6267c478bd9Sstevel@tonic-gate ff->pff_width, ff->pff_header);
6277c478bd9Sstevel@tonic-gate return (used);
6287c478bd9Sstevel@tonic-gate }
6297c478bd9Sstevel@tonic-gate
6307c478bd9Sstevel@tonic-gate /*
6317c478bd9Sstevel@tonic-gate * Print one statistic line according to the definitions in 'lf'.
6327c478bd9Sstevel@tonic-gate */
6337c478bd9Sstevel@tonic-gate static void
prt_stat_line(poolstat_line_format_t * lf)6347c478bd9Sstevel@tonic-gate prt_stat_line(poolstat_line_format_t *lf)
6357c478bd9Sstevel@tonic-gate {
6367c478bd9Sstevel@tonic-gate poolstat_list_element_t *le; /* list element in the print sequence */
6377c478bd9Sstevel@tonic-gate char *line;
6387c478bd9Sstevel@tonic-gate int pos = 0; /* position in the printed line */
6397c478bd9Sstevel@tonic-gate int len = MAXLINE; /* the length of the line */
6407c478bd9Sstevel@tonic-gate int left = len; /* chars left to use in the line */
6417c478bd9Sstevel@tonic-gate
6427c478bd9Sstevel@tonic-gate line = ZALLOC(len);
6437c478bd9Sstevel@tonic-gate for (le = lf->plf_prt_seq; le; le = le->ple_next) {
6447c478bd9Sstevel@tonic-gate int used;
6457c478bd9Sstevel@tonic-gate poolstat_field_format_t *ff =
6467c478bd9Sstevel@tonic-gate (poolstat_field_format_t *)le->ple_obj;
6477c478bd9Sstevel@tonic-gate /* if the filed is marked to be printed */
6487c478bd9Sstevel@tonic-gate if (ff->pff_prt & PABLE_FIELD) {
6497c478bd9Sstevel@tonic-gate if (((used = ff->pff_format(line, pos, left, ff,
6507c478bd9Sstevel@tonic-gate *ff->pff_data_ptr)) + 1) >= left) {
6517c478bd9Sstevel@tonic-gate /* if field doesn't fit allocate new space */
6527c478bd9Sstevel@tonic-gate len += used + MAXLINE;
6537c478bd9Sstevel@tonic-gate left += used + MAXLINE;
6547c478bd9Sstevel@tonic-gate line = REALLOC(line, len);
6557c478bd9Sstevel@tonic-gate if (((used = ff->pff_format(line, pos, left, ff,
6567c478bd9Sstevel@tonic-gate *ff->pff_data_ptr)) + 1) >= left)
6577c478bd9Sstevel@tonic-gate die(gettext(ERR_STATS_FORMAT), line);
6587c478bd9Sstevel@tonic-gate }
6597c478bd9Sstevel@tonic-gate left -= used;
6607c478bd9Sstevel@tonic-gate pos += used;
6617c478bd9Sstevel@tonic-gate if (le->ple_next != NULL) {
6627c478bd9Sstevel@tonic-gate /* separate columns with a space */
6637c478bd9Sstevel@tonic-gate line[pos++] = ' ';
6647c478bd9Sstevel@tonic-gate left--;
6657c478bd9Sstevel@tonic-gate }
6667c478bd9Sstevel@tonic-gate }
6677c478bd9Sstevel@tonic-gate }
6687c478bd9Sstevel@tonic-gate
6697c478bd9Sstevel@tonic-gate (void) printf("%s\n", line);
6707c478bd9Sstevel@tonic-gate FREE(line);
6717c478bd9Sstevel@tonic-gate }
6727c478bd9Sstevel@tonic-gate
6737c478bd9Sstevel@tonic-gate /*
6747c478bd9Sstevel@tonic-gate * Print a statistics header line for a given resource type.
6757c478bd9Sstevel@tonic-gate */
6767c478bd9Sstevel@tonic-gate static void
prt_stat_hd(const char * type)6777c478bd9Sstevel@tonic-gate prt_stat_hd(const char *type)
6787c478bd9Sstevel@tonic-gate {
6797c478bd9Sstevel@tonic-gate poolstat_line_format_t *lf; /* line format */
6807c478bd9Sstevel@tonic-gate poolstat_list_element_t *le; /* list element in the print sequence */
6817c478bd9Sstevel@tonic-gate char *line;
6827c478bd9Sstevel@tonic-gate int pos = 0; /* position in the printed line */
6837c478bd9Sstevel@tonic-gate int len = MAXLINE; /* the length of the line */
6847c478bd9Sstevel@tonic-gate int left = len; /* chars left to use in the line */
6857c478bd9Sstevel@tonic-gate
6867c478bd9Sstevel@tonic-gate if (strcmp(type, POOL_TYPE_NAME) == 0) {
6877c478bd9Sstevel@tonic-gate /* pool format needs an extra header */
6887c478bd9Sstevel@tonic-gate (void) printf("%*s\n", 19 + 15, "pset");
6897c478bd9Sstevel@tonic-gate lf = &pool_lf;
6907c478bd9Sstevel@tonic-gate } else if (strcmp(type, PSET_TYPE_NAME) == 0) {
6917c478bd9Sstevel@tonic-gate lf = &pset_lf;
6927c478bd9Sstevel@tonic-gate } else {
6937c478bd9Sstevel@tonic-gate die(gettext(ERR_UNSUPP_RTYPE), type);
6947c478bd9Sstevel@tonic-gate }
6957c478bd9Sstevel@tonic-gate line = ZALLOC(len);
6967c478bd9Sstevel@tonic-gate for (le = lf->plf_prt_seq; le; le = le->ple_next) {
6977c478bd9Sstevel@tonic-gate int used; /* used chars in line */
6987c478bd9Sstevel@tonic-gate poolstat_field_format_t *ff =
6997c478bd9Sstevel@tonic-gate (poolstat_field_format_t *)le->ple_obj;
7007c478bd9Sstevel@tonic-gate /* if the filed is marked to be printed */
7017c478bd9Sstevel@tonic-gate if (ff->pff_prt& PABLE_FIELD) {
7027c478bd9Sstevel@tonic-gate if (((used = header_f(line, pos, left, ff, NULL)) + 1)
7037c478bd9Sstevel@tonic-gate >= left) {
7047c478bd9Sstevel@tonic-gate /* if field doesn't fit allocate new space */
7057c478bd9Sstevel@tonic-gate len += used + MAXLINE;
7067c478bd9Sstevel@tonic-gate left += used + MAXLINE;
7077c478bd9Sstevel@tonic-gate line = REALLOC(line, len);
7087c478bd9Sstevel@tonic-gate if (((used = header_f(line, pos, left, ff,
7097c478bd9Sstevel@tonic-gate NULL)) + 1) >= left)
7107c478bd9Sstevel@tonic-gate die(gettext(ERR_STATS_FORMAT), line);
7117c478bd9Sstevel@tonic-gate }
7127c478bd9Sstevel@tonic-gate left -= used;
7137c478bd9Sstevel@tonic-gate pos += used;
7147c478bd9Sstevel@tonic-gate if (le->ple_next != NULL) {
7157c478bd9Sstevel@tonic-gate /* separate columns with a space */
7167c478bd9Sstevel@tonic-gate line[pos++] = ' ';
7177c478bd9Sstevel@tonic-gate left--;
7187c478bd9Sstevel@tonic-gate }
7197c478bd9Sstevel@tonic-gate }
7207c478bd9Sstevel@tonic-gate }
7217c478bd9Sstevel@tonic-gate
7227c478bd9Sstevel@tonic-gate /* only header line with non space characters should be printed */
7237c478bd9Sstevel@tonic-gate pos = 0;
7247c478bd9Sstevel@tonic-gate while (*(line + pos) != '\n') {
7257c478bd9Sstevel@tonic-gate if (!isspace(*(line + pos))) {
7267c478bd9Sstevel@tonic-gate (void) printf("%s\n", line);
7277c478bd9Sstevel@tonic-gate
7287c478bd9Sstevel@tonic-gate break;
7297c478bd9Sstevel@tonic-gate }
7307c478bd9Sstevel@tonic-gate pos++;
7317c478bd9Sstevel@tonic-gate }
7327c478bd9Sstevel@tonic-gate FREE(line);
7337c478bd9Sstevel@tonic-gate }
7347c478bd9Sstevel@tonic-gate
7357c478bd9Sstevel@tonic-gate /*
7367c478bd9Sstevel@tonic-gate * Create a pool value instance and set its name to 'name'.
7377c478bd9Sstevel@tonic-gate */
7387c478bd9Sstevel@tonic-gate static pool_value_t *
create_pool_value(const char * name)7397c478bd9Sstevel@tonic-gate create_pool_value(const char *name)
7407c478bd9Sstevel@tonic-gate {
7417c478bd9Sstevel@tonic-gate pool_value_t *pval;
7427c478bd9Sstevel@tonic-gate
7437c478bd9Sstevel@tonic-gate if ((pval = pool_value_alloc()) == NULL) {
7447c478bd9Sstevel@tonic-gate return (NULL);
7457c478bd9Sstevel@tonic-gate }
7467c478bd9Sstevel@tonic-gate if (pool_value_set_name(pval, name) != PO_SUCCESS) {
7477c478bd9Sstevel@tonic-gate pool_value_free(pval);
7487c478bd9Sstevel@tonic-gate return (NULL);
7497c478bd9Sstevel@tonic-gate }
7507c478bd9Sstevel@tonic-gate
7517c478bd9Sstevel@tonic-gate return (pval);
7527c478bd9Sstevel@tonic-gate }
7537c478bd9Sstevel@tonic-gate
7547c478bd9Sstevel@tonic-gate /*
7557c478bd9Sstevel@tonic-gate * Find all resources of type 'rtype'.
7567c478bd9Sstevel@tonic-gate * If 'pool_name' is defined find all resources bound to this pool.
7577c478bd9Sstevel@tonic-gate */
7587c478bd9Sstevel@tonic-gate static pool_resource_t **
get_resources(const char * pool_name,const char * rtype,uint_t * nelem)7597c478bd9Sstevel@tonic-gate get_resources(const char *pool_name, const char *rtype, uint_t *nelem)
7607c478bd9Sstevel@tonic-gate {
7617c478bd9Sstevel@tonic-gate pool_resource_t **resources = NULL;
7627c478bd9Sstevel@tonic-gate pool_value_t *pvals[] = { NULL, NULL, NULL};
7637c478bd9Sstevel@tonic-gate pool_value_t *pv_sys_id;
7647c478bd9Sstevel@tonic-gate pool_value_t *pv_name;
7657c478bd9Sstevel@tonic-gate char *name_prop; /* set name property */
7667c478bd9Sstevel@tonic-gate
7677c478bd9Sstevel@tonic-gate if (strcmp(rtype, PSET_TYPE_NAME) == 0) {
7687c478bd9Sstevel@tonic-gate if ((pv_sys_id = create_pool_value(PSET_SYSID)) == NULL)
7697c478bd9Sstevel@tonic-gate goto on_error;
7707c478bd9Sstevel@tonic-gate name_prop = PSET_NAME;
7717c478bd9Sstevel@tonic-gate } else {
7727c478bd9Sstevel@tonic-gate die(gettext(ERR_UNSUPP_RTYPE), rtype);
7737c478bd9Sstevel@tonic-gate }
7747c478bd9Sstevel@tonic-gate
7757c478bd9Sstevel@tonic-gate if ((pvals[0] = create_pool_value("type")) == NULL)
7767c478bd9Sstevel@tonic-gate goto on_error;
7777c478bd9Sstevel@tonic-gate if ((pool_value_set_string(pvals[0], rtype)) == -1)
7787c478bd9Sstevel@tonic-gate goto on_error;
7797c478bd9Sstevel@tonic-gate
7807c478bd9Sstevel@tonic-gate if ((pv_name = create_pool_value(name_prop)) == NULL)
7817c478bd9Sstevel@tonic-gate goto on_error;
7827c478bd9Sstevel@tonic-gate
7837c478bd9Sstevel@tonic-gate if (pool_name != NULL) {
7847c478bd9Sstevel@tonic-gate /* collect resources associated to 'pool_name' */
7857c478bd9Sstevel@tonic-gate pool_t *pool;
7867c478bd9Sstevel@tonic-gate if ((pool = pool_get_pool(conf, pool_name)) == NULL)
7877c478bd9Sstevel@tonic-gate die(gettext(ERR_STATS_POOL_N), pool_name);
7887c478bd9Sstevel@tonic-gate if ((resources = pool_query_pool_resources(
7897c478bd9Sstevel@tonic-gate conf, pool, nelem, pvals)) == NULL)
7907c478bd9Sstevel@tonic-gate goto on_error;
7917c478bd9Sstevel@tonic-gate } else {
7927c478bd9Sstevel@tonic-gate /* collect all resources */
7937c478bd9Sstevel@tonic-gate if ((resources =
7947c478bd9Sstevel@tonic-gate pool_query_resources(conf, nelem, pvals)) == NULL)
7957c478bd9Sstevel@tonic-gate goto on_error;
7967c478bd9Sstevel@tonic-gate }
7977c478bd9Sstevel@tonic-gate
7987c478bd9Sstevel@tonic-gate if (pv_name != NULL)
7997c478bd9Sstevel@tonic-gate pool_value_free(pv_name);
8007c478bd9Sstevel@tonic-gate if (pv_sys_id != NULL)
8017c478bd9Sstevel@tonic-gate pool_value_free(pv_sys_id);
8027c478bd9Sstevel@tonic-gate if (pvals[0] != NULL)
8037c478bd9Sstevel@tonic-gate pool_value_free(pvals[0]);
8047c478bd9Sstevel@tonic-gate
8057c478bd9Sstevel@tonic-gate return (resources);
8067c478bd9Sstevel@tonic-gate on_error:
8077c478bd9Sstevel@tonic-gate die(gettext(ERR_STATS_RES), get_errstr());
8087c478bd9Sstevel@tonic-gate /*NOTREACHED*/
8097c478bd9Sstevel@tonic-gate }
8107c478bd9Sstevel@tonic-gate
8117c478bd9Sstevel@tonic-gate /*
8127c478bd9Sstevel@tonic-gate * Print statistics for all resources of type 'rtype' passed in 'resources'.
8137c478bd9Sstevel@tonic-gate */
8147c478bd9Sstevel@tonic-gate static void
prt_resource_stats_by_type(pool_resource_t ** resources,const char * rtype)8157c478bd9Sstevel@tonic-gate prt_resource_stats_by_type(pool_resource_t **resources, const char *rtype)
8167c478bd9Sstevel@tonic-gate {
8177c478bd9Sstevel@tonic-gate int i;
8187c478bd9Sstevel@tonic-gate pool_elem_t *elem;
8197c478bd9Sstevel@tonic-gate pool_value_t *pv_name;
8207c478bd9Sstevel@tonic-gate char *name_prop;
8217c478bd9Sstevel@tonic-gate
8227c478bd9Sstevel@tonic-gate poolstat_line_format_t *lf;
8237c478bd9Sstevel@tonic-gate statistic_bag_t *sbag;
8247c478bd9Sstevel@tonic-gate
8257c478bd9Sstevel@tonic-gate if (strcmp(rtype, PSET_TYPE_NAME) == 0) {
8267c478bd9Sstevel@tonic-gate name_prop = PSET_NAME;
8277c478bd9Sstevel@tonic-gate lf = &pset_lf;
8287c478bd9Sstevel@tonic-gate sbag = pset_sbag;
8297c478bd9Sstevel@tonic-gate } else {
8307c478bd9Sstevel@tonic-gate die(gettext(ERR_UNSUPP_RTYPE), rtype);
8317c478bd9Sstevel@tonic-gate }
8327c478bd9Sstevel@tonic-gate
8337c478bd9Sstevel@tonic-gate if ((pv_name = create_pool_value(name_prop)) == NULL)
8347c478bd9Sstevel@tonic-gate goto on_error;
8357c478bd9Sstevel@tonic-gate
8367c478bd9Sstevel@tonic-gate /* collect and print statistics for the given resources */
8377c478bd9Sstevel@tonic-gate for (i = 0; resources[i] != NULL; i++) {
8387c478bd9Sstevel@tonic-gate if ((elem = pool_resource_to_elem(conf, resources[i])) == NULL)
8397c478bd9Sstevel@tonic-gate goto on_error;
8407c478bd9Sstevel@tonic-gate if (pool_get_property(conf, elem, name_prop, pv_name) == -1)
8417c478bd9Sstevel@tonic-gate goto on_error;
8427c478bd9Sstevel@tonic-gate if (pool_value_get_string(pv_name, &sbag->sb_name) == -1)
8437c478bd9Sstevel@tonic-gate goto on_error;
8447c478bd9Sstevel@tonic-gate sa_update(sbag, 0);
8457c478bd9Sstevel@tonic-gate
8467c478bd9Sstevel@tonic-gate prt_stat_line(lf);
8477c478bd9Sstevel@tonic-gate }
8487c478bd9Sstevel@tonic-gate
8497c478bd9Sstevel@tonic-gate if (pv_name != NULL)
8507c478bd9Sstevel@tonic-gate pool_value_free(pv_name);
8517c478bd9Sstevel@tonic-gate return;
8527c478bd9Sstevel@tonic-gate on_error:
8537c478bd9Sstevel@tonic-gate die(gettext(ERR_STATS_RES), get_errstr());
8547c478bd9Sstevel@tonic-gate }
8557c478bd9Sstevel@tonic-gate
8567c478bd9Sstevel@tonic-gate /*
8577c478bd9Sstevel@tonic-gate * Update statistics for all resources of type 'rtype' pased in 'resources'.
8587c478bd9Sstevel@tonic-gate */
8597c478bd9Sstevel@tonic-gate static void
update_resource_stats(pool_resource_t * resource,const char * rtype)8607c478bd9Sstevel@tonic-gate update_resource_stats(pool_resource_t *resource, const char *rtype)
8617c478bd9Sstevel@tonic-gate {
8627c478bd9Sstevel@tonic-gate pool_elem_t *elem;
8637c478bd9Sstevel@tonic-gate pool_value_t *pv_name;
8647c478bd9Sstevel@tonic-gate char *name_prop; /* set name property */
8657c478bd9Sstevel@tonic-gate
8667c478bd9Sstevel@tonic-gate statistic_bag_t *sbag;
8677c478bd9Sstevel@tonic-gate
8687c478bd9Sstevel@tonic-gate if (strcmp(rtype, PSET_TYPE_NAME) == 0) {
8697c478bd9Sstevel@tonic-gate name_prop = PSET_NAME;
8707c478bd9Sstevel@tonic-gate sbag = pset_sbag;
8717c478bd9Sstevel@tonic-gate } else {
8727c478bd9Sstevel@tonic-gate die(gettext(ERR_UNSUPP_RTYPE), rtype);
8737c478bd9Sstevel@tonic-gate }
8747c478bd9Sstevel@tonic-gate
8757c478bd9Sstevel@tonic-gate if ((pv_name = create_pool_value(name_prop)) == NULL)
8767c478bd9Sstevel@tonic-gate goto on_error;
8777c478bd9Sstevel@tonic-gate
8787c478bd9Sstevel@tonic-gate if ((elem = pool_resource_to_elem(conf, resource)) == NULL)
8797c478bd9Sstevel@tonic-gate goto on_error;
8807c478bd9Sstevel@tonic-gate if (pool_get_property(conf, elem, name_prop, pv_name) == -1)
8817c478bd9Sstevel@tonic-gate goto on_error;
8827c478bd9Sstevel@tonic-gate if (pool_value_get_string(pv_name, &sbag->sb_name) == -1)
8837c478bd9Sstevel@tonic-gate goto on_error;
8847c478bd9Sstevel@tonic-gate sa_update(sbag, 0);
8857c478bd9Sstevel@tonic-gate
8867c478bd9Sstevel@tonic-gate if (pv_name != NULL)
8877c478bd9Sstevel@tonic-gate pool_value_free(pv_name);
8887c478bd9Sstevel@tonic-gate return;
8897c478bd9Sstevel@tonic-gate
8907c478bd9Sstevel@tonic-gate on_error:
8917c478bd9Sstevel@tonic-gate die(gettext(ERR_STATS_RES), get_errstr());
8927c478bd9Sstevel@tonic-gate }
8937c478bd9Sstevel@tonic-gate
8947c478bd9Sstevel@tonic-gate /*
8957c478bd9Sstevel@tonic-gate * For each pool in the configuration print statistics of associated resources.
8967c478bd9Sstevel@tonic-gate * If the pool name list 'pn' is defined, only print resources of pools
8977c478bd9Sstevel@tonic-gate * specified in the list. The list can specify the pool name or its system id.
8987c478bd9Sstevel@tonic-gate */
8997c478bd9Sstevel@tonic-gate static void
prt_pool_stats(poolstat_list_element_t * pn)9007c478bd9Sstevel@tonic-gate prt_pool_stats(poolstat_list_element_t *pn)
9017c478bd9Sstevel@tonic-gate {
9027c478bd9Sstevel@tonic-gate uint_t nelem;
9037c478bd9Sstevel@tonic-gate pool_elem_t *elem;
9047c478bd9Sstevel@tonic-gate int i;
9057c478bd9Sstevel@tonic-gate int error;
9067c478bd9Sstevel@tonic-gate pool_t **pools = NULL;
9077c478bd9Sstevel@tonic-gate pool_value_t *pvals[] = { NULL, NULL };
9087c478bd9Sstevel@tonic-gate pool_value_t *pv_name = NULL;
9097c478bd9Sstevel@tonic-gate pool_value_t *pv_sys_id = NULL;
9107c478bd9Sstevel@tonic-gate statistic_bag_t *sbag = pool_sbag;
9117c478bd9Sstevel@tonic-gate poolstat_list_element_t *rtype;
9127c478bd9Sstevel@tonic-gate pool_resource_t **resources;
9137c478bd9Sstevel@tonic-gate
9147c478bd9Sstevel@tonic-gate if ((pv_sys_id = create_pool_value(POOL_SYSID)) == NULL)
9157c478bd9Sstevel@tonic-gate goto on_error;
9167c478bd9Sstevel@tonic-gate if ((pv_name = create_pool_value(POOL_NAME)) == NULL)
9177c478bd9Sstevel@tonic-gate goto on_error;
9187c478bd9Sstevel@tonic-gate
9197c478bd9Sstevel@tonic-gate if (pn == NULL) {
9207c478bd9Sstevel@tonic-gate /* collect all pools */
9217c478bd9Sstevel@tonic-gate if ((pools = pool_query_pools(conf, &nelem, NULL)) == NULL)
9227c478bd9Sstevel@tonic-gate goto on_error;
9237c478bd9Sstevel@tonic-gate } else {
9247c478bd9Sstevel@tonic-gate /*
9257c478bd9Sstevel@tonic-gate * collect pools specified in the 'pn' list.
9267c478bd9Sstevel@tonic-gate * 'poolid' the pool identifier can be a pool name or sys_id.
9277c478bd9Sstevel@tonic-gate */
9287c478bd9Sstevel@tonic-gate poolstat_list_element_t *poolid;
9297c478bd9Sstevel@tonic-gate for (poolid = pn, i = 1; poolid; poolid = poolid->ple_next)
9307c478bd9Sstevel@tonic-gate i++;
9317c478bd9Sstevel@tonic-gate pools = ZALLOC(sizeof (pool_t *) * (i + 1));
9327c478bd9Sstevel@tonic-gate for (poolid = pn, i = 0; poolid;
9337c478bd9Sstevel@tonic-gate poolid = poolid->ple_next, i++) {
9347c478bd9Sstevel@tonic-gate pool_t **pool;
9357c478bd9Sstevel@tonic-gate int64_t sysid = Atoi(poolid->ple_obj, &error);
9367c478bd9Sstevel@tonic-gate if (error == 0) {
9377c478bd9Sstevel@tonic-gate /* the pool is identified by sys_id */
9387c478bd9Sstevel@tonic-gate pool_value_set_int64(pv_sys_id, sysid);
9397c478bd9Sstevel@tonic-gate pvals[0] = pv_sys_id;
9407c478bd9Sstevel@tonic-gate pool = pool_query_pools(conf, &nelem, pvals);
9417c478bd9Sstevel@tonic-gate } else {
9427c478bd9Sstevel@tonic-gate if (pool_value_set_string(pv_name,
9437c478bd9Sstevel@tonic-gate poolid->ple_obj) == -1)
9447c478bd9Sstevel@tonic-gate die(gettext(ERR_NOMEM));
9457c478bd9Sstevel@tonic-gate pvals[0] = pv_name;
9467c478bd9Sstevel@tonic-gate pool = pool_query_pools(conf, &nelem, pvals);
9477c478bd9Sstevel@tonic-gate }
9487c478bd9Sstevel@tonic-gate if (pool == NULL)
9497c478bd9Sstevel@tonic-gate die(gettext(ERR_STATS_POOL_N), poolid->ple_obj);
9507c478bd9Sstevel@tonic-gate pools[i] = pool[0];
9517c478bd9Sstevel@tonic-gate FREE(pool);
9527c478bd9Sstevel@tonic-gate }
9537c478bd9Sstevel@tonic-gate }
9547c478bd9Sstevel@tonic-gate
9557c478bd9Sstevel@tonic-gate /* print statistic for all pools found */
9567c478bd9Sstevel@tonic-gate if (!rflag) {
9577c478bd9Sstevel@tonic-gate /* print the common resource header */
9587c478bd9Sstevel@tonic-gate prt_stat_hd(POOL_TYPE_NAME);
9597c478bd9Sstevel@tonic-gate
9607c478bd9Sstevel@tonic-gate /* print statistics for the resources bound to the pools */
9617c478bd9Sstevel@tonic-gate for (i = 0; pools[i] != NULL; i++) {
9627c478bd9Sstevel@tonic-gate elem = pool_to_elem(conf, pools[i]);
9637c478bd9Sstevel@tonic-gate if (pool_get_property(conf, elem, POOL_NAME, pv_name)
9647c478bd9Sstevel@tonic-gate == -1)
9657c478bd9Sstevel@tonic-gate goto on_error;
9667c478bd9Sstevel@tonic-gate if (pool_value_get_string(pv_name, &sbag->sb_name) != 0)
9677c478bd9Sstevel@tonic-gate goto on_error;
9687c478bd9Sstevel@tonic-gate if (pool_get_property(
9697c478bd9Sstevel@tonic-gate conf, elem, "pool.sys_id", pv_sys_id) == -1)
9707c478bd9Sstevel@tonic-gate goto on_error;
9717c478bd9Sstevel@tonic-gate if (pool_value_get_int64(
9727c478bd9Sstevel@tonic-gate pv_sys_id, &sbag->sb_sysid) != 0)
9737c478bd9Sstevel@tonic-gate goto on_error;
9747c478bd9Sstevel@tonic-gate
9757c478bd9Sstevel@tonic-gate for (rtype = rtypes; rtype; rtype = rtype->ple_next) {
9767c478bd9Sstevel@tonic-gate resources = get_resources(
9777c478bd9Sstevel@tonic-gate sbag->sb_name, rtype->ple_obj, &nelem);
9787c478bd9Sstevel@tonic-gate update_resource_stats(*resources,
9797c478bd9Sstevel@tonic-gate rtype->ple_obj);
9807c478bd9Sstevel@tonic-gate FREE(resources);
9817c478bd9Sstevel@tonic-gate }
9827c478bd9Sstevel@tonic-gate prt_stat_line(&pool_lf);
9837c478bd9Sstevel@tonic-gate }
9847c478bd9Sstevel@tonic-gate } else {
9857c478bd9Sstevel@tonic-gate /* print statistic for all resource types defined in rtypes */
9867c478bd9Sstevel@tonic-gate for (rtype = rtypes; rtype; rtype = rtype->ple_next) {
9877c478bd9Sstevel@tonic-gate prt_stat_hd(rtype->ple_obj);
9887c478bd9Sstevel@tonic-gate for (i = 0; pools[i] != NULL; i++) {
9897c478bd9Sstevel@tonic-gate elem = pool_to_elem(conf, pools[i]);
9907c478bd9Sstevel@tonic-gate if (pool_get_property(
9917c478bd9Sstevel@tonic-gate conf, elem, POOL_NAME, pv_name) == -1)
9927c478bd9Sstevel@tonic-gate goto on_error;
9937c478bd9Sstevel@tonic-gate if (pool_value_get_string(
9947c478bd9Sstevel@tonic-gate pv_name, &sbag->sb_name) != 0)
9957c478bd9Sstevel@tonic-gate goto on_error;
9967c478bd9Sstevel@tonic-gate if (pool_get_property(
997f5cd957fSRobert Harris conf, elem, POOL_SYSID, pv_sys_id) == -1)
9987c478bd9Sstevel@tonic-gate goto on_error;
9997c478bd9Sstevel@tonic-gate if (pool_value_get_int64(
10007c478bd9Sstevel@tonic-gate pv_sys_id, &sbag->sb_sysid) != 0)
10017c478bd9Sstevel@tonic-gate goto on_error;
10027c478bd9Sstevel@tonic-gate resources = get_resources(
10037c478bd9Sstevel@tonic-gate sbag->sb_name, rtype->ple_obj, &nelem);
10047c478bd9Sstevel@tonic-gate if (resources == NULL)
10057c478bd9Sstevel@tonic-gate continue;
10067c478bd9Sstevel@tonic-gate update_resource_stats(
10077c478bd9Sstevel@tonic-gate *resources, rtype->ple_obj);
10087c478bd9Sstevel@tonic-gate prt_resource_stats_by_type(resources,
10097c478bd9Sstevel@tonic-gate rtype->ple_obj);
10107c478bd9Sstevel@tonic-gate FREE(resources);
10117c478bd9Sstevel@tonic-gate }
10127c478bd9Sstevel@tonic-gate }
10137c478bd9Sstevel@tonic-gate }
10147c478bd9Sstevel@tonic-gate
10157c478bd9Sstevel@tonic-gate FREE(pools);
10167c478bd9Sstevel@tonic-gate if (pv_name != NULL)
10177c478bd9Sstevel@tonic-gate pool_value_free(pv_name);
10187c478bd9Sstevel@tonic-gate if (pv_sys_id != NULL)
10197c478bd9Sstevel@tonic-gate pool_value_free(pv_sys_id);
10207c478bd9Sstevel@tonic-gate
10217c478bd9Sstevel@tonic-gate return;
10227c478bd9Sstevel@tonic-gate on_error:
10237c478bd9Sstevel@tonic-gate die(gettext(ERR_STATS_POOL), get_errstr());
10247c478bd9Sstevel@tonic-gate }
1025