/*
*
* Coda: an Experimental Distributed File System
* Release 3.1
*
* Copyright (c) 1987-1998 Carnegie Mellon University
* All Rights Reserved
*
* Permission to use, copy, modify and distribute this software and its
* documentation is hereby granted, provided that both the copyright
* notice and this permission notice appear in all copies of the
* software, derivative works or modified versions, and any portions
* thereof, and that both notices appear in supporting documentation, and
* that credit is given to Carnegie Mellon University in all documents
* and publicity pertaining to direct or indirect use of this code or its
* derivatives.
*
* CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS KNOWN TO HAVE BUGS,
* SOME OF WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON ALLOWS
* FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION. CARNEGIE MELLON
* DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER
* RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE OR OF
* ANY DERIVATIVE WORK.
*
* Carnegie Mellon encourages users of this software to return any
* improvements or extensions that they make, and to grant Carnegie
* Mellon the rights to redistribute these changes without encumbrance.
*
* @(#) coda/coda_subr.c,v 1.1.1.1 1998/08/29 21:26:45 rvb Exp $
*/
/*
* Mach Operating System
* Copyright (c) 1989 Carnegie-Mellon University
* All rights reserved. The CMU software License Agreement specifies
* the terms and conditions for use and redistribution.
*/
/*
* This code was written for the Coda file system at Carnegie Mellon
* University. Contributers include David Steere, James Kistler, and
* M. Satyanarayanan. */
/* NOTES: rvb
* 1. Added coda_unmounting to mark all cnodes as being UNMOUNTING. This has to
* be done before dounmount is called. Because some of the routines that
* dounmount calls before coda_unmounted might try to force flushes to venus.
* The vnode pager does this.
* 2. coda_unmounting marks all cnodes scanning coda_cache.
* 3. cfs_checkunmounting (under DEBUG) checks all cnodes by chasing the vnodes
* under the /coda mount point.
* 4. coda_cacheprint (under DEBUG) prints names with vnode/cnode address
*/
/*
* Lookup a cnode by fid. If the cnode is dying, it is bogus so skip it.
* The cnode is returned locked with the vnode referenced.
*/
struct cnode *
coda_find(CodaFid *fid)
{
int i;
struct vnode *vp;
struct cnode *cp;
for (i = 0; i < NVCODA; i++) {
if (!coda_mnttbl[i].mi_started)
continue;
if (vcache_get(coda_mnttbl[i].mi_vfsp,
fid, sizeof(CodaFid), &vp) != 0)
continue;
mutex_enter(vp->v_interlock);
cp = VTOC(vp);
if (vp->v_type == VNON || cp == NULL || IS_UNMOUNTING(cp)) {
mutex_exit(vp->v_interlock);
vrele(vp);
continue;
}
mutex_enter(&cp->c_lock);
mutex_exit(vp->v_interlock);
return cp;
}
return NULL;
}
/*
* Iterate over all nodes attached to coda mounts.
*/
static void
coda_iterate(bool (*f)(void *, struct vnode *), void *cl)
{
int i;
struct vnode_iterator *marker;
struct vnode *vp;
for (i = 0; i < NVCODA; i++) {
if (coda_mnttbl[i].mi_vfsp == NULL)
continue;
vfs_vnode_iterator_init(coda_mnttbl[i].mi_vfsp, &marker);
while ((vp = vfs_vnode_iterator_next(marker, f, cl)) != NULL)
vrele(vp);
vfs_vnode_iterator_destroy(marker);
}
}
/*
* coda_kill is called as a side effect to vcopen. To prevent any
* cnodes left around from an earlier run of a venus or warden from
* causing problems with the new instance, mark any outstanding cnodes
* as dying. Future operations on these cnodes should fail (excepting
* coda_inactive of course!). Since multiple venii/wardens can be
* running, only kill the cnodes for a particular entry in the
* coda_mnttbl. -- DCS 12/1/94 */
int
coda_kill(struct mount *whoIam, enum dc_status dcstat)
{
int count = 0;
struct vnode_iterator *marker;
/*
* Algorithm is as follows:
* Second, flush whatever vnodes we can from the name cache.
*/
/* This is slightly overkill, but should work. Eventually it'd be
* nice to only flush those entries from the namecache that
* reference a vnode in this vfs. */
coda_nc_flush(dcstat);
/*
* There are two reasons why a cnode may be in use, it may be in the
* name cache or it may be executing.
*/
static bool
coda_flush_selector(void *cl, struct vnode *vp)
{
struct cnode *cp = VTOC(vp);
if (cp != NULL && !IS_DIR(cp->c_fid)) /* only files can be executed */
coda_vmflush(cp);
coda_nc_flush(dcstat); /* flush files from the name cache */
coda_iterate(coda_flush_selector, NULL);
}
/*
* As a debugging measure, print out any cnodes that lived through a
* name cache flush.
*/
static bool
coda_testflush_selector(void *cl, struct vnode *vp)
{
struct cnode *cp = VTOC(vp);
/*
* First, step through all cnodes and mark them unmounting.
* NetBSD kernels may try to fsync them now that venus
* is dead, which would be a bad thing.
*
*/
static bool
coda_unmounting_selector(void *cl, struct vnode *vp)
{
struct cnode *cp = VTOC(vp);
/*
* There are 6 cases where invalidations occur. The semantics of each
* is listed here.
*
* CODA_FLUSH -- flush all entries from the name cache and the cnode cache.
* CODA_PURGEUSER -- flush all entries from the name cache for a specific user
* This call is a result of token expiration.
*
* The next two are the result of callbacks on a file or directory.
* CODA_ZAPDIR -- flush the attributes for the dir from its cnode.
* Zap all children of this directory from the namecache.
* CODA_ZAPFILE -- flush the attributes for a file.
*
* The fifth is a result of Venus detecting an inconsistent file.
* CODA_PURGEFID -- flush the attribute for the file
* If it is a dir (odd vnode), purge its
* children from the namecache
* remove the file from the namecache.
*
* The sixth allows Venus to replace local fids with global ones
* during reintegration.
*
* CODA_REPLACE -- replace one CodaFid with another throughout the name cache
*/
int handleDownCall(int opcode, union outputArgs *out)
{
int error;