cachefs_fscache.c revision da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (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 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <sys/pathname.h>
#include <sys/sysmacros.h>
/* external references */
/* forward references */
/*
* ------------------------------------------------------------------
*
* fscache_create
*
* Description:
* Creates a fscache object.
* Arguments:
* cachep cache to create fscache object for
* Returns:
* Returns a fscache object.
* Preconditions:
* precond(cachep)
*/
{
/* create and initialize the fscache object */
return (fscp);
}
/*
* ------------------------------------------------------------------
*
* fscache_destroy
*
* Description:
* Destroys the fscache object.
* Arguments:
* fscp the fscache object to destroy
* Returns:
* Preconditions:
* precond(fscp)
* precond(fs_ref == 0)
*/
void
{
(void) fscache_info_sync(fscp);
if (strl != 0)
}
if (fscp->fs_hostname) {
if (strl != 0)
}
if (fscp->fs_backfsname) {
if (strl != 0)
}
/* drop the inum translation table */
if (fscp->fs_inum_size > 0)
/* drop references to the fscache directory */
if (fscp->fs_fscdirvp)
if (fscp->fs_fsattrdir)
/* drop logging references */
}
/*
* ------------------------------------------------------------------
*
* fscache_setup
*
* Description:
* Activates a fscache by associating the fscache object
* with on disk data.
* If the fscache directory of the specified fsid exists then
* it will be used.
* Otherwise a new fscache directory will be created using namep
* and optp with fsid being ignored. However if namep or optp
* are not NULL or the cache is in NOFILL then this routine fails.
* Arguments:
* fscp the fscache object to activate
* fsid unique identifier for the cache
* namep name of the cache
* optp options for the cache
* Returns:
* Returns 0 for success, !0 on failure.
* Preconditions:
* precond(fscp)
* precond(the cache must not be in NOCACHE mode)
* precond(the cache must not alread by active)
*/
static int
{
int error;
/* see if the fscache directory already exists */
if (error) {
/* return error if cannot create the directory */
return (error);
}
if (backfileno == 0)
return (EAGAIN);
/* remember the root back fileno for disconnected mounts */
/* copy options into the fscache */
/* create the directory */
if (error) {
"CacheFS: not enough space to create %s",
namep);
else
"CacheFS: error %d creating %s",
return (error);
}
} else if (optp) {
/* compare the options to make sure they are compatible */
if (error) {
"CacheFS: mount failed, options do not match.");
return (error);
}
/* copy options into the fscache */
/*
* The fileid of the root of the filesystem can change
* in NFSv4, so make sure we update the fi_root
* with the new filenumber.
*/
if (CFS_ISFS_BACKFS_NFSV4(fscp) &&
}
}
if (setflags) {
}
return (0);
}
/*
* ------------------------------------------------------------------
*
* fscache_activate
*
* Description:
* A wrapper routine for fscache_setup, telling it to setup the
* fscache for general use.
*
*/
int
{
}
/*
* ------------------------------------------------------------------
*
* fscache_enable
*
* Description:
* A wrapper routine for fscache_setup, telling it to create a
* fscache that can be used during remount. In this case the
* fscache flags that allow general use are not yet turned on.
* A later call to fscache_activate_rw will set the flags.
*
*/
int
{
}
/*
* ------------------------------------------------------------------
*
* fscache_activate_rw
*
* Description:
* Makes the fscache both readable and writable.
* Arguments:
* fscp fscache object
* Returns:
* Preconditions:
* precond(fscp)
*/
void
{
}
/*
* ------------------------------------------------------------------
*
* fscache_hold
*
* Description:
* Increments the reference count on the fscache object
* Arguments:
* fscp fscache object to incriment reference count on
* Returns:
* Preconditions:
* precond(fscp)
*/
void
{
}
/*
* ------------------------------------------------------------------
*
* fscache_rele
*
* Description:
* Decriments the reference count on the fscache object
* Arguments:
* fscp fscache object to decriment reference count on
* Returns:
* Preconditions:
* precond(fscp)
*/
void
{
}
/*
* ------------------------------------------------------------------
*
* fscache_cnodecnt
*
* Description:
* Changes the count of number of cnodes on this fscache
* by the specified amount.
* Arguments:
* fscp fscache object to to modify count on
* cnt amount to adjust by
* Returns:
* Returns new count of number of cnodes.
* Preconditions:
* precond(fscp)
*/
int
{
int xx;
return (xx);
}
/*
* ------------------------------------------------------------------
*
* fscache_mounted
*
* Description:
* Called to indicate the the fscache is mounted.
* Arguments:
* fscp fscache object
* cfsvfsp cachefs vfsp
* backvfsp vfsp of back file system
* Returns:
* Returns 0 for success, -1 if the cache is already mounted.
* Preconditions:
* precond(fscp)
*/
int
{
int error = 0;
error = -1;
goto out;
}
if (CFS_ISFS_SNR(fscp)) {
/*
* If there is a dlog file present, then we assume the cache
* was left in disconnected mode.
* Also if the back file system was not mounted we also
* start off in disconnected mode.
*/
fscp->fs_cdtransition = 0;
}
/* invalidate any local fileno mappings */
/* if connected, invalidate any local time mappings */
if (backvfsp)
}
error = 0;
/* set up the consistency mode */
} else {
}
out:
(void) fscache_info_sync(fscp);
return (error);
}
/*
* Compares fscache state with new mount options
* to make sure compatible.
* Returns ESRCH if not compatible or 0 for success.
*/
int
{
return (0);
} else {
return (ESRCH);
}
}
/*
* ------------------------------------------------------------------
*
* fscache_sync
*
* Description:
* Syncs any data for this fscache to the front file system.
* Arguments:
* fscp fscache to sync
* Returns:
* Preconditions:
* precond(fscp)
*/
void
{
int xx;
(void) fscache_info_sync(fscp);
/* sync the cnodes */
/* sync the attrcache files */
(void) filegrp_sync(fgp);
}
}
/* garbage collect any unused file groups */
}
/*
* ------------------------------------------------------------------
*
* fscache_acset
*
* Description:
* Sets the ac timeout values for the fscache.
* Arguments:
* fscp fscache object
* Returns:
* Preconditions:
* precond(fscp)
*/
void
{
if (acregmin != 0)
if (acregmax != 0)
if (acdirmin != 0)
if (acdirmax != 0)
}
/*
* ------------------------------------------------------------------
*
* fscache_list_find
*
* Description:
* Finds the desired fscache structure on a cache's
* file system list.
* Arguments:
* cachep holds the list of fscache objects to search
* fsid the numeric identifier of the fscache
* Returns:
* Returns an fscache object on success or NULL on failure.
* Preconditions:
* precond(cachep)
* precond(the fslistlock must be held)
*/
{
break;
}
}
return (fscp);
}
/*
* ------------------------------------------------------------------
*
* fscache_list_add
*
* Description:
* Adds the specified fscache object to the list on
* the specified cachep.
* Arguments:
* cachep holds the list of fscache objects
* fscp fscache object to add to list
* Returns:
* Preconditions:
* precond(cachep)
* precond(fscp)
* precond(fscp cannot already be on a list)
* precond(the fslistlock must be held)
*/
void
{
}
/*
* ------------------------------------------------------------------
*
* fscache_list_remove
*
* Description:
* Removes the specified fscache object from the list
* on the specified cachep.
* Arguments:
* cachep holds the list of fscache objects
* fscp fscache object to remove from list
* Returns:
* Preconditions:
* precond(cachep)
* precond(fscp)
* precond(the fslistlock must be held)
*/
void
{
break;
}
}
}
/*
* ------------------------------------------------------------------
*
* fscache_list_gc
*
* Description:
* Traverses the list of fscache objects on the cachep
* list and destroys any that are not mounted and
* that are not referenced.
* Arguments:
* cachep holds the list of fscache objects
* Returns:
* Preconditions:
* precond(cachep)
* precond(the fslistlock must be held)
*/
void
{
} else {
}
}
}
/*
* ------------------------------------------------------------------
*
* fscache_list_mounted
*
* Description:
* Returns the number of fscache objects that are mounted.
* Arguments:
* cachep holds the list of fscache objects
* Returns:
* Preconditions:
* precond(cachep)
* precond(the fslistlock must be held)
*/
int
{
int count;
count = 0;
count++;
}
return (count);
}
/*
* Creates the fs cache directory.
* The directory name is the ascii version of the fsid.
* Also makes a symlink to the directory using the specified name.
*/
int
{
int error;
char name[CFS_FRONTFILE_NAME_SIZE];
int files;
int blocks = 0;
/* directory, symlink and options file + attrcache dir */
files = 0;
while (files < 4) {
if (error)
goto out;
files++;
}
if (error)
goto out;
blocks = 4;
if (error) {
goto out;
}
/*
* Created the directory. Get the fileno. That'll be the cachefs_fsid.
*/
if (error) {
goto out;
}
if (error) {
goto out;
}
if (error) {
goto out;
}
/* write out the info file */
if (error)
goto out;
/*
* Install the symlink from cachefs_fsid -> directory.
*/
if (error) {
goto out;
}
0);
if (error) {
goto out;
}
/*
* Finally, make the attrcache directory
*/
0, NULL);
if (error) {
goto out;
}
out:
if (error) {
while (files-- > 0)
if (fscdirvp)
if (blocks)
if (attrvp)
if (infovp)
}
if (attrp)
return (error);
}
/*
* Tries to find the fscache directory indicated by fsid.
*/
int
{
int error;
char dirname[CFS_FRONTFILE_NAME_SIZE];
/* convert the fsid value to the name of the directory */
/* try to find the directory */
if (error)
goto out;
/* this better be a directory or we are hosed */
" run fsck, %s", dirname);
goto out;
}
/* try to find the info file */
if (error) {
" run fsck, %s", dirname);
goto out;
}
/* read in info struct */
/*LINTED alignment okay*/
if (error) {
" run fsck, %s", dirname);
goto out;
}
/* try to find the attrcache directory */
if (error) {
" run fsck, %s", dirname);
goto out;
}
out:
if (error) {
if (infovp)
if (fscdirvp)
}
return (error);
}
/*
* fscache_info_sync
* Writes out the fs_info data if necessary.
*/
static int
{
int error = 0;
goto out;
}
/* if the data is dirty and we have the file vnode */
/*LINTED alignment okay*/
if (error) {
"cachefs: Can not write to info file.");
} else {
}
}
out:
return (error);
}
/*
* ------------------------------------------------------------------
*
* fscache_name_to_fsid
*
* Description:
* Takes the name of a cache and determines it corresponding
* fsid.
* Arguments:
* cachep cache object to find name of fs cache in
* namep the name of the fs cache
* fsidp set to the fsid if found
* Returns:
* Returns 0 on success, !0 on error.
* Preconditions:
* precond(cachep)
* precond(namep)
* precond(fsidp)
*/
int
{
int error;
char dirname[CFS_FRONTFILE_NAME_SIZE];
char *pd;
int xx;
int c;
/* get the vnode of the name */
if (error)
goto out;
/* the vnode had better be a link */
goto out;
}
/* read the contents of the link */
uio.uio_loffset = 0;
if (error) {
goto out;
}
/* convert the contents of the link to a ino64_t */
nodeid = 0;
nodeid <<= 4;
c = *pd++;
if (c <= '9')
c -= '0';
else if (c <= 'F')
c = c - 'A' + 10;
else
c = c - 'a' + 10;
nodeid += c;
}
out:
if (linkvp)
return (error);
}
/*
* Suspends the thread until access to the cache is granted.
* If !SOFT then
* waitconnected == 1 means wait until connected
* waitconnected == 0 means wait until connected or disconnected
* else then
* wait until connected or disconnected
* writing is set to 1 if writing, 0 if reading
* Returns 0, EINTR, or ETIMEDOUT.
*/
int
{
int nosig;
int error = 0;
int waithappens = 0;
#ifdef CFS_CD_DEBUG
#endif
for (;;) {
/* if we have to wait */
if (waithappens ||
(waitconnected &&
/* do not make soft mounts wait until connected */
break;
}
/* wait for a wakeup or a signal */
/* if we got a signal */
if (nosig == 0) {
break;
}
if (waitconnected &&
waitconnected = 0;
/* try again to get access */
waithappens = 0;
continue;
}
/* if transitioning modes */
if (fscp->fs_cdtransition) {
waithappens = 1;
continue;
}
/* if rolling the log */
/* if writing or not the cachefsd */
if (writing ||
waithappens = 1;
continue;
}
}
/* if the daemon is not running */
if (fscp->fs_cddaemonid == 0) {
/* if writing and not connected */
if (writing &&
waithappens = 1;
continue;
}
}
/*
* Verify don't set wait for NFSv4 (doesn't support
* disconnected behavior).
*/
(waithappens == 0 && waitconnected == 0));
fscp->fs_cdrefcnt++;
#ifdef CFS_CD_DEBUG
#endif
break;
}
return (error);
}
/*
* Call to check if can have access after a cache miss has occurred.
* Only read access is allowed, do not call this routine if want
* to write.
* Returns 1 if yes, 0 if no.
*/
int
{
#ifdef CFS_CD_DEBUG
#endif
/* should not get called if connected */
/* if no back file system, then no */
return (0);
/* if daemon is not running, then yes */
if (fscp->fs_cddaemonid == 0) {
return (1);
}
/* if daemon is running, only daemon is allowed to have access */
return (0);
}
return (1);
}
/*
* Releases an access to the file system.
*/
void
{
#ifdef CFS_CD_DEBUG
#endif
/* decriment hold on file system */
fscp->fs_cdrefcnt--;
/* Verify no connected state transitions for NFSv4 */
/* wake up cachefsd */
}
/*
* Called when a network timeout error has occurred.
* If connected, switches state to disconnected.
*/
void
{
int state;
/* nothing to do if not snr or not connected */
return;
#ifdef CFS_CD_DEBUG
#endif
/* Verify no state changes done for NFSv4 */
}