cachefs_module.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"
/*
* This is the loadable module wrapper.
*/
static int cachefs_init(int, char *);
static void cachefs_fini();
static int cachefs_unloadable = 0; /* tunable */
/*
* this is a list of possible hash table sizes, for the `double
* hashing' algorithm described in rosen's `elementary number theory
* and its applications'. minimally, this needs to be a list of
* increasing prime integers, terminated by a 0. ideally, they should
* be the larger of twin primes; i.e. P and P-2 are both prime.
*/
/*
* Module linkage information for the kernel.
*/
};
"cache filesystem",
};
static struct modlinkage modlinkage = {
};
char _depends_on[] = "strmod/rpcmod";
int
_init(void)
{
int status;
if (status != 0) {
/*
* Could not load module, clean up the work performed
* by cachefs_init() which was indirectly called by
* mod_installfs() which in turn was called by mod_install().
*/
cachefs_fini();
}
return (status);
}
int
{
}
int
_fini(void)
{
int status;
if (!cachefs_unloadable)
return (EBUSY);
/*
* Module has been unloaded, now clean up
*/
cachefs_fini();
}
return (status);
}
extern kmutex_t cachefs_newnum_lock;
extern kmutex_t cachefs_kstat_key_lock;
extern kmutex_t cachefs_rename_lock;
extern kmutex_t cachefs_kmem_lock;
extern major_t cachefs_major;
/*
* Cache initialization routine. This routine should only be called
* once. It performs the following tasks:
* - Initalize all global locks
* - Call sub-initialization routines (localize access to variables)
*/
static int
{
int error;
if (error != 0)
return (error);
if (error != 0)
return (error);
#ifdef CFSRLDEBUG
#endif /* CFSRLDEBUG */
/*
* set up kmem_cache entities
*/
sizeof (struct cachefs_req), 0,
sizeof (filegrp_t), 0,
/*
* set up the cachefs.0.key kstat
*/
cachefs_kstat_key_n = 0;
}
/*
* Assign unique major number for all nfs mounts
*/
"cachefs: init: can't get unique device number");
cachefs_major = 0;
}
cachefs_up = B_TRUE;
#ifdef CFSRLDEBUG
#endif /* CFSRLDEBUG */
return (0);
}
/*
* Cache clean up routine. This routine is called if mod_install() failed
* and we have to clean up because the module could not be installed,
* or by _fini() when we're unloading the module.
*/
static void
{
extern int cachefsfstyp;
extern struct vnodeops *cachefs_vnodeops;
if (cachefs_up == B_FALSE) {
/*
* cachefs_init() was not called on _init(),
* nothing to deallocate.
*/
return;
}
/*
* Clean up cachefs.0.key kstat.
* Currently, you can only do a
* modunload if cachefs_unloadable is nonzero, and that's
* pretty much just for debugging. however, if there ever
* comes a day when cachefs is more freely unloadable
* (e.g. the modunload daemon can do it normally), then we'll
* have to make changes in the stats_ API. this is because a
* stats_cookie_t holds the id # derived from here, and it
* will all go away at modunload time. thus, the API will
* need to somehow be more robust than is currently necessary.
*/
if (cachefs_kstat_key != NULL) {
int i;
for (i = 0; i < cachefs_kstat_key_n; i++) {
key = cachefs_kstat_key + i;
}
cachefs_kstat_key_n * sizeof (*cachefs_kstat_key));
}
/*
* Clean up kmem_cache entities
*/
#ifdef CFSRLDEBUG
if (cachefs_rl_debug_cache != NULL)
#endif /* CFSRLDEBUG */
/*
* Clean up the operations structures
*/
(void) vfs_freevfsops_by_type(cachefsfstyp);
/*
* Destroy mutexes
*/
#ifdef CFSRLDEBUG
#endif /* CFSRLDEBUG */
}