cb5caa98562cf06753163f558cbcfe30b8f4673adjl * CDDL HEADER START
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * The contents of this file are subject to the terms of the
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * Common Development and Distribution License (the "License").
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * You may not use this file except in compliance with the License.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * See the License for the specific language governing permissions
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * and limitations under the License.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * When distributing Covered Code, include this CDDL HEADER in each
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * If applicable, add the following below this CDDL HEADER, with the
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * fields enclosed by brackets "[]" replaced with your own identifying
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * information: Portions Copyright [yyyy] [name of copyright owner]
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * CDDL HEADER END
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * Use is subject to license terms.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl#pragma ident "%Z%%M% %I% %E% SMI"
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * Access control structure for a piece of nscd data. This structure
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * is always tagged before the nscd data. nscd_alloc, which should
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * be used to allocate memory that requires access control or usage
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * count control, will initialize this access control structure at the
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * start of the memory returned to the caller.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl void (*free_func)(nscd_acc_data_t *data); /* destructor */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl/* size should be in multiple of 8 */
cb5caa98562cf06753163f558cbcfe30b8f4673adjlstatic int sizeof_access = roundup(sizeof (nscd_access_t));
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * FUNCTION: _nscd_release
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * Decrements the usage count maintained in the access data
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * tagged before 'data'. Delete the nscd data item if the delete
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * flag is set and the usage count reaches 0.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl "seq = %lld, nUse = %d\n",
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * if we get here, no other thread could be
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * holding the access->mutex lock, It is safe
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * to free the memory containing the mutex
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * structure. No mutex_unlock is necessary.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * FUNCTION: _nscd_destroy
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * Marks the nscd data item as to-be-deleted and then releases
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * (If the usage count happens to be zero, then _nscd_release()
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * will destroy the data.)
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * Note that _nscd_destroy should only be called if the
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * caller has created the nscd data with _nscd_alloc
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * (with the exception of _nscd_set). That nscd data
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * item should be private to the caller.
cb5caa98562cf06753163f558cbcfe30b8f4673adjlstatic void
cb5caa98562cf06753163f558cbcfe30b8f4673adjl (me, "data = %p, access->data = %p\n", data, access->data);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * FUNCTION: _nscd_get
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * Increment the usage count by one if 'data' can
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * be found in the internal address database.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl (me, "data = %p, access->data = %p, seq#= %lld, nUse = %d\n",
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * see if this addr is still valid,
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * if so, _nscd_is_int_addr will
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * do a read lock on the returned
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * multiple readers/single writer lock
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * to prevent the access data from being
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * deleted while it is being accessed.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * done with the multiple readers/single writer lock
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * FUNCTION: _nscd_set
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * _nscd_set sets the address of a nscd data item
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * to 'new' and delete the old nscd data (old).
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * The pointer 'new' is returned.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl /* if old_data == new_data, both must be NULL */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * FUNCTION: _nscd_rdlock
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * Lock (rw_rdlock) a nscd data item for reading. The caller
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * needs to call _nscd_rw_unlock() to unlock the data item
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * when done using the data.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl (me, "data = %p, access->data = %p\n", data, access->data);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * FUNCTION: _nscd_wrlock
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * Lock (rw_wrlock) a nscd data item for writing. The caller
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * needs to call _nscd_rw_unlock() to unlock the data item
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * when done using the data.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl (me, "data = %p, access->data = %p\n", data, access->data);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * FUNCTION: _nscd_rw_unlock
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * Unlock (rw_unlock) a locked nscd data item.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * FUNCTION: _nscd_rw_unlock_no_release
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * Unlock (rw_unlock) a locked nscd data item but without release
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * it, i.e., without decrement the usage count to indicate that
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * the data item is still being referenced.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * FUNCTION: _nscd_mutex_lock
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * Lock (mutex_lock) a nscd data item. The caller needs
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * to call _nscd_mutex_unlock() to unlock the data item
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * when done using the data.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl (me, "data = %p, access->data = %p\n", data, access->data);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * FUNCTION: _nscd_mutex_unlock
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * Unlock a locked nscd data item (that were locked by _nscd_mutex_lock)..
cb5caa98562cf06753163f558cbcfe30b8f4673adjl (me, "data = %p, access->data = %p\n", data, access->data);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * FUNCTION: _nscd_cond_wait
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * Perform a condition wait with the cond_t and mutex_t associated
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * with data.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl (me, "data = %p, access->data = %p\n", data, access->data);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl assert(access->data_cond != NULL && access->data_mutex != NULL);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl (void) cond_wait(access->data_cond, access->data_mutex);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * FUNCTION: _nscd_cond_signal
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * Perform a condition signal with the cond_t associated with 'data'.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl (me, "data = %p, access->data = %p\n", data, access->data);
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * FUNCTION: _nscd_alloc
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * Allocate a piece of nscd memory. 'data_free'
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * is the function to invoke to free the data
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * stored in this memory, i.e., the desctrctor.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * 'option' indicate whether a mutex or a
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * readers/writer (or both, or none) should also
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * be allocated.
cb5caa98562cf06753163f558cbcfe30b8f4673adjl if ((rwlock = (rwlock_t *)calloc(1, sizeof (rwlock_t))) ==
cb5caa98562cf06753163f558cbcfe30b8f4673adjl /* get current sequence number */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl /* add the address to the internal address database */
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * FUNCTION: _nscd_free
cb5caa98562cf06753163f558cbcfe30b8f4673adjl * Free a piece of nscd memory.
cb5caa98562cf06753163f558cbcfe30b8f4673adjlstatic void
cb5caa98562cf06753163f558cbcfe30b8f4673adjl /* remove the address from the internal address database */