xref: /illumos-gate/usr/src/cmd/fm/fmd/common/fmd_ustat.h (revision 2a8bcb4e)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
22*d9638e54Smws 
237c478bd9Sstevel@tonic-gate /*
24*d9638e54Smws  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
257c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
267c478bd9Sstevel@tonic-gate  */
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate #ifndef	_FMD_USTAT_H
297c478bd9Sstevel@tonic-gate #define	_FMD_USTAT_H
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #include <pthread.h>
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
347c478bd9Sstevel@tonic-gate extern "C" {
357c478bd9Sstevel@tonic-gate #endif
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate #include <fmd_api.h>
387c478bd9Sstevel@tonic-gate #include <fmd_list.h>
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate typedef struct fmd_ustat_snap {
417c478bd9Sstevel@tonic-gate 	fmd_stat_t *uss_buf;		/* array of statistic data */
427c478bd9Sstevel@tonic-gate 	uint_t uss_len;			/* length of uss_buf array */
437c478bd9Sstevel@tonic-gate } fmd_ustat_snap_t;
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate typedef struct fmd_ustat_chunk {
467c478bd9Sstevel@tonic-gate 	fmd_list_t usc_list;		/* linked list next/prev pointers */
477c478bd9Sstevel@tonic-gate 	fmd_stat_t *usc_base;		/* base of chunk allocation */
487c478bd9Sstevel@tonic-gate 	uint_t usc_len;			/* number of stat structs in chunk */
497c478bd9Sstevel@tonic-gate 	uint_t usc_refs;		/* reference count on chunk */
507c478bd9Sstevel@tonic-gate } fmd_ustat_chunk_t;
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate typedef struct fmd_ustat_elem {
537c478bd9Sstevel@tonic-gate 	struct fmd_ustat_elem *use_next; /* pointer to next statistic in hash */
547c478bd9Sstevel@tonic-gate 	const fmd_stat_t *use_stat;	/* pointer to statistic data storage */
557c478bd9Sstevel@tonic-gate 	fmd_ustat_chunk_t *use_chunk;	/* pointer to alloc chunk (or NULL) */
567c478bd9Sstevel@tonic-gate } fmd_ustat_elem_t;
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate typedef struct fmd_ustat {
597c478bd9Sstevel@tonic-gate 	pthread_rwlock_t us_lock;	/* lock protecting ustat collection */
607c478bd9Sstevel@tonic-gate 	fmd_list_t us_chunks;		/* linked list of allocation chunks */
617c478bd9Sstevel@tonic-gate 	fmd_ustat_elem_t **us_hash;	/* hash bucket array of stat elements */
627c478bd9Sstevel@tonic-gate 	uint_t us_hashlen;		/* length of us_hash bucket array */
637c478bd9Sstevel@tonic-gate 	uint_t us_nelems;		/* number of elements in collection */
647c478bd9Sstevel@tonic-gate } fmd_ustat_t;
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate extern fmd_ustat_t *fmd_ustat_create(void);
677c478bd9Sstevel@tonic-gate extern void fmd_ustat_destroy(fmd_ustat_t *);
687c478bd9Sstevel@tonic-gate extern int fmd_ustat_snapshot(fmd_ustat_t *, fmd_ustat_snap_t *);
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate #define	FMD_USTAT_NOALLOC	0x0	/* fmd should use caller's memory */
717c478bd9Sstevel@tonic-gate #define	FMD_USTAT_ALLOC		0x1	/* fmd should allocate stats memory */
727c478bd9Sstevel@tonic-gate #define	FMD_USTAT_VALIDATE	0x2	/* fmd should validate stat names */
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate #if FMD_STAT_NOALLOC != FMD_USTAT_NOALLOC
757c478bd9Sstevel@tonic-gate #error "FMD_STAT_NOALLOC must match FMD_USTAT_NOALLOC"
767c478bd9Sstevel@tonic-gate #endif
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate #if FMD_STAT_ALLOC != FMD_USTAT_ALLOC
797c478bd9Sstevel@tonic-gate #error "FMD_STAT_ALLOC must match FMD_USTAT_ALLOC"
807c478bd9Sstevel@tonic-gate #endif
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate extern fmd_stat_t *fmd_ustat_insert(fmd_ustat_t *,
837c478bd9Sstevel@tonic-gate     uint_t, uint_t, fmd_stat_t *, fmd_stat_t **);
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate extern void fmd_ustat_delete(fmd_ustat_t *, uint_t, fmd_stat_t *);
86*d9638e54Smws extern void fmd_ustat_delete_references(fmd_ustat_t *);
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
897c478bd9Sstevel@tonic-gate }
907c478bd9Sstevel@tonic-gate #endif
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate #endif	/* _FMD_USTAT_H */
93