aboutsummaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorPoul-Henning Kamp <phk@FreeBSD.org>2002-01-21 20:50:06 +0000
committerPoul-Henning Kamp <phk@FreeBSD.org>2002-01-21 20:50:06 +0000
commitb4a4f93c5ec904611c1f186b9dc8b59991e4af76 (patch)
treee9b23cfd393480dd2d0fdc3548ebed07a83132fc /sys
parent1e22a4f0485b5759a5467259812f01f57235c814 (diff)
downloadsrc-b4a4f93c5ec904611c1f186b9dc8b59991e4af76.tar.gz
src-b4a4f93c5ec904611c1f186b9dc8b59991e4af76.zip
Restructure slightly, eliminating some repetitive source lines and
making GEOM patches simpler and more readable at the same time.
Notes
Notes: svn path=/head/; revision=89628
Diffstat (limited to 'sys')
-rw-r--r--sys/dev/md/md.c111
1 files changed, 34 insertions, 77 deletions
diff --git a/sys/dev/md/md.c b/sys/dev/md/md.c
index ef2273160203..280581ac0e32 100644
--- a/sys/dev/md/md.c
+++ b/sys/dev/md/md.c
@@ -223,26 +223,14 @@ mdioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td)
return (ENOIOCTL);
}
-static void
-mdstart_malloc(struct md_s *sc)
+static int
+mdstart_malloc(struct md_s *sc, struct bio *bp)
{
int i;
- struct bio *bp;
devstat_trans_flags dop;
u_char *secp, **secpp, *dst;
unsigned secno, nsec, secval, uc;
- for (;;) {
- /* XXX: LOCK(unique unit numbers) */
- bp = bioq_first(&sc->bio_queue);
- if (bp)
- bioq_remove(&sc->bio_queue, bp);
- /* XXX: UNLOCK(unique unit numbers) */
- if (!bp)
- break;
-
- devstat_start_transaction(&sc->stats);
-
if (bp->bio_cmd == BIO_DELETE)
dop = DEVSTAT_NO_DATA;
else if (bp->bio_cmd == BIO_READ)
@@ -306,29 +294,15 @@ mdstart_malloc(struct md_s *sc)
dst += sc->secsize;
}
bp->bio_resid = 0;
- biofinish(bp, &sc->stats, 0);
- }
- return;
+ return (0);
}
-static void
-mdstart_preload(struct md_s *sc)
+static int
+mdstart_preload(struct md_s *sc, struct bio *bp)
{
- struct bio *bp;
devstat_trans_flags dop;
- for (;;) {
- /* XXX: LOCK(unique unit numbers) */
- bp = bioq_first(&sc->bio_queue);
- if (bp)
- bioq_remove(&sc->bio_queue, bp);
- /* XXX: UNLOCK(unique unit numbers) */
- if (!bp)
- break;
-
- devstat_start_transaction(&sc->stats);
-
if (bp->bio_cmd == BIO_DELETE) {
dop = DEVSTAT_NO_DATA;
} else if (bp->bio_cmd == BIO_READ) {
@@ -339,16 +313,13 @@ mdstart_preload(struct md_s *sc)
bcopy(bp->bio_data, sc->pl_ptr + (bp->bio_pblkno << DEV_BSHIFT), bp->bio_bcount);
}
bp->bio_resid = 0;
- biofinish(bp, &sc->stats, 0);
- }
- return;
+ return (0);
}
-static void
-mdstart_vnode(struct md_s *sc)
+static int
+mdstart_vnode(struct md_s *sc, struct bio *bp)
{
int error;
- struct bio *bp;
struct uio auio;
struct iovec aiov;
struct mount *mp;
@@ -361,17 +332,6 @@ mdstart_vnode(struct md_s *sc)
* still valid.
*/
- for (;;) {
- /* XXX: LOCK(unique unit numbers) */
- bp = bioq_first(&sc->bio_queue);
- if (bp)
- bioq_remove(&sc->bio_queue, bp);
- /* XXX: UNLOCK(unique unit numbers) */
- if (!bp)
- break;
-
- devstat_start_transaction(&sc->stats);
-
bzero(&auio, sizeof(auio));
aiov.iov_base = bp->bio_data;
@@ -402,45 +362,25 @@ mdstart_vnode(struct md_s *sc)
}
VOP_UNLOCK(sc->vnode, 0, curthread);
bp->bio_resid = auio.uio_resid;
- biofinish(bp, &sc->stats, error);
- }
- return;
+ return (error);
}
-static void
-mdstart_swap(struct md_s *sc)
+static int
+mdstart_swap(struct md_s *sc, struct bio *bp)
{
- struct bio *bp;
-
- for (;;) {
- /* XXX: LOCK(unique unit numbers) */
- bp = bioq_first(&sc->bio_queue);
- if (bp)
- bioq_remove(&sc->bio_queue, bp);
- /* XXX: UNLOCK(unique unit numbers) */
- if (!bp)
- break;
-
-#if 0
- devstat_start_transaction(&sc->stats);
-#endif
if ((bp->bio_cmd == BIO_DELETE) && (sc->flags & MD_RESERVE))
biodone(bp);
else
vm_pager_strategy(sc->object, bp);
-
-#if 0
- devstat_end_transaction_bio(&sc->stats, bp);
-#endif
- }
- return;
+ return (-1);
}
static void
mdstrategy(struct bio *bp)
{
struct md_s *sc;
+ int error;
if (md_debug > 1)
printf("mdstrategy(%p) %s %x, %d, %ld, %p)\n",
@@ -456,22 +396,39 @@ mdstrategy(struct bio *bp)
if (atomic_cmpset_int(&sc->busy, 0, 1) == 0)
return;
+ for (;;) {
+ /* XXX: LOCK(unique unit numbers) */
+ bp = bioq_first(&sc->bio_queue);
+ if (bp)
+ bioq_remove(&sc->bio_queue, bp);
+ /* XXX: UNLOCK(unique unit numbers) */
+ if (!bp)
+ break;
+
+
switch (sc->type) {
case MD_MALLOC:
- mdstart_malloc(sc);
+ devstat_start_transaction(&sc->stats);
+ error = mdstart_malloc(sc, bp);
break;
case MD_PRELOAD:
- mdstart_preload(sc);
+ devstat_start_transaction(&sc->stats);
+ error = mdstart_preload(sc, bp);
break;
case MD_VNODE:
- mdstart_vnode(sc);
+ devstat_start_transaction(&sc->stats);
+ error = mdstart_vnode(sc, bp);
break;
case MD_SWAP:
- mdstart_swap(sc);
+ error = mdstart_swap(sc, bp);
break;
default:
panic("Impossible md(type)");
break;
+ }
+
+ if (error != -1)
+ biofinish(bp, &sc->stats, error);
}
sc->busy = 0;
}