From 407c6ab231cb4e283e1d34d30ca554a78f12e6db Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Sat, 11 Jun 2005 00:05:46 +0000 Subject: [PATCH] spl->critical section conversion. --- sys/dev/raid/vinum/vinumdaemon.c | 13 +++++-------- sys/dev/raid/vinum/vinumhdr.h | 3 ++- sys/dev/raid/vinum/vinumlock.c | 7 +++---- sys/dev/raid/vinum/vinummemory.c | 19 +++++++++---------- sys/dev/raid/vinum/vinumrequest.c | 31 ++++++++----------------------- sys/dev/raid/vinum/vinumrevive.c | 25 +++++++++++-------------- 6 files changed, 38 insertions(+), 60 deletions(-) diff --git a/sys/dev/raid/vinum/vinumdaemon.c b/sys/dev/raid/vinum/vinumdaemon.c index 09cb37630c..c6ad6f8ccf 100644 --- a/sys/dev/raid/vinum/vinumdaemon.c +++ b/sys/dev/raid/vinum/vinumdaemon.c @@ -36,7 +36,7 @@ * * $Id: vinumdaemon.c,v 1.8 2000/01/03 05:22:03 grog Exp grog $ * $FreeBSD: src/sys/dev/vinum/vinumdaemon.c,v 1.16 2000/01/05 06:03:56 grog Exp $ - * $DragonFly: src/sys/dev/raid/vinum/vinumdaemon.c,v 1.4 2003/08/07 21:17:09 dillon Exp $ + * $DragonFly: src/sys/dev/raid/vinum/vinumdaemon.c,v 1.5 2005/06/11 00:05:46 dillon Exp $ */ #include "vinumhdr.h" @@ -67,7 +67,6 @@ struct daemonq *intqp; /* and pointer in it */ void vinum_daemon(void) { - int s; struct daemonq *request; curproc->p_flag |= P_INMEM | P_SYSTEM; /* we're a system process */ @@ -88,12 +87,12 @@ vinum_daemon(void) return; } while (daemonq != NULL) { /* we have work to do, */ - s = splhigh(); /* don't get interrupted here */ + crit_enter(); request = daemonq; /* get the request */ daemonq = daemonq->next; /* and detach it */ if (daemonq == NULL) /* got to the end, */ dqend = NULL; /* no end any more */ - splx(s); + crit_exit(); switch (request->type) { /* @@ -215,8 +214,6 @@ recover_io(struct request *rq) void queue_daemon_request(enum daemonrq type, union daemoninfo info) { - int s; - struct daemonq *qelt = (struct daemonq *) Malloc(sizeof(struct daemonq)); if (qelt == NULL) { /* malloc failed, we're prepared for that */ @@ -237,7 +234,7 @@ queue_daemon_request(enum daemonrq type, union daemoninfo info) qelt->next = NULL; /* end of the chain */ qelt->type = type; qelt->info = info; - s = splhigh(); + crit_enter(); if (daemonq) { /* something queued already */ dqend->next = qelt; dqend = qelt; @@ -245,7 +242,7 @@ queue_daemon_request(enum daemonrq type, union daemoninfo info) daemonq = qelt; /* this is the whole queue */ dqend = qelt; } - splx(s); + crit_exit(); wakeup(&vinum_daemon); /* and give the dæmon a kick */ } diff --git a/sys/dev/raid/vinum/vinumhdr.h b/sys/dev/raid/vinum/vinumhdr.h index 7a3fa769a3..0ff2875812 100644 --- a/sys/dev/raid/vinum/vinumhdr.h +++ b/sys/dev/raid/vinum/vinumhdr.h @@ -38,7 +38,7 @@ /* * $Id: vinumhdr.h,v 1.18 2001/01/04 00:14:14 grog Exp grog $ * $FreeBSD: src/sys/dev/vinum/vinumhdr.h,v 1.16.2.1 2001/03/13 02:59:43 grog Exp $ - * $DragonFly: src/sys/dev/raid/vinum/vinumhdr.h,v 1.8 2004/12/22 11:01:49 joerg Exp $ + * $DragonFly: src/sys/dev/raid/vinum/vinumhdr.h,v 1.9 2005/06/11 00:05:46 dillon Exp $ */ #include @@ -75,6 +75,7 @@ #endif #include +#include #include #include "vinumvar.h" diff --git a/sys/dev/raid/vinum/vinumlock.c b/sys/dev/raid/vinum/vinumlock.c index f4c6994afb..9fa752bbee 100644 --- a/sys/dev/raid/vinum/vinumlock.c +++ b/sys/dev/raid/vinum/vinumlock.c @@ -39,7 +39,7 @@ * * $Id: vinumlock.c,v 1.13 2000/05/02 23:25:02 grog Exp grog $ * $FreeBSD: src/sys/dev/vinum/vinumlock.c,v 1.18.2.3 2001/04/04 06:27:11 grog Exp $ - * $DragonFly: src/sys/dev/raid/vinum/vinumlock.c,v 1.4 2003/08/07 21:17:09 dillon Exp $ + * $DragonFly: src/sys/dev/raid/vinum/vinumlock.c,v 1.5 2005/06/11 00:05:46 dillon Exp $ */ #include "vinumhdr.h" @@ -108,7 +108,6 @@ unlockdrive(struct drive *drive) struct rangelock * lockrange(daddr_t stripe, struct buf *bp, struct plex *plex) { - int s; struct rangelock *lock; struct rangelock *pos; /* position of first free lock */ int foundlocks; /* number of locks found */ @@ -135,7 +134,7 @@ lockrange(daddr_t stripe, struct buf *bp, struct plex *plex) * We give the locks back from an interrupt * context, so we need to raise the spl here. */ - s = splbio(); + crit_enter(); /* Wait here if the table is full */ while (plex->usedlocks == PLEX_LOCKS) /* all in use */ @@ -190,7 +189,7 @@ lockrange(daddr_t stripe, struct buf *bp, struct plex *plex) pos->stripe = stripe; pos->bp = bp; plex->usedlocks++; /* one more lock */ - splx(s); + crit_exit(); #ifdef VINUMDEBUG if (debug & DEBUG_LASTREQS) logrq(loginfo_lock, (union rqinfou) pos, bp); diff --git a/sys/dev/raid/vinum/vinummemory.c b/sys/dev/raid/vinum/vinummemory.c index bf5402bc00..b341fe79bd 100644 --- a/sys/dev/raid/vinum/vinummemory.c +++ b/sys/dev/raid/vinum/vinummemory.c @@ -35,7 +35,7 @@ * * $Id: vinummemory.c,v 1.25 2000/05/04 01:57:48 grog Exp grog $ * $FreeBSD: src/sys/dev/vinum/vinummemory.c,v 1.22.2.1 2000/06/02 04:26:11 grog Exp $ - * $DragonFly: src/sys/dev/raid/vinum/vinummemory.c,v 1.5 2005/01/27 02:43:12 joerg Exp $ + * $DragonFly: src/sys/dev/raid/vinum/vinummemory.c,v 1.6 2005/06/11 00:05:46 dillon Exp $ */ #include "vinumhdr.h" @@ -111,9 +111,8 @@ expand_table(void **table, int oldsize, int newsize) { if (newsize > oldsize) { int *temp; - int s; - s = splhigh(); + crit_enter(); temp = (int *) Malloc(newsize); /* allocate a new table */ CHECKALLOC(temp, "vinum: Can't expand table\n"); bzero((char *) temp, newsize); /* clean it all out */ @@ -122,7 +121,7 @@ expand_table(void **table, int oldsize, int newsize) Free(*table); } *table = temp; - splx(s); + crit_exit(); } } @@ -156,7 +155,7 @@ MMalloc(int size, char *file, int line) if (result == NULL) log(LOG_ERR, "vinum: can't allocate %d bytes from %s:%d\n", size, file, line); else { - s = splhigh(); + crit_enter(); for (i = 0; i < malloccount; i++) { if (((result + size) > malloced[i].address) && (result < malloced[i].address + malloced[i].size)) /* overlap */ @@ -177,7 +176,7 @@ MMalloc(int size, char *file, int line) } if (malloccount > highwater) highwater = malloccount; - splx(s); + crit_exit(); } return result; } @@ -185,10 +184,9 @@ MMalloc(int size, char *file, int line) void FFree(void *mem, char *file, int line) { - int s; int i; - s = splhigh(); + crit_enter(); for (i = 0; i < malloccount; i++) { if ((caddr_t) mem == malloced[i].address) { /* found it */ bzero(mem, malloced[i].size); /* XXX */ @@ -215,17 +213,18 @@ FFree(void *mem, char *file, int line) } if (i < malloccount) /* more coming after */ bcopy(&malloced[i + 1], &malloced[i], (malloccount - i) * sizeof(struct mc)); - splx(s); + crit_exit(); return; } } - splx(s); + crit_enter(); log(LOG_ERR, "Freeing unallocated data at 0x%p from %s, line %d\n", mem, file, line); Debugger("Free"); + crit_exit(); } void diff --git a/sys/dev/raid/vinum/vinumrequest.c b/sys/dev/raid/vinum/vinumrequest.c index ccb599bb80..d0d0a6dfae 100644 --- a/sys/dev/raid/vinum/vinumrequest.c +++ b/sys/dev/raid/vinum/vinumrequest.c @@ -39,7 +39,7 @@ * * $Id: vinumrequest.c,v 1.30 2001/01/09 04:20:55 grog Exp grog $ * $FreeBSD: src/sys/dev/vinum/vinumrequest.c,v 1.44.2.5 2002/08/28 04:30:56 grog Exp $ - * $DragonFly: src/sys/dev/raid/vinum/vinumrequest.c,v 1.4 2003/08/07 21:17:09 dillon Exp $ + * $DragonFly: src/sys/dev/raid/vinum/vinumrequest.c,v 1.5 2005/06/11 00:05:46 dillon Exp $ */ #include "vinumhdr.h" @@ -74,7 +74,7 @@ struct rqinfo *rqip = rqinfo; void logrq(enum rqinfo_type type, union rqinfou info, struct buf *ubp) { - int s = splhigh(); + crit_enter(); microtime(&rqip->timestamp); /* when did this happen? */ rqip->type = type; @@ -112,7 +112,7 @@ logrq(enum rqinfo_type type, union rqinfou info, struct buf *ubp) rqip++; if (rqip >= &rqinfo[RQINFO_SIZE]) /* wrap around */ rqip = rqinfo; - splx(s); + crit_exit(); } #endif @@ -305,7 +305,6 @@ launch_requests(struct request *rq, int reviveok) struct rqelement *rqe; /* current element */ struct drive *drive; int rcount; /* request count */ - int s; /* * First find out whether we're reviving, and the @@ -359,19 +358,6 @@ launch_requests(struct request *rq, int reviveok) logrq(loginfo_user_bpl, (union rqinfou) rq->bp, rq->bp); #endif - /* - * We used to have an splbio() here anyway, out - * of superstition. With the division of labour - * below (first count the requests, then issue - * them), it looks as if we don't need this - * splbio() protection. In fact, as dillon - * points out, there's a race condition - * incrementing and decrementing rq->active and - * rqg->active. This splbio() didn't help - * there, because the device strategy routine - * can sleep. Solve this by putting shorter - * duration locks on the code. - */ /* * This loop happens without any participation * of the bottom half, so it requires no @@ -391,9 +377,9 @@ launch_requests(struct request *rq, int reviveok) /* * Now fire off the requests. In this loop the * bottom half could be completing requests - * before we finish, so we need splbio() protection. + * before we finish, so we need critical section protection. */ - s = splbio (); + crit_enter(); for (rqg = rq->rqg; rqg != NULL;) { /* through the whole request chain */ if (rqg->lockbase >= 0) /* this rqg needs a lock first */ rqg->lock = lockrange(rqg->lockbase, rqg->rq->bp, &PLEX[rqg->plexno]); @@ -435,7 +421,7 @@ launch_requests(struct request *rq, int reviveok) } } } - splx (s); + crit_exit(); return 0; } @@ -885,7 +871,6 @@ check_range_covered(struct request *rq) void sdio(struct buf *bp) { - int s; /* spl */ struct sd *sd; struct sdbuf *sbp; daddr_t endoffset; @@ -967,13 +952,13 @@ sdio(struct buf *bp) (int) sbp->b.b_blkno, sbp->b.b_bcount); #endif - s = splbio(); + crit_enter(); #if VINUMDEBUG if (debug & DEBUG_LASTREQS) logrq(loginfo_sdiol, (union rqinfou) &sbp->b, &sbp->b); #endif BUF_STRATEGY(&sbp->b, 0); - splx(s); + crit_exit(); } /* diff --git a/sys/dev/raid/vinum/vinumrevive.c b/sys/dev/raid/vinum/vinumrevive.c index 9d2f97f6e7..690b88d9aa 100644 --- a/sys/dev/raid/vinum/vinumrevive.c +++ b/sys/dev/raid/vinum/vinumrevive.c @@ -39,7 +39,7 @@ * * $Id: vinumrevive.c,v 1.14 2000/12/21 01:55:11 grog Exp grog $ * $FreeBSD: src/sys/dev/vinum/vinumrevive.c,v 1.22.2.5 2001/03/13 02:59:43 grog Exp $ - * $DragonFly: src/sys/dev/raid/vinum/vinumrevive.c,v 1.4 2003/11/15 21:05:42 dillon Exp $ + * $DragonFly: src/sys/dev/raid/vinum/vinumrevive.c,v 1.5 2005/06/11 00:05:46 dillon Exp $ */ #include "vinumhdr.h" @@ -57,7 +57,6 @@ int revive_block(int sdno) { - int s; /* priority level */ struct sd *sd; struct plex *plex; struct volume *vol; @@ -140,9 +139,9 @@ revive_block(int sdno) if (bp == NULL) /* no buffer space */ return ENOMEM; /* chicken out */ } else { /* data block */ - s = splbio(); + crit_enter(); bp = geteblk(size); /* Get a buffer */ - splx(s); + crit_exit(); if (bp == NULL) return ENOMEM; @@ -352,7 +351,6 @@ parityrebuild(struct plex *plex, off_t * errorloc) { int error; - int s; int sdno; u_int64_t stripe; /* stripe number */ int *parity_buf; /* buffer address for current parity block */ @@ -392,18 +390,18 @@ parityrebuild(struct plex *plex, for (sdno = 0; sdno < bufcount; sdno++) { /* for each subdisk */ if ((sdno != psd) || (op != rebuildparity)) { /* Get a buffer header and initialize it. */ - s = splbio(); + crit_enter(); bpp[sdno] = geteblk(mysize); /* Get a buffer */ if (bpp[sdno] == NULL) { while (sdno-- > 0) { /* release the ones we got */ bpp[sdno]->b_flags |= B_INVAL; brelse(bpp[sdno]); /* give back our resources */ } - splx(s); + crit_exit(); printf("vinum: can't allocate buffer space for parity op.\n"); return NULL; /* no bpps */ } - splx(s); + crit_exit(); if (sdno == psd) parity_buf = (int *) bpp[sdno]->b_data; if (sdno == newpsd) /* the new one? */ @@ -506,7 +504,6 @@ parityrebuild(struct plex *plex, int initsd(int sdno, int verify) { - int s; /* priority level */ struct sd *sd; struct plex *plex; struct volume *vol; @@ -540,9 +537,9 @@ initsd(int sdno, int verify) verified = 0; while (!verified) { /* until we're happy with it, */ - s = splbio(); + crit_enter(); bp = geteblk(size); /* Get a buffer */ - splx(s); + crit_exit(); if (bp == NULL) return ENOMEM; @@ -562,10 +559,10 @@ initsd(int sdno, int verify) brelse(bp); /* is this kosher? */ } if ((error == 0) && verify) { /* check that it got there */ - s = splbio(); + crit_enter(); bp = geteblk(size); /* get a buffer */ if (bp == NULL) { - splx(s); + crit_exit(); error = ENOMEM; } else { bp->b_bcount = size; @@ -573,7 +570,7 @@ initsd(int sdno, int verify) bp->b_blkno = sd->initialized; /* read from here */ bp->b_dev = VINUM_SD(sdno); /* create the device number */ bp->b_flags |= B_READ; /* read it back */ - splx(s); + crit_exit(); sdio(bp); biowait(bp); /* -- 2.41.0