From 028066b1d303239d97cf844f16713d5796d15451 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Tue, 8 May 2007 02:31:43 +0000 Subject: [PATCH] Replace NOCDEV with NULL. NOCDEV was ((void *)-1) and as inherited from *BSD a long time ago due to the device pointer / device number duality. Now that the pointer and device number has been separated, we can just use NULL to indicate no-pointer. Replace si_refs with si_sysref. Use SYSREF for ref-count cdev_t. Enable cdev_t reclamation on deletion. --- lib/libkvm/kvm_proc.c | 6 +- sys/bus/firewire/fwdev.c | 4 +- sys/conf/nfsswapkernel.c | 6 +- sys/dev/misc/kbd/kbd.c | 4 +- sys/dev/misc/snp/snp.c | 10 +- sys/dev/raid/vinum/vinumio.c | 4 +- sys/dev/sound/pcm/sndstat.c | 6 +- sys/emulation/linux/linux_stats.c | 6 +- sys/kern/kern_conf.c | 165 +++++++++++++++------------ sys/kern/kern_kinfo.c | 4 +- sys/kern/kern_shutdown.c | 10 +- sys/kern/vfs_conf.c | 20 ++-- sys/kern/vfs_subr.c | 18 +-- sys/netproto/smb/smb_dev.c | 4 +- sys/platform/pc32/i386/autoconf.c | 6 +- sys/platform/vkernel/i386/autoconf.c | 6 +- sys/sys/conf.h | 14 ++- sys/sys/disklabel.h | 6 +- sys/sys/disklabel32.h | 6 +- sys/sys/odisklabel.h | 6 +- sys/sys/param.h | 3 +- sys/sys/sysref.h | 9 +- sys/vfs/nfs/nfsdiskless.h | 4 +- sys/vm/vm_swap.c | 6 +- 24 files changed, 182 insertions(+), 151 deletions(-) diff --git a/lib/libkvm/kvm_proc.c b/lib/libkvm/kvm_proc.c index 9bc2df4373..4dd8f514ac 100644 --- a/lib/libkvm/kvm_proc.c +++ b/lib/libkvm/kvm_proc.c @@ -35,7 +35,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libkvm/kvm_proc.c,v 1.25.2.3 2002/08/24 07:27:46 kris Exp $ - * $DragonFly: src/lib/libkvm/kvm_proc.c,v 1.13 2007/04/29 01:36:04 dillon Exp $ + * $DragonFly: src/lib/libkvm/kvm_proc.c,v 1.14 2007/05/08 02:31:36 dillon Exp $ * * @(#)kvm_proc.c 8.3 (Berkeley) 9/23/93 */ @@ -192,9 +192,9 @@ kvm_proclist(kvm_t *kd, int what, int arg, struct proc *p, return (-1); } sess.s_ttyp = &tty; - if (tty.t_dev && tty.t_dev != NOCDEV) { + if (tty.t_dev && tty.t_dev != NULL) { if (KREAD(kd, (u_long)tty.t_dev, &cdev)) - tty.t_dev = NOCDEV; + tty.t_dev = NULL; else tty.t_dev = &cdev; } diff --git a/sys/bus/firewire/fwdev.c b/sys/bus/firewire/fwdev.c index a1040b8ff9..2a3b584299 100644 --- a/sys/bus/firewire/fwdev.c +++ b/sys/bus/firewire/fwdev.c @@ -32,7 +32,7 @@ * POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/dev/firewire/fwdev.c,v 1.36 2004/01/22 14:41:17 simokawa Exp $ - * $DragonFly: src/sys/bus/firewire/fwdev.c,v 1.18 2006/12/06 11:50:06 corecode Exp $ + * $DragonFly: src/sys/bus/firewire/fwdev.c,v 1.19 2007/05/08 02:31:37 dillon Exp $ * */ @@ -806,7 +806,7 @@ fwdev_clone(void *arg, char *name, int namelen, cdev_t *dev) int devflag[NDEVTYPE] = {0, FWMEM_FLAG}; int i, unit = 0, sub = 0; - if (*dev != NOCDEV) + if (*dev != NULL) return; for (i = 0; i < NDEVTYPE; i++) diff --git a/sys/conf/nfsswapkernel.c b/sys/conf/nfsswapkernel.c index 9553f61b99..28833c518c 100644 --- a/sys/conf/nfsswapkernel.c +++ b/sys/conf/nfsswapkernel.c @@ -35,7 +35,7 @@ * * from: @(#)nfsswapvmunix.c 8.1 (Berkeley) 6/10/93 * $FreeBSD: src/sys/conf/nfsswapkernel.c,v 1.6 1999/08/28 00:41:01 peter Exp $ - * $DragonFly: src/sys/conf/nfsswapkernel.c,v 1.4 2006/09/10 01:26:33 dillon Exp $ + * $DragonFly: src/sys/conf/nfsswapkernel.c,v 1.5 2007/05/08 02:31:38 dillon Exp $ */ /* @@ -56,8 +56,8 @@ extern int nfs_mountroot(); int (*mountroot)() = nfs_mountroot; -cdev_t rootdev = NOCDEV; -cdev_t dumpdev = NOCDEV; +cdev_t rootdev = NULL; +cdev_t dumpdev = NULL; struct nfs_diskless nfs_diskless = { { { 'q', 'e', '0', '\0' }, diff --git a/sys/dev/misc/kbd/kbd.c b/sys/dev/misc/kbd/kbd.c index ebf1230785..8bdcc57813 100644 --- a/sys/dev/misc/kbd/kbd.c +++ b/sys/dev/misc/kbd/kbd.c @@ -24,7 +24,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/dev/kbd/kbd.c,v 1.17.2.2 2001/07/30 16:46:43 yokota Exp $ - * $DragonFly: src/sys/dev/misc/kbd/kbd.c,v 1.22 2006/12/22 23:26:17 swildner Exp $ + * $DragonFly: src/sys/dev/misc/kbd/kbd.c,v 1.23 2007/05/08 02:31:39 dillon Exp $ */ /* * Generic keyboard driver. @@ -492,7 +492,7 @@ kbd_detach(keyboard_t *kbd) * Deal with refs properly. The KBD driver really ought to have * recorded the cdev_t separately. */ - if ((dev = make_adhoc_dev(&kbd_ops, kbd->kb_index)) != NOCDEV) { + if ((dev = make_adhoc_dev(&kbd_ops, kbd->kb_index)) != NULL) { if (dev->si_drv1) { kfree(dev->si_drv1, M_DEVBUF); dev->si_drv1 = NULL; diff --git a/sys/dev/misc/snp/snp.c b/sys/dev/misc/snp/snp.c index 7964fb5edb..8763fe956b 100644 --- a/sys/dev/misc/snp/snp.c +++ b/sys/dev/misc/snp/snp.c @@ -13,7 +13,7 @@ * Snoop stuff. * * $FreeBSD: src/sys/dev/snp/snp.c,v 1.69.2.2 2002/05/06 07:30:02 dd Exp $ - * $DragonFly: src/sys/dev/misc/snp/snp.c,v 1.18 2006/12/22 23:26:18 swildner Exp $ + * $DragonFly: src/sys/dev/misc/snp/snp.c,v 1.19 2007/05/08 02:31:41 dillon Exp $ */ #include @@ -387,7 +387,7 @@ snpopen(struct dev_open_args *ap) * snp_tty == NULL is for inactive snoop devices. */ snp->snp_tty = NULL; - snp->snp_target = NOCDEV; + snp->snp_target = NULL; LIST_INSERT_HEAD(&snp_sclist, snp, snp_list); return (0); @@ -419,7 +419,7 @@ snp_detach(struct snoop *snp) kprintf("Snoop: bad attached tty data.\n"); snp->snp_tty = NULL; - snp->snp_target = NOCDEV; + snp->snp_target = NULL; detach_notty: selwakeup(&snp->snp_sel); @@ -472,7 +472,7 @@ snpioctl(struct dev_ioctl_args *ap) switch (ap->a_cmd) { case SNPSTTY: tdev = udev2dev(*((udev_t *)ap->a_data), 0); - if (tdev == NOCDEV) + if (tdev == NULL) return (snp_down(snp)); tp = snpdevtotty(tdev); @@ -483,7 +483,7 @@ snpioctl(struct dev_ioctl_args *ap) crit_enter(); - if (snp->snp_target == NOCDEV) { + if (snp->snp_target == NULL) { tpo = snp->snp_tty; if (tpo) tpo->t_state &= ~TS_SNOOP; diff --git a/sys/dev/raid/vinum/vinumio.c b/sys/dev/raid/vinum/vinumio.c index e4509d60fe..1d2dfedea5 100644 --- a/sys/dev/raid/vinum/vinumio.c +++ b/sys/dev/raid/vinum/vinumio.c @@ -35,7 +35,7 @@ * * $Id: vinumio.c,v 1.30 2000/05/10 23:23:30 grog Exp grog $ * $FreeBSD: src/sys/dev/vinum/vinumio.c,v 1.52.2.6 2002/05/02 08:43:44 grog Exp $ - * $DragonFly: src/sys/dev/raid/vinum/vinumio.c,v 1.21 2007/03/12 12:10:13 swildner Exp $ + * $DragonFly: src/sys/dev/raid/vinum/vinumio.c,v 1.22 2007/05/08 02:31:42 dillon Exp $ */ #include "vinumhdr.h" @@ -139,7 +139,7 @@ open_drive(struct drive *drive, struct proc *p, int verbose) drive->dev = udev2dev(makeudev(devmajor, devminor), 0); - if (drive->dev == NOCDEV) + if (drive->dev == NULL) return ENODEV; drive->dev->si_iosize_max = DFLTPHYS; diff --git a/sys/dev/sound/pcm/sndstat.c b/sys/dev/sound/pcm/sndstat.c index bc5885982d..08471e4527 100644 --- a/sys/dev/sound/pcm/sndstat.c +++ b/sys/dev/sound/pcm/sndstat.c @@ -24,7 +24,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/sound/pcm/sndstat.c,v 1.20.2.2 2005/12/30 19:55:54 netchild Exp $ - * $DragonFly: src/sys/dev/sound/pcm/sndstat.c,v 1.11 2007/01/04 21:47:03 corecode Exp $ + * $DragonFly: src/sys/dev/sound/pcm/sndstat.c,v 1.12 2007/05/08 02:31:42 dillon Exp $ */ #include @@ -33,7 +33,7 @@ #include #endif -SND_DECLARE_FILE("$DragonFly: src/sys/dev/sound/pcm/sndstat.c,v 1.11 2007/01/04 21:47:03 corecode Exp $"); +SND_DECLARE_FILE("$DragonFly: src/sys/dev/sound/pcm/sndstat.c,v 1.12 2007/05/08 02:31:42 dillon Exp $"); #define SS_TYPE_MODULE 0 #define SS_TYPE_FIRST 1 @@ -345,7 +345,7 @@ sndstat_init(void) { lockinit(&sndstat_lock, "sndstat", 0, 0); if (make_dev(&sndstat_cdevsw, SND_DEV_STATUS, - UID_ROOT, GID_WHEEL, 0444, "sndstat") == NOCDEV) + UID_ROOT, GID_WHEEL, 0444, "sndstat") == NULL) return ENXIO; dev_ops_add(&sndstat_cdevsw, -1, SND_DEV_STATUS); diff --git a/sys/emulation/linux/linux_stats.c b/sys/emulation/linux/linux_stats.c index d1ae4843c4..2a455adfcf 100644 --- a/sys/emulation/linux/linux_stats.c +++ b/sys/emulation/linux/linux_stats.c @@ -26,7 +26,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/compat/linux/linux_stats.c,v 1.22.2.3 2001/11/05 19:08:23 marcel Exp $ - * $DragonFly: src/sys/emulation/linux/linux_stats.c,v 1.25 2006/12/23 00:27:02 swildner Exp $ + * $DragonFly: src/sys/emulation/linux/linux_stats.c,v 1.26 2007/05/08 02:31:42 dillon Exp $ */ #include @@ -76,7 +76,7 @@ newstat_copyout(struct stat *buf, void *ubuf) * in FreeBSD but block devices under Linux. */ if (S_ISCHR(tbuf.st_mode) && - (dev = udev2dev(buf->st_rdev, 0)) != NOCDEV) { + (dev = udev2dev(buf->st_rdev, 0)) != NULL) { if (dev_is_good(dev) && (dev_dflags(dev) & D_DISK)) { tbuf.st_mode &= ~S_IFMT; tbuf.st_mode |= S_IFBLK; @@ -320,7 +320,7 @@ sys_linux_ustat(struct linux_ustat_args *args) * ustat in that case. */ dev = udev2dev(makeudev(args->dev >> 8, args->dev & 0xFF), 0); - if (dev != NOCDEV && vfinddev(dev, VCHR, &vp)) { + if (dev != NULL && vfinddev(dev, VCHR, &vp)) { if (vp->v_mount == NULL) { return (EINVAL); } diff --git a/sys/kern/kern_conf.c b/sys/kern/kern_conf.c index dbb6269f4e..b2ca523d9c 100644 --- a/sys/kern/kern_conf.c +++ b/sys/kern/kern_conf.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/kern/kern_conf.c,v 1.73.2.3 2003/03/10 02:18:25 imp Exp $ - * $DragonFly: src/sys/kern/kern_conf.c,v 1.21 2007/05/07 15:43:30 dillon Exp $ + * $DragonFly: src/sys/kern/kern_conf.c,v 1.22 2007/05/08 02:31:42 dillon Exp $ */ #include @@ -46,17 +46,37 @@ #include #include +#include + #define cdevsw_ALLOCSTART (NUMCDEVSW/2) +static void cdev_terminate(struct cdev *dev); + MALLOC_DEFINE(M_DEVT, "cdev_t", "dev_t storage"); +/* + * SYSREF Integration - reference counting, allocation, + * sysid and syslink integration. + */ +static struct sysref_class cdev_sysref_class = { + .name = "cdev", + .mtype = M_DEVT, + .proto = SYSREF_PROTO_DEV, + .offset = offsetof(struct cdev, si_sysref), + .objsize = sizeof(struct cdev), + .mag_capacity = 32, + .flags = 0, + .ops = { + .terminate = (sysref_terminate_func_t)cdev_terminate + } +}; + /* * This is the number of hash-buckets. Experiements with 'real-life' * udev_t's show that a prime halfway between two powers of two works * best. */ #define DEVT_HASH 83 - static LIST_HEAD(, cdev) dev_hash[DEVT_HASH]; static int free_devt; @@ -70,29 +90,29 @@ SYSCTL_INT(_debug, OID_AUTO, dev_refs, CTLFLAG_RW, &dev_ref_debug, 0, ""); * when a device is destroyed. */ int -major(cdev_t x) +major(cdev_t dev) { - if (x == NOCDEV) + if (dev == NULL) return NOUDEV; - return((x->si_udev >> 8) & 0xff); + return((dev->si_udev >> 8) & 0xff); } int -minor(cdev_t x) +minor(cdev_t dev) { - if (x == NOCDEV) + if (dev == NULL) return NOUDEV; - return(x->si_udev & 0xffff00ff); + return(dev->si_udev & 0xffff00ff); } int -lminor(cdev_t x) +lminor(cdev_t dev) { int i; - if (x == NOCDEV) + if (dev == NULL) return NOUDEV; - i = minor(x); + i = minor(dev); return ((i & 0xff) | (i >> 8)); } @@ -133,12 +153,12 @@ hashdev(struct dev_ops *ops, int x, int y, int allow_intercept) return (si); } } - si = kmalloc(sizeof(*si), M_DEVT, M_WAITOK | M_USE_RESERVE | M_ZERO); + si = sysref_alloc(&cdev_sysref_class); si->si_ops = ops; si->si_flags |= SI_HASHED | SI_ADHOC; si->si_udev = udev; - si->si_refs = 1; LIST_INSERT_HEAD(&dev_hash[hash], si, si_hash); + sysref_activate(&si->si_sysref); dev_dclone(si); if (ops != &dead_dev_ops) @@ -146,7 +166,7 @@ hashdev(struct dev_ops *ops, int x, int y, int allow_intercept) if (dev_ref_debug) { kprintf("create dev %p %s(minor=%08x) refs=%d\n", si, devtoname(si), uminor(si->si_udev), - si->si_refs); + si->si_sysref.refcnt); } return (si); } @@ -155,11 +175,11 @@ hashdev(struct dev_ops *ops, int x, int y, int allow_intercept) * Convert a device pointer to a device number */ udev_t -dev2udev(cdev_t x) +dev2udev(cdev_t dev) { - if (x == NOCDEV) + if (dev == NULL) return NOUDEV; - return (x->si_udev); + return (dev->si_udev); } /* @@ -168,7 +188,7 @@ dev2udev(cdev_t x) * to keep ahold of the returned structure long term. * * The returned device is associated with the currently installed cdevsw - * for the requested major number. NOCDEV is returned if the major number + * for the requested major number. NULL is returned if the major number * has not been registered. */ cdev_t @@ -178,10 +198,10 @@ udev2dev(udev_t x, int b) struct dev_ops *ops; if (x == NOUDEV || b != 0) - return(NOCDEV); + return(NULL); ops = dev_ops_get(umajor(x), uminor(x)); if (ops == NULL) - return(NOCDEV); + return(NULL); dev = hashdev(ops, umajor(x), uminor(x), TRUE); return(dev); } @@ -189,7 +209,7 @@ udev2dev(udev_t x, int b) int dev_is_good(cdev_t dev) { - if (dev != NOCDEV && dev->si_ops != &dead_dev_ops) + if (dev != NULL && dev->si_ops != &dead_dev_ops) return(1); return(0); } @@ -303,7 +323,7 @@ destroy_dev(cdev_t dev) { int hash; - if (dev == NOCDEV) + if (dev == NULL) return; if ((dev->si_flags & SI_ADHOC) == 0) { release_dev(dev); @@ -312,13 +332,13 @@ destroy_dev(cdev_t dev) if (dev_ref_debug) { kprintf("destroy dev %p %s(minor=%08x) refs=%d\n", dev, devtoname(dev), uminor(dev->si_udev), - dev->si_refs); + dev->si_sysref.refcnt); } - if (dev->si_refs < 2) { + if (dev->si_sysref.refcnt < 2) { kprintf("destroy_dev(): too few references on device! " "%p %s(minor=%08x) refs=%d\n", dev, devtoname(dev), uminor(dev->si_udev), - dev->si_refs); + dev->si_sysref.refcnt); } dev->si_flags &= ~SI_ADHOC; if (dev->si_flags & SI_HASHED) { @@ -338,8 +358,8 @@ destroy_dev(cdev_t dev) dev->si_drv1 = NULL; dev->si_drv2 = NULL; dev->si_ops = &dead_dev_ops; - --dev->si_refs; /* release adhoc association reference */ - release_dev(dev); /* release callers reference */ + sysref_put(&dev->si_sysref); /* release adhoc association */ + release_dev(dev); /* release callers reference */ } /* @@ -371,7 +391,7 @@ destroy_all_devs(struct dev_ops *ops, u_int mask, u_int match) if (dev->si_ops == ops && (dev->si_udev & mask) == match ) { - ++dev->si_refs; + reference_dev(dev); destroy_dev(dev); } } @@ -390,20 +410,20 @@ destroy_all_devs(struct dev_ops *ops, u_int mask, u_int match) cdev_t reference_dev(cdev_t dev) { - if (dev != NOCDEV) { - ++dev->si_refs; + if (dev != NULL) { + sysref_get(&dev->si_sysref); if (dev_ref_debug) { kprintf("reference dev %p %s(minor=%08x) refs=%d\n", dev, devtoname(dev), uminor(dev->si_udev), - dev->si_refs); + dev->si_sysref.refcnt); } } return(dev); } /* - * release a reference on a device. The device will be freed when the last - * reference has been released. + * release a reference on a device. The device will be terminated when the + * last reference has been released. * * NOTE: we must use si_udev to figure out the original (major, minor), * because si_ops could already be pointing at dead_dev_ops. @@ -411,52 +431,49 @@ reference_dev(cdev_t dev) void release_dev(cdev_t dev) { - if (dev == NOCDEV) + if (dev == NULL) return; - if (free_devt) { - KKASSERT(dev->si_refs > 0); - } else { - if (dev->si_refs <= 0) { - kprintf("Warning: extra release of dev %p(%s)\n", - dev, devtoname(dev)); - free_devt = 0; /* prevent bad things from occuring */ - } - } - --dev->si_refs; + sysref_put(&dev->si_sysref); +} + +static +void +cdev_terminate(struct cdev *dev) +{ + int messedup = 0; + if (dev_ref_debug) { kprintf("release dev %p %s(minor=%08x) refs=%d\n", dev, devtoname(dev), uminor(dev->si_udev), - dev->si_refs); + dev->si_sysref.refcnt); } - if (dev->si_refs == 0) { - if (dev->si_flags & SI_ADHOC) { - kprintf("Warning: illegal final release on ADHOC" - " device %p(%s), the device was never" - " destroyed!\n", - dev, devtoname(dev)); - } - if (dev->si_flags & SI_HASHED) { - kprintf("Warning: last release on device, no call" - " to destroy_dev() was made! dev %p(%s)\n", - dev, devtoname(dev)); - dev->si_refs = 3; - destroy_dev(dev); - dev->si_refs = 0; - } - if (SLIST_FIRST(&dev->si_hlist) != NULL) { - kprintf("Warning: last release on device, vnode" - " associations still exist! dev %p(%s)\n", - dev, devtoname(dev)); - free_devt = 0; /* prevent bad things from occuring */ - } - if (dev->si_ops && dev->si_ops != &dead_dev_ops) { - dev_ops_release(dev->si_ops); - dev->si_ops = NULL; - } - if (free_devt) { - FREE(dev, M_DEVT); - } + if (dev->si_flags & SI_ADHOC) { + kprintf("Warning: illegal final release on ADHOC" + " device %p(%s), the device was never" + " destroyed!\n", + dev, devtoname(dev)); + messedup = 1; + } + if (dev->si_flags & SI_HASHED) { + kprintf("Warning: last release on device, no call" + " to destroy_dev() was made! dev %p(%s)\n", + dev, devtoname(dev)); + reference_dev(dev); + destroy_dev(dev); + messedup = 1; + } + if (SLIST_FIRST(&dev->si_hlist) != NULL) { + kprintf("Warning: last release on device, vnode" + " associations still exist! dev %p(%s)\n", + dev, devtoname(dev)); + messedup = 1; + } + if (dev->si_ops && dev->si_ops != &dead_dev_ops) { + dev_ops_release(dev->si_ops); + dev->si_ops = NULL; } + if (messedup == 0) + sysref_put(&dev->si_sysref); } const char * @@ -467,7 +484,7 @@ devtoname(cdev_t dev) char *p; const char *dname; - if (dev == NOCDEV) + if (dev == NULL) return("#nodev"); if (dev->si_name[0] == '#' || dev->si_name[0] == '\0') { p = dev->si_name; diff --git a/sys/kern/kern_kinfo.c b/sys/kern/kern_kinfo.c index d6a154fdf7..6666115930 100644 --- a/sys/kern/kern_kinfo.c +++ b/sys/kern/kern_kinfo.c @@ -32,7 +32,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sys/kern/kern_kinfo.c,v 1.9 2007/02/25 23:17:12 corecode Exp $ + * $DragonFly: src/sys/kern/kern_kinfo.c,v 1.10 2007/05/08 02:31:42 dillon Exp $ */ /* @@ -107,7 +107,7 @@ fill_kinfo_proc(struct proc *p, struct kinfo_proc *kp) if (SESS_LEADER(p)) kp->kp_auxflags |= KI_SLEADER; if (((p->p_flag & P_CONTROLT) != 0) && (sess->s_ttyp != NULL)) { - kp->kp_tdev = (sess->s_ttyp->t_dev != NOCDEV) ? + kp->kp_tdev = (sess->s_ttyp->t_dev != NULL) ? sess->s_ttyp->t_dev->si_udev : NOUDEV; if (sess->s_ttyp->t_pgrp != NULL) diff --git a/sys/kern/kern_shutdown.c b/sys/kern/kern_shutdown.c index 3e8d001565..4fb0d4d661 100644 --- a/sys/kern/kern_shutdown.c +++ b/sys/kern/kern_shutdown.c @@ -37,7 +37,7 @@ * * @(#)kern_shutdown.c 8.3 (Berkeley) 1/21/94 * $FreeBSD: src/sys/kern/kern_shutdown.c,v 1.72.2.12 2002/02/21 19:15:10 dillon Exp $ - * $DragonFly: src/sys/kern/kern_shutdown.c,v 1.50 2007/04/30 07:18:53 dillon Exp $ + * $DragonFly: src/sys/kern/kern_shutdown.c,v 1.51 2007/05/08 02:31:42 dillon Exp $ */ #include "opt_ddb.h" @@ -550,7 +550,7 @@ setdumpdev(cdev_t dev) int psize; long newdumplo; - if (dev == NOCDEV) { + if (dev == NULL) { dumpdev = dev; return (0); } @@ -580,12 +580,12 @@ dump_conf(void *dummy) path = kmalloc(MNAMELEN, M_TEMP, M_WAITOK); if (TUNABLE_STR_FETCH("dumpdev", path, MNAMELEN) != 0) { dev = kgetdiskbyname(path); - if (dev != NOCDEV) + if (dev != NULL) dumpdev = dev; } kfree(path, M_TEMP); if (setdumpdev(dumpdev) != 0) - dumpdev = NOCDEV; + dumpdev = NULL; } SYSINIT(dump_conf, SI_SUB_DUMP_CONF, SI_ORDER_FIRST, dump_conf, NULL) @@ -624,7 +624,7 @@ dumpsys(void) } if (!dodump) return; - if (dumpdev == NOCDEV) + if (dumpdev == NULL) return; dumpsize = Maxmem; kprintf("\ndumping to dev %s, offset %ld\n", devtoname(dumpdev), dumplo); diff --git a/sys/kern/vfs_conf.c b/sys/kern/vfs_conf.c index 8cf778b634..a1168e1cdf 100644 --- a/sys/kern/vfs_conf.c +++ b/sys/kern/vfs_conf.c @@ -26,7 +26,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/kern/vfs_conf.c,v 1.49.2.5 2003/01/07 11:56:53 joerg Exp $ - * $DragonFly: src/sys/kern/vfs_conf.c,v 1.27 2007/04/30 20:02:45 dillon Exp $ + * $DragonFly: src/sys/kern/vfs_conf.c,v 1.28 2007/05/08 02:31:42 dillon Exp $ */ /* @@ -157,7 +157,7 @@ vfs_mountroot(void *junk) /* * If a vfs set rootdev, try it (XXX VINUM HACK!) */ - if (save_rootdev != NOCDEV) { + if (save_rootdev != NULL) { rootdev = save_rootdev; if (!vfs_mountroot_try("")) return; @@ -237,7 +237,7 @@ vfs_mountroot_try(const char *mountfrom) kprintf("setrootbyname failed\n"); /* If the root device is a type "memory disk", mount RW */ - if (rootdev != NOCDEV && dev_is_good(rootdev) && + if (rootdev != NULL && dev_is_good(rootdev) && (dev_dflags(rootdev) & D_MEMDISK)) { mp->mnt_flag &= ~MNT_RDONLY; } @@ -384,7 +384,7 @@ kgetdiskbyname(const char *name) ++cp; if (cp == name) { kprintf("missing device name\n"); - return (NOCDEV); + return (NULL); } nlen = cp - name; @@ -394,7 +394,7 @@ kgetdiskbyname(const char *name) unit = strtol(cp, &cp, 10); if (name + nlen == (const char *)cp || unit < 0 || unit > DKMAXUNIT) { kprintf("bad unit: %d\n", unit); - return (NOCDEV); + return (NULL); } /* @@ -407,7 +407,7 @@ kgetdiskbyname(const char *name) slice = cp[1] - '0'; if (slice < 1 || slice > 9) { kprintf("bad slice number\n"); - return(NOCDEV); + return(NULL); } ++slice; /* slice #1 starts at 2 */ cp += 2; @@ -427,7 +427,7 @@ kgetdiskbyname(const char *name) if (*cp != '\0') { kprintf("junk after name\n"); - return (NOCDEV); + return (NULL); } /* @@ -446,7 +446,7 @@ kgetdiskbyname(const char *name) } if (cd == NUMCDEVSW) { kprintf("no such device '%*.*s'\n", nlen, nlen, name); - return (NOCDEV); + return (NULL); } /* @@ -466,7 +466,7 @@ setrootbyname(char *name) cdev_t diskdev; diskdev = kgetdiskbyname(name); - if (diskdev != NOCDEV) { + if (diskdev != NULL) { rootdev = diskdev; return (0); } @@ -484,7 +484,7 @@ DB_SHOW_COMMAND(disk, db_getdiskbyname) return; } dev = kgetdiskbyname(modif); - if (dev != NOCDEV) + if (dev != NULL) db_printf("cdev_t = %p\n", dev); else db_printf("No disk device matched.\n"); diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c index 668b3a77a9..ae90b64f02 100644 --- a/sys/kern/vfs_subr.c +++ b/sys/kern/vfs_subr.c @@ -37,7 +37,7 @@ * * @(#)vfs_subr.c 8.31 (Berkeley) 5/26/95 * $FreeBSD: src/sys/kern/vfs_subr.c,v 1.249.2.30 2003/04/04 20:35:57 tegge Exp $ - * $DragonFly: src/sys/kern/vfs_subr.c,v 1.102 2007/05/06 19:23:31 dillon Exp $ + * $DragonFly: src/sys/kern/vfs_subr.c,v 1.103 2007/05/08 02:31:42 dillon Exp $ */ /* @@ -974,7 +974,7 @@ bdevvp(cdev_t dev, struct vnode **vpp) struct vnode *nvp; int error; - if (dev == NOCDEV) { + if (dev == NULL) { *vpp = NULLVP; return (ENXIO); } @@ -996,7 +996,7 @@ v_associate_rdev(struct vnode *vp, cdev_t dev) { lwkt_tokref ilock; - if (dev == NULL || dev == NOCDEV) + if (dev == NULL || dev == NULL) return(ENXIO); if (dev_is_good(dev) == 0) return(ENXIO); @@ -1183,7 +1183,7 @@ vop_stdrevoke(struct vop_revoke_args *ap) if (vp->v_type != VCHR && vp->v_type != VBLK) return(0); if ((dev = vp->v_rdev) == NULL) { - if ((dev = udev2dev(vp->v_udev, vp->v_type == VBLK)) == NOCDEV) + if ((dev = udev2dev(vp->v_udev, vp->v_type == VBLK)) == NULL) return(0); } reference_dev(dev); @@ -1295,7 +1295,7 @@ vfinddev(cdev_t dev, enum vtype type, struct vnode **vpp) /* * Calculate the total number of references to a special device. This * routine may only be called for VBLK and VCHR vnodes since v_rdev is - * an overloaded field. Since udev2dev can now return NOCDEV, we have + * an overloaded field. Since udev2dev can now return NULL, we have * to check for a NULL v_rdev. */ int @@ -1321,7 +1321,7 @@ count_udev(udev_t udev) { cdev_t dev; - if ((dev = udev2dev(udev, 0)) == NOCDEV) + if ((dev = udev2dev(udev, 0)) == NULL) return(0); return(count_dev(dev)); } @@ -1524,7 +1524,7 @@ vfs_mountedon(struct vnode *vp) if ((dev = vp->v_rdev) == NULL) dev = udev2dev(vp->v_udev, (vp->v_type == VBLK)); - if (dev != NOCDEV && dev->si_mountpoint) + if (dev != NULL && dev->si_mountpoint) return (EBUSY); return (0); } @@ -1986,7 +1986,7 @@ cdev_t vn_todev(struct vnode *vp) { if (vp->v_type != VBLK && vp->v_type != VCHR) - return (NOCDEV); + return (NULL); KKASSERT(vp->v_rdev != NULL); return (vp->v_rdev); } @@ -2008,7 +2008,7 @@ vn_isdisk(struct vnode *vp, int *errp) if ((dev = vp->v_rdev) == NULL) dev = udev2dev(vp->v_udev, (vp->v_type == VBLK)); - if (dev == NULL || dev == NOCDEV) { + if (dev == NULL) { if (errp != NULL) *errp = ENXIO; return (0); diff --git a/sys/netproto/smb/smb_dev.c b/sys/netproto/smb/smb_dev.c index 2dcee62ff6..823289bc9c 100644 --- a/sys/netproto/smb/smb_dev.c +++ b/sys/netproto/smb/smb_dev.c @@ -30,7 +30,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/netsmb/smb_dev.c,v 1.2.2.1 2001/05/22 08:32:33 bp Exp $ - * $DragonFly: src/sys/netproto/smb/smb_dev.c,v 1.17 2006/12/22 23:57:54 swildner Exp $ + * $DragonFly: src/sys/netproto/smb/smb_dev.c,v 1.18 2007/05/08 02:31:42 dillon Exp $ */ #include #include @@ -388,7 +388,7 @@ smb_dev2share(int fd, int mode, struct smb_cred *scred, goto done; } dev = vn_todev(vp); - if (dev == NOCDEV) { + if (dev == NULL) { error = EBADF; goto done; } diff --git a/sys/platform/pc32/i386/autoconf.c b/sys/platform/pc32/i386/autoconf.c index fee16d7fce..07c7fd6c64 100644 --- a/sys/platform/pc32/i386/autoconf.c +++ b/sys/platform/pc32/i386/autoconf.c @@ -35,7 +35,7 @@ * * from: @(#)autoconf.c 7.1 (Berkeley) 5/9/91 * $FreeBSD: src/sys/i386/i386/autoconf.c,v 1.146.2.2 2001/06/07 06:05:58 dd Exp $ - * $DragonFly: src/sys/platform/pc32/i386/autoconf.c,v 1.36 2007/05/01 00:05:18 dillon Exp $ + * $DragonFly: src/sys/platform/pc32/i386/autoconf.c,v 1.37 2007/05/08 02:31:42 dillon Exp $ */ /* @@ -108,8 +108,8 @@ SYSINIT(configure2, SI_SUB_CONFIGURE, SI_ORDER_THIRD, configure, NULL); /* SI_ORDER_MIDDLE is hookable */ SYSINIT(configure3, SI_SUB_CONFIGURE, SI_ORDER_ANY, configure_final, NULL); -cdev_t rootdev = NOCDEV; -cdev_t dumpdev = NOCDEV; +cdev_t rootdev = NULL; +cdev_t dumpdev = NULL; /* * Determine i/o configuration for a machine. diff --git a/sys/platform/vkernel/i386/autoconf.c b/sys/platform/vkernel/i386/autoconf.c index e6e0bc1f64..3cac527b2a 100644 --- a/sys/platform/vkernel/i386/autoconf.c +++ b/sys/platform/vkernel/i386/autoconf.c @@ -35,7 +35,7 @@ * * from: @(#)autoconf.c 7.1 (Berkeley) 5/9/91 * $FreeBSD: src/sys/i386/i386/autoconf.c,v 1.146.2.2 2001/06/07 06:05:58 dd Exp $ - * $DragonFly: src/sys/platform/vkernel/i386/autoconf.c,v 1.9 2007/05/01 00:05:18 dillon Exp $ + * $DragonFly: src/sys/platform/vkernel/i386/autoconf.c,v 1.10 2007/05/08 02:31:43 dillon Exp $ */ /* @@ -114,8 +114,8 @@ SYSINIT(configure2, SI_SUB_CONFIGURE, SI_ORDER_THIRD, configure, NULL); /* SI_ORDER_MIDDLE is hookable */ SYSINIT(configure3, SI_SUB_CONFIGURE, SI_ORDER_ANY, configure_final, NULL); -cdev_t rootdev = NOCDEV; -cdev_t dumpdev = NOCDEV; +cdev_t rootdev = NULL; +cdev_t dumpdev = NULL; /* * diff --git a/sys/sys/conf.h b/sys/sys/conf.h index 663128c644..35e463edb8 100644 --- a/sys/sys/conf.h +++ b/sys/sys/conf.h @@ -37,15 +37,23 @@ * * @(#)conf.h 8.5 (Berkeley) 1/9/95 * $FreeBSD: src/sys/sys/conf.h,v 1.103.2.6 2002/03/11 01:14:55 dd Exp $ - * $DragonFly: src/sys/sys/conf.h,v 1.16 2007/05/07 05:21:42 dillon Exp $ + * $DragonFly: src/sys/sys/conf.h,v 1.17 2007/05/08 02:31:43 dillon Exp $ */ #ifndef _SYS_CONF_H_ #define _SYS_CONF_H_ +#if defined(_KERNEL) || defined(_KERNEL_STRUCTURES) + +#ifndef _SYS_QUEUE_H_ #include +#endif +#ifndef _SYS_TIME_H_ #include +#endif +#ifndef _SYS_BIOTRACK_H_ #include +#endif #ifndef _SYS_SYSREF_H_ #include #endif @@ -67,7 +75,6 @@ struct cdev { void *si_drv2; struct dev_ops *si_ops; /* device operations vector */ int si_iosize_max; /* maximum I/O size (for physio &al) */ - int si_refs; struct sysref si_sysref; union { struct { @@ -86,7 +93,7 @@ struct cdev { time_t si_lastwrite; /* time_second */ }; -#define SI_STASHED 0x0001 /* created in stashed storage */ +#define SI_UNUSED01 0x0001 #define SI_HASHED 0x0002 /* in (maj,min) hash table */ #define SI_ADHOC 0x0004 /* created via make_adhoc_dev() or udev2dev() */ #define SI_INTERCEPTED 0x0008 /* device ops was intercepted */ @@ -222,5 +229,6 @@ int dev_is_good(cdev_t dev); #define GID_DIALER 68 #endif /* _KERNEL */ +#endif /* _KERNEL || _KERNEL_STRUCTURES */ #endif /* !_SYS_CONF_H_ */ diff --git a/sys/sys/disklabel.h b/sys/sys/disklabel.h index 69cd3fe2a0..682d05f1fc 100644 --- a/sys/sys/disklabel.h +++ b/sys/sys/disklabel.h @@ -32,7 +32,7 @@ * * @(#)disklabel.h 8.2 (Berkeley) 7/10/94 * $FreeBSD: src/sys/sys/disklabel.h,v 1.49.2.7 2001/05/27 05:58:26 jkh Exp $ - * $DragonFly: src/sys/sys/disklabel.h,v 1.15 2006/09/10 01:26:40 dillon Exp $ + * $DragonFly: src/sys/sys/disklabel.h,v 1.16 2007/05/08 02:31:43 dillon Exp $ */ #ifndef _SYS_DISKLABEL_H_ @@ -47,8 +47,8 @@ #ifndef _SYS_IOCCOM_H_ #include #endif -#ifndef _SYS_CONF_H_ -#include +#if defined(_KERNEL) && !defined(_SYS_CONF_H_) +#include /* for make_sub_dev() */ #endif /* diff --git a/sys/sys/disklabel32.h b/sys/sys/disklabel32.h index 4d5b5e2802..2a56891d10 100644 --- a/sys/sys/disklabel32.h +++ b/sys/sys/disklabel32.h @@ -32,7 +32,7 @@ * * @(#)disklabel.h 8.2 (Berkeley) 7/10/94 * $FreeBSD: src/sys/sys/disklabel.h,v 1.49.2.7 2001/05/27 05:58:26 jkh Exp $ - * $DragonFly: src/sys/sys/disklabel32.h,v 1.15 2006/09/10 01:26:40 dillon Exp $ + * $DragonFly: src/sys/sys/disklabel32.h,v 1.16 2007/05/08 02:31:43 dillon Exp $ */ #ifndef _SYS_DISKLABEL_H_ @@ -47,8 +47,8 @@ #ifndef _SYS_IOCCOM_H_ #include #endif -#ifndef _SYS_CONF_H_ -#include +#if defined(_KERNEL) && !defined(_SYS_CONF_H_) +#include /* for make_sub_dev() */ #endif /* diff --git a/sys/sys/odisklabel.h b/sys/sys/odisklabel.h index f4b811c227..6fb4e50be4 100644 --- a/sys/sys/odisklabel.h +++ b/sys/sys/odisklabel.h @@ -32,7 +32,7 @@ * * @(#)disklabel.h 8.2 (Berkeley) 7/10/94 * $FreeBSD: src/sys/sys/disklabel.h,v 1.49.2.7 2001/05/27 05:58:26 jkh Exp $ - * $DragonFly: src/sys/sys/Attic/odisklabel.h,v 1.15 2006/09/10 01:26:40 dillon Exp $ + * $DragonFly: src/sys/sys/Attic/odisklabel.h,v 1.16 2007/05/08 02:31:43 dillon Exp $ */ #ifndef _SYS_DISKLABEL_H_ @@ -47,8 +47,8 @@ #ifndef _SYS_IOCCOM_H_ #include #endif -#ifndef _SYS_CONF_H_ -#include +#if defined(_KERNEL) && !defined(_SYS_CONF_H_) +#include /* for make_sub_dev() */ #endif /* diff --git a/sys/sys/param.h b/sys/sys/param.h index 63609642ea..97eb464ee1 100644 --- a/sys/sys/param.h +++ b/sys/sys/param.h @@ -37,7 +37,7 @@ * * @(#)param.h 8.3 (Berkeley) 4/4/95 * $FreeBSD: src/sys/sys/param.h,v 1.61.2.38 2003/05/22 17:12:01 fjoe Exp $ - * $DragonFly: src/sys/sys/param.h,v 1.39 2007/01/25 18:57:46 dillon Exp $ + * $DragonFly: src/sys/sys/param.h,v 1.40 2007/05/08 02:31:43 dillon Exp $ */ #ifndef _SYS_PARAM_H_ @@ -136,7 +136,6 @@ #define CMASK 022 /* default file mask: S_IWGRP|S_IWOTH */ #if defined(_KERNEL) || defined(_KERNEL_STRUCTURES) -#define NOCDEV (cdev_t)(-1) /* non-existent device */ #define NOUDEV (udev_t)(-1) /* non-existent device */ #define NOMAJ 256 /* non-existent device */ #endif diff --git a/sys/sys/sysref.h b/sys/sys/sysref.h index 9edae1ca17..91c659beeb 100644 --- a/sys/sys/sysref.h +++ b/sys/sys/sysref.h @@ -31,7 +31,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sys/sys/sysref.h,v 1.1 2007/04/29 01:29:31 dillon Exp $ + * $DragonFly: src/sys/sys/sysref.h,v 1.2 2007/05/08 02:31:43 dillon Exp $ */ /* * System resource registration, reference counter, and allocation @@ -57,6 +57,11 @@ #ifndef _SYS_OBJCACHE_H_ #include #endif +#ifndef _SYS_MALLOC_H_ +#include +#endif + +#if defined(_KERNEL) || defined(_KERNEL_STRUCTURES) /* * Register a resource structure type. Note that the destroy function @@ -111,6 +116,8 @@ struct sysref { RB_HEAD(sysref_rb_tree, sysref); RB_PROTOTYPE2(sysref_rb_tree, sysref, rbnode, rb_sysref_compare, sysid_t); +#endif + /* * Protocol numbers */ diff --git a/sys/vfs/nfs/nfsdiskless.h b/sys/vfs/nfs/nfsdiskless.h index 71611a05e3..1b8cb7740a 100644 --- a/sys/vfs/nfs/nfsdiskless.h +++ b/sys/vfs/nfs/nfsdiskless.h @@ -35,7 +35,7 @@ * * @(#)nfsdiskless.h 8.2 (Berkeley) 3/30/95 * $FreeBSD: src/sys/nfs/nfsdiskless.h,v 1.11 1999/08/28 00:50:02 peter Exp $ - * $DragonFly: src/sys/vfs/nfs/nfsdiskless.h,v 1.3 2006/09/09 19:34:46 dillon Exp $ + * $DragonFly: src/sys/vfs/nfs/nfsdiskless.h,v 1.4 2007/05/08 02:31:43 dillon Exp $ */ @@ -49,7 +49,7 @@ * interface can communicate with the server. * The primary bootstrap is expected to fill in the appropriate fields before * starting the kernel. Whether or not the swap area is nfs mounted is - * determined by the value in swdevt[0]. (equal to NOCDEV --> swap over nfs) + * determined by the value in swdevt[0]. (equal to NULL --> swap over nfs) * Currently only works for AF_INET protocols. * NB: All fields are stored in net byte order to avoid hassles with * client/server byte ordering differences. diff --git a/sys/vm/vm_swap.c b/sys/vm/vm_swap.c index 995b485581..88b481f1ed 100644 --- a/sys/vm/vm_swap.c +++ b/sys/vm/vm_swap.c @@ -32,7 +32,7 @@ * * @(#)vm_swap.c 8.5 (Berkeley) 2/17/94 * $FreeBSD: src/sys/vm/vm_swap.c,v 1.96.2.2 2001/10/14 18:46:47 iedowse Exp $ - * $DragonFly: src/sys/vm/vm_swap.c,v 1.33 2007/01/12 03:05:49 dillon Exp $ + * $DragonFly: src/sys/vm/vm_swap.c,v 1.34 2007/05/08 02:31:43 dillon Exp $ */ #include "opt_swap.h" @@ -271,9 +271,9 @@ swaponvp(struct thread *td, struct vnode *vp, u_long nblks) if (vp->v_type == VCHR) dev = vp->v_rdev; else - dev = NOCDEV; + dev = NULL; - if (nblks == 0 && dev != NOCDEV && ((nblks = dev_dpsize(dev)) == -1)) { + if (nblks == 0 && dev != NULL && ((nblks = dev_dpsize(dev)) == -1)) { VOP_CLOSE(vp, FREAD | FWRITE); return (ENXIO); } -- 2.41.0