cfsd_subr.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 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Various support routines.
*/
#include <libintl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <dirent.h>
#include <wait.h>
#include <stdarg.h>
#include <limits.h>
#include <string.h> /* strcmp */
#include <signal.h>
#include <unistd.h> /* setsid */
#include <memory.h>
#include <stropts.h>
#include <netconfig.h>
#include <thread.h>
#include <synch.h>
#include "cfsd.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
const char *dirp,
const char *idp)
{
int xx;
dbug_enter("subr_add_mount");
/* find or create the cache object */
if (cache_object_p == NULL) {
/* make the cache object */
if (xx == 0) {
dbug_leave("subr_add_mount");
return;
}
}
/* find or create the fscache object */
if (fscache_object_p == NULL) {
/* make the fscache object and add it to the list */
} else {
/* don't do any more if already mounted */
if (fscache_object_p->i_mounted) {
dbug_leave("subr_add_mount");
return;
}
}
/* init the fscache object with mount information */
/* start the disconnect thread if necessary */
if (fscache_object_p->i_disconnectable &&
(fscache_object_p->i_threaded == 0) &&
if (xx) {
/* XXX cachefs kmod cannot allow transition */
fscache_object_p->i_threaded = 0;
}
}
dbug_leave("subr_add_mount");
}
/*
* ------------------------------------------------------------
* 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");
/* close down the message file descriptor */
if (fscache_object_p->i_ofd >= 0) {
errno));
}
fscache_object_p->i_threaded = 0;
dbug_leave("subr_mount_thread");
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
{
int fixcachefstab = 0;
int xx;
char buf[MAXPATHLEN];
char *cp;
char *xcp;
int lockfd;
char pathname[MAXPATHLEN];
int len;
dbug_enter("subr_cache_setup");
/* find all the caches indicated in the CACHEFSTAB file */
} else {
continue;
/*
* if the line did not fit in the buffer
* it is invalid (i.e. no newline char)
*/
#if 0
/*
* if the line is invalid read until
* you get to the next line.
* we only need to do this if we are
* going to continue
*/
do {
#endif
break;
}
if (cache_object_p == NULL) {
/* make the cache object */
if (xx == 0) {
} else {
}
} else {
}
}
CACHEFSTAB, errno));
}
/* read the mnttab file looking for caches we may have missed */
} else {
if (xx != 0)
continue;
else {
cp += 9;
if (xcp)
*xcp = '\0';
}
if (cache_object_p == NULL) {
/* make the cache object */
if (xx == 0) {
} else {
}
} else {
}
}
}
/* read the vfstab file looking for caches we may have missed */
} else {
if (xx != 0)
continue;
else {
cp += 9;
if (xcp)
*xcp = '\0';
}
if (cache_object_p == NULL) {
/* make the cache object */
if (xx == 0) {
} 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
*/
/* fix up the cache if necessary */
if (xx != 0) {
continue;
}
/* lock out activity on the cache */
if (lockfd < 0) {
continue;
}
/* open the cache directory */
continue;
}
sizeof (pathname));
/* read the directory entries */
/* skip . and .. */
continue;
/* get info on the file */
if (xx != 0) {
dbug_print(("error",
continue;
}
/* skip unless a symbolic link */
continue;
/* add this file system to the list */
}
}
dbug_leave("subr_cache_setup");
}
/*
* ------------------------------------------------------------
* 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)
{
char *fsck_argv[4];
int status = 0;
dbug_enter("subr_fsck_cache");
/* fork */
dbug_leave("subr_fsck_cache");
return (1);
}
if (pid == 0) {
/* do the fsck */
} else {
/* wait for the child to exit */
dbug_leave("subr_fsck_cache");
return (1);
}
dbug_leave("subr_fsck_cache");
return (1);
}
if (WEXITSTATUS(status) != 0) {
dbug_leave("subr_fsck_cache");
return (1);
}
}
dbug_leave("subr_fsck_cache");
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
{
char full_path[MAXPATHLEN];
char alter_path[MAXPATHLEN];
dbug_enter("subr_doexec");
/* build the full pathname of the fstype dependent command. */
/* if the program exists */
/* invoke the program */
/* if wrong permissions */
}
#ifdef OBSOLETE
/* if it did not work and the shell might make it */
newargv[0] = "sh";
}
#endif
}
#ifdef OBSOLETE
/* try the alternate path */
/* if wrong permissions */
}
/* if it did not work and the shell might make it */
newargv[0] = "sh";
}
#endif
dbug_leave("subr_doexec");
_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);
}
/*
* -----------------------------------------------------------------
* cfsd_calloc
*
* Description:
* allocates memory of a given size, will retry if error
* Arguments:
* size
* Returns:
* pointer to memory
* Preconditions:
* precond(size)
*/
void *
cfsd_calloc(int size)
{
void *alloc_ptr;
dbug_enter("cfsd_calloc");
/* allocate memory, if calloc fails sleep and retry */
cfsd_sleep(5);
}
dbug_leave("cfsd_calloc");
return (alloc_ptr);
}
/*
* -----------------------------------------------------------------
* cfsd_free
*
* Description:
* frees memory allocated from cfsd_calloc
* Arguments:
* pointer to memeory
* Returns:
* none
* Preconditions:
* precond(size)
*/
void
{
dbug_enter("cfsd_free");
/* free memory */
if (free_ptr)
dbug_leave("cfsd_free");
}
/*
* -----------------------------------------------------------------
* cfsd_sleep
*
* Description:
* A reimplemenation of the sleep(3c) function call using
* cond_timedwait.
* Problem withe sleep(3c) hanging. May return early.
* Arguments:
* sec number of seconds to sleep for
* Returns:
* Preconditions:
*/
void
cfsd_sleep(int sec)
{
dbug_enter("cfsd_sleep");
if (sec > 0) {
mutex_lock(&mt);
mutex_unlock(&mt);
cond_destroy(&cv);
mutex_destroy(&mt);
}
dbug_leave("cfsd_sleep");
}