summaryrefslogtreecommitdiffstats
path: root/sys/fs/devfs/devfs.h
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.h
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.h')
-rw-r--r--sys/fs/devfs/devfs.h42
1 files changed, 9 insertions, 33 deletions
diff --git a/sys/fs/devfs/devfs.h b/sys/fs/devfs/devfs.h
index 07912a9..18061b9 100644
--- a/sys/fs/devfs/devfs.h
+++ b/sys/fs/devfs/devfs.h
@@ -118,32 +118,12 @@ struct devfs_rule {
#ifdef _KERNEL
-/*
- * These are default sizes for the DEVFS inode table and the overflow
- * table. If the default table overflows we allocate the overflow
- * table, the size of which can also be set with a sysctl. If the
- * overflow table fills you're toast.
- */
-#ifndef NDEVFSINO
-#define NDEVFSINO 1024
-#endif
-
-#ifndef NDEVFSOVERFLOW
-#define NDEVFSOVERFLOW 32768
-#endif
-
-/*
- * This is the first "per mount" inode, these are used for directories
- * and symlinks and the like. Must be larger than the number of "true"
- * device nodes and symlinks. It is.
- */
-#define DEVFSINOMOUNT 0x2000000
-
#ifdef MALLOC_DECLARE
MALLOC_DECLARE(M_DEVFS);
#endif
struct devfs_dirent {
+ struct cdev_priv *de_cdp;
int de_inode;
int de_flags;
#define DE_WHITEOUT 0x1
@@ -152,7 +132,6 @@ struct devfs_dirent {
struct dirent *de_dirent;
TAILQ_ENTRY(devfs_dirent) de_list;
TAILQ_HEAD(, devfs_dirent) de_dlist;
- LIST_ENTRY(devfs_dirent) de_alias;
struct devfs_dirent *de_dir;
int de_links;
mode_t de_mode;
@@ -167,22 +146,17 @@ struct devfs_dirent {
};
struct devfs_mount {
+ u_int dm_idx;
struct mount *dm_mount;
struct devfs_dirent *dm_rootdir;
unsigned dm_generation;
- struct devfs_dirent **dm_dirent;
- struct devfs_dirent **dm_overflow;
- int dm_inode;
- struct lock dm_lock;
+ struct sx dm_lock;
devfs_rsnum dm_ruleset;
};
-extern unsigned devfs_rule_depth;
+#define DEVFS_ROOTINO 2
-/*
- * This is what we fill in dm_dirent[N] for a deleted entry.
- */
-#define DE_DELETED ((struct devfs_dirent *)sizeof(struct devfs_dirent))
+extern unsigned devfs_rule_depth;
#define VFSTODEVFS(mp) ((struct devfs_mount *)((mp)->mnt_data))
@@ -192,10 +166,12 @@ void devfs_rules_newmount(struct devfs_mount *dm, struct thread *td);
int devfs_allocv (struct devfs_dirent *de, struct mount *mp, struct vnode **vpp, struct thread *td);
struct cdev **devfs_itod (int inode);
struct devfs_dirent **devfs_itode (struct devfs_mount *dm, int inode);
+void devfs_delete(struct devfs_mount *dm, struct devfs_dirent *de);
void devfs_populate (struct devfs_mount *dm);
+void devfs_cleanup (struct devfs_mount *dm);
struct devfs_dirent *devfs_newdirent (char *name, int namelen);
-void devfs_purge (struct devfs_dirent *dd);
-struct devfs_dirent *devfs_vmkdir (char *name, int namelen, struct devfs_dirent *dotdot);
+struct devfs_dirent *devfs_vmkdir (struct devfs_mount *, char *name, int namelen, struct devfs_dirent *dotdot, u_int inode);
+struct devfs_dirent *devfs_find (struct devfs_dirent *dd, const char *name, int namelen);
#endif /* _KERNEL */
OpenPOWER on IntegriCloud