2001-04-07 19:51:12 +00:00
|
|
|
/*-
|
2012-01-15 13:23:18 +00:00
|
|
|
* Copyright (c) 2001 Dag-Erling Coïdan Smørgrav
|
2001-04-07 19:51:12 +00:00
|
|
|
* 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>
|
2001-10-11 17:52:20 +00:00
|
|
|
#include <sys/lock.h>
|
2001-04-07 19:51:12 +00:00
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/module.h>
|
|
|
|
#include <sys/mount.h>
|
2001-06-10 10:36:16 +00:00
|
|
|
#include <sys/mutex.h>
|
2001-04-07 19:51:12 +00:00
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/sbuf.h>
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <sys/vnode.h>
|
|
|
|
|
|
|
|
#include <fs/pseudofs/pseudofs.h>
|
|
|
|
#include <fs/pseudofs/pseudofs_internal.h>
|
|
|
|
|
2001-10-19 01:43:06 +00:00
|
|
|
static MALLOC_DEFINE(M_PFSNODES, "pfs_nodes", "pseudofs nodes");
|
|
|
|
|
2001-04-07 19:51:12 +00:00
|
|
|
SYSCTL_NODE(_vfs, OID_AUTO, pfs, CTLFLAG_RW, 0,
|
|
|
|
"pseudofs");
|
|
|
|
|
2007-04-15 17:10:01 +00:00
|
|
|
int pfs_trace;
|
|
|
|
SYSCTL_INT(_vfs_pfs, OID_AUTO, trace, CTLFLAG_RW, &pfs_trace, 0,
|
|
|
|
"enable tracing of pseudofs vnode operations");
|
|
|
|
|
2001-11-03 03:07:09 +00:00
|
|
|
#if PFS_FSNAMELEN != MFSNAMELEN
|
|
|
|
#error "PFS_FSNAMELEN is not equal to MFSNAMELEN"
|
|
|
|
#endif
|
|
|
|
|
2007-04-15 17:10:01 +00:00
|
|
|
/*
|
|
|
|
* Allocate and initialize a node
|
|
|
|
*/
|
|
|
|
static struct pfs_node *
|
|
|
|
pfs_alloc_node(struct pfs_info *pi, const char *name, pfs_type_t type)
|
|
|
|
{
|
|
|
|
struct pfs_node *pn;
|
|
|
|
|
|
|
|
KASSERT(strlen(name) < PFS_NAMELEN,
|
|
|
|
("%s(): node name is too long", __func__));
|
|
|
|
|
2008-10-23 15:53:51 +00:00
|
|
|
pn = malloc(sizeof *pn,
|
2007-04-15 17:10:01 +00:00
|
|
|
M_PFSNODES, M_WAITOK|M_ZERO);
|
|
|
|
mtx_init(&pn->pn_mutex, "pfs_node", NULL, MTX_DEF | MTX_DUPOK);
|
|
|
|
strlcpy(pn->pn_name, name, sizeof pn->pn_name);
|
|
|
|
pn->pn_type = type;
|
|
|
|
pn->pn_info = pi;
|
|
|
|
return (pn);
|
|
|
|
}
|
|
|
|
|
2001-10-19 01:43:06 +00:00
|
|
|
/*
|
|
|
|
* Add a node to a directory
|
|
|
|
*/
|
2007-04-15 17:10:01 +00:00
|
|
|
static void
|
|
|
|
pfs_add_node(struct pfs_node *parent, struct pfs_node *pn)
|
2001-10-19 01:43:06 +00:00
|
|
|
{
|
2007-04-15 17:10:01 +00:00
|
|
|
#ifdef INVARIANTS
|
|
|
|
struct pfs_node *iter;
|
|
|
|
#endif
|
|
|
|
|
2001-10-19 01:43:06 +00:00
|
|
|
KASSERT(parent != NULL,
|
2001-12-10 08:09:49 +00:00
|
|
|
("%s(): parent is NULL", __func__));
|
2007-04-15 17:10:01 +00:00
|
|
|
KASSERT(pn->pn_parent == NULL,
|
|
|
|
("%s(): node already has a parent", __func__));
|
2001-10-19 01:43:06 +00:00
|
|
|
KASSERT(parent->pn_info != NULL,
|
2001-12-10 08:09:49 +00:00
|
|
|
("%s(): parent has no pn_info", __func__));
|
2001-10-19 01:43:06 +00:00
|
|
|
KASSERT(parent->pn_type == pfstype_dir ||
|
|
|
|
parent->pn_type == pfstype_procdir ||
|
|
|
|
parent->pn_type == pfstype_root,
|
2001-12-10 08:09:49 +00:00
|
|
|
("%s(): parent is not a directory", __func__));
|
2001-10-19 01:43:06 +00:00
|
|
|
|
2007-04-15 17:10:01 +00:00
|
|
|
#ifdef INVARIANTS
|
|
|
|
/* XXX no locking! */
|
|
|
|
if (pn->pn_type == pfstype_procdir)
|
|
|
|
for (iter = parent; iter != NULL; iter = iter->pn_parent)
|
|
|
|
KASSERT(iter->pn_type != pfstype_procdir,
|
|
|
|
("%s(): nested process directories", __func__));
|
|
|
|
for (iter = parent->pn_nodes; iter != NULL; iter = iter->pn_next) {
|
|
|
|
KASSERT(strcmp(pn->pn_name, iter->pn_name) != 0,
|
|
|
|
("%s(): homonymous siblings", __func__));
|
|
|
|
if (pn->pn_type == pfstype_procdir)
|
|
|
|
KASSERT(iter->pn_type != pfstype_procdir,
|
|
|
|
("%s(): sibling process directories", __func__));
|
|
|
|
}
|
|
|
|
#endif
|
2002-06-06 16:59:24 +00:00
|
|
|
|
2007-04-15 17:10:01 +00:00
|
|
|
pn->pn_parent = parent;
|
|
|
|
pfs_fileno_alloc(pn);
|
2002-06-06 16:59:24 +00:00
|
|
|
|
2007-04-15 17:10:01 +00:00
|
|
|
pfs_lock(parent);
|
|
|
|
pn->pn_next = parent->pn_nodes;
|
|
|
|
if ((parent->pn_flags & PFS_PROCDEP) != 0)
|
|
|
|
pn->pn_flags |= PFS_PROCDEP;
|
|
|
|
parent->pn_nodes = pn;
|
|
|
|
pfs_unlock(parent);
|
2001-10-19 01:43:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-04-15 17:10:01 +00:00
|
|
|
* Detach a node from its aprent
|
2001-10-19 01:43:06 +00:00
|
|
|
*/
|
2007-04-15 17:10:01 +00:00
|
|
|
static void
|
|
|
|
pfs_detach_node(struct pfs_node *pn)
|
2001-10-19 01:43:06 +00:00
|
|
|
{
|
2007-04-15 17:10:01 +00:00
|
|
|
struct pfs_node *parent = pn->pn_parent;
|
|
|
|
struct pfs_node **iter;
|
|
|
|
|
|
|
|
KASSERT(parent != NULL, ("%s(): node has no parent", __func__));
|
|
|
|
KASSERT(parent->pn_info == pn->pn_info,
|
|
|
|
("%s(): parent has different pn_info", __func__));
|
|
|
|
|
|
|
|
pfs_lock(parent);
|
|
|
|
iter = &parent->pn_nodes;
|
|
|
|
while (*iter != NULL) {
|
|
|
|
if (*iter == pn) {
|
|
|
|
*iter = pn->pn_next;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
iter = &(*iter)->pn_next;
|
2001-10-19 01:43:06 +00:00
|
|
|
}
|
2007-04-15 17:10:01 +00:00
|
|
|
pn->pn_parent = NULL;
|
|
|
|
pfs_unlock(parent);
|
|
|
|
}
|
2002-06-06 16:59:24 +00:00
|
|
|
|
2007-04-15 17:10:01 +00:00
|
|
|
/*
|
|
|
|
* Add . and .. to a directory
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
pfs_fixup_dir(struct pfs_node *parent)
|
|
|
|
{
|
|
|
|
struct pfs_node *pn;
|
2001-10-19 01:43:06 +00:00
|
|
|
|
2007-04-15 17:10:01 +00:00
|
|
|
pn = pfs_alloc_node(parent->pn_info, ".", pfstype_this);
|
|
|
|
pfs_add_node(parent, pn);
|
|
|
|
pn = pfs_alloc_node(parent->pn_info, "..", pfstype_parent);
|
|
|
|
pfs_add_node(parent, pn);
|
2001-10-19 01:43:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a directory
|
|
|
|
*/
|
|
|
|
struct pfs_node *
|
2003-12-07 17:41:19 +00:00
|
|
|
pfs_create_dir(struct pfs_node *parent, const char *name,
|
2007-03-12 12:16:52 +00:00
|
|
|
pfs_attr_t attr, pfs_vis_t vis, pfs_destroy_t destroy,
|
|
|
|
int flags)
|
2001-10-19 01:43:06 +00:00
|
|
|
{
|
2007-04-15 17:10:01 +00:00
|
|
|
struct pfs_node *pn;
|
|
|
|
|
|
|
|
pn = pfs_alloc_node(parent->pn_info, name,
|
|
|
|
(flags & PFS_PROCDEP) ? pfstype_procdir : pfstype_dir);
|
|
|
|
pn->pn_attr = attr;
|
|
|
|
pn->pn_vis = vis;
|
|
|
|
pn->pn_destroy = destroy;
|
|
|
|
pn->pn_flags = flags;
|
|
|
|
pfs_add_node(parent, pn);
|
|
|
|
pfs_fixup_dir(pn);
|
|
|
|
|
|
|
|
return (pn);
|
2001-10-19 01:43:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a file
|
|
|
|
*/
|
|
|
|
struct pfs_node *
|
2003-12-07 17:41:19 +00:00
|
|
|
pfs_create_file(struct pfs_node *parent, const char *name, pfs_fill_t fill,
|
2007-03-12 12:16:52 +00:00
|
|
|
pfs_attr_t attr, pfs_vis_t vis, pfs_destroy_t destroy,
|
|
|
|
int flags)
|
2001-10-19 01:43:06 +00:00
|
|
|
{
|
2007-04-15 17:10:01 +00:00
|
|
|
struct pfs_node *pn;
|
2001-10-19 01:43:06 +00:00
|
|
|
|
2007-04-15 17:10:01 +00:00
|
|
|
pn = pfs_alloc_node(parent->pn_info, name, pfstype_file);
|
|
|
|
pn->pn_fill = fill;
|
|
|
|
pn->pn_attr = attr;
|
|
|
|
pn->pn_vis = vis;
|
|
|
|
pn->pn_destroy = destroy;
|
|
|
|
pn->pn_flags = flags;
|
|
|
|
pfs_add_node(parent, pn);
|
2002-06-06 16:59:24 +00:00
|
|
|
|
2007-04-15 17:10:01 +00:00
|
|
|
return (pn);
|
2001-10-19 01:43:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a symlink
|
|
|
|
*/
|
|
|
|
struct pfs_node *
|
2003-12-07 17:41:19 +00:00
|
|
|
pfs_create_link(struct pfs_node *parent, const char *name, pfs_fill_t fill,
|
2007-04-05 13:43:00 +00:00
|
|
|
pfs_attr_t attr, pfs_vis_t vis, pfs_destroy_t destroy,
|
2007-03-12 12:16:52 +00:00
|
|
|
int flags)
|
2001-10-19 01:43:06 +00:00
|
|
|
{
|
2007-04-15 17:10:01 +00:00
|
|
|
struct pfs_node *pn;
|
2001-10-19 01:43:06 +00:00
|
|
|
|
2007-04-15 17:10:01 +00:00
|
|
|
pn = pfs_alloc_node(parent->pn_info, name, pfstype_symlink);
|
|
|
|
pn->pn_fill = fill;
|
|
|
|
pn->pn_attr = attr;
|
|
|
|
pn->pn_vis = vis;
|
|
|
|
pn->pn_destroy = destroy;
|
|
|
|
pn->pn_flags = flags;
|
|
|
|
pfs_add_node(parent, pn);
|
|
|
|
|
|
|
|
return (pn);
|
2001-10-19 01:43:06 +00:00
|
|
|
}
|
|
|
|
|
2003-12-07 17:41:19 +00:00
|
|
|
/*
|
|
|
|
* Locate a node by name
|
|
|
|
*/
|
|
|
|
struct pfs_node *
|
|
|
|
pfs_find_node(struct pfs_node *parent, const char *name)
|
|
|
|
{
|
2007-04-15 17:10:01 +00:00
|
|
|
struct pfs_node *pn;
|
2003-12-07 17:41:19 +00:00
|
|
|
|
2007-04-15 17:10:01 +00:00
|
|
|
pfs_lock(parent);
|
|
|
|
for (pn = parent->pn_nodes; pn != NULL; pn = pn->pn_next)
|
|
|
|
if (strcmp(pn->pn_name, name) == 0)
|
2007-04-14 14:08:30 +00:00
|
|
|
break;
|
2007-04-15 17:10:01 +00:00
|
|
|
pfs_unlock(parent);
|
|
|
|
return (pn);
|
2003-12-07 17:41:19 +00:00
|
|
|
}
|
|
|
|
|
2001-10-19 01:43:06 +00:00
|
|
|
/*
|
2007-04-15 17:10:01 +00:00
|
|
|
* Destroy a node and all its descendants. If the node to be destroyed
|
|
|
|
* has a parent, the parent's mutex must be held.
|
2001-10-19 01:43:06 +00:00
|
|
|
*/
|
|
|
|
int
|
2007-04-15 17:10:01 +00:00
|
|
|
pfs_destroy(struct pfs_node *pn)
|
2001-10-19 01:43:06 +00:00
|
|
|
{
|
2007-04-15 17:10:01 +00:00
|
|
|
struct pfs_node *iter;
|
2002-06-06 16:59:24 +00:00
|
|
|
|
2007-04-15 17:10:01 +00:00
|
|
|
KASSERT(pn != NULL,
|
2001-12-10 08:09:49 +00:00
|
|
|
("%s(): node is NULL", __func__));
|
2007-04-15 17:10:01 +00:00
|
|
|
KASSERT(pn->pn_info != NULL,
|
2001-12-10 08:09:49 +00:00
|
|
|
("%s(): node has no pn_info", __func__));
|
2001-10-19 01:43:06 +00:00
|
|
|
|
2007-04-15 17:10:01 +00:00
|
|
|
if (pn->pn_parent)
|
|
|
|
pfs_detach_node(pn);
|
|
|
|
|
2001-10-19 01:43:06 +00:00
|
|
|
/* destroy children */
|
2007-04-15 17:10:01 +00:00
|
|
|
if (pn->pn_type == pfstype_dir ||
|
|
|
|
pn->pn_type == pfstype_procdir ||
|
|
|
|
pn->pn_type == pfstype_root) {
|
|
|
|
pfs_lock(pn);
|
|
|
|
while (pn->pn_nodes != NULL) {
|
|
|
|
iter = pn->pn_nodes;
|
|
|
|
pn->pn_nodes = iter->pn_next;
|
|
|
|
iter->pn_parent = NULL;
|
|
|
|
pfs_unlock(pn);
|
|
|
|
pfs_destroy(iter);
|
|
|
|
pfs_lock(pn);
|
2001-10-19 01:43:06 +00:00
|
|
|
}
|
2007-04-15 17:10:01 +00:00
|
|
|
pfs_unlock(pn);
|
2001-10-19 01:43:06 +00:00
|
|
|
}
|
|
|
|
|
2007-04-15 17:10:01 +00:00
|
|
|
/* revoke vnodes and fileno */
|
|
|
|
pfs_purge(pn);
|
|
|
|
|
2007-03-12 12:16:52 +00:00
|
|
|
/* callback to free any private resources */
|
2007-04-15 17:10:01 +00:00
|
|
|
if (pn->pn_destroy != NULL)
|
|
|
|
pn_destroy(pn);
|
2007-04-05 13:43:00 +00:00
|
|
|
|
2007-04-15 17:10:01 +00:00
|
|
|
/* destroy the node */
|
|
|
|
pfs_fileno_free(pn);
|
|
|
|
mtx_destroy(&pn->pn_mutex);
|
2008-10-23 15:53:51 +00:00
|
|
|
free(pn, M_PFSNODES);
|
2001-10-19 01:43:06 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2001-04-07 19:51:12 +00:00
|
|
|
/*
|
|
|
|
* Mount a pseudofs instance
|
|
|
|
*/
|
|
|
|
int
|
2009-05-11 15:33:26 +00:00
|
|
|
pfs_mount(struct pfs_info *pi, struct mount *mp)
|
2001-04-07 19:51:12 +00:00
|
|
|
{
|
|
|
|
struct statfs *sbp;
|
2002-06-06 16:59:24 +00:00
|
|
|
|
2001-04-07 19:51:12 +00:00
|
|
|
if (mp->mnt_flag & MNT_UPDATE)
|
|
|
|
return (EOPNOTSUPP);
|
2002-06-06 16:59:24 +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
|
|
|
MNT_ILOCK(mp);
|
2001-04-07 19:51:12 +00:00
|
|
|
mp->mnt_flag |= MNT_LOCAL;
|
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
|
|
|
MNT_IUNLOCK(mp);
|
2007-10-16 10:54:55 +00:00
|
|
|
mp->mnt_data = pi;
|
2001-04-07 19:51:12 +00:00
|
|
|
vfs_getnewfsid(mp);
|
|
|
|
|
|
|
|
sbp = &mp->mnt_stat;
|
2004-12-06 20:52:46 +00:00
|
|
|
vfs_mountedfrom(mp, pi->pi_name);
|
2001-04-07 19:51:12 +00:00
|
|
|
sbp->f_bsize = PAGE_SIZE;
|
|
|
|
sbp->f_iosize = PAGE_SIZE;
|
|
|
|
sbp->f_blocks = 1;
|
|
|
|
sbp->f_bfree = 0;
|
|
|
|
sbp->f_bavail = 0;
|
|
|
|
sbp->f_files = 1;
|
|
|
|
sbp->f_ffree = 0;
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2006-05-15 19:42:10 +00:00
|
|
|
/*
|
2007-04-15 17:10:01 +00:00
|
|
|
* Compatibility shim for old mount(2) system call
|
2006-05-15 19:42:10 +00:00
|
|
|
*/
|
|
|
|
int
|
2012-01-17 01:08:01 +00:00
|
|
|
pfs_cmount(struct mntarg *ma, void *data, uint64_t flags)
|
2006-05-15 19:42:10 +00:00
|
|
|
{
|
2007-04-15 17:10:01 +00:00
|
|
|
int error;
|
|
|
|
|
|
|
|
error = kernel_mount(ma, flags);
|
|
|
|
return (error);
|
2006-05-15 19:42:10 +00:00
|
|
|
}
|
|
|
|
|
2001-04-07 19:51:12 +00:00
|
|
|
/*
|
|
|
|
* Unmount a pseudofs instance
|
|
|
|
*/
|
|
|
|
int
|
2009-05-11 15:33:26 +00:00
|
|
|
pfs_unmount(struct mount *mp, int mntflags)
|
2001-04-07 19:51:12 +00:00
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
2009-05-11 15:33:26 +00:00
|
|
|
error = vflush(mp, 0, (mntflags & MNT_FORCE) ? FORCECLOSE : 0,
|
|
|
|
curthread);
|
2001-04-07 19:51:12 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return a root vnode
|
|
|
|
*/
|
|
|
|
int
|
2009-05-11 15:33:26 +00:00
|
|
|
pfs_root(struct mount *mp, int flags, struct vnode **vpp)
|
2001-04-07 19:51:12 +00:00
|
|
|
{
|
|
|
|
struct pfs_info *pi;
|
|
|
|
|
|
|
|
pi = (struct pfs_info *)mp->mnt_data;
|
2007-04-15 17:10:01 +00:00
|
|
|
return (pfs_vncache_alloc(mp, vpp, pi->pi_root, NO_PID));
|
2001-04-07 19:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return filesystem stats
|
|
|
|
*/
|
|
|
|
int
|
2009-05-11 15:33:26 +00:00
|
|
|
pfs_statfs(struct mount *mp, struct statfs *sbp)
|
2001-04-07 19:51:12 +00:00
|
|
|
{
|
2004-12-06 20:52:46 +00:00
|
|
|
/* no-op: always called with mp->mnt_stat */
|
2001-04-07 19:51:12 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize a pseudofs instance
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
pfs_init(struct pfs_info *pi, struct vfsconf *vfc)
|
|
|
|
{
|
2001-10-19 01:43:06 +00:00
|
|
|
struct pfs_node *root;
|
|
|
|
int error;
|
|
|
|
|
2007-04-14 14:08:30 +00:00
|
|
|
mtx_assert(&Giant, MA_OWNED);
|
2002-06-06 16:59:24 +00:00
|
|
|
|
2007-04-15 17:10:01 +00:00
|
|
|
pfs_fileno_init(pi);
|
|
|
|
|
2001-10-19 01:43:06 +00:00
|
|
|
/* set up the root diretory */
|
2007-04-15 17:10:01 +00:00
|
|
|
root = pfs_alloc_node(pi, "/", pfstype_root);
|
2001-10-19 01:43:06 +00:00
|
|
|
pi->pi_root = root;
|
2007-04-15 17:10:01 +00:00
|
|
|
pfs_fileno_alloc(root);
|
|
|
|
pfs_fixup_dir(root);
|
2001-10-19 01:43:06 +00:00
|
|
|
|
|
|
|
/* construct file hierarchy */
|
|
|
|
error = (pi->pi_init)(pi, vfc);
|
|
|
|
if (error) {
|
|
|
|
pfs_destroy(root);
|
|
|
|
pi->pi_root = NULL;
|
|
|
|
return (error);
|
|
|
|
}
|
2002-06-06 16:59:24 +00:00
|
|
|
|
2001-10-02 22:21:07 +00:00
|
|
|
if (bootverbose)
|
|
|
|
printf("%s registered\n", pi->pi_name);
|
2001-04-07 19:51:12 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Destroy a pseudofs instance
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
pfs_uninit(struct pfs_info *pi, struct vfsconf *vfc)
|
|
|
|
{
|
2001-10-19 01:43:06 +00:00
|
|
|
int error;
|
2002-06-06 16:59:24 +00:00
|
|
|
|
2007-04-14 14:08:30 +00:00
|
|
|
mtx_assert(&Giant, MA_OWNED);
|
|
|
|
|
2001-10-19 01:43:06 +00:00
|
|
|
pfs_destroy(pi->pi_root);
|
|
|
|
pi->pi_root = NULL;
|
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
|
|
|
pfs_fileno_uninit(pi);
|
2001-10-02 22:21:07 +00:00
|
|
|
if (bootverbose)
|
|
|
|
printf("%s unregistered\n", pi->pi_name);
|
2001-10-19 01:43:06 +00:00
|
|
|
error = (pi->pi_uninit)(pi, vfc);
|
|
|
|
return (error);
|
2001-04-07 19:51:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle load / unload events
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
pfs_modevent(module_t mod, int evt, void *arg)
|
|
|
|
{
|
|
|
|
switch (evt) {
|
|
|
|
case MOD_LOAD:
|
|
|
|
pfs_vncache_load();
|
|
|
|
break;
|
|
|
|
case MOD_UNLOAD:
|
|
|
|
case MOD_SHUTDOWN:
|
|
|
|
pfs_vncache_unload();
|
|
|
|
break;
|
|
|
|
default:
|
2004-07-15 08:26:07 +00:00
|
|
|
return EOPNOTSUPP;
|
2001-04-07 19:51:12 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Module declaration
|
|
|
|
*/
|
|
|
|
static moduledata_t pseudofs_data = {
|
|
|
|
"pseudofs",
|
|
|
|
pfs_modevent,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
DECLARE_MODULE(pseudofs, pseudofs_data, SI_SUB_EXEC, SI_ORDER_FIRST);
|
2001-11-27 13:26:27 +00:00
|
|
|
MODULE_VERSION(pseudofs, 1);
|