2001-04-07 19:51:12 +00:00
|
|
|
|
/*-
|
|
|
|
|
* Copyright (c) 2001 Dag-Erling Co<EFBFBD>dan Sm<EFBFBD>rgrav
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
|
* are met:
|
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
|
* notice, this list of conditions and the following disclaimer
|
|
|
|
|
* in this position and unchanged.
|
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
|
* 3. The name of the author may not be used to endorse or promote products
|
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
|
*
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
*/
|
|
|
|
|
|
2005-03-14 15:54:11 +00:00
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
|
|
|
|
|
#include "opt_pseudofs.h"
|
|
|
|
|
|
2001-04-07 19:51:12 +00:00
|
|
|
|
#include <sys/param.h>
|
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
|
#include <sys/systm.h>
|
2003-04-29 13:36:06 +00:00
|
|
|
|
#include <sys/limits.h>
|
2001-06-11 15:04:48 +00:00
|
|
|
|
#include <sys/lock.h>
|
2001-04-07 19:51:12 +00:00
|
|
|
|
#include <sys/malloc.h>
|
2001-06-10 10:36:16 +00:00
|
|
|
|
#include <sys/mutex.h>
|
2007-04-14 14:08:30 +00:00
|
|
|
|
#include <sys/proc.h>
|
2001-04-07 19:51:12 +00:00
|
|
|
|
#include <sys/sysctl.h>
|
Add a flag to struct pfs_vdata to mark the vnode as dead (e.g. process-
specific nodes when the process exits)
Move the vnode-cache-walking loop which was duplicated in pfs_exit() and
pfs_disable() into its own function, pfs_purge(), which looks for vnodes
marked as dead and / or belonging to the specified pfs_node and reclaims
them. Note that this loop is still extremely inefficient.
Add a comment in pfs_vncache_alloc() explaining why we have to purge the
vnode from the vnode cache before returning, in case anyone should be
tempted to remove the call to cache_purge().
Move the special handling for pfstype_root nodes into pfs_fileno_alloc()
and pfs_fileno_free() (the root node's fileno must always be 2). This
also fixes a bug where pfs_fileno_free() would reclaim the root node's
fileno, triggering a panic in the unr code, as that fileno was never
allocated from unr to begin with.
When destroying a pfs_node, release its fileno and purge it from the
vnode cache. I wish we could put off the call to pfs_purge() until
after the entire tree had been destroyed, but then we'd have vnodes
referencing freed pfs nodes. This probably doesn't matter while we're
still under Giant, but might become an issue later.
When destroying a pseudofs instance, destroy the tree before tearing
down the fileno allocator.
In pfs_mount(), acquire the mountpoint interlock when required.
MFC after: 3 weeks
2007-04-11 22:40:57 +00:00
|
|
|
|
#include <sys/systm.h>
|
2001-04-07 19:51:12 +00:00
|
|
|
|
|
|
|
|
|
#include <fs/pseudofs/pseudofs.h>
|
|
|
|
|
#include <fs/pseudofs/pseudofs_internal.h>
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Initialize fileno bitmap
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
pfs_fileno_init(struct pfs_info *pi)
|
|
|
|
|
{
|
|
|
|
|
|
2007-04-14 14:08:30 +00:00
|
|
|
|
mtx_assert(&Giant, MA_OWNED);
|
|
|
|
|
mtx_init(&pi->pi_mutex, "pfs_fileno", NULL, MTX_DEF);
|
|
|
|
|
pi->pi_unrhdr = new_unrhdr(3, INT_MAX / NO_PID, &pi->pi_mutex);
|
2001-04-07 19:51:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Tear down fileno bitmap
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
pfs_fileno_uninit(struct pfs_info *pi)
|
|
|
|
|
{
|
|
|
|
|
|
2007-04-14 14:08:30 +00:00
|
|
|
|
mtx_assert(&Giant, MA_OWNED);
|
|
|
|
|
delete_unrhdr(pi->pi_unrhdr);
|
2005-03-19 08:22:36 +00:00
|
|
|
|
pi->pi_unrhdr = NULL;
|
2007-04-14 14:08:30 +00:00
|
|
|
|
mtx_destroy(&pi->pi_mutex);
|
2001-04-07 19:51:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Allocate a file number
|
|
|
|
|
*/
|
|
|
|
|
void
|
2007-04-14 14:08:30 +00:00
|
|
|
|
pfs_fileno_alloc(struct pfs_node *pn)
|
2001-04-07 19:51:12 +00:00
|
|
|
|
{
|
Add a flag to struct pfs_vdata to mark the vnode as dead (e.g. process-
specific nodes when the process exits)
Move the vnode-cache-walking loop which was duplicated in pfs_exit() and
pfs_disable() into its own function, pfs_purge(), which looks for vnodes
marked as dead and / or belonging to the specified pfs_node and reclaims
them. Note that this loop is still extremely inefficient.
Add a comment in pfs_vncache_alloc() explaining why we have to purge the
vnode from the vnode cache before returning, in case anyone should be
tempted to remove the call to cache_purge().
Move the special handling for pfstype_root nodes into pfs_fileno_alloc()
and pfs_fileno_free() (the root node's fileno must always be 2). This
also fixes a bug where pfs_fileno_free() would reclaim the root node's
fileno, triggering a panic in the unr code, as that fileno was never
allocated from unr to begin with.
When destroying a pfs_node, release its fileno and purge it from the
vnode cache. I wish we could put off the call to pfs_purge() until
after the entire tree had been destroyed, but then we'd have vnodes
referencing freed pfs nodes. This probably doesn't matter while we're
still under Giant, but might become an issue later.
When destroying a pseudofs instance, destroy the tree before tearing
down the fileno allocator.
In pfs_mount(), acquire the mountpoint interlock when required.
MFC after: 3 weeks
2007-04-11 22:40:57 +00:00
|
|
|
|
|
2007-04-15 17:10:01 +00:00
|
|
|
|
if (pn->pn_parent)
|
|
|
|
|
PFS_TRACE(("%s/%s", pn->pn_parent->pn_name, pn->pn_name));
|
|
|
|
|
else
|
|
|
|
|
PFS_TRACE(("%s", pn->pn_name));
|
|
|
|
|
pfs_assert_not_owned(pn);
|
2002-06-06 16:59:24 +00:00
|
|
|
|
|
2001-04-07 19:51:12 +00:00
|
|
|
|
switch (pn->pn_type) {
|
|
|
|
|
case pfstype_root:
|
Add a flag to struct pfs_vdata to mark the vnode as dead (e.g. process-
specific nodes when the process exits)
Move the vnode-cache-walking loop which was duplicated in pfs_exit() and
pfs_disable() into its own function, pfs_purge(), which looks for vnodes
marked as dead and / or belonging to the specified pfs_node and reclaims
them. Note that this loop is still extremely inefficient.
Add a comment in pfs_vncache_alloc() explaining why we have to purge the
vnode from the vnode cache before returning, in case anyone should be
tempted to remove the call to cache_purge().
Move the special handling for pfstype_root nodes into pfs_fileno_alloc()
and pfs_fileno_free() (the root node's fileno must always be 2). This
also fixes a bug where pfs_fileno_free() would reclaim the root node's
fileno, triggering a panic in the unr code, as that fileno was never
allocated from unr to begin with.
When destroying a pfs_node, release its fileno and purge it from the
vnode cache. I wish we could put off the call to pfs_purge() until
after the entire tree had been destroyed, but then we'd have vnodes
referencing freed pfs nodes. This probably doesn't matter while we're
still under Giant, but might become an issue later.
When destroying a pseudofs instance, destroy the tree before tearing
down the fileno allocator.
In pfs_mount(), acquire the mountpoint interlock when required.
MFC after: 3 weeks
2007-04-11 22:40:57 +00:00
|
|
|
|
/* root must always be 2 */
|
|
|
|
|
pn->pn_fileno = 2;
|
|
|
|
|
break;
|
2001-04-07 19:51:12 +00:00
|
|
|
|
case pfstype_dir:
|
|
|
|
|
case pfstype_file:
|
|
|
|
|
case pfstype_symlink:
|
2001-06-10 18:39:21 +00:00
|
|
|
|
case pfstype_procdir:
|
2007-04-14 14:08:30 +00:00
|
|
|
|
pn->pn_fileno = alloc_unr(pn->pn_info->pi_unrhdr);
|
2001-04-07 19:51:12 +00:00
|
|
|
|
break;
|
|
|
|
|
case pfstype_this:
|
|
|
|
|
KASSERT(pn->pn_parent != NULL,
|
2007-04-15 17:10:01 +00:00
|
|
|
|
("%s(): pfstype_this node has no parent", __func__));
|
2001-04-07 19:51:12 +00:00
|
|
|
|
pn->pn_fileno = pn->pn_parent->pn_fileno;
|
|
|
|
|
break;
|
|
|
|
|
case pfstype_parent:
|
|
|
|
|
KASSERT(pn->pn_parent != NULL,
|
2007-04-15 17:10:01 +00:00
|
|
|
|
("%s(): pfstype_parent node has no parent", __func__));
|
|
|
|
|
if (pn->pn_parent->pn_type == pfstype_root) {
|
2001-04-07 19:51:12 +00:00
|
|
|
|
pn->pn_fileno = pn->pn_parent->pn_fileno;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
KASSERT(pn->pn_parent->pn_parent != NULL,
|
2007-04-15 17:10:01 +00:00
|
|
|
|
("%s(): pfstype_parent node has no grandparent", __func__));
|
2001-04-07 19:51:12 +00:00
|
|
|
|
pn->pn_fileno = pn->pn_parent->pn_parent->pn_fileno;
|
|
|
|
|
break;
|
|
|
|
|
case pfstype_none:
|
2001-06-10 18:39:21 +00:00
|
|
|
|
KASSERT(0,
|
2007-04-15 17:10:01 +00:00
|
|
|
|
("%s(): pfstype_none node", __func__));
|
2001-04-07 19:51:12 +00:00
|
|
|
|
break;
|
2002-06-06 16:59:24 +00:00
|
|
|
|
}
|
2001-06-10 18:39:21 +00:00
|
|
|
|
|
|
|
|
|
#if 0
|
2007-04-15 17:10:01 +00:00
|
|
|
|
printf("%s(): %s: ", __func__, pn->pn_info->pi_name);
|
2001-04-07 19:51:12 +00:00
|
|
|
|
if (pn->pn_parent) {
|
|
|
|
|
if (pn->pn_parent->pn_parent) {
|
|
|
|
|
printf("%s/", pn->pn_parent->pn_parent->pn_name);
|
|
|
|
|
}
|
|
|
|
|
printf("%s/", pn->pn_parent->pn_name);
|
|
|
|
|
}
|
|
|
|
|
printf("%s -> %d\n", pn->pn_name, pn->pn_fileno);
|
2001-06-10 18:39:21 +00:00
|
|
|
|
#endif
|
2001-04-07 19:51:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Release a file number
|
|
|
|
|
*/
|
|
|
|
|
void
|
2007-04-14 14:08:30 +00:00
|
|
|
|
pfs_fileno_free(struct pfs_node *pn)
|
2001-04-07 19:51:12 +00:00
|
|
|
|
{
|
Add a flag to struct pfs_vdata to mark the vnode as dead (e.g. process-
specific nodes when the process exits)
Move the vnode-cache-walking loop which was duplicated in pfs_exit() and
pfs_disable() into its own function, pfs_purge(), which looks for vnodes
marked as dead and / or belonging to the specified pfs_node and reclaims
them. Note that this loop is still extremely inefficient.
Add a comment in pfs_vncache_alloc() explaining why we have to purge the
vnode from the vnode cache before returning, in case anyone should be
tempted to remove the call to cache_purge().
Move the special handling for pfstype_root nodes into pfs_fileno_alloc()
and pfs_fileno_free() (the root node's fileno must always be 2). This
also fixes a bug where pfs_fileno_free() would reclaim the root node's
fileno, triggering a panic in the unr code, as that fileno was never
allocated from unr to begin with.
When destroying a pfs_node, release its fileno and purge it from the
vnode cache. I wish we could put off the call to pfs_purge() until
after the entire tree had been destroyed, but then we'd have vnodes
referencing freed pfs nodes. This probably doesn't matter while we're
still under Giant, but might become an issue later.
When destroying a pseudofs instance, destroy the tree before tearing
down the fileno allocator.
In pfs_mount(), acquire the mountpoint interlock when required.
MFC after: 3 weeks
2007-04-11 22:40:57 +00:00
|
|
|
|
|
2007-04-15 17:10:01 +00:00
|
|
|
|
pfs_assert_not_owned(pn);
|
|
|
|
|
|
2001-04-07 19:51:12 +00:00
|
|
|
|
switch (pn->pn_type) {
|
|
|
|
|
case pfstype_root:
|
Add a flag to struct pfs_vdata to mark the vnode as dead (e.g. process-
specific nodes when the process exits)
Move the vnode-cache-walking loop which was duplicated in pfs_exit() and
pfs_disable() into its own function, pfs_purge(), which looks for vnodes
marked as dead and / or belonging to the specified pfs_node and reclaims
them. Note that this loop is still extremely inefficient.
Add a comment in pfs_vncache_alloc() explaining why we have to purge the
vnode from the vnode cache before returning, in case anyone should be
tempted to remove the call to cache_purge().
Move the special handling for pfstype_root nodes into pfs_fileno_alloc()
and pfs_fileno_free() (the root node's fileno must always be 2). This
also fixes a bug where pfs_fileno_free() would reclaim the root node's
fileno, triggering a panic in the unr code, as that fileno was never
allocated from unr to begin with.
When destroying a pfs_node, release its fileno and purge it from the
vnode cache. I wish we could put off the call to pfs_purge() until
after the entire tree had been destroyed, but then we'd have vnodes
referencing freed pfs nodes. This probably doesn't matter while we're
still under Giant, but might become an issue later.
When destroying a pseudofs instance, destroy the tree before tearing
down the fileno allocator.
In pfs_mount(), acquire the mountpoint interlock when required.
MFC after: 3 weeks
2007-04-11 22:40:57 +00:00
|
|
|
|
/* not allocated from unrhdr */
|
|
|
|
|
return;
|
2001-04-07 19:51:12 +00:00
|
|
|
|
case pfstype_dir:
|
|
|
|
|
case pfstype_file:
|
|
|
|
|
case pfstype_symlink:
|
2001-06-10 18:39:21 +00:00
|
|
|
|
case pfstype_procdir:
|
2007-04-14 14:08:30 +00:00
|
|
|
|
free_unr(pn->pn_info->pi_unrhdr, pn->pn_fileno);
|
2001-04-07 19:51:12 +00:00
|
|
|
|
break;
|
|
|
|
|
case pfstype_this:
|
|
|
|
|
case pfstype_parent:
|
|
|
|
|
/* ignore these, as they don't "own" their file number */
|
|
|
|
|
break;
|
|
|
|
|
case pfstype_none:
|
2001-06-10 18:39:21 +00:00
|
|
|
|
KASSERT(0,
|
2001-04-07 19:51:12 +00:00
|
|
|
|
("pfs_fileno_free() called for pfstype_none node"));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|