1999-08-07 08:11:22 +00:00
|
|
|
/* vinuminterrupt.c: bottom half of the driver */
|
1998-12-28 04:56:24 +00:00
|
|
|
|
|
|
|
/*-
|
1999-08-07 08:11:22 +00:00
|
|
|
* Copyright (c) 1997, 1998, 1999
|
1998-12-28 04:56:24 +00:00
|
|
|
* Nan Yang Computer Services Limited. All rights reserved.
|
|
|
|
*
|
1999-08-07 08:11:22 +00:00
|
|
|
* Parts copyright (c) 1997, 1998 Cybernet Corporation, NetMAX project.
|
|
|
|
*
|
|
|
|
* Written by Greg Lehey
|
|
|
|
*
|
1998-12-28 04:56:24 +00:00
|
|
|
* This software is distributed under the so-called ``Berkeley
|
|
|
|
* License'':
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by Nan Yang Computer
|
|
|
|
* Services Limited.
|
|
|
|
* 4. Neither the name of the Company nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* This software is provided ``as is'', and any express or implied
|
|
|
|
* warranties, including, but not limited to, the implied warranties of
|
|
|
|
* merchantability and fitness for a particular purpose are disclaimed.
|
|
|
|
* In no event shall the company or contributors be liable for any
|
|
|
|
* direct, indirect, incidental, special, exemplary, or consequential
|
|
|
|
* damages (including, but not limited to, procurement of substitute
|
|
|
|
* goods or services; loss of use, data, or profits; or business
|
|
|
|
* interruption) however caused and on any theory of liability, whether
|
|
|
|
* in contract, strict liability, or tort (including negligence or
|
|
|
|
* otherwise) arising in any way out of the use of this software, even if
|
|
|
|
* advised of the possibility of such damage.
|
|
|
|
*
|
2001-05-23 23:24:05 +00:00
|
|
|
* $Id: vinuminterrupt.c,v 1.14 2001/05/23 23:03:37 grog Exp grog $
|
1999-08-28 01:08:13 +00:00
|
|
|
* $FreeBSD$
|
1998-12-28 04:56:24 +00:00
|
|
|
*/
|
|
|
|
|
1998-12-28 16:28:24 +00:00
|
|
|
#include <dev/vinum/vinumhdr.h>
|
|
|
|
#include <dev/vinum/request.h>
|
1998-12-28 04:56:24 +00:00
|
|
|
#include <sys/resourcevar.h>
|
|
|
|
|
|
|
|
void complete_raid5_write(struct rqelement *);
|
|
|
|
void complete_rqe(struct buf *bp);
|
|
|
|
void sdio_done(struct buf *bp);
|
|
|
|
|
1999-01-29 01:17:54 +00:00
|
|
|
/*
|
|
|
|
* Take a completed buffer, transfer the data back if
|
1998-12-28 04:56:24 +00:00
|
|
|
* it's a read, and complete the high-level request
|
|
|
|
* if this is the last subrequest.
|
|
|
|
*
|
|
|
|
* The bp parameter is in fact a struct rqelement, which
|
|
|
|
* includes a couple of extras at the end.
|
|
|
|
*/
|
1999-08-24 02:23:21 +00:00
|
|
|
void
|
1998-12-28 04:56:24 +00:00
|
|
|
complete_rqe(struct buf *bp)
|
|
|
|
{
|
|
|
|
struct rqelement *rqe;
|
|
|
|
struct request *rq;
|
|
|
|
struct rqgroup *rqg;
|
|
|
|
struct buf *ubp; /* user buffer */
|
1999-10-13 03:17:21 +00:00
|
|
|
struct drive *drive;
|
2001-05-22 02:31:08 +00:00
|
|
|
struct sd *sd;
|
|
|
|
char *gravity; /* for error messages */
|
1998-12-28 04:56:24 +00:00
|
|
|
|
|
|
|
rqe = (struct rqelement *) bp; /* point to the element element that completed */
|
|
|
|
rqg = rqe->rqg; /* and the request group */
|
|
|
|
rq = rqg->rq; /* and the complete request */
|
|
|
|
ubp = rq->bp; /* user buffer */
|
|
|
|
|
1998-12-28 16:28:24 +00:00
|
|
|
#ifdef VINUMDEBUG
|
1998-12-28 04:56:24 +00:00
|
|
|
if (debug & DEBUG_LASTREQS)
|
1999-03-18 23:26:22 +00:00
|
|
|
logrq(loginfo_iodone, (union rqinfou) rqe, ubp);
|
1998-12-28 04:56:24 +00:00
|
|
|
#endif
|
1999-10-13 03:17:21 +00:00
|
|
|
drive = &DRIVE[rqe->driveno];
|
|
|
|
drive->active--; /* one less outstanding I/O on this drive */
|
|
|
|
vinum_conf.active--; /* one less outstanding I/O globally */
|
|
|
|
if ((drive->active == (DRIVE_MAXACTIVE - 1)) /* we were at the drive limit */
|
|
|
|
||(vinum_conf.active == VINUM_MAXACTIVE)) /* or the global limit */
|
|
|
|
wakeup(&launch_requests); /* let another one at it */
|
2000-05-04 07:33:40 +00:00
|
|
|
if ((bp->b_io.bio_flags & BIO_ERROR) != 0) { /* transfer in error */
|
2001-05-22 02:31:08 +00:00
|
|
|
gravity = "";
|
|
|
|
sd = &SD[rqe->sdno];
|
|
|
|
|
1998-12-28 04:56:24 +00:00
|
|
|
if (bp->b_error != 0) /* did it return a number? */
|
|
|
|
rq->error = bp->b_error; /* yes, put it in. */
|
|
|
|
else if (rq->error == 0) /* no: do we have one already? */
|
|
|
|
rq->error = EIO; /* no: catchall "I/O error" */
|
2001-05-22 02:31:08 +00:00
|
|
|
sd->lasterror = rq->error;
|
2000-05-04 07:33:40 +00:00
|
|
|
if (bp->b_iocmd == BIO_READ) { /* read operation */
|
2001-05-22 02:31:08 +00:00
|
|
|
if ((rq->error == ENXIO) || (sd->flags & VF_RETRYERRORS) == 0) {
|
|
|
|
gravity = " fatal";
|
|
|
|
set_sd_state(rqe->sdno, sd_crashed, setstate_force); /* subdisk is crashed */
|
|
|
|
}
|
|
|
|
log(LOG_ERR,
|
2002-03-15 18:49:47 +00:00
|
|
|
"%s:%s read error, block %lld for %ld bytes\n",
|
2001-05-22 02:31:08 +00:00
|
|
|
gravity,
|
|
|
|
sd->name,
|
2002-11-07 21:52:51 +00:00
|
|
|
(long long)bp->b_blkno,
|
2001-05-22 02:31:08 +00:00
|
|
|
bp->b_bcount);
|
1999-01-21 00:34:14 +00:00
|
|
|
} else { /* write operation */
|
2001-05-22 02:31:08 +00:00
|
|
|
if ((rq->error == ENXIO) || (sd->flags & VF_RETRYERRORS) == 0) {
|
|
|
|
gravity = "fatal ";
|
|
|
|
set_sd_state(rqe->sdno, sd_stale, setstate_force); /* subdisk is stale */
|
|
|
|
}
|
|
|
|
log(LOG_ERR,
|
2002-03-15 18:49:47 +00:00
|
|
|
"%s:%s write error, block %lld for %ld bytes\n",
|
2001-05-22 02:31:08 +00:00
|
|
|
gravity,
|
|
|
|
sd->name,
|
2002-11-07 21:52:51 +00:00
|
|
|
(long long)bp->b_blkno,
|
2001-05-22 02:31:08 +00:00
|
|
|
bp->b_bcount);
|
1999-01-21 00:34:14 +00:00
|
|
|
}
|
2001-05-22 02:31:08 +00:00
|
|
|
log(LOG_ERR,
|
2002-03-15 18:49:47 +00:00
|
|
|
"%s: user buffer block %lld for %ld bytes\n",
|
2001-05-22 02:31:08 +00:00
|
|
|
sd->name,
|
2002-11-07 21:52:51 +00:00
|
|
|
(long long)ubp->b_blkno,
|
2001-05-22 02:31:08 +00:00
|
|
|
ubp->b_bcount);
|
1999-01-21 00:34:14 +00:00
|
|
|
if (rq->error == ENXIO) { /* the drive's down too */
|
2001-05-22 02:31:08 +00:00
|
|
|
log(LOG_ERR,
|
2002-03-15 18:49:47 +00:00
|
|
|
"%s: fatal drive I/O error, block %lld for %ld bytes\n",
|
2001-05-22 02:31:08 +00:00
|
|
|
DRIVE[rqe->driveno].label.name,
|
2002-11-07 21:52:51 +00:00
|
|
|
(long long)bp->b_blkno,
|
2001-05-22 02:31:08 +00:00
|
|
|
bp->b_bcount);
|
1999-01-21 00:34:14 +00:00
|
|
|
DRIVE[rqe->driveno].lasterror = rq->error;
|
1998-12-28 04:56:24 +00:00
|
|
|
set_drive_state(rqe->driveno, /* take the drive down */
|
|
|
|
drive_down,
|
1999-01-21 00:34:14 +00:00
|
|
|
setstate_force);
|
|
|
|
}
|
1998-12-28 04:56:24 +00:00
|
|
|
}
|
|
|
|
/* Now update the statistics */
|
2000-05-11 07:23:50 +00:00
|
|
|
if (bp->b_iocmd == BIO_READ) { /* read operation */
|
1998-12-28 04:56:24 +00:00
|
|
|
DRIVE[rqe->driveno].reads++;
|
|
|
|
DRIVE[rqe->driveno].bytes_read += bp->b_bcount;
|
|
|
|
SD[rqe->sdno].reads++;
|
|
|
|
SD[rqe->sdno].bytes_read += bp->b_bcount;
|
|
|
|
PLEX[rqe->rqg->plexno].reads++;
|
|
|
|
PLEX[rqe->rqg->plexno].bytes_read += bp->b_bcount;
|
2000-05-04 07:33:40 +00:00
|
|
|
if (PLEX[rqe->rqg->plexno].volno >= 0) { /* volume I/O, not plex */
|
|
|
|
VOL[PLEX[rqe->rqg->plexno].volno].reads++;
|
2000-03-01 07:23:13 +00:00
|
|
|
VOL[PLEX[rqe->rqg->plexno].volno].bytes_read += bp->b_bcount;
|
2000-05-04 07:33:40 +00:00
|
|
|
}
|
1998-12-28 04:56:24 +00:00
|
|
|
} else { /* write operation */
|
|
|
|
DRIVE[rqe->driveno].writes++;
|
|
|
|
DRIVE[rqe->driveno].bytes_written += bp->b_bcount;
|
|
|
|
SD[rqe->sdno].writes++;
|
|
|
|
SD[rqe->sdno].bytes_written += bp->b_bcount;
|
|
|
|
PLEX[rqe->rqg->plexno].writes++;
|
|
|
|
PLEX[rqe->rqg->plexno].bytes_written += bp->b_bcount;
|
2000-05-04 07:33:40 +00:00
|
|
|
if (PLEX[rqe->rqg->plexno].volno >= 0) { /* volume I/O, not plex */
|
|
|
|
VOL[PLEX[rqe->rqg->plexno].volno].writes++;
|
2000-03-01 07:23:13 +00:00
|
|
|
VOL[PLEX[rqe->rqg->plexno].volno].bytes_written += bp->b_bcount;
|
2000-05-11 07:23:50 +00:00
|
|
|
}
|
2000-05-04 07:33:40 +00:00
|
|
|
}
|
1999-08-07 08:11:22 +00:00
|
|
|
if (rqg->flags & XFR_RECOVERY_READ) { /* recovery read, */
|
|
|
|
int *sdata; /* source */
|
|
|
|
int *data; /* and group data */
|
|
|
|
int length; /* and count involved */
|
|
|
|
int count; /* loop counter */
|
|
|
|
struct rqelement *urqe = &rqg->rqe[rqg->badsdno]; /* rqe of the bad subdisk */
|
|
|
|
|
|
|
|
/* XOR destination is the user data */
|
|
|
|
sdata = (int *) &rqe->b.b_data[rqe->groupoffset << DEV_BSHIFT]; /* old data contents */
|
|
|
|
data = (int *) &urqe->b.b_data[urqe->groupoffset << DEV_BSHIFT]; /* destination */
|
2000-05-04 07:33:40 +00:00
|
|
|
length = urqe->grouplen * (DEV_BSIZE / sizeof(int)); /* and number of ints */
|
1999-08-07 08:11:22 +00:00
|
|
|
|
|
|
|
for (count = 0; count < length; count++)
|
|
|
|
data[count] ^= sdata[count];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* In a normal read, we will normally read directly
|
|
|
|
* into the user buffer. This doesn't work if
|
|
|
|
* we're also doing a recovery, so we have to
|
1999-08-24 02:23:21 +00:00
|
|
|
* copy it
|
1999-08-07 08:11:22 +00:00
|
|
|
*/
|
|
|
|
if (rqe->flags & XFR_NORMAL_READ) { /* normal read as well, */
|
|
|
|
char *src = &rqe->b.b_data[rqe->dataoffset << DEV_BSHIFT]; /* read data is here */
|
|
|
|
char *dst;
|
|
|
|
|
|
|
|
dst = (char *) ubp->b_data + (rqe->useroffset << DEV_BSHIFT); /* where to put it in user buffer */
|
|
|
|
length = rqe->datalen << DEV_BSHIFT; /* and count involved */
|
|
|
|
bcopy(src, dst, length); /* move it */
|
|
|
|
}
|
2000-02-29 06:10:21 +00:00
|
|
|
} else if ((rqg->flags & (XFR_NORMAL_WRITE | XFR_DEGRADED_WRITE)) /* RAID 4/5 group write operation */
|
2000-05-04 07:33:40 +00:00
|
|
|
&&(rqg->active == 1)) /* and this is the last active request */
|
1999-08-07 08:11:22 +00:00
|
|
|
complete_raid5_write(rqe);
|
2000-05-04 07:33:40 +00:00
|
|
|
/*
|
|
|
|
* This is the earliest place where we can be
|
|
|
|
* sure that the request has really finished,
|
|
|
|
* since complete_raid5_write can issue new
|
|
|
|
* requests.
|
|
|
|
*/
|
|
|
|
rqg->active--; /* this request now finished */
|
2000-01-05 06:09:43 +00:00
|
|
|
if (rqg->active == 0) { /* request group finished, */
|
1998-12-28 04:56:24 +00:00
|
|
|
rq->active--; /* one less */
|
2000-01-05 06:09:43 +00:00
|
|
|
if (rqg->lock) { /* got a lock? */
|
|
|
|
unlockrange(rqg->plexno, rqg->lock); /* yes, free it */
|
|
|
|
rqg->lock = 0;
|
|
|
|
}
|
|
|
|
}
|
1998-12-28 04:56:24 +00:00
|
|
|
if (rq->active == 0) { /* request finished, */
|
2001-05-23 23:24:05 +00:00
|
|
|
#ifdef VINUMDEBUG
|
1998-12-28 04:56:24 +00:00
|
|
|
if (debug & DEBUG_RESID) {
|
|
|
|
if (ubp->b_resid != 0) /* still something to transfer? */
|
|
|
|
Debugger("resid");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (rq->error) { /* did we have an error? */
|
1999-01-21 00:34:14 +00:00
|
|
|
if (rq->isplex) { /* plex operation, */
|
2000-05-04 07:33:40 +00:00
|
|
|
ubp->b_io.bio_flags |= BIO_ERROR; /* yes, propagate to user */
|
1999-01-21 00:34:14 +00:00
|
|
|
ubp->b_error = rq->error;
|
|
|
|
} else /* try to recover */
|
1999-03-18 23:26:22 +00:00
|
|
|
queue_daemon_request(daemonrq_ioerror, (union daemoninfo) rq); /* let the daemon complete */
|
1999-01-21 00:34:14 +00:00
|
|
|
} else {
|
1998-12-28 04:56:24 +00:00
|
|
|
ubp->b_resid = 0; /* completed our transfer */
|
1999-01-21 00:34:14 +00:00
|
|
|
if (rq->isplex == 0) /* volume request, */
|
|
|
|
VOL[rq->volplex.volno].active--; /* another request finished */
|
2001-05-22 02:31:08 +00:00
|
|
|
if (rq->flags & XFR_COPYBUF) {
|
|
|
|
Free(ubp->b_data);
|
|
|
|
ubp->b_data = rq->save_data;
|
|
|
|
}
|
2000-04-16 07:18:08 +00:00
|
|
|
bufdone(ubp); /* top level buffer completed */
|
1999-01-21 00:34:14 +00:00
|
|
|
freerq(rq); /* return the request storage */
|
|
|
|
}
|
1998-12-28 04:56:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Free a request block and anything hanging off it */
|
1999-08-24 02:23:21 +00:00
|
|
|
void
|
1998-12-28 04:56:24 +00:00
|
|
|
freerq(struct request *rq)
|
|
|
|
{
|
|
|
|
struct rqgroup *rqg;
|
|
|
|
struct rqgroup *nrqg; /* next in chain */
|
|
|
|
int rqno;
|
|
|
|
|
|
|
|
for (rqg = rq->rqg; rqg != NULL; rqg = nrqg) { /* through the whole request chain */
|
1999-08-14 06:25:52 +00:00
|
|
|
if (rqg->lock) /* got a lock? */
|
1999-08-24 02:23:21 +00:00
|
|
|
unlockrange(rqg->plexno, rqg->lock); /* yes, free it */
|
2000-12-20 05:13:26 +00:00
|
|
|
for (rqno = 0; rqno < rqg->count; rqno++) {
|
1998-12-28 04:56:24 +00:00
|
|
|
if ((rqg->rqe[rqno].flags & XFR_MALLOCED) /* data buffer was malloced, */
|
|
|
|
&&rqg->rqe[rqno].b.b_data) /* and the allocation succeeded */
|
|
|
|
Free(rqg->rqe[rqno].b.b_data); /* free it */
|
2000-12-20 05:13:26 +00:00
|
|
|
if (rqg->rqe[rqno].flags & XFR_BUFLOCKED) { /* locked this buffer, */
|
|
|
|
BUF_UNLOCK(&rqg->rqe[rqno].b); /* unlock it again */
|
|
|
|
BUF_LOCKFREE(&rqg->rqe[rqno].b);
|
|
|
|
}
|
|
|
|
}
|
1998-12-28 04:56:24 +00:00
|
|
|
nrqg = rqg->next; /* note the next one */
|
|
|
|
Free(rqg); /* and free this one */
|
|
|
|
}
|
|
|
|
Free(rq); /* free the request itself */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* I/O on subdisk completed */
|
1999-08-24 02:23:21 +00:00
|
|
|
void
|
1998-12-28 04:56:24 +00:00
|
|
|
sdio_done(struct buf *bp)
|
|
|
|
{
|
|
|
|
struct sdbuf *sbp;
|
|
|
|
|
|
|
|
sbp = (struct sdbuf *) bp;
|
2000-05-04 07:33:40 +00:00
|
|
|
if (sbp->b.b_io.bio_flags & BIO_ERROR) { /* had an error */
|
|
|
|
sbp->bp->b_io.bio_flags |= BIO_ERROR; /* propagate upwards */
|
1999-10-17 23:56:47 +00:00
|
|
|
sbp->bp->b_error = sbp->b.b_error;
|
1998-12-28 04:56:24 +00:00
|
|
|
}
|
1999-09-28 22:45:21 +00:00
|
|
|
#ifdef VINUMDEBUG
|
|
|
|
if (debug & DEBUG_LASTREQS)
|
|
|
|
logrq(loginfo_sdiodone, (union rqinfou) bp, bp);
|
|
|
|
#endif
|
1999-08-14 06:25:52 +00:00
|
|
|
sbp->bp->b_resid = sbp->b.b_resid; /* copy the resid field */
|
1998-12-28 04:56:24 +00:00
|
|
|
/* Now update the statistics */
|
2000-05-11 07:23:50 +00:00
|
|
|
if (bp->b_iocmd == BIO_READ) { /* read operation */
|
1998-12-28 04:56:24 +00:00
|
|
|
DRIVE[sbp->driveno].reads++;
|
1999-10-17 23:56:47 +00:00
|
|
|
DRIVE[sbp->driveno].bytes_read += sbp->b.b_bcount;
|
1998-12-28 04:56:24 +00:00
|
|
|
SD[sbp->sdno].reads++;
|
1999-10-17 23:56:47 +00:00
|
|
|
SD[sbp->sdno].bytes_read += sbp->b.b_bcount;
|
1998-12-28 04:56:24 +00:00
|
|
|
} else { /* write operation */
|
|
|
|
DRIVE[sbp->driveno].writes++;
|
1999-10-17 23:56:47 +00:00
|
|
|
DRIVE[sbp->driveno].bytes_written += sbp->b.b_bcount;
|
1998-12-28 04:56:24 +00:00
|
|
|
SD[sbp->sdno].writes++;
|
1999-10-17 23:56:47 +00:00
|
|
|
SD[sbp->sdno].bytes_written += sbp->b.b_bcount;
|
1998-12-28 04:56:24 +00:00
|
|
|
}
|
2000-04-16 07:18:08 +00:00
|
|
|
bufdone(sbp->bp); /* complete the caller's I/O */
|
2000-12-20 05:13:26 +00:00
|
|
|
BUF_UNLOCK(&sbp->b);
|
|
|
|
BUF_LOCKFREE(&sbp->b);
|
1998-12-28 04:56:24 +00:00
|
|
|
Free(sbp);
|
|
|
|
}
|
1999-08-07 08:11:22 +00:00
|
|
|
|
2000-02-29 06:10:21 +00:00
|
|
|
/* Start the second phase of a RAID-4 or RAID-5 group write operation. */
|
1999-08-24 02:23:21 +00:00
|
|
|
void
|
1999-08-07 08:11:22 +00:00
|
|
|
complete_raid5_write(struct rqelement *rqe)
|
|
|
|
{
|
|
|
|
int *sdata; /* source */
|
|
|
|
int *pdata; /* and parity block data */
|
|
|
|
int length; /* and count involved */
|
|
|
|
int count; /* loop counter */
|
|
|
|
int rqno; /* request index */
|
|
|
|
int rqoffset; /* offset of request data from parity data */
|
2000-05-04 07:33:40 +00:00
|
|
|
struct buf *ubp; /* user buffer header */
|
1999-08-07 08:11:22 +00:00
|
|
|
struct request *rq; /* pointer to our request */
|
|
|
|
struct rqgroup *rqg; /* and to the request group */
|
|
|
|
struct rqelement *prqe; /* point to the parity block */
|
|
|
|
struct drive *drive; /* drive to access */
|
|
|
|
|
|
|
|
rqg = rqe->rqg; /* and to our request group */
|
|
|
|
rq = rqg->rq; /* point to our request */
|
2000-05-04 07:33:40 +00:00
|
|
|
ubp = rq->bp; /* user's buffer header */
|
1999-08-07 08:11:22 +00:00
|
|
|
prqe = &rqg->rqe[0]; /* point to the parity block */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we get to this function, we have normal or
|
|
|
|
* degraded writes, or a combination of both. We do
|
|
|
|
* the same thing in each case: we perform an
|
|
|
|
* exclusive or to the parity block. The only
|
|
|
|
* difference is the origin of the data and the
|
1999-08-24 02:23:21 +00:00
|
|
|
* address range.
|
1999-08-07 08:11:22 +00:00
|
|
|
*/
|
|
|
|
if (rqe->flags & XFR_DEGRADED_WRITE) { /* do the degraded write stuff */
|
|
|
|
pdata = (int *) (&prqe->b.b_data[(prqe->groupoffset) << DEV_BSHIFT]); /* parity data pointer */
|
|
|
|
bzero(pdata, prqe->grouplen << DEV_BSHIFT); /* start with nothing in the parity block */
|
|
|
|
|
|
|
|
/* Now get what data we need from each block */
|
|
|
|
for (rqno = 1; rqno < rqg->count; rqno++) { /* for all the data blocks */
|
|
|
|
rqe = &rqg->rqe[rqno]; /* this request */
|
|
|
|
sdata = (int *) (&rqe->b.b_data[rqe->groupoffset << DEV_BSHIFT]); /* old data */
|
|
|
|
length = rqe->grouplen << (DEV_BSHIFT - 2); /* and count involved */
|
|
|
|
|
|
|
|
/*
|
2000-05-04 07:33:40 +00:00
|
|
|
* Add the data block to the parity block. Before
|
1999-08-07 08:11:22 +00:00
|
|
|
* we started the request, we zeroed the parity
|
|
|
|
* block, so the result of adding all the other
|
|
|
|
* blocks and the block we want to write will be
|
1999-08-24 02:23:21 +00:00
|
|
|
* the correct parity block.
|
1999-08-07 08:11:22 +00:00
|
|
|
*/
|
|
|
|
for (count = 0; count < length; count++)
|
|
|
|
pdata[count] ^= sdata[count];
|
|
|
|
if ((rqe->flags & XFR_MALLOCED) /* the buffer was malloced, */
|
|
|
|
&&((rqg->flags & XFR_NORMAL_WRITE) == 0)) { /* and we have no normal write, */
|
|
|
|
Free(rqe->b.b_data); /* free it now */
|
|
|
|
rqe->flags &= ~XFR_MALLOCED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (rqg->flags & XFR_NORMAL_WRITE) { /* do normal write stuff */
|
|
|
|
/* Get what data we need from each block */
|
|
|
|
for (rqno = 1; rqno < rqg->count; rqno++) { /* for all the data blocks */
|
|
|
|
rqe = &rqg->rqe[rqno]; /* this request */
|
|
|
|
if ((rqe->flags & (XFR_DATA_BLOCK | XFR_BAD_SUBDISK | XFR_NORMAL_WRITE))
|
|
|
|
== (XFR_DATA_BLOCK | XFR_NORMAL_WRITE)) { /* good data block to write */
|
|
|
|
sdata = (int *) &rqe->b.b_data[rqe->dataoffset << DEV_BSHIFT]; /* old data contents */
|
|
|
|
rqoffset = rqe->dataoffset + rqe->sdoffset - prqe->sdoffset; /* corresponding parity block offset */
|
|
|
|
pdata = (int *) (&prqe->b.b_data[rqoffset << DEV_BSHIFT]); /* parity data pointer */
|
2000-05-04 07:33:40 +00:00
|
|
|
length = rqe->datalen * (DEV_BSIZE / sizeof(int)); /* and number of ints */
|
|
|
|
|
1999-08-07 08:11:22 +00:00
|
|
|
/*
|
|
|
|
* "remove" the old data block
|
1999-08-24 02:23:21 +00:00
|
|
|
* from the parity block
|
1999-08-07 08:11:22 +00:00
|
|
|
*/
|
|
|
|
if ((pdata < ((int *) prqe->b.b_data))
|
|
|
|
|| (&pdata[length] > ((int *) (prqe->b.b_data + prqe->b.b_bcount)))
|
|
|
|
|| (sdata < ((int *) rqe->b.b_data))
|
|
|
|
|| (&sdata[length] > ((int *) (rqe->b.b_data + rqe->b.b_bcount))))
|
1999-08-14 06:25:52 +00:00
|
|
|
panic("complete_raid5_write: bounds overflow");
|
1999-08-07 08:11:22 +00:00
|
|
|
for (count = 0; count < length; count++)
|
|
|
|
pdata[count] ^= sdata[count];
|
|
|
|
|
|
|
|
/* "add" the new data block */
|
2000-05-04 07:33:40 +00:00
|
|
|
sdata = (int *) (&ubp->b_data[rqe->useroffset << DEV_BSHIFT]); /* new data */
|
|
|
|
if ((sdata < ((int *) ubp->b_data))
|
|
|
|
|| (&sdata[length] > ((int *) (ubp->b_data + ubp->b_bcount))))
|
1999-08-14 06:25:52 +00:00
|
|
|
panic("complete_raid5_write: bounds overflow");
|
1999-08-07 08:11:22 +00:00
|
|
|
for (count = 0; count < length; count++)
|
|
|
|
pdata[count] ^= sdata[count];
|
|
|
|
|
|
|
|
/* Free the malloced buffer */
|
|
|
|
if (rqe->flags & XFR_MALLOCED) { /* the buffer was malloced, */
|
|
|
|
Free(rqe->b.b_data); /* free it */
|
|
|
|
rqe->flags &= ~XFR_MALLOCED;
|
|
|
|
} else
|
1999-08-14 06:25:52 +00:00
|
|
|
panic("complete_raid5_write: malloc conflict");
|
1999-08-07 08:11:22 +00:00
|
|
|
|
2000-05-11 07:23:50 +00:00
|
|
|
if ((rqe->b.b_iocmd == BIO_READ) /* this was a read */
|
1999-08-07 08:11:22 +00:00
|
|
|
&&((rqe->flags & XFR_BAD_SUBDISK) == 0)) { /* and we can write this block */
|
2000-05-11 07:23:50 +00:00
|
|
|
rqe->b.b_flags &= ~B_DONE; /* start a new request */
|
2000-03-26 23:06:12 +00:00
|
|
|
rqe->b.b_iocmd = BIO_WRITE; /* we're writing now */
|
2000-03-20 10:44:49 +00:00
|
|
|
rqe->b.b_iodone = complete_rqe; /* call us here when done */
|
1999-08-26 03:26:39 +00:00
|
|
|
rqe->flags &= ~XFR_PARITYOP; /* reset flags that brought us here */
|
2000-05-04 07:33:40 +00:00
|
|
|
rqe->b.b_data = &ubp->b_data[rqe->useroffset << DEV_BSHIFT]; /* point to the user data */
|
1999-08-07 08:11:22 +00:00
|
|
|
rqe->b.b_bcount = rqe->datalen << DEV_BSHIFT; /* length to write */
|
|
|
|
rqe->b.b_bufsize = rqe->b.b_bcount; /* don't claim more */
|
|
|
|
rqe->b.b_resid = rqe->b.b_bcount; /* nothing transferred */
|
|
|
|
rqe->b.b_blkno += rqe->dataoffset; /* point to the correct block */
|
|
|
|
rqg->active++; /* another active request */
|
|
|
|
drive = &DRIVE[rqe->driveno]; /* drive to access */
|
1999-10-13 03:17:21 +00:00
|
|
|
|
|
|
|
/* We can't sleep here, so we just increment the counters. */
|
|
|
|
drive->active++;
|
|
|
|
if (drive->active >= drive->maxactive)
|
|
|
|
drive->maxactive = drive->active;
|
|
|
|
vinum_conf.active++;
|
|
|
|
if (vinum_conf.active >= vinum_conf.maxactive)
|
|
|
|
vinum_conf.maxactive = vinum_conf.active;
|
2001-05-23 23:24:05 +00:00
|
|
|
#ifdef VINUMDEBUG
|
1999-08-07 08:11:22 +00:00
|
|
|
if (debug & DEBUG_ADDRESSES)
|
|
|
|
log(LOG_DEBUG,
|
2002-03-15 18:49:47 +00:00
|
|
|
" %s dev %d.%d, sd %d, offset 0x%x, devoffset 0x%llx, length %ld\n",
|
2000-03-20 10:44:49 +00:00
|
|
|
rqe->b.b_iocmd == BIO_READ ? "Read" : "Write",
|
1999-08-07 08:11:22 +00:00
|
|
|
major(rqe->b.b_dev),
|
|
|
|
minor(rqe->b.b_dev),
|
|
|
|
rqe->sdno,
|
|
|
|
(u_int) (rqe->b.b_blkno - SD[rqe->sdno].driveoffset),
|
2002-11-07 21:52:51 +00:00
|
|
|
(long long)rqe->b.b_blkno,
|
1999-08-14 06:25:52 +00:00
|
|
|
rqe->b.b_bcount);
|
1999-08-07 08:11:22 +00:00
|
|
|
if (debug & DEBUG_LASTREQS)
|
2000-05-04 07:33:40 +00:00
|
|
|
logrq(loginfo_raid5_data, (union rqinfou) rqe, ubp);
|
1999-08-07 08:11:22 +00:00
|
|
|
#endif
|
2000-03-20 11:29:10 +00:00
|
|
|
DEV_STRATEGY(&rqe->b, 0);
|
1999-08-07 08:11:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Finally, write the parity block */
|
|
|
|
rqe = &rqg->rqe[0];
|
2000-03-26 23:06:12 +00:00
|
|
|
rqe->b.b_flags &= ~B_DONE; /* we're not done */
|
|
|
|
rqe->b.b_iocmd = BIO_WRITE; /* we're writing now */
|
2000-03-20 10:44:49 +00:00
|
|
|
rqe->b.b_iodone = complete_rqe; /* call us here when done */
|
1999-08-26 03:26:39 +00:00
|
|
|
rqg->flags &= ~XFR_PARITYOP; /* reset flags that brought us here */
|
1999-08-07 08:11:22 +00:00
|
|
|
rqe->b.b_bcount = rqe->buflen << DEV_BSHIFT; /* length to write */
|
|
|
|
rqe->b.b_bufsize = rqe->b.b_bcount; /* don't claim we have more */
|
|
|
|
rqe->b.b_resid = rqe->b.b_bcount; /* nothing transferred */
|
|
|
|
rqg->active++; /* another active request */
|
|
|
|
drive = &DRIVE[rqe->driveno]; /* drive to access */
|
1999-10-13 03:17:21 +00:00
|
|
|
|
|
|
|
/* We can't sleep here, so we just increment the counters. */
|
|
|
|
drive->active++;
|
|
|
|
if (drive->active >= drive->maxactive)
|
|
|
|
drive->maxactive = drive->active;
|
|
|
|
vinum_conf.active++;
|
|
|
|
if (vinum_conf.active >= vinum_conf.maxactive)
|
|
|
|
vinum_conf.maxactive = vinum_conf.active;
|
|
|
|
|
2001-05-23 23:24:05 +00:00
|
|
|
#ifdef VINUMDEBUG
|
1999-08-07 08:11:22 +00:00
|
|
|
if (debug & DEBUG_ADDRESSES)
|
|
|
|
log(LOG_DEBUG,
|
2002-03-15 18:49:47 +00:00
|
|
|
" %s dev %d.%d, sd %d, offset 0x%x, devoffset 0x%llx, length %ld\n",
|
2000-03-20 10:44:49 +00:00
|
|
|
rqe->b.b_iocmd == BIO_READ ? "Read" : "Write",
|
1999-08-07 08:11:22 +00:00
|
|
|
major(rqe->b.b_dev),
|
|
|
|
minor(rqe->b.b_dev),
|
|
|
|
rqe->sdno,
|
|
|
|
(u_int) (rqe->b.b_blkno - SD[rqe->sdno].driveoffset),
|
2002-11-07 21:52:51 +00:00
|
|
|
(long long)rqe->b.b_blkno,
|
1999-08-14 06:25:52 +00:00
|
|
|
rqe->b.b_bcount);
|
1999-08-07 08:11:22 +00:00
|
|
|
if (debug & DEBUG_LASTREQS)
|
2000-05-04 07:33:40 +00:00
|
|
|
logrq(loginfo_raid5_parity, (union rqinfou) rqe, ubp);
|
1999-08-07 08:11:22 +00:00
|
|
|
#endif
|
2000-03-20 11:29:10 +00:00
|
|
|
DEV_STRATEGY(&rqe->b, 0);
|
1999-08-07 08:11:22 +00:00
|
|
|
}
|
2000-05-04 07:33:40 +00:00
|
|
|
|
|
|
|
/* Local Variables: */
|
|
|
|
/* fill-column: 50 */
|
|
|
|
/* End: */
|