sndr_stats.c revision e31df31051ab05e561eab5b23bb1c00627a10d64
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
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 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
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 * CDDL HEADER END
e31df31051ab05e561eab5b23bb1c00627a10d64Thomas Atkins * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint sndr_strcmp(char *, char *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void update_sighandler(int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void discover_sighandler(int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sndr_discover() - looks for new statistics to be monitored.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Verifies that any statistics found are now already being
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * monitored.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte static int validated = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Loop on all kstats */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ksp = kc->kc_chain; ksp; ksp = ksp->ks_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Serach for SNDR set */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strcmp(ksp->ks_module, RDC_KSTAT_MODULE) != 0 ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Validate kstat structure
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Duplicate check
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (cur = sndr_top; cur != NULL; cur = cur->next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur_vname = kstat_value(cur->pre_set, RDC_IKSTAT_FILE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Initialize new record
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sndrstat = (sndrstat_t *)calloc(1, sizeof (sndrstat_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Bitmap kstat
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sprintf(kname, "%s%d", RDC_KSTAT_BMPNAME, kinst);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bmp_ksp = kstat_lookup(kc, RDC_KSTAT_BMPNAME, kinst, kname);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Secondary kstat
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sprintf(kname, "%s%d", RDC_KSTAT_RDCNAME, kinst);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sec_ksp = kstat_lookup(kc, RDC_KSTAT_MODULE, kinst, kname);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Check if we got a complete set of stats
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Add to linked list
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sndr_update() - updates all of the statistics currently being monitored.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (cur = sndr_top; cur != NULL; cur = cur->next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Age off old stats
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strncpy(kname, cur->pre_set->ks_name, KSTAT_STRLEN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ksp = kstat_lookup(kc, RDC_KSTAT_MODULE, kinst, kname);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((cur->cur_set = kstat_retrieve(kc, ksp)) == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Validate set
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur_vname = kstat_value(cur->pre_set, RDC_IKSTAT_FILE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tst_vname = kstat_value(cur->cur_set, RDC_IKSTAT_FILE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Bitmap kstat
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sprintf(kname, "%s%d", RDC_KSTAT_BMPNAME, kinst);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ksp = kstat_lookup(kc, RDC_KSTAT_BMPNAME, kinst, kname);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((cur->cur_bmp = kstat_retrieve(kc, ksp)) == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Secondary kstat
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sprintf(kname, "%s%d", RDC_KSTAT_RDCNAME, kinst);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ksp = kstat_lookup(kc, RDC_KSTAT_MODULE, kinst, kname);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((cur->cur_sec = kstat_retrieve(kc, ksp)) == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sndr_report() - outputs statistics for the statistics currently being
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * monitored. Deletes statistics for volumes that have been disabled.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Create padding string for secondary report lines */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (cur = sndr_top; cur != NULL; ) { /*CSTYLED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check to see if this is this a complete */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* notify user of set being disabled */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte c = kstat_value(cur->pre_set, RDC_IKSTAT_SECFILE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* free memory and remove stat from list */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check to see if the user specified this volume */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check to see if zflag applies */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Calculate flags */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Async. queue statistics */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Calculate sync needed percentages */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sprintf(snpct, DATA_F62, getSyncNeeded(cur->cur_set));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Output */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Only print last 15 characters */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Async. queue statistics */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte c = kstat_value(cur->pre_set, RDC_IKSTAT_BITMAP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Only print last 15 characters */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Async. queue statistics */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sndr_add_stat() - adds a fully populated sndrstat_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 * parameters
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sndrstat_t *sndrstat - to be added to the list.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (cur = sndr_top; cur != NULL; cur = cur->next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cur_vname = kstat_value(cur->pre_set, RDC_IKSTAT_FILE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tst_vname = kstat_value(sndrstat->pre_set, RDC_IKSTAT_FILE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If we get to the last item in the list, then just
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * add this one to the end
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sndr_del_stat() - deallocate memory for the structure being
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * passed in.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * parameters
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sndrstat_t *sndrstat - structure to be deallocated
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sndrstat_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 * sndr_value_check() - check to determine if any activity was registered
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * on this volume by checking the previous stats vs. the current stats.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * parameters
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sndrstat_t *sndrstat - structure to be checked
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 - no activity
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 1 - activity
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sndr_validate() - validates the fields required by dsstat exist in
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the kstat_t structure passed in. This check keeps dsstat from
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * core dumping if the kstat_named_t structures change in any of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * services that dsstat monitors.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * paramaters
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * kstat_t *ksp - kstat_t structure to check. The ks_data field
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * should have been populated with a call to kstat_read()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 0 - all fields are contained in the kstat
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 1 - a field required by dsstat is not in the kstat
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syn_flags = kstat_value(ksp, RDC_IKSTAT_SYNCFLAGS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bmp_flags = kstat_value(ksp, RDC_IKSTAT_BMPFLAGS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Special handling for compatibility.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * "dsstat -s <set>" allows set name to be the last 15 chars,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * due to 15 characters limit of old kstat information.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return 0 if:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 1) full and partial are same
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 2) partial is the last 15 chars of full
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc != 0 &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (vslist = vs_top; vslist != NULL; vslist = vslist->next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* If no host specified, check local only */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check primary */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check secondary */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vh = kstat_value(ksp, RDC_IKSTAT_SECONDARY_HOST);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Filler for async. queue fields */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte val = (uint32_t *)kstat_value(cur_set, RDC_IKSTAT_ASYNC_ITEMS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte val = (uint32_t *)kstat_value(cur_set, RDC_IKSTAT_ASYNC_BLOCKS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte val = (uint32_t *)kstat_value(cur_set, RDC_IKSTAT_ASYNC_ITEM_HWM);