From owner-svn-src-all@FreeBSD.ORG Wed Apr 10 08:49:38 2013 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id AD836E27; Wed, 10 Apr 2013 08:49:38 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id 9F5B5E30; Wed, 10 Apr 2013 08:49:38 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.6/8.14.6) with ESMTP id r3A8nckU054183; Wed, 10 Apr 2013 08:49:38 GMT (envelope-from kib@svn.freebsd.org) Received: (from kib@localhost) by svn.freebsd.org (8.14.6/8.14.5/Submit) id r3A8ncOk054180; Wed, 10 Apr 2013 08:49:38 GMT (envelope-from kib@svn.freebsd.org) Message-Id: <201304100849.r3A8ncOk054180@svn.freebsd.org> From: Konstantin Belousov Date: Wed, 10 Apr 2013 08:49:38 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org Subject: svn commit: r249329 - in stable/9/sys: kern sys X-SVN-Group: stable-9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 10 Apr 2013 08:49:38 -0000 Author: kib Date: Wed Apr 10 08:49:37 2013 New Revision: 249329 URL: http://svnweb.freebsd.org/changeset/base/249329 Log: MFC r248792: Add dev_strategy_csw() function. Use it from physio(), to avoid two extra dev_mtx lock and unlock. Do some style cleanup in physio(). Modified: stable/9/sys/kern/kern_physio.c stable/9/sys/kern/vfs_bio.c stable/9/sys/sys/conf.h Directory Properties: stable/9/sys/ (props changed) stable/9/sys/sys/ (props changed) Modified: stable/9/sys/kern/kern_physio.c ============================================================================== --- stable/9/sys/kern/kern_physio.c Wed Apr 10 08:48:10 2013 (r249328) +++ stable/9/sys/kern/kern_physio.c Wed Apr 10 08:49:37 2013 (r249329) @@ -34,11 +34,11 @@ __FBSDID("$FreeBSD$"); int physio(struct cdev *dev, struct uio *uio, int ioflag) { - int i; - int error; + struct buf *bp; + struct cdevsw *csw; caddr_t sa; u_int iolen; - struct buf *bp; + int error, i; /* Keep the process UPAGES from being swapped. XXX: why ? */ PHOLD(curproc); @@ -90,14 +90,14 @@ physio(struct cdev *dev, struct uio *uio bp->b_bufsize = bp->b_bcount; bp->b_blkno = btodb(bp->b_offset); - - if (uio->uio_segflg == UIO_USERSPACE) + csw = dev->si_devsw; + if (uio->uio_segflg == UIO_USERSPACE) { if (vmapbuf(bp) < 0) { error = EFAULT; goto doerror; } - - dev_strategy(dev, bp); + } + dev_strategy_csw(dev, csw, bp); if (uio->uio_rw == UIO_READ) bwait(bp, PRIBIO, "physrd"); else Modified: stable/9/sys/kern/vfs_bio.c ============================================================================== --- stable/9/sys/kern/vfs_bio.c Wed Apr 10 08:48:10 2013 (r249328) +++ stable/9/sys/kern/vfs_bio.c Wed Apr 10 08:49:37 2013 (r249329) @@ -3317,11 +3317,34 @@ void dev_strategy(struct cdev *dev, struct buf *bp) { struct cdevsw *csw; - struct bio *bip; int ref; - if ((!bp->b_iocmd) || (bp->b_iocmd & (bp->b_iocmd - 1))) - panic("b_iocmd botch"); + KASSERT(dev->si_refcount > 0, + ("dev_strategy on un-referenced struct cdev *(%s) %p", + devtoname(dev), dev)); + + csw = dev_refthread(dev, &ref); + dev_strategy_csw(dev, csw, bp); + dev_relthread(dev, ref); +} + +void +dev_strategy_csw(struct cdev *dev, struct cdevsw *csw, struct buf *bp) +{ + struct bio *bip; + + KASSERT(bp->b_iocmd == BIO_READ || bp->b_iocmd == BIO_WRITE, + ("b_iocmd botch")); + KASSERT(((dev->si_flags & SI_ETERNAL) != 0 && csw != NULL) || + dev->si_threadcount > 0, + ("dev_strategy_csw threadcount cdev *(%s) %p", devtoname(dev), + dev)); + if (csw == NULL) { + bp->b_error = ENXIO; + bp->b_ioflags = BIO_ERROR; + bufdone(bp); + return; + } for (;;) { bip = g_new_bio(); if (bip != NULL) @@ -3337,19 +3360,7 @@ dev_strategy(struct cdev *dev, struct bu bip->bio_done = bufdonebio; bip->bio_caller2 = bp; bip->bio_dev = dev; - KASSERT(dev->si_refcount > 0, - ("dev_strategy on un-referenced struct cdev *(%s)", - devtoname(dev))); - csw = dev_refthread(dev, &ref); - if (csw == NULL) { - g_destroy_bio(bip); - bp->b_error = ENXIO; - bp->b_ioflags = BIO_ERROR; - bufdone(bp); - return; - } (*csw->d_strategy)(bip); - dev_relthread(dev, ref); } /* Modified: stable/9/sys/sys/conf.h ============================================================================== --- stable/9/sys/sys/conf.h Wed Apr 10 08:48:10 2013 (r249328) +++ stable/9/sys/sys/conf.h Wed Apr 10 08:49:37 2013 (r249329) @@ -258,6 +258,7 @@ void dev_ref(struct cdev *dev); void dev_refl(struct cdev *dev); void dev_rel(struct cdev *dev); void dev_strategy(struct cdev *dev, struct buf *bp); +void dev_strategy_csw(struct cdev *dev, struct cdevsw *csw, struct buf *bp); struct cdev *make_dev(struct cdevsw *_devsw, int _unit, uid_t _uid, gid_t _gid, int _perms, const char *_fmt, ...) __printflike(6, 7); struct cdev *make_dev_cred(struct cdevsw *_devsw, int _unit,