Rename lminor() to dev2unit(). This function gives a linear unit number

which hides the 'hole' in the minor bits.

Introduce unit2minor() to do the reverse operation.

Fix some some make_dev() calls which didn't use UID_* or GID_* macros.

Kill the v_hashchain alias macro, it hides the real relationship.

Introduce experimental SI_CHEAPCLONE flag set it on cloned bpfs.
This commit is contained in:
Poul-Henning Kamp 2000-09-19 10:28:44 +00:00
parent 19cf3044c1
commit b0d17ba69e
9 changed files with 29 additions and 18 deletions

View File

@ -178,7 +178,7 @@ minor(dev_t x)
}
int
lminor(dev_t x)
dev2unit(dev_t x)
{
int i;
@ -188,6 +188,13 @@ lminor(dev_t x)
return ((i & 0xff) | (i >> 8));
}
int
unit2minor(int unit)
{
return ((unit & 0xff) | ((unit << 8) & ~0xffff));
}
dev_t
makebdev(int x, int y)
{

View File

@ -150,9 +150,9 @@ ptyinit(n)
pt = malloc(sizeof(*pt), M_PTY, M_WAITOK);
bzero(pt, sizeof(*pt));
pt->devs = devs = make_dev(&pts_cdevsw, n,
0, 0, 0666, "tty%c%r", names[n / 32], n % 32);
UID_ROOT, GID_WHEEL, 0666, "tty%c%r", names[n / 32], n % 32);
pt->devc = devc = make_dev(&ptc_cdevsw, n,
0, 0, 0666, "pty%c%r", names[n / 32], n % 32);
UID_ROOT, GID_WHEEL, 0666, "pty%c%r", names[n / 32], n % 32);
devs->si_drv1 = devc->si_drv1 = pt;
devs->si_tty = devc->si_tty = &pt->pt_tty;

View File

@ -1861,7 +1861,7 @@ vgonel(vp, p)
*/
if ((vp->v_type == VBLK || vp->v_type == VCHR) && vp->v_rdev != NULL) {
simple_lock(&spechash_slock);
SLIST_REMOVE(&vp->v_hashchain, vp, vnode, v_specnext);
SLIST_REMOVE(&vp->v_rdev->si_hlist, vp, vnode, v_specnext);
freedev(vp->v_rdev);
simple_unlock(&spechash_slock);
vp->v_rdev = NULL;
@ -1929,7 +1929,7 @@ vcount(vp)
count = 0;
simple_lock(&spechash_slock);
SLIST_FOREACH(vq, &vp->v_hashchain, v_specnext)
SLIST_FOREACH(vq, &vp->v_rdev->si_hlist, v_specnext)
count += vq->v_usecount;
simple_unlock(&spechash_slock);
return (count);

View File

@ -1861,7 +1861,7 @@ vgonel(vp, p)
*/
if ((vp->v_type == VBLK || vp->v_type == VCHR) && vp->v_rdev != NULL) {
simple_lock(&spechash_slock);
SLIST_REMOVE(&vp->v_hashchain, vp, vnode, v_specnext);
SLIST_REMOVE(&vp->v_rdev->si_hlist, vp, vnode, v_specnext);
freedev(vp->v_rdev);
simple_unlock(&spechash_slock);
vp->v_rdev = NULL;
@ -1929,7 +1929,7 @@ vcount(vp)
count = 0;
simple_lock(&spechash_slock);
SLIST_FOREACH(vq, &vp->v_hashchain, v_specnext)
SLIST_FOREACH(vq, &vp->v_rdev->si_hlist, v_specnext)
count += vq->v_usecount;
simple_unlock(&spechash_slock);
return (count);

View File

@ -363,7 +363,8 @@ bpfopen(dev, flags, fmt, p)
*/
if (d)
return (EBUSY);
make_dev(&bpf_cdevsw, minor(dev), 0, 0, 0600, "bpf%d", lminor(dev));
make_dev(&bpf_cdevsw, minor(dev), UID_ROOT, GID_WHEEL, 0600,
"bpf%d", dev2unit(dev));
MALLOC(d, struct bpf_d *, sizeof(*d), M_BPF, M_WAITOK);
bzero(d, sizeof(*d));
dev->si_drv1 = d;
@ -1377,8 +1378,9 @@ bpf_clone(arg, name, namelen, dev)
return;
if (dev_stdclone(name, NULL, "bpf", &u) != 1)
return;
/* XXX: minor encoding if u > 255 */
*dev = make_dev(&bpf_cdevsw, u, 0, 0, 0600, "bpf%d", u);
*dev = make_dev(&bpf_cdevsw, unit2minor(u), UID_ROOT, GID_WHEEL, 0600,
"bpf%d", u);
(*dev)->si_flags |= SI_CHEAPCLONE;
return;
}

View File

@ -211,12 +211,12 @@ tapcreate(dev)
/* select device: tap or vmnet */
if (minor(dev) & VMNET_DEV_MASK) {
name = VMNET;
unit = lminor(dev) & 0xff;
unit = dev2unit(dev) & 0xff;
tp->tap_flags |= TAP_VMNET;
}
else {
name = TAP;
unit = lminor(dev);
unit = dev2unit(dev);
}
tp->tap_dev = make_dev(&tap_cdevsw, minor(dev), UID_ROOT, GID_WHEEL,

View File

@ -129,14 +129,14 @@ tuncreate(dev)
struct ifnet *ifp;
dev = make_dev(&tun_cdevsw, minor(dev),
UID_UUCP, GID_DIALER, 0600, "tun%d", lminor(dev));
UID_UUCP, GID_DIALER, 0600, "tun%d", dev2unit(dev));
MALLOC(sc, struct tun_softc *, sizeof(*sc), M_TUN, M_WAITOK);
bzero(sc, sizeof *sc);
sc->tun_flags = TUN_INITED;
ifp = &sc->tun_if;
ifp->if_unit = lminor(dev);
ifp->if_unit = dev2unit(dev);
ifp->if_name = "tun";
ifp->if_mtu = TUNMTU;
ifp->if_ioctl = tunifioctl;

View File

@ -56,6 +56,7 @@ struct specinfo {
#define SI_STASHED 0x0001 /* created in stashed storage */
#define SI_ALIAS 0x0002 /* carrier of alias name */
#define SI_NAMED 0x0004 /* make_dev{_alias} has been called */
#define SI_CHEAPCLONE 0x0008 /* can be removed_dev'ed when vnode reclaims */
struct timespec si_atime;
struct timespec si_ctime;
struct timespec si_mtime;
@ -93,7 +94,6 @@ struct specinfo {
/*
* Exported shorthand
*/
#define v_hashchain v_rdev->si_hlist
#define v_specmountpoint v_rdev->si_mountpoint
/*
@ -291,7 +291,8 @@ int iszerodev __P((dev_t dev));
dev_t makebdev __P((int maj, int min));
dev_t make_dev __P((struct cdevsw *devsw, int minor, uid_t uid, gid_t gid, int perms, char *fmt, ...)) __printflike(6, 7);
dev_t make_dev_alias __P((dev_t pdev, char *fmt, ...)) __printflike(2, 3);
int lminor __P((dev_t dev));
int dev2unit __P((dev_t dev));
int unit2minor __P((int unit));
void setconf __P((void));
dev_t getdiskbyname(char *name);

View File

@ -56,6 +56,7 @@ struct specinfo {
#define SI_STASHED 0x0001 /* created in stashed storage */
#define SI_ALIAS 0x0002 /* carrier of alias name */
#define SI_NAMED 0x0004 /* make_dev{_alias} has been called */
#define SI_CHEAPCLONE 0x0008 /* can be removed_dev'ed when vnode reclaims */
struct timespec si_atime;
struct timespec si_ctime;
struct timespec si_mtime;
@ -93,7 +94,6 @@ struct specinfo {
/*
* Exported shorthand
*/
#define v_hashchain v_rdev->si_hlist
#define v_specmountpoint v_rdev->si_mountpoint
/*
@ -291,7 +291,8 @@ int iszerodev __P((dev_t dev));
dev_t makebdev __P((int maj, int min));
dev_t make_dev __P((struct cdevsw *devsw, int minor, uid_t uid, gid_t gid, int perms, char *fmt, ...)) __printflike(6, 7);
dev_t make_dev_alias __P((dev_t pdev, char *fmt, ...)) __printflike(2, 3);
int lminor __P((dev_t dev));
int dev2unit __P((dev_t dev));
int unit2minor __P((int unit));
void setconf __P((void));
dev_t getdiskbyname(char *name);