10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 70Sstevel@tonic-gate * with the License. 80Sstevel@tonic-gate * 90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 110Sstevel@tonic-gate * See the License for the specific language governing permissions 120Sstevel@tonic-gate * and limitations under the License. 130Sstevel@tonic-gate * 140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 190Sstevel@tonic-gate * 200Sstevel@tonic-gate * CDDL HEADER END 210Sstevel@tonic-gate */ 22*1193Smws 230Sstevel@tonic-gate /* 24*1193Smws * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 250Sstevel@tonic-gate * Use is subject to license terms. 260Sstevel@tonic-gate */ 270Sstevel@tonic-gate 280Sstevel@tonic-gate #ifndef _FMD_USTAT_H 290Sstevel@tonic-gate #define _FMD_USTAT_H 300Sstevel@tonic-gate 310Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 320Sstevel@tonic-gate 330Sstevel@tonic-gate #include <pthread.h> 340Sstevel@tonic-gate 350Sstevel@tonic-gate #ifdef __cplusplus 360Sstevel@tonic-gate extern "C" { 370Sstevel@tonic-gate #endif 380Sstevel@tonic-gate 390Sstevel@tonic-gate #include <fmd_api.h> 400Sstevel@tonic-gate #include <fmd_list.h> 410Sstevel@tonic-gate 420Sstevel@tonic-gate typedef struct fmd_ustat_snap { 430Sstevel@tonic-gate fmd_stat_t *uss_buf; /* array of statistic data */ 440Sstevel@tonic-gate uint_t uss_len; /* length of uss_buf array */ 450Sstevel@tonic-gate } fmd_ustat_snap_t; 460Sstevel@tonic-gate 470Sstevel@tonic-gate typedef struct fmd_ustat_chunk { 480Sstevel@tonic-gate fmd_list_t usc_list; /* linked list next/prev pointers */ 490Sstevel@tonic-gate fmd_stat_t *usc_base; /* base of chunk allocation */ 500Sstevel@tonic-gate uint_t usc_len; /* number of stat structs in chunk */ 510Sstevel@tonic-gate uint_t usc_refs; /* reference count on chunk */ 520Sstevel@tonic-gate } fmd_ustat_chunk_t; 530Sstevel@tonic-gate 540Sstevel@tonic-gate typedef struct fmd_ustat_elem { 550Sstevel@tonic-gate struct fmd_ustat_elem *use_next; /* pointer to next statistic in hash */ 560Sstevel@tonic-gate const fmd_stat_t *use_stat; /* pointer to statistic data storage */ 570Sstevel@tonic-gate fmd_ustat_chunk_t *use_chunk; /* pointer to alloc chunk (or NULL) */ 580Sstevel@tonic-gate } fmd_ustat_elem_t; 590Sstevel@tonic-gate 600Sstevel@tonic-gate typedef struct fmd_ustat { 610Sstevel@tonic-gate pthread_rwlock_t us_lock; /* lock protecting ustat collection */ 620Sstevel@tonic-gate fmd_list_t us_chunks; /* linked list of allocation chunks */ 630Sstevel@tonic-gate fmd_ustat_elem_t **us_hash; /* hash bucket array of stat elements */ 640Sstevel@tonic-gate uint_t us_hashlen; /* length of us_hash bucket array */ 650Sstevel@tonic-gate uint_t us_nelems; /* number of elements in collection */ 660Sstevel@tonic-gate } fmd_ustat_t; 670Sstevel@tonic-gate 680Sstevel@tonic-gate extern fmd_ustat_t *fmd_ustat_create(void); 690Sstevel@tonic-gate extern void fmd_ustat_destroy(fmd_ustat_t *); 700Sstevel@tonic-gate extern int fmd_ustat_snapshot(fmd_ustat_t *, fmd_ustat_snap_t *); 710Sstevel@tonic-gate 720Sstevel@tonic-gate #define FMD_USTAT_NOALLOC 0x0 /* fmd should use caller's memory */ 730Sstevel@tonic-gate #define FMD_USTAT_ALLOC 0x1 /* fmd should allocate stats memory */ 740Sstevel@tonic-gate #define FMD_USTAT_VALIDATE 0x2 /* fmd should validate stat names */ 750Sstevel@tonic-gate 760Sstevel@tonic-gate #if FMD_STAT_NOALLOC != FMD_USTAT_NOALLOC 770Sstevel@tonic-gate #error "FMD_STAT_NOALLOC must match FMD_USTAT_NOALLOC" 780Sstevel@tonic-gate #endif 790Sstevel@tonic-gate 800Sstevel@tonic-gate #if FMD_STAT_ALLOC != FMD_USTAT_ALLOC 810Sstevel@tonic-gate #error "FMD_STAT_ALLOC must match FMD_USTAT_ALLOC" 820Sstevel@tonic-gate #endif 830Sstevel@tonic-gate 840Sstevel@tonic-gate extern fmd_stat_t *fmd_ustat_insert(fmd_ustat_t *, 850Sstevel@tonic-gate uint_t, uint_t, fmd_stat_t *, fmd_stat_t **); 860Sstevel@tonic-gate 870Sstevel@tonic-gate extern void fmd_ustat_delete(fmd_ustat_t *, uint_t, fmd_stat_t *); 88*1193Smws extern void fmd_ustat_delete_references(fmd_ustat_t *); 890Sstevel@tonic-gate 900Sstevel@tonic-gate #ifdef __cplusplus 910Sstevel@tonic-gate } 920Sstevel@tonic-gate #endif 930Sstevel@tonic-gate 940Sstevel@tonic-gate #endif /* _FMD_USTAT_H */ 95