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>
|
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");
|
|
|
|
|
|
2001-11-03 03:07:09 +00:00
|
|
|
|
#if PFS_FSNAMELEN != MFSNAMELEN
|
|
|
|
|
#error "PFS_FSNAMELEN is not equal to MFSNAMELEN"
|
|
|
|
|
#endif
|
|
|
|
|
|
2001-10-19 01:43:06 +00:00
|
|
|
|
/*
|
|
|
|
|
* Add a node to a directory
|
|
|
|
|
*/
|
|
|
|
|
static int
|
|
|
|
|
_pfs_add_node(struct pfs_node *parent, struct pfs_node *node)
|
|
|
|
|
{
|
|
|
|
|
KASSERT(parent != NULL,
|
2001-12-10 08:09:49 +00:00
|
|
|
|
("%s(): parent is NULL", __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
|
|
|
|
|
|
|
|
|
/* XXX should check for duplicate names etc. */
|
2002-06-06 16:59:24 +00:00
|
|
|
|
|
2001-10-19 01:43:06 +00:00
|
|
|
|
mtx_lock(&parent->pn_info->pi_mutex);
|
|
|
|
|
node->pn_info = parent->pn_info;
|
|
|
|
|
node->pn_parent = parent;
|
|
|
|
|
node->pn_next = parent->pn_nodes;
|
|
|
|
|
parent->pn_nodes = node;
|
2002-09-14 09:02:28 +00:00
|
|
|
|
/* Propagate flag to all child nodes (and thus their vnodes) */
|
|
|
|
|
if ((parent->pn_flags & PFS_PROCDEP) != 0)
|
|
|
|
|
node->pn_flags |= PFS_PROCDEP;
|
2001-10-19 01:43:06 +00:00
|
|
|
|
mtx_unlock(&parent->pn_info->pi_mutex);
|
2002-06-06 16:59:24 +00:00
|
|
|
|
|
2001-10-19 01:43:06 +00:00
|
|
|
|
return (0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Add . and .. to a directory
|
|
|
|
|
*/
|
|
|
|
|
static int
|
|
|
|
|
_pfs_fixup_dir(struct pfs_node *parent)
|
|
|
|
|
{
|
|
|
|
|
struct pfs_node *dir;
|
2002-06-06 16:59:24 +00:00
|
|
|
|
|
2001-10-19 01:43:06 +00:00
|
|
|
|
MALLOC(dir, struct pfs_node *, sizeof *dir,
|
2003-02-19 05:47:46 +00:00
|
|
|
|
M_PFSNODES, M_WAITOK|M_ZERO);
|
2001-10-19 01:43:06 +00:00
|
|
|
|
dir->pn_name[0] = '.';
|
|
|
|
|
dir->pn_type = pfstype_this;
|
2002-06-06 16:59:24 +00:00
|
|
|
|
|
2001-10-19 01:43:06 +00:00
|
|
|
|
if (_pfs_add_node(parent, dir) != 0) {
|
|
|
|
|
FREE(dir, M_PFSNODES);
|
|
|
|
|
return (-1);
|
|
|
|
|
}
|
2002-06-06 16:59:24 +00:00
|
|
|
|
|
2001-10-19 01:43:06 +00:00
|
|
|
|
MALLOC(dir, struct pfs_node *, sizeof *dir,
|
2003-02-19 05:47:46 +00:00
|
|
|
|
M_PFSNODES, M_WAITOK|M_ZERO);
|
2001-10-19 01:43:06 +00:00
|
|
|
|
dir->pn_name[0] = dir->pn_name[1] = '.';
|
|
|
|
|
dir->pn_type = pfstype_parent;
|
2002-06-06 16:59:24 +00:00
|
|
|
|
|
2001-10-19 01:43:06 +00:00
|
|
|
|
if (_pfs_add_node(parent, dir) != 0) {
|
|
|
|
|
FREE(dir, M_PFSNODES);
|
|
|
|
|
return (-1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 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
|
|
|
|
{
|
|
|
|
|
struct pfs_node *dir;
|
|
|
|
|
|
|
|
|
|
KASSERT(strlen(name) < PFS_NAMELEN,
|
2001-12-10 08:09:49 +00:00
|
|
|
|
("%s(): node name is too long", __func__));
|
2001-10-19 01:43:06 +00:00
|
|
|
|
|
|
|
|
|
MALLOC(dir, struct pfs_node *, sizeof *dir,
|
2003-02-19 05:47:46 +00:00
|
|
|
|
M_PFSNODES, M_WAITOK|M_ZERO);
|
2001-10-19 01:43:06 +00:00
|
|
|
|
strcpy(dir->pn_name, name);
|
|
|
|
|
dir->pn_type = (flags & PFS_PROCDEP) ? pfstype_procdir : pfstype_dir;
|
|
|
|
|
dir->pn_attr = attr;
|
|
|
|
|
dir->pn_vis = vis;
|
2007-03-12 12:16:52 +00:00
|
|
|
|
dir->pn_destroy = destroy;
|
2002-09-14 09:02:28 +00:00
|
|
|
|
dir->pn_flags = flags;
|
2001-10-19 01:43:06 +00:00
|
|
|
|
|
|
|
|
|
if (_pfs_add_node(parent, dir) != 0) {
|
|
|
|
|
FREE(dir, M_PFSNODES);
|
|
|
|
|
return (NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_pfs_fixup_dir(dir) != 0) {
|
|
|
|
|
pfs_destroy(dir);
|
|
|
|
|
return (NULL);
|
|
|
|
|
}
|
2002-06-06 16:59:24 +00:00
|
|
|
|
|
2001-10-19 01:43:06 +00:00
|
|
|
|
return (dir);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 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
|
|
|
|
{
|
|
|
|
|
struct pfs_node *node;
|
|
|
|
|
|
|
|
|
|
KASSERT(strlen(name) < PFS_NAMELEN,
|
2001-12-10 08:09:49 +00:00
|
|
|
|
("%s(): node name is too long", __func__));
|
2001-10-19 01:43:06 +00:00
|
|
|
|
|
|
|
|
|
MALLOC(node, struct pfs_node *, sizeof *node,
|
2003-02-19 05:47:46 +00:00
|
|
|
|
M_PFSNODES, M_WAITOK|M_ZERO);
|
2001-10-19 01:43:06 +00:00
|
|
|
|
strcpy(node->pn_name, name);
|
|
|
|
|
node->pn_type = pfstype_file;
|
|
|
|
|
node->pn_func = fill;
|
|
|
|
|
node->pn_attr = attr;
|
|
|
|
|
node->pn_vis = vis;
|
2007-03-12 12:16:52 +00:00
|
|
|
|
node->pn_destroy = destroy;
|
2001-10-19 01:43:06 +00:00
|
|
|
|
node->pn_flags = flags;
|
|
|
|
|
|
|
|
|
|
if (_pfs_add_node(parent, node) != 0) {
|
|
|
|
|
FREE(node, M_PFSNODES);
|
|
|
|
|
return (NULL);
|
|
|
|
|
}
|
2002-06-06 16:59:24 +00:00
|
|
|
|
|
2001-10-19 01:43:06 +00:00
|
|
|
|
return (node);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 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
|
|
|
|
{
|
|
|
|
|
struct pfs_node *node;
|
|
|
|
|
|
2007-03-12 12:16:52 +00:00
|
|
|
|
node = pfs_create_file(parent, name, fill, attr, vis, destroy, flags);
|
2001-10-19 01:43:06 +00:00
|
|
|
|
if (node == NULL)
|
|
|
|
|
return (NULL);
|
|
|
|
|
node->pn_type = pfstype_symlink;
|
|
|
|
|
return (node);
|
|
|
|
|
}
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
struct pfs_node *node;
|
|
|
|
|
|
|
|
|
|
for (node = parent->pn_nodes; node != NULL; node = node->pn_next)
|
|
|
|
|
if (strcmp(node->pn_name, name) == 0)
|
|
|
|
|
return (node);
|
|
|
|
|
return (NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2001-10-19 01:43:06 +00:00
|
|
|
|
/*
|
|
|
|
|
* Destroy a node or a tree of nodes
|
|
|
|
|
*/
|
|
|
|
|
int
|
|
|
|
|
pfs_destroy(struct pfs_node *node)
|
|
|
|
|
{
|
|
|
|
|
struct pfs_node *parent, *rover;
|
2002-06-06 16:59:24 +00:00
|
|
|
|
|
2001-10-19 01:43:06 +00:00
|
|
|
|
KASSERT(node != NULL,
|
2001-12-10 08:09:49 +00:00
|
|
|
|
("%s(): node is NULL", __func__));
|
2001-10-19 01:43:06 +00:00
|
|
|
|
KASSERT(node->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
|
|
|
|
|
|
|
|
|
/* destroy children */
|
|
|
|
|
if (node->pn_type == pfstype_dir ||
|
|
|
|
|
node->pn_type == pfstype_procdir ||
|
|
|
|
|
node->pn_type == pfstype_root)
|
|
|
|
|
while (node->pn_nodes != NULL)
|
|
|
|
|
pfs_destroy(node->pn_nodes);
|
|
|
|
|
|
|
|
|
|
/* unlink from parent */
|
|
|
|
|
if ((parent = node->pn_parent) != NULL) {
|
|
|
|
|
KASSERT(parent->pn_info == node->pn_info,
|
2001-12-10 08:09:49 +00:00
|
|
|
|
("%s(): parent has different pn_info", __func__));
|
2001-10-19 01:43:06 +00:00
|
|
|
|
mtx_lock(&node->pn_info->pi_mutex);
|
|
|
|
|
if (parent->pn_nodes == node) {
|
|
|
|
|
parent->pn_nodes = node->pn_next;
|
|
|
|
|
} else {
|
|
|
|
|
rover = parent->pn_nodes;
|
|
|
|
|
while (rover->pn_next != NULL) {
|
|
|
|
|
if (rover->pn_next == node) {
|
|
|
|
|
rover->pn_next = node->pn_next;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
rover = rover->pn_next;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
mtx_unlock(&node->pn_info->pi_mutex);
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-12 12:16:52 +00:00
|
|
|
|
/* callback to free any private resources */
|
2007-04-05 13:43:00 +00:00
|
|
|
|
if (node->pn_destroy != NULL)
|
2007-03-12 12:16:52 +00:00
|
|
|
|
(node->pn_destroy)(node);
|
2007-04-05 13:43:00 +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
|
|
|
|
/* revoke fileno and vnodes and release memory */
|
|
|
|
|
if (node->pn_fileno)
|
|
|
|
|
pfs_fileno_free(node->pn_info, node);
|
|
|
|
|
pfs_purge(node);
|
2001-10-19 01:43:06 +00:00
|
|
|
|
FREE(node, M_PFSNODES);
|
|
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
|
}
|
|
|
|
|
|
2001-04-07 19:51:12 +00:00
|
|
|
|
/*
|
|
|
|
|
* Mount a pseudofs instance
|
|
|
|
|
*/
|
|
|
|
|
int
|
2004-07-30 22:08:52 +00:00
|
|
|
|
pfs_mount(struct pfs_info *pi, struct mount *mp, struct thread *td)
|
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
|
|
|
|
#if 0
|
|
|
|
|
/* not quite ready for this yet */
|
|
|
|
|
mp->mnt_kern_flag |= MNTK_MPSAFE;
|
|
|
|
|
#endif
|
|
|
|
|
MNT_IUNLOCK(mp);
|
2001-04-07 19:51:12 +00:00
|
|
|
|
mp->mnt_data = (qaddr_t)pi;
|
|
|
|
|
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
|
|
|
|
/*
|
|
|
|
|
* Compatibility shim for old mount(2) system call.
|
|
|
|
|
*/
|
|
|
|
|
int
|
|
|
|
|
pfs_cmount(struct mntarg *ma, void *data, int flags, struct thread *td)
|
|
|
|
|
{
|
|
|
|
|
return kernel_mount(ma, flags);
|
|
|
|
|
}
|
|
|
|
|
|
2001-04-07 19:51:12 +00:00
|
|
|
|
/*
|
|
|
|
|
* Unmount a pseudofs instance
|
|
|
|
|
*/
|
|
|
|
|
int
|
2001-09-12 08:38:13 +00:00
|
|
|
|
pfs_unmount(struct mount *mp, int mntflags, struct thread *td)
|
2001-04-07 19:51:12 +00:00
|
|
|
|
{
|
|
|
|
|
struct pfs_info *pi;
|
|
|
|
|
int error;
|
|
|
|
|
|
|
|
|
|
pi = (struct pfs_info *)mp->mnt_data;
|
|
|
|
|
|
|
|
|
|
/* XXX do stuff with pi... */
|
2002-06-06 16:59:24 +00:00
|
|
|
|
|
2004-07-12 08:14:09 +00:00
|
|
|
|
error = vflush(mp, 0, (mntflags & MNT_FORCE) ? FORCECLOSE : 0, td);
|
2001-04-07 19:51:12 +00:00
|
|
|
|
return (error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Return a root vnode
|
|
|
|
|
*/
|
|
|
|
|
int
|
2005-03-24 07:36:16 +00:00
|
|
|
|
pfs_root(struct mount *mp, int flags, struct vnode **vpp, struct thread *td)
|
2001-04-07 19:51:12 +00:00
|
|
|
|
{
|
|
|
|
|
struct pfs_info *pi;
|
|
|
|
|
|
|
|
|
|
pi = (struct pfs_info *)mp->mnt_data;
|
2001-06-10 18:39:21 +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
|
2001-09-12 08:38:13 +00:00
|
|
|
|
pfs_statfs(struct mount *mp, struct statfs *sbp, struct thread *td)
|
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;
|
|
|
|
|
|
2002-04-04 21:03:38 +00:00
|
|
|
|
mtx_init(&pi->pi_mutex, "pseudofs", NULL, MTX_DEF);
|
2002-06-06 16:59:24 +00:00
|
|
|
|
|
2001-10-19 01:43:06 +00:00
|
|
|
|
/* set up the root diretory */
|
|
|
|
|
MALLOC(root, struct pfs_node *, sizeof *root,
|
2003-02-19 05:47:46 +00:00
|
|
|
|
M_PFSNODES, M_WAITOK|M_ZERO);
|
2001-10-19 01:43:06 +00:00
|
|
|
|
root->pn_type = pfstype_root;
|
|
|
|
|
root->pn_name[0] = '/';
|
|
|
|
|
root->pn_info = pi;
|
|
|
|
|
if (_pfs_fixup_dir(root) != 0) {
|
|
|
|
|
FREE(root, M_PFSNODES);
|
|
|
|
|
return (ENODEV); /* XXX not really the right errno */
|
|
|
|
|
}
|
|
|
|
|
pi->pi_root = root;
|
|
|
|
|
|
|
|
|
|
/* construct file hierarchy */
|
|
|
|
|
error = (pi->pi_init)(pi, vfc);
|
|
|
|
|
if (error) {
|
|
|
|
|
pfs_destroy(root);
|
|
|
|
|
pi->pi_root = NULL;
|
|
|
|
|
mtx_destroy(&pi->pi_mutex);
|
|
|
|
|
return (error);
|
|
|
|
|
}
|
2002-06-06 16:59:24 +00:00
|
|
|
|
|
2001-04-07 19:51:12 +00:00
|
|
|
|
pfs_fileno_init(pi);
|
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
|
|
|
|
|
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-04-07 19:51:12 +00:00
|
|
|
|
mtx_destroy(&pi->pi_mutex);
|
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);
|