cfsd_logfile.cc 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
*/
// -----------------------------------------------------------------
//
//
// Methods of the cfsd_maptbl classes.
#pragma ident "%Z%%M% %I% %E% SMI"
// Copyright (c) 1994 by Sun Microsystems, Inc.
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <synch.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include "cfsd_logfile.h"
//
// cfsd_logfile::cfsd_logfile
//
// Description:
// Arguments:
// Returns:
// Preconditions:
{
dbug_enter("cfsd_logfile::cfsd_logfile");
i_fid = -1;
i_map_entry.i_paoff = 0;
i_map_entry.i_paend = 0;
i_map_entry.i_palen = 0;
i_cur_offset = 0;
i_cur_entry = NULL;
}
//
// cfsd_logfile::~cfsd_logfile
//
// Description:
// Arguments:
// Returns:
// Preconditions:
{
dbug_enter("cfsd_logfile::~cfsd_logfile");
logfile_sync();
}
//
// cfsd_logfile::i_domap
//
// Description:
// Maps in the specified section of the file.
// Arguments:
// off The offset to map in. Must be i_pagesize aligned.
// map 0 means use map_entry, 1 means use map_offset
// Returns:
// Returns 0 for success or an errno value on failure.
// Preconditions:
int
{
dbug_enter("cfsd_logfile::i_domap");
dbug_precond(i_fid >= 0);
int xx;
// destroy old mapping if it exists
// determine how far we have to move the map
// remove the map
if (xx == -1) {
}
}
// do the mapping
dbug_print("error",
("Could not map %s, error %d, off %d, len %d",
return (xx);
}
return (0);
}
//
// cfsd_logfile::i_getaddr
//
// Description:
// Returns an address of a particular offset in the file.
// The size of the item to map is i_maxmap
// This routine assumes that if we have to remap that i_maxmap
// will fit inside the default mapping size.
// Arguments:
// start offset in the file to map
// map 0 means use map_entry, 1 means use map_offset
// Returns:
// Returns NULL for a failure with the mapping file.
// Preconditions:
{
dbug_enter("cfsd_logfile::i_getaddr");
// determine the end of the item
// map the entry in if necessary
return (NULL);
}
// make an address and return it
return (pa);
}
//
// cfsd_logfile::logfile_setup
//
// Description:
// Sets up to use the specified file.
// Call this routine before using any of the other routines.
// Arguments:
// filename file to use
// maxmap max amount needed after a map
// Returns:
// Returns 0 for success or an errno value.
// Preconditions:
// precond(filename)
int
{
dbug_enter("cfsd_logfile::logfile_setup");
int xx;
// clean up from a previous setup
// get the page info
// get the size and type of file
if (xx) {
} else {
}
return (xx);
}
// sanity check, better be a regular file
return (xx);
}
// better not be too small
if (i_size < sizeof (long)) {
return (0);
}
// open the file
if (i_fid == -1) {
xx));
return (xx);
}
// initialize statistic gathering
i_stat_mapmove = 0;
i_stat_mapdist = 0;
// check the version number
long *versionp;
return (EIO);
if (*versionp != CFS_DLOG_VERSION) {
*versionp, CFS_DLOG_VERSION));
return (EINVAL);
}
// return success
return (0);
}
//
// cfsd_logfile::logfile_teardown
//
// Description:
// Uninitializes the object.
// Call logfile_setup before using this object again.
// Arguments:
// Returns:
// Preconditions:
void
{
dbug_enter("cfsd_logfile::logfile_teardown");
int xx;
if (i_map_entry.i_pa) {
if (xx == -1) {
}
}
i_map_entry.i_paoff = 0;
i_map_entry.i_paend = 0;
i_map_entry.i_palen = 0;
if (i_map_offset.i_pa) {
if (xx == -1) {
}
}
i_map_offset.i_paoff = 0;
i_map_offset.i_paend = 0;
i_map_offset.i_palen = 0;
if (i_fid != -1) {
i_fid = -1;
}
i_cur_offset = 0;
i_cur_entry = NULL;
}
//
// cfsd_logfile::logfile_entry
//
// Description:
// Sets addrp to the address of the log entry at offset
// The mapping remains in effect until:
// a) this routine is called again
// b) logfile_teardown is called
// c) this object is destroyed
// Arguments:
// offset offset to start of entry
// entpp place to store address
// Returns:
// Returns 0 for success, 1 for EOF, -1 if a fatal error occurs.
// Preconditions:
// precond(addrp)
int
{
dbug_enter("cfsd_logfile::logfile_entrynext");
dbug_precond(offset >= sizeof (long));
// check for eof
return (1);
// get the address of the entry
return (-1);
// sanity check, record should be alligned
dbug_print("error",
("Record at offset %d length is not alligned %d",
return (-1);
}
// sanity check record should a reasonable size
return (-1);
}
// preserve offset and pointer
i_cur_entry = entp;
// return success
return (0);
}
//
// cfsd_logfile::logfile_offset
//
// Description:
// Sets addrp to the address of the specified offset.
// The mapping remains in effect until:
// a) this routine is called again
// b) logfile_teardown is called
// c) this object is destroyed
// Arguments:
// offset offset into file, must be 0 <= offset < i_size
// addrp returns mapped address
// Returns:
// Returns 0 for success, -1 if a fatal error occurs.
// Preconditions:
// precond(addrp)
int
{
dbug_enter("cfsd_logfile::logfile_offset");
// get the address for the offset
return (-1);
// return success
return (0);
}
//
// cfsd_logfile::logfile_sync
//
// Description:
// Performs an fsync on the log file.
// Arguments:
// Returns:
// Returns 0 for success or an errno value on failure.
// Preconditions:
int
{
dbug_enter("cfsd_logfile::logfile_sync");
if (i_fid == -1)
return (0);
if (xx) {
}
return (xx);
}
//
// cfsd_logfile::logfile_dumpstats
//
// Description:
// Prints out various stats about the hashing.
// Arguments:
// Returns:
// Preconditions:
void
{
dbug_enter("cfsd_logfile::logfile_dumpstats");
if (i_stat_mapmove == 0)
return;
int xx;
double dd;
}