fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The contents of this file are subject to the terms of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Common Development and Distribution License (the "License").
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You may not use this file except in compliance with the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or http://www.opensolaris.org/os/licensing.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If applicable, add the following below this CDDL HEADER, with the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stdio.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stdlib.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <string.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "isns_server.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "isns_cache.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "isns_msgq.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "isns_obj.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "isns_htab.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * external variables
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern msg_queue_t *sys_q;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int verbose_lock;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * global data
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint cache_flag = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * local variables
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic cache_t *imc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * local functions.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cache_init:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * create the cache data initially, including to invoke individual
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * functions for creating the hash tables for object storage and
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * discovery domain membership matrix.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return - 0: no error; 1: otherwise.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecache_init(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * allocate global cache memory.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte imc = (cache_t *)calloc(sizeof (cache_t), 1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (imc == NULL ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte obj_tab_init(imc) != 0 ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dd_matrix_init(imc) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cache_destroy();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1); /* no memory */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * initialize global cache rwlock.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) rwlock_init(&imc->l, NULL, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * inintialize global cache functions.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte imc->get_hval = obj_hval;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte imc->get_uid = get_obj_uid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte imc->set_uid = set_obj_uid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte imc->timestamp = get_timestamp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte imc->add_hook = add_object;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte imc->replace_hook = replace_object;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte imc->cmp = obj_cmp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte imc->clone = assoc_clone;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte imc->ddd = update_ddd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte imc->dump = obj_dump;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cache_destroy:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * destroy the cache data.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecache_destroy(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* do nothing */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cache_lock:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * grab the lock on the cache data.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * mode - the read/write mode of the lock.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return - error code.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecache_lock(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int mode
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ret = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (mode) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case CACHE_WRITE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = rw_wrlock(&imc->l);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (verbose_lock) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte printf("cache locked for writing.\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case CACHE_READ:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = rw_rdlock(&imc->l);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (verbose_lock) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte printf("cache locked for reading.\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case CACHE_TRY_READ:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ret = rw_tryrdlock(&imc->l);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (verbose_lock) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ret == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte printf("cache locked for reading.\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte printf("cache locked for reading failed.\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ret);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cache_unlock:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * release the lock on the cache data.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if the cache was locked for writing, a synchronization between
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the cache and persistent data store needs to be performed.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * mode - the read/write mode which the cache data was locked for.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ec - 0: commit the cache update; otherwise retreat it.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return - error code.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecache_unlock(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int mode,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ec
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (mode != CACHE_NO_ACTION) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* sync between cache and data store */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (mode == CACHE_WRITE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sys_q) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ec = data_sync(ec);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* rest the cache update flag */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RESET_CACHE_UPDATED();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(!IS_CACHE_UPDATED());
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* unlock it */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) rw_unlock(&imc->l);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (verbose_lock) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte printf("cache unlocked.\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ec);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cache_lock_read:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * grab the read lock on the cache.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return - error code.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecache_lock_read(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (cache_lock(CACHE_READ));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cache_lock_write:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * grab the write lock on the cache.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return - error code.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecache_lock_write(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (cache_lock(CACHE_WRITE));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cache_unlock_sync:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * synchronize the cache with persistent data store and
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * release the lock.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ec - 0: commit the cache update; otherwise retreat it.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return - error code.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecache_unlock_sync(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ec
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (cache_unlock(CACHE_WRITE, ec));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cache_unlock_nosync:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * release the lock, no need to sync the data between cache and
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * data store.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if the cache has been updated, do not call this function, call
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cache_unlock_sync() with non-zero error code to indicate the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sync action.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return - error code.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecache_unlock_nosync(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (cache_unlock(CACHE_READ, 0));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cache_get_htab:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * get the hash table for individual type of object.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * type - the object type.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return - the hash table.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortehtab_t *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecache_get_htab(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_type_t type
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (type > 0 && type < MAX_OBJ_TYPE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (imc->t[type]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cache_get_matrix:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * get the membership matrix for a discovery domain or a
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * discovery domain set.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * type - the discovery domain or discovery domain set object type.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return - the matrix.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortematrix_t *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecache_get_matrix(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_type_t type
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte matrix_t *x = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (type) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case OBJ_DD:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte x = imc->x[0];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case OBJ_DDS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte x = imc->x[1];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (x);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cache_lookup:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * invoke the hash table lookup for looking up a specific object and
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * perform the callback function on the object.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * lcp - the object lookup control data.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * uid_p - the pointer of object UID for returning.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * callback - the callback function for the object.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return - error code.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecache_lookup(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lookup_ctrl_t *lcp,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t *uid_p,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int (*callback)(void *, void *)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (htab_lookup(imc->t[lcp->type],
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lcp,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (lcp->op[0] == OP_INTEGER) ? lcp->data[0].ui : 0,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uid_p,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte callback,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cache_lookup:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * invoke the hash table lookup for looking up a specific object,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the callback function is going to change the key of the object.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * lcp - the object lookup control data.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * uid_p - the pointer of object UID for returning.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * callback - the callback function for the object.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return - error code.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecache_rekey(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lookup_ctrl_t *lcp,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t *uid_p,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int (*callback)(void *, void *)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (htab_lookup(imc->t[lcp->type],
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lcp,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (lcp->op[0] == OP_INTEGER) ? lcp->data[0].ui : 0,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uid_p,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte callback,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 1));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cache_add:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * invoke hash table add to add an object.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * obj - the object being added.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * flag - 0: a real object;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * otherwise an association object for discovery domain membership.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * uid_p - the pointer of object UID for returning.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * update_p - the pointer of flag (update object or newly register)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * for returning.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return - error code.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecache_add(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_obj_t *obj,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int flag,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t *uid_p,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int *update_p
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (htab_add(imc->t[obj->type], obj, flag, uid_p, update_p));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cache_remove:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * invoke hash table remove to remove an object.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * lcp - the lookup control data for the object being removed.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * flag - 0: a real object;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * otherwise an association object for discovery domain membership.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return - the removed object.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteisns_obj_t *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecache_remove(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lookup_ctrl_t *lcp,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int flag
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (htab_remove(imc->t[lcp->type],
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lcp,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (lcp->op[0] == OP_INTEGER) ? lcp->data[0].ui : 0,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte flag));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cache_dump_htab:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * dump the hash table for debugging purpose.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * type - the object type.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ****************************************************************************
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecache_dump_htab(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isns_type_t type
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) htab_dump(imc->t[type]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif