/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "isns_server.h"
#include "isns_cache.h"
#include "isns_msgq.h"
#include "isns_obj.h"
#include "isns_htab.h"
/*
* external variables
*/
extern msg_queue_t *sys_q;
#ifdef DEBUG
extern int verbose_lock;
#endif
/*
* global data
*/
int cache_flag = 0;
/*
* local variables
*/
/*
* local functions.
*/
/*
* ****************************************************************************
* cache_init:
* create the cache data initially, including to invoke individual
* functions for creating the hash tables for object storage and
* discovery domain membership matrix.
*
* return - 0: no error; 1: otherwise.
*
* ****************************************************************************
*/
int
)
{
/*
* allocate global cache memory.
*/
obj_tab_init(imc) != 0 ||
dd_matrix_init(imc) != 0) {
return (1); /* no memory */
}
/*
* initialize global cache rwlock.
*/
/*
* inintialize global cache functions.
*/
#ifdef DEBUG
#endif
return (0);
}
/*
* ****************************************************************************
* cache_destroy:
* destroy the cache data.
*
* ****************************************************************************
*/
void
)
{
/* do nothing */
}
/*
* ****************************************************************************
* cache_lock:
* grab the lock on the cache data.
*
* return - error code.
*
* ****************************************************************************
*/
int
int mode
)
{
int ret = 0;
switch (mode) {
case CACHE_WRITE:
#ifdef DEBUG
if (verbose_lock) {
printf("cache locked for writing.\n");
}
#endif
break;
case CACHE_READ:
#ifdef DEBUG
if (verbose_lock) {
printf("cache locked for reading.\n");
}
#endif
break;
case CACHE_TRY_READ:
#ifdef DEBUG
if (verbose_lock) {
if (ret == 0) {
printf("cache locked for reading.\n");
} else {
printf("cache locked for reading failed.\n");
}
}
#endif
break;
default:
break;
}
return (ret);
}
/*
* ****************************************************************************
* cache_unlock:
* release the lock on the cache data.
* if the cache was locked for writing, a synchronization between
* the cache and persistent data store needs to be performed.
*
* ec - 0: commit the cache update; otherwise retreat it.
* return - error code.
*
* ****************************************************************************
*/
int
int mode,
int ec
)
{
if (mode != CACHE_NO_ACTION) {
/* sync between cache and data store */
if (mode == CACHE_WRITE) {
if (sys_q) {
}
/* rest the cache update flag */
}
ASSERT(!IS_CACHE_UPDATED());
/* unlock it */
#ifdef DEBUG
if (verbose_lock) {
printf("cache unlocked.\n");
}
#endif
}
return (ec);
}
/*
* ****************************************************************************
* cache_lock_read:
* grab the read lock on the cache.
*
* return - error code.
*
* ****************************************************************************
*/
int
)
{
return (cache_lock(CACHE_READ));
}
/*
* ****************************************************************************
* cache_lock_write:
* grab the write lock on the cache.
*
* return - error code.
*
* ****************************************************************************
*/
int
)
{
return (cache_lock(CACHE_WRITE));
}
/*
* ****************************************************************************
* cache_unlock_sync:
* synchronize the cache with persistent data store and
* release the lock.
*
* ec - 0: commit the cache update; otherwise retreat it.
* return - error code.
*
* ****************************************************************************
*/
int
int ec
)
{
}
/*
* ****************************************************************************
* cache_unlock_nosync:
* release the lock, no need to sync the data between cache and
* data store.
* if the cache has been updated, do not call this function, call
* cache_unlock_sync() with non-zero error code to indicate the
* sync action.
*
* return - error code.
*
* ****************************************************************************
*/
int
)
{
return (cache_unlock(CACHE_READ, 0));
}
/*
* ****************************************************************************
* cache_get_htab:
* get the hash table for individual type of object.
*
* type - the object type.
* return - the hash table.
*
* ****************************************************************************
*/
htab_t *
)
{
}
return (NULL);
}
/*
* ****************************************************************************
* cache_get_matrix:
* get the membership matrix for a discovery domain or a
* discovery domain set.
*
* type - the discovery domain or discovery domain set object type.
* return - the matrix.
*
* ****************************************************************************
*/
matrix_t *
)
{
switch (type) {
case OBJ_DD:
x = imc->x[0];
break;
case OBJ_DDS:
x = imc->x[1];
break;
default:
break;
}
return (x);
}
/*
* ****************************************************************************
* cache_lookup:
* invoke the hash table lookup for looking up a specific object and
* perform the callback function on the object.
*
* lcp - the object lookup control data.
* uid_p - the pointer of object UID for returning.
* callback - the callback function for the object.
* return - error code.
*
* ****************************************************************************
*/
int
int (*callback)(void *, void *)
)
{
lcp,
0));
}
/*
* ****************************************************************************
* cache_lookup:
* invoke the hash table lookup for looking up a specific object,
* the callback function is going to change the key of the object.
*
* lcp - the object lookup control data.
* uid_p - the pointer of object UID for returning.
* callback - the callback function for the object.
* return - error code.
*
* ****************************************************************************
*/
int
int (*callback)(void *, void *)
)
{
lcp,
1));
}
/*
* ****************************************************************************
* cache_add:
* invoke hash table add to add an object.
*
* obj - the object being added.
* flag - 0: a real object;
* otherwise an association object for discovery domain membership.
* uid_p - the pointer of object UID for returning.
* update_p - the pointer of flag (update object or newly register)
* for returning.
* return - error code.
*
* ****************************************************************************
*/
int
int flag,
int *update_p
)
{
}
/*
* ****************************************************************************
* cache_remove:
* invoke hash table remove to remove an object.
*
* lcp - the lookup control data for the object being removed.
* flag - 0: a real object;
* otherwise an association object for discovery domain membership.
* return - the removed object.
*
* ****************************************************************************
*/
int flag
)
{
lcp,
flag));
}
/*
* ****************************************************************************
* cache_dump_htab:
* dump the hash table for debugging purpose.
*
* type - the object type.
*
* ****************************************************************************
*/
#ifdef DEBUG
void
)
{
}
#endif