datastore.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 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdlib.h>
#include <string.h>
#include <stropts.h>
#include <synch.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <dhcp_svc_private.h>
#include <dhcpmsg.h>
#include "dsvclockd.h"
#include "datastore.h"
/*
* Create a datastore named `ds_name' and a door which will service requests
* for this datastore. When the door is called, callback `ds_callback'.
* Returns the created datastore.
*/
{
char door_path[MAXPATHLEN];
int fd;
unsigned int i;
ds_name);
return (NULL);
}
ds_name);
return (NULL);
}
ds_name);
return (NULL);
}
for (i = 0; i < DSVCD_DS_HASH_SIZE; i++) {
}
/*
* Create the door name in the filesystem. First, check to see if
* a door already exists at the specified pathname. If it does,
* and the server process (no doubt another copy of us) is already
* running, then fail. Otherwise, unlink the old door and fattach
* a new one.
*/
if (fd != -1) {
return (NULL);
}
}
if (fd == -1) {
"`%s'", ds_name);
return (NULL);
}
/*
* Attach the door onto the name
*/
"`%s'", ds_name);
return (NULL);
}
return (ds);
}
/*
* Destroy a datastore `ds' and its associated containers, and remove
* its door from the filesystem.
*/
void
{
unsigned int i;
char door_path[MAXPATHLEN];
/*
* Detach and revoke access to the door. The detach makes it so
* new callers who open the door will fail; the revoke makes it
* so that callers that already have a door descriptor will fail.
* We do this prior to calling cn_destroy() to make it easier for
* the container lockcount to drain.
*/
/*
* Destroy all the underlying containers. We're single-threaded at
* this point, so don't worry about locks.
*/
for (i = 0; i < DSVCD_DS_HASH_SIZE; i++) {
cn_destroy(cn);
}
}
}
/*
* Get a container with id `cn_id' from datastore `ds'; create the
* container if it does not exist. If `crosshost' is set and the container
* does not yet exist, then the container will synchronize across hosts. .
* If the container cannot be found or created, NULL is returned. When the
* calling thread is done with the container, ds_release_container() must
* be called.
*/
{
break;
}
cn->cn_lastrel = 0;
}
}
return (cn);
}
/*
* Release a container `cn' belonging to datastore `ds'. Once a container
* has been released, it can no longer be used by the releasing thread.
* Used to track the number of active instances of a container.
*/
void
{
}
/*
* Destroy any containers in datastore `ds' that have not been accessed in
* the last `idle' seconds. Return the number of destroyed (reaped)
* containers.
*/
unsigned int
{
unsigned int i, nreaped = 0;
for (i = 0; i < DSVCD_DS_HASH_SIZE; i++) {
/*
* Since a container is not checked out across a
* lock operation, we must check if the lock is
* held as well as the number of instances checked
* out.
*/
continue;
else
cn_destroy(cn);
nreaped++;
}
}
return (nreaped);
}
/*
* Hash a container identified by `cn_id' into a 32-bit unsigned integer
* suitable for use as a key in a hash table.
*/
static uint32_t
{
unsigned int i;
for (i = 0; cn_id[i] != '\0'; i++)
return (result);
}