Don't enforce unique device minor number policy anymore.

Except for the case where we use the cloner library (clone_create() and
friends), there is no reason to enforce a unique device minor number
policy. There are various drivers in the source tree that allocate unr
pools and such to provide minor numbers, without using them themselves.

Because we still need to support unique device minor numbers for the
cloner library, introduce a new flag called D_NEEDMINOR. All cdevsw's
that are used in combination with the cloner library should be marked
with this flag to make the cloning work.

This means drivers can now freely use si_drv0 to store their own flags
and state, making it effectively the same as si_drv1 and si_drv2. We
still keep the minor() and dev2unit() routines around to make drivers
happy.

The NTFS code also used the minor number in its hash table. We should
not do this anymore. If the si_drv0 field would be changed, it would no
longer end up in the same list.

Approved by:	philip (mentor)
This commit is contained in:
ed 2008-06-11 18:55:19 +00:00
parent caec8ca318
commit 1bfc292986
11 changed files with 22 additions and 15 deletions

View File

@ -16445,6 +16445,7 @@ void dtrace_invop_uninit(void);
static struct cdevsw dtrace_cdevsw = {
.d_version = D_VERSION,
.d_flags = D_NEEDMINOR,
.d_close = dtrace_close,
.d_ioctl = dtrace_ioctl,
.d_open = dtrace_open,

View File

@ -68,7 +68,7 @@ static struct cdevsw nmdm_cdevsw = {
.d_open = nmdmopen,
.d_close = nmdmclose,
.d_name = "nmdn",
.d_flags = D_TTY | D_PSEUDO | D_NEEDGIANT,
.d_flags = D_TTY | D_PSEUDO | D_NEEDGIANT | D_NEEDMINOR,
};
#define BUFSIZ 100 /* Chunk size iomoved to/from user */

View File

@ -44,7 +44,7 @@ static d_poll_t snppoll;
static struct cdevsw snp_cdevsw = {
.d_version = D_VERSION,
.d_flags = D_PSEUDO | D_NEEDGIANT,
.d_flags = D_PSEUDO | D_NEEDGIANT | D_NEEDMINOR,
.d_open = snpopen,
.d_close = snpclose,
.d_read = snpread,

View File

@ -158,7 +158,7 @@ static int vkbd_data_read(vkbd_state_t *, int);
static struct cdevsw vkbd_dev_cdevsw = {
.d_version = D_VERSION,
.d_flags = D_PSEUDO | D_NEEDGIANT,
.d_flags = D_PSEUDO | D_NEEDGIANT | D_NEEDMINOR,
.d_open = vkbd_dev_open,
.d_close = vkbd_dev_close,
.d_read = vkbd_dev_read,

View File

@ -52,7 +52,7 @@ MALLOC_DEFINE(M_NTFSNTHASH, "ntfs_nthash", "NTFS ntnode hash tables");
*/
static LIST_HEAD(nthashhead, ntnode) *ntfs_nthashtbl;
static u_long ntfs_nthash; /* size of hash table - 1 */
#define NTNOHASH(device, inum) (&ntfs_nthashtbl[(minor(device) + (inum)) & ntfs_nthash])
#define NTNOHASH(inum) (&ntfs_nthashtbl[(inum) & ntfs_nthash])
static struct mtx ntfs_nthash_mtx;
struct lock ntfs_hashlock;
@ -90,7 +90,7 @@ ntfs_nthashlookup(dev, inum)
struct ntnode *ip;
mtx_lock(&ntfs_nthash_mtx);
LIST_FOREACH(ip, NTNOHASH(dev, inum), i_hash)
LIST_FOREACH(ip, NTNOHASH(inum), i_hash)
if (inum == ip->i_number && dev == ip->i_dev)
break;
mtx_unlock(&ntfs_nthash_mtx);
@ -108,7 +108,7 @@ ntfs_nthashins(ip)
struct nthashhead *ipp;
mtx_lock(&ntfs_nthash_mtx);
ipp = NTNOHASH(ip->i_dev, ip->i_number);
ipp = NTNOHASH(ip->i_number);
LIST_INSERT_HEAD(ipp, ip, i_hash);
ip->i_flag |= IN_HASHED;
mtx_unlock(&ntfs_nthash_mtx);

View File

@ -84,7 +84,7 @@ static struct filterops apm_readfiltops =
static struct cdevsw apm_cdevsw = {
.d_version = D_VERSION,
.d_flags = D_TRACKCLOSE,
.d_flags = D_TRACKCLOSE | D_NEEDMINOR,
.d_open = apmopen,
.d_close = apmclose,
.d_write = apmwrite,

View File

@ -566,10 +566,13 @@ newdev(struct cdevsw *csw, int y, struct cdev *si)
mtx_assert(&devmtx, MA_OWNED);
udev = y;
LIST_FOREACH(si2, &csw->d_devs, si_list) {
if (si2->si_drv0 == udev) {
dev_free_devlocked(si);
return (si2);
if (csw->d_flags & D_NEEDMINOR) {
/* We may want to return an existing device */
LIST_FOREACH(si2, &csw->d_devs, si_list) {
if (si2->si_drv0 == udev) {
dev_free_devlocked(si);
return (si2);
}
}
}
si->si_drv0 = udev;
@ -1016,6 +1019,8 @@ clone_create(struct clonedevs **cdp, struct cdevsw *csw, int *up, struct cdev **
("Illegal extra bits (0x%x) in clone_create", extra));
KASSERT(*up <= CLONE_UNITMASK,
("Too high unit (0x%x) in clone_create", *up));
KASSERT(csw->d_flags & D_NEEDMINOR,
("clone_create() on cdevsw without minor numbers"));
/*

View File

@ -132,7 +132,7 @@ static struct filterops tap_write_filterops = {
static struct cdevsw tap_cdevsw = {
.d_version = D_VERSION,
.d_flags = D_PSEUDO | D_NEEDGIANT,
.d_flags = D_PSEUDO | D_NEEDGIANT | D_NEEDMINOR,
.d_open = tapopen,
.d_close = tapclose,
.d_read = tapread,

View File

@ -162,7 +162,7 @@ static struct filterops tun_write_filterops = {
static struct cdevsw tun_cdevsw = {
.d_version = D_VERSION,
.d_flags = D_PSEUDO | D_NEEDGIANT,
.d_flags = D_PSEUDO | D_NEEDGIANT | D_NEEDMINOR,
.d_open = tunopen,
.d_close = tunclose,
.d_read = tunread,

View File

@ -177,7 +177,7 @@ static d_kqfilter_t audit_pipe_kqfilter;
static struct cdevsw audit_pipe_cdevsw = {
.d_version = D_VERSION,
.d_flags = D_PSEUDO | D_NEEDGIANT,
.d_flags = D_PSEUDO | D_NEEDGIANT | D_NEEDMINOR,
.d_open = audit_pipe_open,
.d_close = audit_pipe_close,
.d_read = audit_pipe_read,

View File

@ -71,7 +71,7 @@ struct cdev {
gid_t si_gid;
mode_t si_mode;
struct ucred *si_cred; /* cached clone-time credential */
u_int si_drv0;
int si_drv0;
int si_refcount;
LIST_ENTRY(cdev) si_list;
LIST_ENTRY(cdev) si_clone;
@ -171,6 +171,7 @@ typedef int dumper_t(
#define D_MMAP_ANON 0x00100000 /* special treatment in vm_mmap.c */
#define D_PSEUDO 0x00200000 /* make_dev() can return NULL */
#define D_NEEDGIANT 0x00400000 /* driver want Giant */
#define D_NEEDMINOR 0x00800000 /* driver uses clone_create() */
/*
* Version numbers.