cfsd_maptbl.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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 1994-2002 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Methods of the cfsd_maptbl classes.
*/
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <synch.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include "cfsd.h"
#include "cfsd_maptbl.h"
/*
* cfsd_maptbl_create
*
* Description:
* Constructor for the cfsd_maptbl class.
* Just does some setup not much else.
* Arguments:
* Returns:
* Preconditions:
*/
cfsd_maptbl_create(void)
{
dbug_enter("cfsd_maptbl_create");
maptbl_object_p->i_paoff = 0;
maptbl_object_p->i_paend = 0;
maptbl_object_p->i_palen = 0;
dbug_leave("cfsd_maptbl_create");
return (maptbl_object_p);
}
/*
* cfsd_maptbl_destroy
*
* Description:
* Destructor for the cfsd_maptbl class.
* Arguments:
* Returns:
* Preconditions:
*/
void
{
dbug_enter("cfsd_maptbl_destroy");
dbug_leave("cfsd_maptbl_destroy");
}
/*
* maptbl_domap
*
* Description:
* Maps in the specified section of the file.
* Arguments:
* off The offset to map in. Must be i_pagesize aligned.
* Returns:
* Returns 0 for success or an errno value on failure.
* Preconditions:
*/
int
{
int xx;
int len;
dbug_enter("maptbl_domap");
/* destroy old mapping if it exists */
if (maptbl_object_p->i_pa) {
/* determine how far we have to move the map */
/* remove the map */
if (xx == -1) {
}
maptbl_object_p->i_palen = 0;
maptbl_object_p->i_paoff = 0;
maptbl_object_p->i_paend = 0;
}
/* do the mapping */
dbug_print(("error",
"Could not map %s, error %d, off %d, len %d",
dbug_leave("maptbl_domap");
return (xx);
}
dbug_leave("maptbl_domap");
return (0);
}
/*
* maptbl_getaddr
*
* Description:
* Returns an address of a particular entry in the file.
* Arguments:
* index
* Returns:
* Returns NULL for a failure with the mapping file.
* Preconditions:
*/
{
dbug_enter("maptbl_getaddr");
/* find the boundaries of the entry */
/* map the entry in if necessary */
dbug_leave("maptbl_getaddr");
return (NULL);
}
}
/* make an address and return it */
dbug_leave("maptbl_getaddr");
return (pa);
}
/*
* maptbl_cidhashaddr
*
* Description:
* Finds the address of the specified cid by hashing to
* the appropriate entry. If the cid does not already
* exist in the file, then the address of where it should
* reside is returned.
* Arguments:
* cid
* addrp
* Returns:
* Returns 0 for success, 1 if entry not found, -1 if an
* error occurs in the mapping file.
* Preconditions:
*/
int
{
int index;
int start_index;
dbug_enter("maptbl_cidhashaddr");
/* get the index from the first hash function */
/* get the address of the entry */
dbug_leave("maptbl_cidhashaddr");
return (-1);
}
/* check for match */
dbug_leave("maptbl_cidhashaddr");
return (0);
}
/* check for not found */
if (fileno == 0) {
dbug_leave("maptbl_cidhashaddr");
return (1);
}
/* get the index from the second hash function */
/* do a linear search for a match or empty entry */
start_index = index;
do {
/* get the address of the entry */
dbug_leave("maptbl_cidhashaddr");
return (-1);
}
/* check for match */
dbug_leave("maptbl_cidhashaddr");
return (0);
}
/* check for not found */
if (fileno == 0) {
dbug_leave("maptbl_cidhashaddr");
return (1);
}
/* move to the next entry */
index++;
} while (start_index != index);
/* table full, this is bad */
dbug_leave("maptbl_cidhashaddr");
return (-1);
}
/*
* maptbl_hash1
*
* Description:
* Hashes a cid into an index into the table.
* Arguments:
* cid
* Returns:
* Returns the index.
* Preconditions:
*/
int
{
unsigned int xx;
unsigned int a, b;
#if 0
#else
b = a ^ cid.cid_fileno;
#endif
return (xx);
}
/*
* maptbl_hash2
*
* Description:
* Hashes a cid into an index into the table.
* Arguments:
* cid
* index
* Returns:
* Returns the index.
* Preconditions:
*/
int
{
unsigned int xx;
unsigned int a, b, c, d;
#if 0
b = cid.cid_fileno ^ a ^ b;
#else
#endif
return (xx);
}
/*
* maptbl_setup
*
* Description:
* Performs setup for the cfsd_maptbl class.
* This routine must be called before other routines are used.
* Arguments:
* filename
* Returns:
* Returns 0 for success or an errno value.
* Preconditions:
* precond(filename)
*/
int
{
int xx;
long *lp;
dbug_enter("maptbl_setup");
/* clean up from a previous setup */
sizeof (maptbl_object_p->i_name));
/* get the page info */
/* open the file */
O_RDWR | O_NONBLOCK);
dbug_print(("error",
dbug_leave("maptbl_setup");
return (xx);
}
/* get the size and type of file */
if (xx) {
dbug_print(("error",
dbug_leave("maptbl_setup");
return (xx);
}
/* sanity check, better be a regular file */
dbug_print(("error",
dbug_leave("maptbl_setup");
return (xx);
}
/* determine number of entries */
/* set up modulo value for second hash function */
/* initialize statistic gathering */
maptbl_object_p->i_stat_probes = 0;
maptbl_object_p->i_stat_filled = 0;
/* zero the file */
/* map in a section of the file */
if (xx) {
dbug_leave("maptbl_setup");
return (xx);
}
/* zero this section of the file */
} else {
dbug_assert((cnt * sizeof (long)) ==
}
}
/* return success */
dbug_leave("maptbl_setup");
return (0);
}
/*
* maptbl_teardown
*
* Description:
* Arguments:
* Returns:
* Preconditions:
*/
void
{
int xx;
dbug_enter("maptbl_teardown");
if (maptbl_object_p->i_pa) {
if (xx == -1) {
}
}
maptbl_object_p->i_paoff = 0;
maptbl_object_p->i_paend = 0;
maptbl_object_p->i_palen = 0;
errno));
}
dbug_leave("maptbl_teardown");
}
/*
* maptbl_get
*
* Description:
* Gets the mapping info for the specified cid.
* Arguments:
* cid
* valuep
* Returns:
* Returns 0 for success, 1 if entry not found, -1 if an
* error occurs in the mapping file.
* Preconditions:
* precond(valuep)
*/
int
struct cfs_dlog_mapping_space *valuep)
{
int xx;
struct cfs_dlog_mapping_space *pa;
dbug_enter("maptbl_get");
if (maptbl_object_p->i_entries == 0) {
dbug_leave("maptbl_get");
return (1);
}
if (xx == 0)
dbug_leave("maptbl_get");
return (xx);
}
/*
* maptbl_set
*
* Description:
* Sets the mapping info for the cid.
* If insert is 1 then if the entry is not found it is put in the
* table.
* Arguments:
* valuep
* insert
* Returns:
* Returns 0 if mapping info placed in the table, 1 if entry
* is not found an insert is 0, -1 if an error occurs in the
* mapping file.
* Preconditions:
* precond(valuep)
*/
int
struct cfs_dlog_mapping_space *valuep,
int insert)
{
int xx;
struct cfs_dlog_mapping_space *pa;
dbug_enter("maptbl_set");
if (xx == 1)
xx = 0;
}
dbug_leave("maptbl_set");
return (xx);
}
/*
* maptbl_dumpstats
*
* Description:
* Prints out various stats about the hashing.
* Arguments:
* Returns:
* Preconditions:
*/
void
{
int xx;
double dd;
dbug_enter("maptbl_dumpstats");
if (maptbl_object_p->i_stat_requests == 0) {
dbug_leave("maptbl_dumpstats");
return;
}
dbug_leave("maptbl_dumpstats");
}