Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/pgoyette-localcount]: src/sys/kern Use {b, c}devsw_acquire() and {b, c}dev...



details:   https://anonhg.NetBSD.org/src/rev/475eb38dfcad
branches:  pgoyette-localcount
changeset: 852906:475eb38dfcad
user:      pgoyette <pgoyette%NetBSD.org@localhost>
date:      Tue Apr 25 21:53:06 2017 +0000

description:
Use {b,c}devsw_acquire() and {b,c}devsw_release() in the various device
acccess methods.

diffstat:

 sys/kern/subr_devsw.c |  101 ++++++++++++++++++++++++++++++++++---------------
 1 files changed, 69 insertions(+), 32 deletions(-)

diffs (truncated from 359 to 300 lines):

diff -r aafe4efdfd73 -r 475eb38dfcad sys/kern/subr_devsw.c
--- a/sys/kern/subr_devsw.c     Tue Apr 25 21:36:41 2017 +0000
+++ b/sys/kern/subr_devsw.c     Tue Apr 25 21:53:06 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: subr_devsw.c,v 1.34.2.16 2017/04/25 21:36:41 pgoyette Exp $    */
+/*     $NetBSD: subr_devsw.c,v 1.34.2.17 2017/04/25 21:53:06 pgoyette Exp $    */
 
 /*-
  * Copyright (c) 2001, 2002, 2007, 2008 The NetBSD Foundation, Inc.
@@ -69,7 +69,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_devsw.c,v 1.34.2.16 2017/04/25 21:36:41 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_devsw.c,v 1.34.2.17 2017/04/25 21:53:06 pgoyette Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_dtrace.h"
@@ -877,7 +877,7 @@
         * with attach/detach.
         */
        mutex_enter(&device_lock);
-       d = bdevsw_lookup(dev);
+       d = bdevsw_lookup_acquire(dev);
        mutex_exit(&device_lock);
        if (d == NULL)
                return ENXIO;
@@ -885,6 +885,7 @@
        DEV_LOCK(d);
        rv = (*d->d_open)(dev, flag, devtype, l);
        DEV_UNLOCK(d);
+       bdevsw_release(dev);
 
        return rv;
 }
@@ -895,12 +896,13 @@
        const struct bdevsw *d;
        int rv, mpflag;
 
-       if ((d = bdevsw_lookup(dev)) == NULL)
+       if ((d = bdevsw_lookup_acquire(dev)) == NULL)
                return ENXIO;
 
        DEV_LOCK(d);
        rv = (*d->d_close)(dev, flag, devtype, l);
        DEV_UNLOCK(d);
+       bdevsw_release(dev);
 
        return rv;
 }
@@ -916,7 +918,7 @@
 
        SDT_PROBE1(io, kernel, , start, bp);
 
-       if ((d = bdevsw_lookup(bp->b_dev)) == NULL) {
+       if ((d = bdevsw_lookup_acquire(bp->b_dev)) == NULL) {
                bp->b_error = ENXIO;
                bp->b_resid = bp->b_bcount;
                biodone_vfs(bp); /* biodone() iff vfs present */
@@ -926,6 +928,7 @@
        DEV_LOCK(d);
        (*d->d_strategy)(bp);
        DEV_UNLOCK(d);
+       bdevsw_release(bp->b_dev);
 }
 
 int
@@ -934,12 +937,13 @@
        const struct bdevsw *d;
        int rv, mpflag;
 
-       if ((d = bdevsw_lookup(dev)) == NULL)
+       if ((d = bdevsw_lookup_acquire(dev)) == NULL)
                return ENXIO;
 
        DEV_LOCK(d);
        rv = (*d->d_ioctl)(dev, cmd, data, flag, l);
        DEV_UNLOCK(d);
+       bdevsw_release(dev);
 
        return rv;
 }
@@ -969,20 +973,28 @@
 bdev_flags(dev_t dev)
 {
        const struct bdevsw *d;
+       int rv;
 
-       if ((d = bdevsw_lookup(dev)) == NULL)
+       if ((d = bdevsw_lookup_acquire(dev)) == NULL)
                return 0;
-       return d->d_flag & ~D_TYPEMASK;
+       rv = d->d_flag & ~D_TYPEMASK;
+       bdevsw_release();
+
+       return rv;
 }
 
 int
 bdev_type(dev_t dev)
 {
        const struct bdevsw *d;
+       int rv;
 
-       if ((d = bdevsw_lookup(dev)) == NULL)
+       if ((d = bdevsw_lookup_acquire(dev)) == NULL)
                return D_OTHER;
-       return d->d_flag & D_TYPEMASK;
+       rv = d->d_flag & D_TYPEMASK;
+       bdevsw_release(dev);
+
+       return rv;
 }
 
 int
@@ -991,7 +1003,7 @@
        const struct bdevsw *d;
        int rv, mpflag = 0;
 
-       if ((d = bdevsw_lookup(dev)) == NULL ||
+       if ((d = bdevsw_lookup_acquire(dev)) == NULL ||
            d->d_psize == NULL)
                return -1;
 
@@ -1004,7 +1016,7 @@
        rv = (*d->d_psize)(dev);
        if ((boothowto & RB_DUMP) == 0)
                DEV_UNLOCK(d);
-
+       bdevsw_release(dev);
        return rv;
 }
 
@@ -1014,12 +1026,13 @@
        const struct bdevsw *d;
        int rv, mpflag;
 
-       if ((d = bdevsw_lookup(dev)) == NULL)
+       if ((d = bdevsw_lookup_acquire(dev)) == NULL)
                return ENXIO;
 
        DEV_LOCK(d);
        rv = (*d->d_discard)(dev, pos, len);
        DEV_UNLOCK(d);
+       bdevsw_release(dev);
 
        return rv;
 }
@@ -1035,7 +1048,7 @@
         * with attach/detach.
         */
        mutex_enter(&device_lock);
-       d = cdevsw_lookup(dev);
+       d = cdevsw_lookup_acquire(dev);
        mutex_exit(&device_lock);
        if (d == NULL)
                return ENXIO;
@@ -1043,6 +1056,7 @@
        DEV_LOCK(d);
        rv = (*d->d_open)(dev, flag, devtype, l);
        DEV_UNLOCK(d);
+       cdevsw_release(dev);
 
        return rv;
 }
@@ -1053,12 +1067,13 @@
        const struct cdevsw *d;
        int rv, mpflag;
 
-       if ((d = cdevsw_lookup(dev)) == NULL)
+       if ((d = cdevsw_lookup_acquire(dev)) == NULL)
                return ENXIO;
 
        DEV_LOCK(d);
        rv = (*d->d_close)(dev, flag, devtype, l);
        DEV_UNLOCK(d);
+       cdevsw_release(dev);
 
        return rv;
 }
@@ -1069,12 +1084,13 @@
        const struct cdevsw *d;
        int rv, mpflag;
 
-       if ((d = cdevsw_lookup(dev)) == NULL)
+       if ((d = cdevsw_lookup_acquire(dev)) == NULL)
                return ENXIO;
 
        DEV_LOCK(d);
        rv = (*d->d_read)(dev, uio, flag);
        DEV_UNLOCK(d);
+       cdevsw_release(dev);
 
        return rv;
 }
@@ -1085,12 +1101,13 @@
        const struct cdevsw *d;
        int rv, mpflag;
 
-       if ((d = cdevsw_lookup(dev)) == NULL)
+       if ((d = cdevsw_lookup_acquire(dev)) == NULL)
                return ENXIO;
 
        DEV_LOCK(d);
        rv = (*d->d_write)(dev, uio, flag);
        DEV_UNLOCK(d);
+       cdevsw_release(dev);
 
        return rv;
 }
@@ -1101,12 +1118,13 @@
        const struct cdevsw *d;
        int rv, mpflag;
 
-       if ((d = cdevsw_lookup(dev)) == NULL)
+       if ((d = cdevsw_lookup_acquire(dev)) == NULL)
                return ENXIO;
 
        DEV_LOCK(d);
        rv = (*d->d_ioctl)(dev, cmd, data, flag, l);
        DEV_UNLOCK(d);
+       cdevsw_release(dev);
 
        return rv;
 }
@@ -1117,27 +1135,32 @@
        const struct cdevsw *d;
        int mpflag;
 
-       if ((d = cdevsw_lookup(tp->t_dev)) == NULL)
+       if ((d = cdevsw_lookup_acquire(tp->t_dev)) == NULL)
                return;
 
        DEV_LOCK(d);
        (*d->d_stop)(tp, flag);
        DEV_UNLOCK(d);
+       cdevsw_release(tp->t_dev);
 }
 
 struct tty *
 cdev_tty(dev_t dev)
 {
        const struct cdevsw *d;
+       struct tty *rv;
 
-       if ((d = cdevsw_lookup(dev)) == NULL)
+       if ((d = cdevsw_lookup_acquire(dev)) == NULL)
                return NULL;
 
        /* XXX Check if necessary. */
        if (d->d_tty == NULL)
-               return NULL;
+               rv = NULL;
+       else
+               rv= (*d->d_tty)(dev);
+       cdevsw_release(dev);
 
-       return (*d->d_tty)(dev);
+       return rv;
 }
 
 int
@@ -1146,12 +1169,13 @@
        const struct cdevsw *d;
        int rv, mpflag;
 
-       if ((d = cdevsw_lookup(dev)) == NULL)
+       if ((d = cdevsw_lookup_acquire(dev)) == NULL)
                return POLLERR;
 
        DEV_LOCK(d);
        rv = (*d->d_poll)(dev, flag, l);
        DEV_UNLOCK(d);
+       cdevsw_release(dev);
 
        return rv;
 }
@@ -1163,12 +1187,13 @@
        paddr_t rv;
        int mpflag;
 
-       if ((d = cdevsw_lookup(dev)) == NULL)
+       if ((d = cdevsw_lookup_acquire(dev)) == NULL)
                return (paddr_t)-1LL;
 
        DEV_LOCK(d);
        rv = (*d->d_mmap)(dev, off, flag);
        DEV_UNLOCK(d);
+       cdevsw_release(dev);
 
        return rv;
 }
@@ -1179,12 +1204,13 @@
        const struct cdevsw *d;
        int rv, mpflag;
 
-       if ((d = cdevsw_lookup(dev)) == NULL)
+       if ((d = cdevsw_lookup_acquire(dev)) == NULL)
                return ENXIO;
 



Home | Main Index | Thread Index | Old Index