cfsd_subr.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
*/
// ------------------------------------------------------------
//
// cfsd_subr.cc
//
// Various support routines.
//
#pragma ident "%Z%%M% %I% %E% SMI"
// Copyright (c) 1994 by Sun Microsystems, Inc.
#include <libintl.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <dirent.h>
#include <wait.h>
#include <varargs.h>
#include <limits.h>
#include <string.h> /* strcmp */
#include <signal.h>
#include <sysent.h> /* getdtablesize, open */
#include <unistd.h> /* setsid */
#include <memory.h>
#include <stropts.h>
#include <netconfig.h>
#include <thread.h>
#include <synch.h>
#include "cfsd_kmod.h"
#include "cfsd_maptbl.h"
#include "cfsd_logfile.h"
#include "cfsd_fscache.h"
#include "cfsd_cache.h"
#include "cfsd_all.h"
#include <common/cachefsd.h>
// forward references
void *subr_mount_thread(void *datap);
int subr_fsck_cache(const char *cachedirp);
//
// subr_add_mount
//
// Description:
// Adds the specified file system to the data structures.
// Arguments:
// allp ptr to set of data structures
// dirp ptr to name of cache directory
// idp ptr to id of file system cache in dirp
// Returns:
// Preconditions:
// precond(allp)
// precond(dirp)
// precond(idp)
void
{
dbug_enter("subr_add_mount");
int xx;
// find or create the cache object
// make the cache object
cachep = new cfsd_cache;
if (xx == 0) {
delete cachep;
allp->all_unlock();
return;
}
}
cachep->cache_lock();
cachep->cache_refinc();
cachep->cache_unlock();
allp->all_unlock();
// find or create the fscache object
cachep->cache_lock();
// make the fscache object and add it to the list
} else {
/* don't do any more if already mounted */
fscachep->fscache_lock();
if (fscachep->fscache_mounted()) {
cachep->cache_refdec();
cachep->cache_unlock();
return;
}
}
fscachep->fscache_lock();
cachep->cache_unlock();
// init the fscache object with mount information
fscachep->fscache_lock();
// start the disconnect thread if necessary
if (fscachep->fscache_disconnectable() &&
fscachep->fscache_mounted() &&
(fscachep->fscache_threaded() == 0) &&
if (xx) {
// XXX cachefs kmod cannot allow transition
fscachep->fscache_threaded(0);
}
}
cachep->cache_lock();
cachep->cache_refdec();
cachep->cache_unlock();
}
// -----------------------------------------------------------------
//
// subr_mount_thread
//
// Description:
// Called when a thread is created via thr_create to process
// an fscache.
// Arguments:
// datap ptr to cfsd_fscache to process
// Returns:
// Returns NULL.
// Preconditions:
// precond(datap)
void *
subr_mount_thread(void *datap)
{
dbug_enter("subr_mount_thread");
fscachep->fscache_lock();
fscachep->fscache_threaded(0);
return (NULL);
}
// -----------------------------------------------------------------
//
// subr_cache_setup
//
// Description:
// Called once when the daemon starts up to get the current state
// of caches reflected in the daemon.
// Arguments:
// allp
// Returns:
// Preconditions:
// precond(allp)
void
{
dbug_enter("subr_cache_setup");
int fixcachefstab = 0;
// find all the caches indicated in the CACHEFSTAB file
int xx;
} else {
char buf[MAXPATHLEN];
if (xx != 1)
continue;
// make the cache object
cachep = new cfsd_cache;
if (xx == 0) {
delete cachep;
} else {
}
} else {
}
}
}
// read the mnttab file looking for caches we may have missed
} else {
if (xx != 0)
continue;
else {
cp += 9;
if (xcp)
*xcp = '\0';
}
// make the cache object
cachep = new cfsd_cache;
if (xx == 0) {
delete cachep;
} else {
}
}
}
}
// read the vfstab file looking for caches we may have missed
} else {
if (xx != 0)
continue;
else {
cp += 9;
if (xcp)
*xcp = '\0';
}
// make the cache object
cachep = new cfsd_cache;
if (xx == 0) {
delete cachep;
} else {
}
}
}
}
// fix up the CACHEFSTAB file if it is out of date
if (fixcachefstab)
// now for each cache we found, find all the file systems in the cache
cachep->cache_lock();
cachep->cache_refinc();
cachep->cache_unlock();
allp->all_unlock();
// fix up the cache if necessary
if (xx != 0) {
cachep->cache_cachedir()));
continue;
}
// lock out activity on the cache
if (lockfd < 0) {
cachep->cache_cachedir()));
continue;
}
// open the cache directory
cachep->cache_cachedir()));
continue;
}
// read the directory entries
// skip . and ..
continue;
// get info on the file
if (xx != 0) {
continue;
}
// skip unless a symbolic link
continue;
// add this file system to the list
}
cachep->cache_lock();
cachep->cache_refdec();
cachep->cache_unlock();
}
allp->all_unlock();
}
// -----------------------------------------------------------------
//
// subr_fsck_cache
//
// Description:
// Fixes the cache if necessary.
// Arguments:
// cachedirp
// Returns:
// Returns 0 for success !0 if the cache is not fixed.
// Preconditions:
// precond(cachedirp)
int
subr_fsck_cache(const char *cachedirp)
{
dbug_enter("subr_fsck_cache");
char *fsck_argv[4];
int status = 0;
/* fork */
return (1);
}
if (pid == 0) {
/* do the fsck */
} else {
/* wait for the child to exit */
return (1);
}
return (1);
}
if (WEXITSTATUS(status) != 0) {
return (1);
}
}
return (0);
}
// -----------------------------------------------------------------
//
// subr_doexec
//
// Description:
// Execs the specified program with the specified command line arguments.
// This function never returns.
// Arguments:
// fstype type of file system
// newargv command line arguments
// progp name of program to exec
// Returns:
// Preconditions:
// precond(fstype)
// precond(newargv)
// precond(progp)
void
{
dbug_enter("subr_doexec");
char alter_path[PATH_MAX];
/* build the full pathname of the fstype dependent command. */
/* if the program exists */
/* invoke the program */
/* if wrong permissions */
}
/* if it did not work and the shell might make it */
newargv[0] = "sh";
}
}
/* try the alternate path */
/* if wrong permissions */
}
/* if it did not work and the shell might make it */
newargv[0] = "sh";
}
_exit(1);
}
// -----------------------------------------------------------------
//
// pr_err
//
// Description:
// Arguments:
// fmt
// Returns:
// Preconditions:
// precond(fmt)
void
{
}
//
// subr_strdup
//
// Description:
// Returns the string dupped. Returns NULL if passed NULL.
// Calls new to allocate memory.
// Arguments:
// strp
// Returns:
// Preconditions:
char *
subr_strdup(const char *strp)
{
int len;
if (strp) {
if (retp)
}
return (retp);
}