summaryrefslogtreecommitdiffstats
path: root/sys/fs/devfs/devfs_vfsops.c
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>2005-09-19 19:56:48 +0000
committerphk <phk@FreeBSD.org>2005-09-19 19:56:48 +0000
commit6a408cbd71bd73e59f73f6e904c7247467a361a1 (patch)
tree9e64ec73d7bfbd95c61da0bd311167a94851cc3d /sys/fs/devfs/devfs_vfsops.c
parent92d485220134cae42bad5e6d43661f3d923907df (diff)
downloadFreeBSD-src-6a408cbd71bd73e59f73f6e904c7247467a361a1.zip
FreeBSD-src-6a408cbd71bd73e59f73f6e904c7247467a361a1.tar.gz
Rewamp DEVFS internals pretty severely [1].
Give DEVFS a proper inode called struct cdev_priv. It is important to keep in mind that this "inode" is shared between all DEVFS mountpoints, therefore it is protected by the global device mutex. Link the cdev_priv's into a list, protected by the global device mutex. Keep track of each cdev_priv's state with a flag bit and of references from mountpoints with a dedicated usecount. Reap the benefits of much improved kernel memory allocator and the generally better defined device driver APIs to get rid of the tables of pointers + serial numbers, their overflow tables, the atomics to muck about in them and all the trouble that resulted in. This makes RAM the only limit on how many devices we can have. The cdev_priv is actually a super struct containing the normal cdev as the "public" part, and therefore allocation and freeing has moved to devfs_devs.c from kern_conf.c. The overall responsibility is (to be) split such that kern/kern_conf.c is the stuff that deals with drivers and struct cdev and fs/devfs handles filesystems and struct cdev_priv and their private liason exposed only in devfs_int.h. Move the inode number from cdev to cdev_priv and allocate inode numbers properly with unr. Local dirents in the mountpoints (directories, symlinks) allocate inodes from the same pool to guarantee against overlaps. Various other fields are going to migrate from cdev to cdev_priv in the future in order to hide them. A few fields may migrate from devfs_dirent to cdev_priv as well. Protect the DEVFS mountpoint with an sx lock instead of lockmgr, this lock also protects the directory tree of the mountpoint. Give each mountpoint a unique integer index, allocated with unr. Use it into an array of devfs_dirent pointers in each cdev_priv. Initially the array points to a single element also inside cdev_priv, but as more devfs instances are mounted, the array is extended with malloc(9) as necessary when the filesystem populates its directory tree. Retire the cdev alias lists, the cdev_priv now know about all the relevant devfs_dirents (and their vnodes) and devfs_revoke() will pick them up from there. We still spelunk into other mountpoints and fondle their data without 100% good locking. It may make better sense to vector the revoke event into the tty code and there do a destroy_dev/make_dev on the tty's devices, but that's for further study. Lots of shuffling of stuff and churn of bits for no good reason[2]. XXX: There is still nothing preventing the dev_clone EVENTHANDLER from being invoked at the same time in two devfs mountpoints. It is not obvious what the best course of action is here. XXX: comment out an if statement that lost its body, until I can find out what should go there so it doesn't do damage in the meantime. XXX: Leave in a few extra malloc types and KASSERTS to help track down any remaining issues. Much testing provided by: Kris Much confusion caused by (races in): md(4) [1] You are not supposed to understand anything past this point. [2] This line should simplify life for the peanut gallery.
Diffstat (limited to 'sys/fs/devfs/devfs_vfsops.c')
-rw-r--r--sys/fs/devfs/devfs_vfsops.c58
1 files changed, 25 insertions, 33 deletions
diff --git a/sys/fs/devfs/devfs_vfsops.c b/sys/fs/devfs/devfs_vfsops.c
index 307b4a2..6aad2b0 100644
--- a/sys/fs/devfs/devfs_vfsops.c
+++ b/sys/fs/devfs/devfs_vfsops.c
@@ -45,10 +45,14 @@
#include <sys/malloc.h>
#include <sys/mount.h>
#include <sys/proc.h>
+#include <sys/sx.h>
#include <sys/vnode.h>
+#include <sys/limits.h>
#include <fs/devfs/devfs.h>
+static struct unrhdr *devfs_unr;
+
MALLOC_DEFINE(M_DEVFS, "DEVFS", "DEVFS data");
static vfs_mount_t devfs_mount;
@@ -66,39 +70,35 @@ devfs_mount(struct mount *mp, struct thread *td)
struct devfs_mount *fmp;
struct vnode *rvp;
+ if (devfs_unr == NULL)
+ devfs_unr = new_unrhdr(0, INT_MAX, NULL);
+
error = 0;
if (mp->mnt_flag & (MNT_UPDATE | MNT_ROOTFS))
return (EOPNOTSUPP);
- MALLOC(fmp, struct devfs_mount *, sizeof(struct devfs_mount),
- M_DEVFS, M_WAITOK | M_ZERO);
- MALLOC(fmp->dm_dirent, struct devfs_dirent **,
- sizeof(struct devfs_dirent *) * NDEVFSINO,
- M_DEVFS, M_WAITOK | M_ZERO);
- lockinit(&fmp->dm_lock, PVFS, "devfs", 0, 0);
+ fmp = malloc(sizeof *fmp, M_DEVFS, M_WAITOK | M_ZERO);
+ fmp->dm_idx = alloc_unr(devfs_unr);
+ sx_init(&fmp->dm_lock, "devfsmount");
mp->mnt_flag |= MNT_LOCAL;
+ mp->mnt_kern_flag |= MNTK_MPSAFE;
#ifdef MAC
mp->mnt_flag |= MNT_MULTILABEL;
#endif
fmp->dm_mount = mp;
- mp->mnt_data = (qaddr_t) fmp;
+ mp->mnt_data = (void *) fmp;
vfs_getnewfsid(mp);
- fmp->dm_inode = DEVFSINOMOUNT;
-
- fmp->dm_rootdir = devfs_vmkdir("(root)", 6, NULL);
- fmp->dm_rootdir->de_inode = 2;
-#ifdef MAC
- mac_create_devfs_directory(mp, "", 0, fmp->dm_rootdir);
-#endif
+ fmp->dm_rootdir = devfs_vmkdir(fmp, NULL, 0, NULL, DEVFS_ROOTINO);
devfs_rules_newmount(fmp, td);
error = devfs_root(mp, LK_EXCLUSIVE, &rvp, td);
if (error) {
- lockdestroy(&fmp->dm_lock);
- FREE(fmp, M_DEVFS);
+ sx_destroy(&fmp->dm_lock);
+ free_unr(devfs_unr, fmp->dm_idx);
+ free(fmp, M_DEVFS);
return (error);
}
@@ -110,10 +110,7 @@ devfs_mount(struct mount *mp, struct thread *td)
}
static int
-devfs_unmount(mp, mntflags, td)
- struct mount *mp;
- int mntflags;
- struct thread *td;
+devfs_unmount(struct mount *mp, int mntflags, struct thread *td)
{
int error;
int flags = 0;
@@ -124,10 +121,12 @@ devfs_unmount(mp, mntflags, td)
error = vflush(mp, 1, flags, td);
if (error)
return (error);
- devfs_purge(fmp->dm_rootdir);
- mp->mnt_data = 0;
- lockdestroy(&fmp->dm_lock);
- free(fmp->dm_dirent, M_DEVFS);
+ sx_xlock(&fmp->dm_lock);
+ devfs_cleanup(fmp);
+ sx_xunlock(&fmp->dm_lock);
+ mp->mnt_data = NULL;
+ sx_destroy(&fmp->dm_lock);
+ free_unr(devfs_unr, fmp->dm_idx);
free(fmp, M_DEVFS);
return 0;
}
@@ -135,11 +134,7 @@ devfs_unmount(mp, mntflags, td)
/* Return locked reference to root. */
static int
-devfs_root(mp, flags, vpp, td)
- struct mount *mp;
- int flags;
- struct vnode **vpp;
- struct thread *td;
+devfs_root(struct mount *mp, int flags, struct vnode **vpp, struct thread *td)
{
int error;
struct vnode *vp;
@@ -155,10 +150,7 @@ devfs_root(mp, flags, vpp, td)
}
static int
-devfs_statfs(mp, sbp, td)
- struct mount *mp;
- struct statfs *sbp;
- struct thread *td;
+devfs_statfs(struct mount *mp, struct statfs *sbp, struct thread *td)
{
sbp->f_flags = 0;
OpenPOWER on IntegriCloud