Struct cdev is always the member of the struct cdev_priv. When devfs

needed to promote cdev to cdev_priv, the si_priv pointer was followed.

Use member2struct() to calculate address of the wrapping cdev_priv.
Rename si_priv to __si_reserved.

Tested by:	pho
Reviewed by:	ed
MFC after:	2 weeks
This commit is contained in:
Konstantin Belousov 2008-06-16 17:34:59 +00:00
parent 4c20b7670c
commit 05427aafc6
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=179828
6 changed files with 19 additions and 19 deletions

View File

@ -125,7 +125,6 @@ devfs_alloc(void)
cdp->cdp_maxdirent = 0;
cdev = &cdp->cdp_c;
cdev->si_priv = cdp;
cdev->si_name = cdev->__si_namebuf;
LIST_INIT(&cdev->si_children);
@ -137,7 +136,7 @@ devfs_free(struct cdev *cdev)
{
struct cdev_priv *cdp;
cdp = cdev->si_priv;
cdp = cdev2priv(cdev);
if (cdev->si_cred != NULL)
crfree(cdev->si_cred);
if (cdp->cdp_inode > 0)
@ -510,7 +509,7 @@ devfs_create(struct cdev *dev)
struct cdev_priv *cdp;
mtx_assert(&devmtx, MA_OWNED);
cdp = dev->si_priv;
cdp = cdev2priv(dev);
cdp->cdp_flags |= CDP_ACTIVE;
cdp->cdp_inode = alloc_unrl(devfs_inos);
dev_refl(dev);
@ -524,7 +523,7 @@ devfs_destroy(struct cdev *dev)
struct cdev_priv *cdp;
mtx_assert(&devmtx, MA_OWNED);
cdp = dev->si_priv;
cdp = cdev2priv(dev);
cdp->cdp_flags &= ~CDP_ACTIVE;
devfs_generation++;
}

View File

@ -68,6 +68,8 @@ struct cdev_priv {
LIST_HEAD(, cdev_privdata) cdp_fdpriv;
};
#define cdev2priv(c) member2struct(cdev_priv, cdp_c, c)
struct cdev *devfs_alloc(void);
void devfs_free(struct cdev *);
void devfs_create(struct cdev *dev);

View File

@ -132,7 +132,7 @@ devfs_set_cdevpriv(void *priv, cdevpriv_dtr_t priv_dtr)
fp = curthread->td_fpop;
if (fp == NULL)
return (ENOENT);
cdp = ((struct cdev *)fp->f_data)->si_priv;
cdp = cdev2priv((struct cdev *)fp->f_data);
p = malloc(sizeof(struct cdev_privdata), M_CDEVPDATA, M_WAITOK);
p->cdpd_data = priv;
p->cdpd_dtr = priv_dtr;
@ -541,7 +541,7 @@ devfs_getattr(struct vop_getattr_args *ap)
fix(dev->si_ctime);
vap->va_ctime = dev->si_ctime;
vap->va_rdev = dev->si_priv->cdp_inode;
vap->va_rdev = cdev2priv(dev)->cdp_inode;
}
vap->va_gen = 0;
vap->va_flags = 0;
@ -742,7 +742,7 @@ devfs_lookupx(struct vop_lookup_args *ap, int *dm_unlock)
}
dev_lock();
dde = &cdev->si_priv->cdp_dirents[dmp->dm_idx];
dde = &cdev2priv(cdev)->cdp_dirents[dmp->dm_idx];
if (dde != NULL && *dde != NULL)
de = *dde;
dev_unlock();
@ -1141,7 +1141,7 @@ devfs_revoke(struct vop_revoke_args *ap)
KASSERT((ap->a_flags & REVOKEALL) != 0, ("devfs_revoke !REVOKEALL"));
dev = vp->v_rdev;
cdp = dev->si_priv;
cdp = cdev2priv(dev);
dev_lock();
cdp->cdp_inuse++;
@ -1419,7 +1419,7 @@ dev2udev(struct cdev *x)
{
if (x == NULL)
return (NODEV);
return (x->si_priv->cdp_inode);
return (cdev2priv(x)->cdp_inode);
}
static struct fileops devfs_ops_f = {

View File

@ -115,7 +115,7 @@ dev_free_devlocked(struct cdev *cdev)
struct cdev_priv *cdp;
mtx_assert(&devmtx, MA_OWNED);
cdp = cdev->si_priv;
cdp = cdev2priv(cdev);
TAILQ_INSERT_HEAD(&cdevp_free_list, cdp, cdp_list);
}
@ -187,7 +187,7 @@ dev_refthread(struct cdev *dev)
dev_lock();
csw = dev->si_devsw;
if (csw != NULL) {
cdp = dev->si_priv;
cdp = cdev2priv(dev);
if ((cdp->cdp_flags & CDP_SCHED_DTR) == 0)
dev->si_threadcount++;
else
@ -208,7 +208,7 @@ devvn_refthread(struct vnode *vp, struct cdev **devp)
dev_lock();
*devp = vp->v_rdev;
if (*devp != NULL) {
cdp = (*devp)->si_priv;
cdp = cdev2priv(*devp);
if ((cdp->cdp_flags & CDP_SCHED_DTR) == 0) {
csw = (*devp)->si_devsw;
if (csw != NULL)
@ -851,7 +851,7 @@ destroy_devl(struct cdev *dev)
dev_unlock();
notify_destroy(dev);
mtx_lock(&cdevpriv_mtx);
LIST_FOREACH_SAFE(p, &dev->si_priv->cdp_fdpriv, cdpd_list, p1) {
LIST_FOREACH_SAFE(p, &cdev2priv(dev)->cdp_fdpriv, cdpd_list, p1) {
devfs_destroy_cdevpriv(p);
mtx_lock(&cdevpriv_mtx);
}
@ -1071,7 +1071,7 @@ clone_cleanup(struct clonedevs **cdp)
KASSERT(dev->si_flags & SI_CLONELIST,
("Dev %p(%s) should be on clonelist", dev, dev->si_name));
dev->si_flags &= ~SI_CLONELIST;
cp = dev->si_priv;
cp = cdev2priv(dev);
if (!(cp->cdp_flags & CDP_SCHED_DTR)) {
cp->cdp_flags |= CDP_SCHED_DTR;
KASSERT(dev->si_flags & SI_NAMED,
@ -1125,7 +1125,7 @@ destroy_dev_sched_cbl(struct cdev *dev, void (*cb)(void *), void *arg)
struct cdev_priv *cp;
mtx_assert(&devmtx, MA_OWNED);
cp = dev->si_priv;
cp = cdev2priv(dev);
if (cp->cdp_flags & CDP_SCHED_DTR) {
dev_unlock();
return (0);

View File

@ -53,7 +53,7 @@ struct cdevsw;
struct file;
struct cdev {
struct cdev_priv *si_priv;
void *__si_reserved;
u_int si_flags;
#define SI_ALIAS 0x0002 /* carrier of alias name */
#define SI_NAMED 0x0004 /* make_dev{_alias} has been called */

View File

@ -97,6 +97,7 @@ __FBSDID("$FreeBSD$");
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <unistd.h>
#include <netdb.h>
@ -895,10 +896,8 @@ dev_t
dev2udev(struct cdev *dev)
{
struct cdev_priv priv;
struct cdev si;
if (KVM_READ(dev, &si, sizeof si) &&
KVM_READ(si.si_priv, &priv, sizeof priv)) {
if (KVM_READ(cdev2priv(dev), &priv, sizeof priv)) {
return ((dev_t)priv.cdp_inode);
} else {
dprintf(stderr, "can't convert cdev *%p to a dev_t\n", dev);