1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #ifndef _FMD_USTAT_H 28 #define _FMD_USTAT_H 29 30 #pragma ident "%Z%%M% %I% %E% SMI" 31 32 #include <pthread.h> 33 34 #ifdef __cplusplus 35 extern "C" { 36 #endif 37 38 #include <fmd_api.h> 39 #include <fmd_list.h> 40 41 typedef struct fmd_ustat_snap { 42 fmd_stat_t *uss_buf; /* array of statistic data */ 43 uint_t uss_len; /* length of uss_buf array */ 44 } fmd_ustat_snap_t; 45 46 typedef struct fmd_ustat_chunk { 47 fmd_list_t usc_list; /* linked list next/prev pointers */ 48 fmd_stat_t *usc_base; /* base of chunk allocation */ 49 uint_t usc_len; /* number of stat structs in chunk */ 50 uint_t usc_refs; /* reference count on chunk */ 51 } fmd_ustat_chunk_t; 52 53 typedef struct fmd_ustat_elem { 54 struct fmd_ustat_elem *use_next; /* pointer to next statistic in hash */ 55 const fmd_stat_t *use_stat; /* pointer to statistic data storage */ 56 fmd_ustat_chunk_t *use_chunk; /* pointer to alloc chunk (or NULL) */ 57 } fmd_ustat_elem_t; 58 59 typedef struct fmd_ustat { 60 pthread_rwlock_t us_lock; /* lock protecting ustat collection */ 61 fmd_list_t us_chunks; /* linked list of allocation chunks */ 62 fmd_ustat_elem_t **us_hash; /* hash bucket array of stat elements */ 63 uint_t us_hashlen; /* length of us_hash bucket array */ 64 uint_t us_nelems; /* number of elements in collection */ 65 } fmd_ustat_t; 66 67 extern fmd_ustat_t *fmd_ustat_create(void); 68 extern void fmd_ustat_destroy(fmd_ustat_t *); 69 extern int fmd_ustat_snapshot(fmd_ustat_t *, fmd_ustat_snap_t *); 70 71 #define FMD_USTAT_NOALLOC 0x0 /* fmd should use caller's memory */ 72 #define FMD_USTAT_ALLOC 0x1 /* fmd should allocate stats memory */ 73 #define FMD_USTAT_VALIDATE 0x2 /* fmd should validate stat names */ 74 75 #if FMD_STAT_NOALLOC != FMD_USTAT_NOALLOC 76 #error "FMD_STAT_NOALLOC must match FMD_USTAT_NOALLOC" 77 #endif 78 79 #if FMD_STAT_ALLOC != FMD_USTAT_ALLOC 80 #error "FMD_STAT_ALLOC must match FMD_USTAT_ALLOC" 81 #endif 82 83 extern fmd_stat_t *fmd_ustat_insert(fmd_ustat_t *, 84 uint_t, uint_t, fmd_stat_t *, fmd_stat_t **); 85 86 extern void fmd_ustat_delete(fmd_ustat_t *, uint_t, fmd_stat_t *); 87 88 #ifdef __cplusplus 89 } 90 #endif 91 92 #endif /* _FMD_USTAT_H */ 93