Add an ext2_uninit() routine that undoes the actions performed by

ext2_init(). This permits the ext2fs module to be unloaded without
causing panics and leaking memory.
This commit is contained in:
Ian Dowse 2002-05-18 22:18:17 +00:00
parent ca305f613f
commit 6a681d9a3c
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=96881
5 changed files with 39 additions and 12 deletions

View File

@ -69,6 +69,7 @@ void ext2_ihashins(struct inode *);
struct vnode *
ext2_ihashlookup(dev_t, ino_t);
void ext2_ihashrem(struct inode *);
void ext2_ihashuninit(void);
void ext2_itimes(struct vnode *vp);
int ext2_reallocblks(struct vop_reallocblks_args *);
int ext2_reclaim(struct vop_reclaim_args *);

View File

@ -62,10 +62,27 @@ void
ext2_ihashinit()
{
KASSERT(ihashtbl == NULL, ("ext2_ihashinit called twice"));
ihashtbl = hashinit(desiredvnodes, M_EXT2IHASH, &ihash);
mtx_init(&ext2_ihash_mtx, "ext2 ihash", NULL, MTX_DEF);
}
/*
* Destroy the inode hash table.
*/
void
ext2_ihashuninit()
{
struct ihashhead *hp;
for (hp = ihashtbl; hp < &ihashtbl[ihash]; hp++)
if (!LIST_EMPTY(hp))
panic("ext2_ihashuninit: ihash not empty");
free(ihashtbl, M_EXT2IHASH);
ihashtbl = NULL;
mtx_destroy(&ext2_ihash_mtx);
}
/*
* Use the device/inum pair to find the incore inode, and return a pointer
* to it. If it is in core, return it, even if it is locked.

View File

@ -75,6 +75,7 @@ static int ext2_root(struct mount *, struct vnode **vpp);
static int ext2_sbupdate(struct ext2mount *, int);
static int ext2_statfs(struct mount *, struct statfs *, struct thread *);
static int ext2_sync(struct mount *, int, struct ucred *, struct thread *);
static int ext2_uninit(struct vfsconf *);
static int ext2_unmount(struct mount *, int, struct thread *);
static int ext2_vget(struct mount *, ino_t, int, struct vnode **);
static int ext2_vptofh(struct vnode *, struct fid *);
@ -95,7 +96,7 @@ static struct vfsops ext2fs_vfsops = {
vfs_stdcheckexp,
ext2_vptofh,
ext2_init,
vfs_stduninit,
ext2_uninit,
vfs_stdextattrctl,
};
@ -1207,12 +1208,15 @@ ext2_root(mp, vpp)
static int
ext2_init(struct vfsconf *vfsp)
{
static int done;
if (done)
return (0);
done = 1;
ext2_ihashinit();
return (0);
}
static int
ext2_uninit(struct vfsconf *vfsp)
{
ext2_ihashuninit();
return (0);
}

View File

@ -69,6 +69,7 @@ void ext2_ihashins(struct inode *);
struct vnode *
ext2_ihashlookup(dev_t, ino_t);
void ext2_ihashrem(struct inode *);
void ext2_ihashuninit(void);
void ext2_itimes(struct vnode *vp);
int ext2_reallocblks(struct vop_reallocblks_args *);
int ext2_reclaim(struct vop_reclaim_args *);

View File

@ -75,6 +75,7 @@ static int ext2_root(struct mount *, struct vnode **vpp);
static int ext2_sbupdate(struct ext2mount *, int);
static int ext2_statfs(struct mount *, struct statfs *, struct thread *);
static int ext2_sync(struct mount *, int, struct ucred *, struct thread *);
static int ext2_uninit(struct vfsconf *);
static int ext2_unmount(struct mount *, int, struct thread *);
static int ext2_vget(struct mount *, ino_t, int, struct vnode **);
static int ext2_vptofh(struct vnode *, struct fid *);
@ -95,7 +96,7 @@ static struct vfsops ext2fs_vfsops = {
vfs_stdcheckexp,
ext2_vptofh,
ext2_init,
vfs_stduninit,
ext2_uninit,
vfs_stdextattrctl,
};
@ -1207,12 +1208,15 @@ ext2_root(mp, vpp)
static int
ext2_init(struct vfsconf *vfsp)
{
static int done;
if (done)
return (0);
done = 1;
ext2_ihashinit();
return (0);
}
static int
ext2_uninit(struct vfsconf *vfsp)
{
ext2_ihashuninit();
return (0);
}