From 1a52a73d68632fda840fd88a8377c4e791bfff20 Mon Sep 17 00:00:00 2001 From: Poul-Henning Kamp Date: Thu, 23 Sep 2004 14:45:04 +0000 Subject: [PATCH] Eliminate DEV_STRATEGY() macro: call dev_strategy() directly. Make dev_strategy() handle errors and departing devices properly. --- sys/fs/specfs/spec_vnops.c | 20 ++------------------ sys/kern/kern_physio.c | 2 +- sys/kern/vfs_aio.c | 2 +- sys/kern/vfs_bio.c | 15 ++++++++++++--- sys/sys/conf.h | 2 -- 5 files changed, 16 insertions(+), 25 deletions(-) diff --git a/sys/fs/specfs/spec_vnops.c b/sys/fs/specfs/spec_vnops.c index f1f8075c5e27..1d4a12a343af 100644 --- a/sys/fs/specfs/spec_vnops.c +++ b/sys/fs/specfs/spec_vnops.c @@ -476,7 +476,6 @@ static int spec_xstrategy(struct vnode *vp, struct buf *bp) { struct mount *mp; - struct cdevsw *dsw; struct thread *td = curthread; KASSERT(bp->b_iocmd == BIO_READ || bp->b_iocmd == BIO_WRITE, @@ -508,23 +507,8 @@ spec_xstrategy(struct vnode *vp, struct buf *bp) mp->mnt_stat.f_syncreads++; } } - dsw = devsw(bp->b_dev); - if (dsw == NULL) { - bp->b_error = ENXIO; - bp->b_ioflags |= BIO_ERROR; - bufdone(bp); - return (0); - } - KASSERT(dsw->d_strategy != NULL, - ("No strategy on dev %s responsible for buffer %p\n", - devtoname(bp->b_dev), bp)); - - if (!(dsw->d_flags & D_NEEDGIANT)) { - /* XXX: notyet DROP_GIANT(); */ - DEV_STRATEGY(bp); - /* XXX: notyet PICKUP_GIANT(); */ - } else - DEV_STRATEGY(bp); + + dev_strategy(bp); return (0); } diff --git a/sys/kern/kern_physio.c b/sys/kern/kern_physio.c index 803995c0380b..a6d47e1fbbe0 100644 --- a/sys/kern/kern_physio.c +++ b/sys/kern/kern_physio.c @@ -95,7 +95,7 @@ physio(struct cdev *dev, struct uio *uio, int ioflag) goto doerror; } - DEV_STRATEGY(bp); + dev_strategy(bp); if (uio->uio_rw == UIO_READ) bwait(bp, PRIBIO, "physrd"); else diff --git a/sys/kern/vfs_aio.c b/sys/kern/vfs_aio.c index 21bc1019b228..b72e3c3bd324 100644 --- a/sys/kern/vfs_aio.c +++ b/sys/kern/vfs_aio.c @@ -1144,7 +1144,7 @@ aio_qphysio(struct proc *p, struct aiocblist *aiocbe) splx(s); /* Perform transfer. */ - DEV_STRATEGY(bp); + dev_strategy(bp); notify = 0; s = splbio(); diff --git a/sys/kern/vfs_bio.c b/sys/kern/vfs_bio.c index b2e73b96e210..853803c540dc 100644 --- a/sys/kern/vfs_bio.c +++ b/sys/kern/vfs_bio.c @@ -3105,14 +3105,23 @@ dev_strategy(struct buf *bp) bp->b_io.bio_done = bufdonebio; bp->b_io.bio_caller2 = bp; dev = bp->b_io.bio_dev; - csw = devsw(dev); KASSERT(dev->si_refcount > 0, ("dev_strategy on un-referenced struct cdev *(%s)", devtoname(dev))); dev_lock(); - dev->si_threadcount++; + csw = devsw(dev); + if (csw != NULL) + dev->si_threadcount++; dev_unlock(); - (*devsw(bp->b_io.bio_dev)->d_strategy)(&bp->b_io); + if (csw == NULL) { + bp->b_error = ENXIO; + bp->b_ioflags = BIO_ERROR; + mtx_lock(&Giant); /* XXX: too defensive ? */ + bufdone(bp); + mtx_unlock(&Giant); /* XXX: too defensive ? */ + return; + } + (*csw->d_strategy)(&bp->b_io); dev_lock(); dev->si_threadcount--; dev_unlock(); diff --git a/sys/sys/conf.h b/sys/sys/conf.h index c714019c1e10..eed4b4b9d293 100644 --- a/sys/sys/conf.h +++ b/sys/sys/conf.h @@ -160,8 +160,6 @@ typedef int dumper_t( off_t offset, /* Byte-offset to write at. */ size_t length); /* Number of bytes to dump. */ -#define DEV_STRATEGY(bp) dev_strategy(bp) - #endif /* _KERNEL */ /*