xref: /illumos-gate/usr/src/cmd/fm/fmd/common/fmd_ustat.h (revision 2a8bcb4e)
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 /*
24  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
25  * Use is subject to license terms.
26  */
27 
28 #ifndef	_FMD_USTAT_H
29 #define	_FMD_USTAT_H
30 
31 #include <pthread.h>
32 
33 #ifdef	__cplusplus
34 extern "C" {
35 #endif
36 
37 #include <fmd_api.h>
38 #include <fmd_list.h>
39 
40 typedef struct fmd_ustat_snap {
41 	fmd_stat_t *uss_buf;		/* array of statistic data */
42 	uint_t uss_len;			/* length of uss_buf array */
43 } fmd_ustat_snap_t;
44 
45 typedef struct fmd_ustat_chunk {
46 	fmd_list_t usc_list;		/* linked list next/prev pointers */
47 	fmd_stat_t *usc_base;		/* base of chunk allocation */
48 	uint_t usc_len;			/* number of stat structs in chunk */
49 	uint_t usc_refs;		/* reference count on chunk */
50 } fmd_ustat_chunk_t;
51 
52 typedef struct fmd_ustat_elem {
53 	struct fmd_ustat_elem *use_next; /* pointer to next statistic in hash */
54 	const fmd_stat_t *use_stat;	/* pointer to statistic data storage */
55 	fmd_ustat_chunk_t *use_chunk;	/* pointer to alloc chunk (or NULL) */
56 } fmd_ustat_elem_t;
57 
58 typedef struct fmd_ustat {
59 	pthread_rwlock_t us_lock;	/* lock protecting ustat collection */
60 	fmd_list_t us_chunks;		/* linked list of allocation chunks */
61 	fmd_ustat_elem_t **us_hash;	/* hash bucket array of stat elements */
62 	uint_t us_hashlen;		/* length of us_hash bucket array */
63 	uint_t us_nelems;		/* number of elements in collection */
64 } fmd_ustat_t;
65 
66 extern fmd_ustat_t *fmd_ustat_create(void);
67 extern void fmd_ustat_destroy(fmd_ustat_t *);
68 extern int fmd_ustat_snapshot(fmd_ustat_t *, fmd_ustat_snap_t *);
69 
70 #define	FMD_USTAT_NOALLOC	0x0	/* fmd should use caller's memory */
71 #define	FMD_USTAT_ALLOC		0x1	/* fmd should allocate stats memory */
72 #define	FMD_USTAT_VALIDATE	0x2	/* fmd should validate stat names */
73 
74 #if FMD_STAT_NOALLOC != FMD_USTAT_NOALLOC
75 #error "FMD_STAT_NOALLOC must match FMD_USTAT_NOALLOC"
76 #endif
77 
78 #if FMD_STAT_ALLOC != FMD_USTAT_ALLOC
79 #error "FMD_STAT_ALLOC must match FMD_USTAT_ALLOC"
80 #endif
81 
82 extern fmd_stat_t *fmd_ustat_insert(fmd_ustat_t *,
83     uint_t, uint_t, fmd_stat_t *, fmd_stat_t **);
84 
85 extern void fmd_ustat_delete(fmd_ustat_t *, uint_t, fmd_stat_t *);
86 extern void fmd_ustat_delete_references(fmd_ustat_t *);
87 
88 #ifdef	__cplusplus
89 }
90 #endif
91 
92 #endif	/* _FMD_USTAT_H */
93