fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The contents of this file are subject to the terms of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Common Development and Distribution License (the "License").
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You may not use this file except in compliance with the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or http://www.opensolaris.org/os/licensing.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If applicable, add the following below this CDDL HEADER, with the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stdio.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stdlib.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <string.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <unistd.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <errno.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <inttypes.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <kstat.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/nsctl/nsctl.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/nsctl/sd_bcache.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "sdbc_stats.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "dsstat.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "common.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "report.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic sdbcstat_t *sdbc_top;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortekstat_t *sdbc_global = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid sdbc_header();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint sdbc_value_check(sdbcstat_t *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint sdbc_validate(kstat_t *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteuint32_t sdbc_getdelta(sdbcstat_t *, char *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid sdbc_addstat(sdbcstat_t *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesdbcstat_t *sdbc_delstat(sdbcstat_t *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid center(int, char *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbc_discover() - looks for new statistics to be monitored.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Verifies that any statistics found are now already being
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * monitored.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesdbc_discover(kstat_ctl_t *kc)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte static int validated = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_t *ksp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ksp = kc->kc_chain; ksp; ksp = ksp->ks_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int kinst;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char kname[KSTAT_STRLEN + 1];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbcstat_t *cur;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbcstat_t *sdbcstat = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_t *io_ksp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strcmp(ksp->ks_module, SDBC_KSTAT_MODULE) != 0 ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strncmp(ksp->ks_name, SDBC_KSTAT_CDSTATS, 2) != 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (kstat_read(kc, ksp, NULL) == -1)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Validate kstat structure
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (! validated) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_validate(ksp))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte validated++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Duplicate check
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (cur = sdbc_top; cur; cur = cur->next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *cur_vname, *tst_vname;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur_vname = kstat_value(cur->pre_set,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDBC_CDKSTAT_VOL_NAME);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tst_vname = kstat_value(ksp,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDBC_CDKSTAT_VOL_NAME);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strncmp(cur_vname, tst_vname, NAMED_LEN) == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Initialize new record
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbcstat = (sdbcstat_t *)calloc(1, sizeof (sdbcstat_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kinst = ksp->ks_instance;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Set kstat
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbcstat->pre_set = kstat_retrieve(kc, ksp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbcstat->pre_set == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbcstat->collected |= GOT_SET_KSTAT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * I/O kstat
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) sprintf(kname, "%s%d", SDBC_IOKSTAT_CDSTATS, kinst);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte io_ksp = kstat_lookup(kc, SDBC_KSTAT_MODULE, kinst, kname);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbcstat->pre_io = kstat_retrieve(kc, io_ksp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbcstat->pre_io == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbcstat->collected |= GOT_IO_KSTAT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortenext:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Check if we got a complete set of stats
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbcstat == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (SDBC_COMPLETE(sdbcstat->collected)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sdbc_delstat(sdbcstat);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_addstat(sdbcstat);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_top == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EAGAIN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbc_update() - updates all of the statistics currently being monitored.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesdbc_update(kstat_ctl_t *kc)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_t *ksp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbcstat_t *cur;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Update global kstat information */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ksp = kstat_lookup(kc, SDBC_KSTAT_MODULE, -1, SDBC_KSTAT_GSTATS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ksp == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EAGAIN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_global)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_free(sdbc_global);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_global = kstat_retrieve(kc, ksp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (cur = sdbc_top; cur != NULL; cur = cur->next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int kinst;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *kname, *cname, *pname;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_t *set_ksp, *io_ksp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur->collected = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Age off old stats
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cur->cur_set != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_free(cur->pre_set);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_free(cur->pre_io);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur->pre_set = cur->cur_set;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur->pre_io = cur->cur_io;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Update set kstat
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kinst = cur->pre_set->ks_instance;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kname = cur->pre_set->ks_name;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte set_ksp = kstat_lookup(kc, SDBC_KSTAT_MODULE, kinst, kname);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((cur->cur_set = kstat_retrieve(kc, set_ksp)) == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur->collected |= GOT_SET_KSTAT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Validate set
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pname = kstat_value(cur->pre_set, SDBC_CDKSTAT_VOL_NAME);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cname = kstat_value(cur->cur_set, SDBC_CDKSTAT_VOL_NAME);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strncmp(pname, cname, NAMED_LEN) != 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Update I/O kstat
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kinst = cur->pre_io->ks_instance;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kname = cur->pre_io->ks_name;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte io_ksp = kstat_lookup(kc, SDBC_KSTAT_MODULE, kinst, kname);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((cur->cur_io = kstat_retrieve(kc, io_ksp)) == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur->collected |= GOT_IO_KSTAT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbc_report() - outputs statistics for the statistics currently being
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * monitored. Deletes statistics for volumes that have been disabled.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesdbc_report()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vslist_t *vslist = vs_top;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbcstat_t *cur, *pre = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_top == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (cur = sdbc_top; cur != NULL; ) { /* CSTYLED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte static uint32_t linesout = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t *offline;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char volname[NAMED_LEN + 1];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char rmode[STAT_HDR_SIZE];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char wmode[STAT_HDR_SIZE];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Parse volume name */
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) strncpy(volname, kstat_value(cur->pre_set,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDBC_CDKSTAT_VOL_NAME), NAMED_LEN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte volname[NAMED_LEN] = '\0';
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check to see if the user specified this volume */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (vslist = vs_top; vslist != NULL; vslist = vslist->next)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strcmp(volname, vslist->volname) == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (vs_top != NULL && vslist == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check if volume is offline and zflag applies */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (zflag && sdbc_value_check(cur) == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Output volume name */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_header();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(DATA_C16, volname);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (SDBC_COMPLETE(cur->collected)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbcstat_t *next = sdbc_delstat(cur);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (! pre)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur = sdbc_top = next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur = pre->next = next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(" <<volume disabled>>\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte offline = kstat_value(cur->cur_set, SDBC_CDKSTAT_FAILED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*offline) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(" <<volume offline>>\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte linesout++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Type/status flags */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dflags & FLAGS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t *dhint, *nhint;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t hints;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dhint = kstat_value(cur->cur_set, SDBC_CDKSTAT_CDHINTS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nhint = kstat_value(sdbc_global, SDBC_GKSTAT_NODEHINTS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (! nhint)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hints = *nhint;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hints &= (NSC_FORCED_WRTHRU | NSC_NO_FORCED_WRTHRU |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_NOCACHE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hints |= *dhint;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (hints & NSC_NOCACHE)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcpy(rmode, "D");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcpy(rmode, "C");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((hints & NSC_FORCED_WRTHRU) || (hints & NSC_WRTHRU))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcpy(wmode, "D");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcpy(wmode, "C");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(DATA_C2, rmode);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(DATA_C2, wmode);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Output set information */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cd_report(cur);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortenext:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pre = cur;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur = cur->next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbc_header() - outputs an appropriate header by referencing the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * global variables dflsgs
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesdbc_header()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rcount = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (hflags == HEADERS_EXL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((linesout % DISPLAY_LINES) != 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (hflags == HEADERS_BOR)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (linesout != 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (hflags & HEADERS_ATT)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (hflags & HEADERS_OUT)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hflags |= HEADERS_OUT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (linesout)
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) printf("\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* first line header */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (! (dflags & SUMMARY) && dflags != FLAGS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(VOL_HDR_FMT, " ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dflags & FLAGS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(STAT_HDR_FMT, " ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(STAT_HDR_FMT, " ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dflags & READ) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte size = KPS_HDR_SIZE * 2 + HIT_HDR_SIZE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte center(size, "- read -");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rcount++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dflags & WRITE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte size = KPS_HDR_SIZE * 2 + HIT_HDR_SIZE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte center(size, "- write -");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rcount++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dflags != FLAGS)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf("\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* second line header */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(VOL_HDR_FMT, "volume");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dflags & FLAGS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(STAT_HDR_FMT, "rd");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(STAT_HDR_FMT, "wr");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dflags & SUMMARY) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(KPS_HDR_FMT, "ckps");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(KPS_HDR_FMT, "dkps");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(HIT_HDR_FMT, HIT_HDR_TXT);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dflags & READ) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(KPS_HDR_FMT, "ckps");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(KPS_HDR_FMT, "dkps");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(HIT_HDR_FMT, RHIT_HDR_TXT);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dflags & WRITE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(KPS_HDR_FMT, "ckps");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(KPS_HDR_FMT, "dkps");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(HIT_HDR_FMT, WHIT_HDR_TXT);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dflags & DESTAGED)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(KPS_HDR_FMT, "dstg");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dflags & WRCANCEL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(KPS_HDR_FMT, "cwrl");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteout:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf("\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbc_getstat() - find cache stat by name matching
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * paraemters
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * char *vn - the volume name to match against
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * returns
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbcstat_t * - the matching strcture, NULL if not found
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesdbcstat_t *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesdbc_getstat(char *vn)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbcstat_t *cur, *pre = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (cur = sdbc_top; cur; ) { /* CSTYLED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *volname =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_value(cur->pre_set, SDBC_CDKSTAT_VOL_NAME);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (SDBC_COMPLETE(cur->collected)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbcstat_t *next = sdbc_delstat(cur);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (! pre)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur = sdbc_top = next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur = pre->next = next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strncmp(volname, vn, NAMED_LEN) == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (cur);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pre = cur;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur = cur->next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbc_addstat() - adds a fully populated sdbcstat_t structure
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to the linked list of currently monitored kstats. The structure
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * will be added in alphabetical order, using the volume name as the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * key.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * parameters
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbcstat_t *sdbcstat - to be added to the list.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesdbc_addstat(sdbcstat_t *sdbcstat)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbcstat_t *cur;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_top == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_top = sdbcstat;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (cur = sdbc_top; cur != NULL; cur = cur->next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *cur_vname, *nxt_vname, *tst_vname;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur_vname = kstat_value(cur->pre_set,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDBC_CDKSTAT_VOL_NAME);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tst_vname = kstat_value(sdbcstat->pre_set,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDBC_CDKSTAT_VOL_NAME);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strncmp(cur_vname, tst_vname, NAMED_LEN) > 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cur == sdbc_top)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbc_top = sdbcstat;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbcstat->next = cur;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If we get to the last item in the list, then just
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * add this one to the end
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cur->next == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur->next = sdbcstat;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nxt_vname = kstat_value(cur->next->pre_set,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SDBC_CDKSTAT_VOL_NAME);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strncmp(nxt_vname, tst_vname, NAMED_LEN) > 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbcstat->next = cur->next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur->next = sdbcstat;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbc_delstat() - deallocate memory for the structure being
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * passed in.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * parameters
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbcstat_t *sdbcstat - structure to be deallocated
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * returns
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbcstat_t * - pointer to the "next" structures in the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * linked list. May be NULL if we are removing the last
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * structure in the linked list.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesdbcstat_t *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesdbc_delstat(sdbcstat_t *sdbcstat)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbcstat_t *next = sdbcstat->next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_free(sdbcstat->pre_set);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_free(sdbcstat->pre_io);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_free(sdbcstat->cur_set);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_free(sdbcstat->cur_io);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(sdbcstat);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbcstat = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (next);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbc_value_check() - Checks for activity, supports -z switch
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * parameters
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbcstat_t *sdbcstat - structure to be checked
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * returns
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 1 - activity
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 - no activity
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesdbc_value_check(sdbcstat_t *sdbcstat)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (SDBC_COMPLETE(sdbcstat->collected))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_getdelta(sdbcstat, SDBC_CDKSTAT_CACHE_READ) != 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_getdelta(sdbcstat, SDBC_CDKSTAT_DISK_READ) != 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_getdelta(sdbcstat, SDBC_CDKSTAT_CACHE_WRITE) != 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_getdelta(sdbcstat, SDBC_CDKSTAT_DISK_WRITE) != 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbc_getdelta(sdbcstat, SDBC_CDKSTAT_WRCANCELNS) != 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (io_value_check(sdbcstat->pre_io->ks_data,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sdbcstat->cur_io->ks_data) != 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbc_validate() - validates the structure of the kstats by attempting to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * lookup fields used by this module
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * parameters
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * kstat_t *ksp - kstat to be examined
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * returns
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 1 - one or more fields missing
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 - all fields present
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesdbc_validate(kstat_t *ksp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (! kstat_value(ksp, SDBC_CDKSTAT_VOL_NAME) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ! kstat_value(ksp, SDBC_CDKSTAT_FAILED) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ! kstat_value(ksp, SDBC_CDKSTAT_CDHINTS) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ! kstat_value(ksp, SDBC_CDKSTAT_CACHE_READ) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ! kstat_value(ksp, SDBC_CDKSTAT_DISK_READ) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ! kstat_value(ksp, SDBC_CDKSTAT_CACHE_WRITE) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ! kstat_value(ksp, SDBC_CDKSTAT_DISK_WRITE) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ! kstat_value(ksp, SDBC_CDKSTAT_DESTAGED) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ! kstat_value(ksp, SDBC_CDKSTAT_WRCANCELNS))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbc_getvalues() - populates a values structure with data obtained from the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * kstat
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * parameters
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbcstat_t *sdbcstat - pointer to the structure containing the kstats
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbcvals_t *vals - pointer to the structure that will receive the values
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * int flags - flags that describe adjustments made to the values
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * returns
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 1 - failure
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 - success
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesdbc_getvalues(sdbcstat_t *sdbcstat, sdbcvals_t *vals, int flags)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int divisor = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int factors;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint64_t hr_etime;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte double etime;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_io_t *cur;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kstat_io_t *pre;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sdbcstat == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur = sdbcstat->cur_io->ks_data;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pre = sdbcstat->pre_io->ks_data;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hr_etime = hrtime_delta(pre->rlastupdate, cur->rlastupdate);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte etime = hr_etime / (double)NANOSEC;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* read data */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vals->cache_read =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte FBA_SIZE(sdbc_getdelta(sdbcstat, SDBC_CDKSTAT_CACHE_READ));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vals->disk_read =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte FBA_SIZE(sdbc_getdelta(sdbcstat, SDBC_CDKSTAT_DISK_READ));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vals->total_reads = vals->cache_read + vals->disk_read;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (vals->cache_read == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vals->read_hit = 0.0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vals->read_hit =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((float)vals->cache_read / vals->total_reads) * 100.0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* write data */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vals->cache_write =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte FBA_SIZE(sdbc_getdelta(sdbcstat, SDBC_CDKSTAT_CACHE_WRITE));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vals->disk_write =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte FBA_SIZE(sdbc_getdelta(sdbcstat, SDBC_CDKSTAT_DISK_WRITE));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vals->total_writes = vals->cache_write + vals->disk_write;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vals->destaged =
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki FBA_SIZE(sdbc_getdelta(sdbcstat, SDBC_CDKSTAT_DESTAGED));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (vals->cache_write == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vals->write_hit = 0.0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vals->write_hit = ((float)vals->cache_write /
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (vals->total_writes - vals->destaged)) * 100.0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* miscellaneous */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vals->write_cancellations =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte FBA_SIZE(sdbc_getdelta(sdbcstat, SDBC_CDKSTAT_WRCANCELNS));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vals->total_cache = vals->cache_read + vals->cache_write;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vals->total_disk = vals->disk_read + vals->disk_write;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* total cache hit calculation */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vals->cache_hit = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte factors = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (vals->cache_read != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vals->cache_hit += vals->read_hit;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte factors++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (vals->cache_write != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vals->cache_hit += vals->write_hit;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte factors++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (vals->cache_hit)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vals->cache_hit /= (float)factors;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* adjustments */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte divisor = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (flags & SDBC_KBYTES)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte divisor *= KILOBYTE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((flags & SDBC_INTAVG) && (etime > 0))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte divisor *= etime;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (divisor != 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vals->cache_read /= divisor;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vals->disk_read /= divisor;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vals->total_reads /= divisor;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vals->cache_write /= divisor;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vals->disk_write /= divisor;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vals->total_writes /= divisor;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vals->total_cache /= divisor;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vals->total_disk /= divisor;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vals->destaged /= divisor;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vals->write_cancellations /= divisor;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbc_getdelta() - calculates the difference between two kstat fields
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * parameters
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sdbcstat_t *sdbcstat - the SDBC stat strcture containing the two fields
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * char *name - the name of the fields
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * returns
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * uint32_t value of the differences adjusted for overflow of the data type
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteuint32_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesdbc_getdelta(sdbcstat_t *sdbcstat, char *name)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t *cur_val;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t *pre_val;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pre_val = kstat_value(sdbcstat->pre_set, name);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur_val = kstat_value(sdbcstat->cur_set, name);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (u32_delta(*pre_val, *cur_val));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecenter(int size, char *hdr)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int lpad = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rpad = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char fmt[10];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (size == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strlen(hdr) < size) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lpad = (size - strlen(hdr)) / 2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (lpad * 2 < size)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lpad++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rpad = size - (lpad + strlen(hdr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteoutput:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sprintf(fmt, "%%%ds%%s%%%ds", lpad, rpad);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(fmt, " ", hdr, " ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}