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 #pragma ident "%Z%%M% %I% %E% SMI" 327c478bd9Sstevel@tonic-gate 337c478bd9Sstevel@tonic-gate #include <pthread.h> 347c478bd9Sstevel@tonic-gate 357c478bd9Sstevel@tonic-gate #ifdef __cplusplus 367c478bd9Sstevel@tonic-gate extern "C" { 377c478bd9Sstevel@tonic-gate #endif 387c478bd9Sstevel@tonic-gate 397c478bd9Sstevel@tonic-gate #include <fmd_api.h> 407c478bd9Sstevel@tonic-gate #include <fmd_list.h> 417c478bd9Sstevel@tonic-gate 427c478bd9Sstevel@tonic-gate typedef struct fmd_ustat_snap { 437c478bd9Sstevel@tonic-gate fmd_stat_t *uss_buf; /* array of statistic data */ 447c478bd9Sstevel@tonic-gate uint_t uss_len; /* length of uss_buf array */ 457c478bd9Sstevel@tonic-gate } fmd_ustat_snap_t; 467c478bd9Sstevel@tonic-gate 477c478bd9Sstevel@tonic-gate typedef struct fmd_ustat_chunk { 487c478bd9Sstevel@tonic-gate fmd_list_t usc_list; /* linked list next/prev pointers */ 497c478bd9Sstevel@tonic-gate fmd_stat_t *usc_base; /* base of chunk allocation */ 507c478bd9Sstevel@tonic-gate uint_t usc_len; /* number of stat structs in chunk */ 517c478bd9Sstevel@tonic-gate uint_t usc_refs; /* reference count on chunk */ 527c478bd9Sstevel@tonic-gate } fmd_ustat_chunk_t; 537c478bd9Sstevel@tonic-gate 547c478bd9Sstevel@tonic-gate typedef struct fmd_ustat_elem { 557c478bd9Sstevel@tonic-gate struct fmd_ustat_elem *use_next; /* pointer to next statistic in hash */ 567c478bd9Sstevel@tonic-gate const fmd_stat_t *use_stat; /* pointer to statistic data storage */ 577c478bd9Sstevel@tonic-gate fmd_ustat_chunk_t *use_chunk; /* pointer to alloc chunk (or NULL) */ 587c478bd9Sstevel@tonic-gate } fmd_ustat_elem_t; 597c478bd9Sstevel@tonic-gate 607c478bd9Sstevel@tonic-gate typedef struct fmd_ustat { 617c478bd9Sstevel@tonic-gate pthread_rwlock_t us_lock; /* lock protecting ustat collection */ 627c478bd9Sstevel@tonic-gate fmd_list_t us_chunks; /* linked list of allocation chunks */ 637c478bd9Sstevel@tonic-gate fmd_ustat_elem_t **us_hash; /* hash bucket array of stat elements */ 647c478bd9Sstevel@tonic-gate uint_t us_hashlen; /* length of us_hash bucket array */ 657c478bd9Sstevel@tonic-gate uint_t us_nelems; /* number of elements in collection */ 667c478bd9Sstevel@tonic-gate } fmd_ustat_t; 677c478bd9Sstevel@tonic-gate 687c478bd9Sstevel@tonic-gate extern fmd_ustat_t *fmd_ustat_create(void); 697c478bd9Sstevel@tonic-gate extern void fmd_ustat_destroy(fmd_ustat_t *); 707c478bd9Sstevel@tonic-gate extern int fmd_ustat_snapshot(fmd_ustat_t *, fmd_ustat_snap_t *); 717c478bd9Sstevel@tonic-gate 727c478bd9Sstevel@tonic-gate #define FMD_USTAT_NOALLOC 0x0 /* fmd should use caller's memory */ 737c478bd9Sstevel@tonic-gate #define FMD_USTAT_ALLOC 0x1 /* fmd should allocate stats memory */ 747c478bd9Sstevel@tonic-gate #define FMD_USTAT_VALIDATE 0x2 /* fmd should validate stat names */ 757c478bd9Sstevel@tonic-gate 767c478bd9Sstevel@tonic-gate #if FMD_STAT_NOALLOC != FMD_USTAT_NOALLOC 777c478bd9Sstevel@tonic-gate #error "FMD_STAT_NOALLOC must match FMD_USTAT_NOALLOC" 787c478bd9Sstevel@tonic-gate #endif 797c478bd9Sstevel@tonic-gate 807c478bd9Sstevel@tonic-gate #if FMD_STAT_ALLOC != FMD_USTAT_ALLOC 817c478bd9Sstevel@tonic-gate #error "FMD_STAT_ALLOC must match FMD_USTAT_ALLOC" 827c478bd9Sstevel@tonic-gate #endif 837c478bd9Sstevel@tonic-gate 847c478bd9Sstevel@tonic-gate extern fmd_stat_t *fmd_ustat_insert(fmd_ustat_t *, 857c478bd9Sstevel@tonic-gate uint_t, uint_t, fmd_stat_t *, fmd_stat_t **); 867c478bd9Sstevel@tonic-gate 877c478bd9Sstevel@tonic-gate extern void fmd_ustat_delete(fmd_ustat_t *, uint_t, fmd_stat_t *); 88*d9638e54Smws extern void fmd_ustat_delete_references(fmd_ustat_t *); 897c478bd9Sstevel@tonic-gate 907c478bd9Sstevel@tonic-gate #ifdef __cplusplus 917c478bd9Sstevel@tonic-gate } 927c478bd9Sstevel@tonic-gate #endif 937c478bd9Sstevel@tonic-gate 947c478bd9Sstevel@tonic-gate #endif /* _FMD_USTAT_H */ 95