summaryrefslogtreecommitdiffstats
path: root/sys/fs/pseudofs/pseudofs.c
diff options
context:
space:
mode:
authordes <des@FreeBSD.org>2007-04-14 14:08:30 +0000
committerdes <des@FreeBSD.org>2007-04-14 14:08:30 +0000
commit8dea6eb551705418618e5d68bee96d521d326dc6 (patch)
tree8776799c42c10769a373413b3de276bdb92b7d60 /sys/fs/pseudofs/pseudofs.c
parent5953cee02a231f279bc2d4cf8fdf52d332e94a29 (diff)
downloadFreeBSD-src-8dea6eb551705418618e5d68bee96d521d326dc6.zip
FreeBSD-src-8dea6eb551705418618e5d68bee96d521d326dc6.tar.gz
Further pseudofs improvements:
The pfs_info mutex is only needed to lock pi_unrhdr. Everything else in struct pfs_info is modified only while Giant is held (during vfs_init() / vfs_uninit()); add assertions to that effect. Simplify pfs_destroy somewhat. Remove superfluous arguments from pfs_fileno_{alloc,free}(), and the assertions which were added in the previous commit to ensure they were consistent. Assert that Giant is held while the vnode cache is initialized and destroyed. Also assert that the cache is empty when it is destroyed. Rename the vnode cache mutex for consistency. Fix a long-standing bug in pfs_getattr(): it would uncritically return the node's pn_fileno as st_ino. This would result in st_ino being 0 if the node had not previously been visited by readdir(), and also in an incorrect st_ino for process directories and any files contained therein. Correct this by abstracting the fileno manipulations previously done in pfs_readdir() into a new function, pfs_fileno(), which is used by both pfs_getattr() and pfs_readdir().
Diffstat (limited to 'sys/fs/pseudofs/pseudofs.c')
-rw-r--r--sys/fs/pseudofs/pseudofs.c34
1 files changed, 13 insertions, 21 deletions
diff --git a/sys/fs/pseudofs/pseudofs.c b/sys/fs/pseudofs/pseudofs.c
index 9464e9c..82ec971 100644
--- a/sys/fs/pseudofs/pseudofs.c
+++ b/sys/fs/pseudofs/pseudofs.c
@@ -73,7 +73,6 @@ _pfs_add_node(struct pfs_node *parent, struct pfs_node *node)
/* XXX should check for duplicate names etc. */
- mtx_lock(&parent->pn_info->pi_mutex);
node->pn_info = parent->pn_info;
node->pn_parent = parent;
node->pn_next = parent->pn_nodes;
@@ -81,7 +80,6 @@ _pfs_add_node(struct pfs_node *parent, struct pfs_node *node)
/* Propagate flag to all child nodes (and thus their vnodes) */
if ((parent->pn_flags & PFS_PROCDEP) != 0)
node->pn_flags |= PFS_PROCDEP;
- mtx_unlock(&parent->pn_info->pi_mutex);
return (0);
}
@@ -210,8 +208,8 @@ pfs_find_node(struct pfs_node *parent, const char *name)
for (node = parent->pn_nodes; node != NULL; node = node->pn_next)
if (strcmp(node->pn_name, name) == 0)
- return (node);
- return (NULL);
+ break;
+ return (node);
}
/*
@@ -220,7 +218,7 @@ pfs_find_node(struct pfs_node *parent, const char *name)
int
pfs_destroy(struct pfs_node *node)
{
- struct pfs_node *parent, *rover;
+ struct pfs_node *parent, **rover;
KASSERT(node != NULL,
("%s(): node is NULL", __func__));
@@ -238,20 +236,14 @@ pfs_destroy(struct pfs_node *node)
if ((parent = node->pn_parent) != NULL) {
KASSERT(parent->pn_info == node->pn_info,
("%s(): parent has different pn_info", __func__));
- 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;
+ rover = &parent->pn_nodes;
+ while (*rover != NULL) {
+ if (*rover == node) {
+ *rover = node->pn_next;
+ break;
}
+ rover = &(*rover)->pn_next;
}
- mtx_unlock(&node->pn_info->pi_mutex);
}
/* callback to free any private resources */
@@ -260,7 +252,7 @@ pfs_destroy(struct pfs_node *node)
/* revoke fileno and vnodes and release memory */
if (node->pn_fileno)
- pfs_fileno_free(node->pn_info, node);
+ pfs_fileno_free(node);
pfs_purge(node);
FREE(node, M_PFSNODES);
@@ -358,7 +350,7 @@ pfs_init(struct pfs_info *pi, struct vfsconf *vfc)
struct pfs_node *root;
int error;
- mtx_init(&pi->pi_mutex, "pseudofs", NULL, MTX_DEF);
+ mtx_assert(&Giant, MA_OWNED);
/* set up the root diretory */
MALLOC(root, struct pfs_node *, sizeof *root,
@@ -377,7 +369,6 @@ pfs_init(struct pfs_info *pi, struct vfsconf *vfc)
if (error) {
pfs_destroy(root);
pi->pi_root = NULL;
- mtx_destroy(&pi->pi_mutex);
return (error);
}
@@ -395,10 +386,11 @@ pfs_uninit(struct pfs_info *pi, struct vfsconf *vfc)
{
int error;
+ mtx_assert(&Giant, MA_OWNED);
+
pfs_destroy(pi->pi_root);
pi->pi_root = NULL;
pfs_fileno_uninit(pi);
- mtx_destroy(&pi->pi_mutex);
if (bootverbose)
printf("%s unregistered\n", pi->pi_name);
error = (pi->pi_uninit)(pi, vfc);
OpenPOWER on IntegriCloud