A bit of sanity-checking in bioqdisksort(): panic if we recurse.

This commit is contained in:
Poul-Henning Kamp 2001-01-14 18:48:42 +00:00
parent 52f1d19f90
commit 9039f19fa0
2 changed files with 10 additions and 0 deletions

@ -47,6 +47,7 @@
#include <sys/disklabel.h> #include <sys/disklabel.h>
#include <sys/diskslice.h> #include <sys/diskslice.h>
#include <sys/syslog.h> #include <sys/syslog.h>
#include <machine/atomic.h>
/* /*
* Seek sort for disks. * Seek sort for disks.
@ -72,6 +73,8 @@ bioqdisksort(bioq, bp)
struct bio *bn; struct bio *bn;
struct bio *be; struct bio *be;
if (!atomic_cmpset_int(&bioq->busy, 0, 1))
panic("Recursing in bioqdisksort()");
be = TAILQ_LAST(&bioq->queue, bio_queue); be = TAILQ_LAST(&bioq->queue, bio_queue);
/* /*
* If the queue is empty or we are an * If the queue is empty or we are an
@ -80,6 +83,7 @@ bioqdisksort(bioq, bp)
if ((bq = bioq_first(bioq)) == NULL if ((bq = bioq_first(bioq)) == NULL
|| (bp->bio_flags & BIO_ORDERED) != 0) { || (bp->bio_flags & BIO_ORDERED) != 0) {
bioq_insert_tail(bioq, bp); bioq_insert_tail(bioq, bp);
bioq->busy = 0;
return; return;
} else if (bioq->insert_point != NULL) { } else if (bioq->insert_point != NULL) {
@ -108,6 +112,7 @@ bioqdisksort(bioq, bp)
if (bq == NULL) { if (bq == NULL) {
bioq->switch_point = bp; bioq->switch_point = bp;
bioq_insert_tail(bioq, bp); bioq_insert_tail(bioq, bp);
bioq->busy = 0;
return; return;
} }
/* /*
@ -118,6 +123,7 @@ bioqdisksort(bioq, bp)
if (bp->bio_pblkno < bq->bio_pblkno) { if (bp->bio_pblkno < bq->bio_pblkno) {
bioq->switch_point = bp; bioq->switch_point = bp;
TAILQ_INSERT_BEFORE(bq, bp, bio_queue); TAILQ_INSERT_BEFORE(bq, bp, bio_queue);
bioq->busy = 0;
return; return;
} }
} else { } else {
@ -130,6 +136,7 @@ bioqdisksort(bioq, bp)
*/ */
if (bp->bio_pblkno < bq->bio_pblkno) { if (bp->bio_pblkno < bq->bio_pblkno) {
TAILQ_INSERT_BEFORE(bq, bp, bio_queue); TAILQ_INSERT_BEFORE(bq, bp, bio_queue);
bioq->busy = 0;
return; return;
} }
} }
@ -141,6 +148,7 @@ bioqdisksort(bioq, bp)
*/ */
if (bp->bio_pblkno > be->bio_pblkno) { if (bp->bio_pblkno > be->bio_pblkno) {
TAILQ_INSERT_AFTER(&bioq->queue, be, bp, bio_queue); TAILQ_INSERT_AFTER(&bioq->queue, be, bp, bio_queue);
bioq->busy = 0;
return; return;
} }
@ -158,6 +166,7 @@ bioqdisksort(bioq, bp)
bq = bn; bq = bn;
} }
TAILQ_INSERT_AFTER(&bioq->queue, bq, bp, bio_queue); TAILQ_INSERT_AFTER(&bioq->queue, bq, bp, bio_queue);
bioq->busy = 0;
} }

@ -108,6 +108,7 @@ struct bio_queue_head {
daddr_t last_pblkno; daddr_t last_pblkno;
struct bio *insert_point; struct bio *insert_point;
struct bio *switch_point; struct bio *switch_point;
int busy;
}; };
static __inline void bioq_init __P((struct bio_queue_head *head)); static __inline void bioq_init __P((struct bio_queue_head *head));