/*
* 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 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include "med_local.h"
#include "med_hash.h"
static int med_db_is_inited = 0;
static int med_db_nma = 0;
static int med_db_nmu = 0;
#ifdef DEBUG
void
{
"key (%d)[keyp=0x%08x]: setno=%ld, setname=<%s>, caller=<%s>\n",
medp->med_caller);
med_eprintf("data(%d)[datap=0x%x08][medrp=0x%x08]: medridx=%d\n",
}
#endif /* DEBUG */
static int
{
int i = datalen;
char *cp;
i = 0;
while (*cp != '\0')
i += *cp++;
while (*cp != '\0')
i += *cp++;
return (i % hsz);
}
/*ARGSUSED*/
static int
{
int ret;
if (ret != 0)
return (ret);
if (ret != 0)
return (ret);
}
static void
{
}
static int
{
int len;
if (len == -1) {
med_eprintf("add_key(): init_cache() failed.\n");
return (-1);
}
}
med_eprintf("add_key(): itemp = Malloc(%d)\n",
sizeof (*itemp));
return (-1);
}
med_eprintf("add_key(): itemp->key = Malloc(%d)\n",
len);
return (-1);
}
"add_key(): tmedp->med_caller = Malloc(%d)\n",
return (-1);
}
"add_key(): tmedp->med_setname = Malloc(%d)\n",
return (-1);
}
med_eprintf("add_key(): itemp->data = Malloc(%d)\n",
sizeof (med_rec_t *));
return (-1);
}
med_eprintf("add_key(): add_cache() failed.\n");
return (-1);
}
return (0);
}
return (1);
}
static int
{
int len;
return (0);
return (0);
return (0);
}
static int
{
int len;
return (-1);
return (-1);
}
static int
{
int i;
for (i = 0; i < MD_MAXSIDES; i++) {
continue;
medrp->med_rec_nodes[i]));
}
/*
* Looping through the actual list of mediator hosts
* because a mediator host may not actually be a host
* in the diskset and so access for such a host needs
* to be added.
*/
for (i = 0; i < MED_MAX_HOSTS; i++) {
}
}
return (0);
}
static int
{
int i;
for (i = 0; i < MD_MAXSIDES; i++) {
continue;
medrp->med_rec_nodes[i]));
}
for (i = 0; i < MED_MAX_HOSTS; i++) {
}
}
return (0);
}
static int
{
"alloc_rec_buf: Malloc()"));
}
return (0);
}
static void
free_rec_buf(void)
{
return;
}
static int
int dbfd,
)
{
if (alloc_rec_buf(medep))
return (-1);
/* Setup the new hdr record */
/* Checksum new header */
/* Position to the beginning of the file */
/* Copy the header into the output buffer */
/* Write out the header */
return (0);
}
static int
int dbfd,
)
{
if (alloc_rec_buf(medep))
return (-1);
/* Checksum the new data */
sizeof (med_data_t), NULL);
}
/* Checksum record */
/* Load the record into the output buffer */
if (save_flags) {
/* Re-checksum the updated record */
}
/* Write out the record */
return (0);
}
static int
{
if (dbfd != -1)
return (0);
/* Open the database file */
"open_dbfile: open(create)"));
}
/* Try to take an advisory lock on the file */
med_exit(1);
}
return (0);
}
static int
{
if (dbfd == -1)
return (0);
/* Make sure we are at the beginning of the file */
/* Release the advisory lock on the file */
med_exit(1);
}
dbfd = -1;
return (0);
}
static int
{
int i;
if (! med_db_is_inited)
return (0);
/* Delete the old keys */
return (-1);
/* Mark the record in core as deleted */
/* Decrement the used slot count */
med_db_nmu--;
/* Get ready to re-write the file */
return (-1);
for (i = 0; i < med_db_nma; i++) {
medrp = &med_db_medrp[i];
continue;
/* Determine our location in the file */
"med_db_del_rec: lseek()"));
return (-1);
}
return (0);
}
static int
{
int ret;
int i;
return (0);
return (0);
/* Can't compare checksums, since the new record has no data yet */
/* Can't compare flags, since the in-core may have golden */
return (0);
return (0);
for (i = 0; i < MD_MAXSIDES; i++) {
continue;
nmedrp->med_rec_nodes[i]);
if (ret != 0)
return (0);
}
sizeof (md_h_arr_t));
if (ret != 0)
return (0);
return (1);
}
/*
* Exported routines
*/
int
{
int i;
int err = 0;
int ret;
int nm;
if (med_db_is_inited)
return (0);
if (open_dbfile(medep))
return (-1);
/* Empty file */
goto out;
/* File should be a multiple of the record size */
if (alloc_rec_buf(medep))
return (-1);
/* Read in the file header */
/*LINTED*/
/* Header magic is not OK */
/* Header revision is not OK */
/* Header checksum is not OK */
/* File size does not add up */
/* Allocate space to hold the records to be read next */
if (med_db_medrp == NULL)
"med_db_init: Calloc(med_db_medrp)"));
}
/* Read in all the records */
for (i = 0; i < nm; i++) {
"med_db_init: lseek()");
goto out;
}
"med_db_init: read() rec");
goto out;
}
"med_db_init");
goto out;
}
/*LINTED*/
/* Record magic is not OK */
"med_db_init");
goto out;
}
/* Record revision is not OK */
"med_db_init");
goto out;
}
/* Record checksum is not OK */
NULL);
if (ret) {
"med_db_init");
goto out;
}
/* Record is not where it is supposed to be */
"med_db_init");
goto out;
}
}
/* Add the keys to access this record */
for (i = 0; i < nm; i++)
goto out;
med_db_nma = nm;
med_db_nmu = nm;
out:
if (!err)
med_db_is_inited = 1;
return (err);
}
{
return (NULL);
}
return (&med_db_medrp[medridx]);
}
{
return (NULL);
}
}
int
{
int i;
int found = 0;
if (! med_db_is_inited)
"med_db_put_rec"));
/* See if we are still considered a mediator - is this a delete? */
for (i = 0; i < MED_MAX_HOSTS; i++) {
continue;
mynode()) == 0) {
found = 1;
break;
}
}
/* If it is a delete, make it happen */
if (! found)
/* See if there is an existing record */
/* Delete the old keys */
return (-1);
/* Decrement the used slot count */
med_db_nmu--;
} else {
for (i = 0; i < MED_MAX_HOSTS; i++) {
continue;
medp->med_caller) == 0)
continue;
if (medridx != -1) {
return (0);
}
}
}
/* Allocate more space if needed */
/* Allocate more space to hold the new record */
sizeof (med_rec_t));
"med_db_put_rec: Re-Calloc(tmedrp)"));
/* Copy the existing information into the new area */
for (i = 0; i < med_db_nma; i++)
med_db_nmu++;
if (med_db_medrp)
/* Initialize */
/* Calculate the record offset */
rec_size);
} else {
/*
* We did not find the record, but have space allocated.
* Find an empty slot.
*/
for (i = 0; i < med_db_nma; i++) {
medrp = &med_db_medrp[i];
continue;
medridx = i;
/* Mark as no longer deleted */
/* Initialize */
/* Calculate the new offset of the record */
/* Clear the old data */
sizeof (med_data_t));
break;
}
}
med_db_nmu++;
}
/* Update the record with the new information */
for (i = 0; i < MD_MAXSIDES; i++)
nmedrp->med_rec_nodes[i]);
return (-1);
/* Position to record location */
return (-1);
/* Add the keys for this record */
return (-1);
return (0);
}
int
{
if (! med_db_is_inited)
"med_db_put_data"));
"med_db_put_data"));
/* Go to location of the record */
return (-1);
return (0);
}
int
{
free_rec_buf();
if (close_dbfile(medep))
return (-1);
return (0);
}